дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 03:05:40 +02:00
Following the active editor already worked, but the option kept IDEA's pre-2023 name and sat second under Behavior, so people didn't find it (#1666). It is now Always Select Opened File, listed first, and the header's Select Opened File button hides while it's on. Find Action still matches the old name; the setting key is unchanged. Closes #1666 Co-authored-by: jaw52 <[email protected]>
95 рядки
3.5 KiB
TypeScript
95 рядки
3.5 KiB
TypeScript
import { shortcutLabel } from "@/platform/keymap";
|
||
import { IconButton, type MenuItem } from "@/ui";
|
||
import { VIEW_MODES, setViewMode, setViewOption, useProjectTree, type ViewOptions } from "./store";
|
||
import type { SortKey } from "./model";
|
||
|
||
/** The title's "Project ▾" pane switcher (IDEA: Project / Project Files / Open Files / …). */
|
||
export function useProjectTitleMenu(): { label: string; items: MenuItem[] } {
|
||
const mode = useProjectTree((s) => s.mode);
|
||
const unity = useProjectTree((s) => s.unity);
|
||
return {
|
||
label: VIEW_MODES.find(([id]) => id === mode)?.[1] ?? "Project",
|
||
items: VIEW_MODES.filter(([id]) => id !== "unity" || unity).map(([id, label]) => ({
|
||
id,
|
||
label,
|
||
checked: id === mode,
|
||
run: () => setViewMode(id),
|
||
})),
|
||
};
|
||
}
|
||
|
||
/** The on / off view options. */
|
||
export type ToggleOption = {
|
||
[K in keyof ViewOptions]-?: ViewOptions[K] extends boolean ? K : never;
|
||
}[keyof ViewOptions];
|
||
|
||
export const OPTION_LABELS: Array<[ToggleOption, string]> = [
|
||
["showHidden", "Show Hidden Files"],
|
||
["showExcluded", "Show Excluded Files"],
|
||
["showMembers", "Show Members"],
|
||
["compact", "Compact Middle Packages"],
|
||
["foldersFirst", "Sort Folders First"],
|
||
["autoscrollFromSource", "Always Select Opened File"],
|
||
["autoscrollToSource", "Autoscroll to Source"],
|
||
["singleClickOpen", "Open Files with Single Click"],
|
||
["singleClickExpand", "Expand Directories with Single Click"],
|
||
["previewTab", "Enable Preview Tab"],
|
||
];
|
||
|
||
/** Header controls of the Project tool window (IDEA: Locate, Expand/Collapse All). */
|
||
export function ProjectHeaderActions() {
|
||
// IDEA hides Select Opened File while Always Select Opened File keeps the tree in sync.
|
||
const alwaysSelect = useProjectTree((s) => s.options.autoscrollFromSource);
|
||
return (
|
||
<>
|
||
{!alwaysSelect && (
|
||
<IconButton
|
||
icon="locate"
|
||
action="navigate.selectInProjectView"
|
||
title="Select Opened File"
|
||
shortcut={shortcutLabel("navigate.selectInProjectView")}
|
||
size="small"
|
||
/>
|
||
)}
|
||
<IconButton icon="expand-all" action="project.expandAll" title="Expand All" size="small" />
|
||
<IconButton icon="collapse-all" action="project.collapseAll" title="Collapse All" size="small" />
|
||
</>
|
||
);
|
||
}
|
||
|
||
export const SORT_LABELS: Array<[SortKey, string]> = [
|
||
["name", "Sort by Name"],
|
||
["type", "Sort by Type"],
|
||
["modified", "Sort by Modification Time"],
|
||
];
|
||
|
||
/** View options in the header's "⋮" menu (IDEA: Project › Options › Appearance / Behavior). */
|
||
export function useProjectHeaderMenu(): MenuItem[] {
|
||
const options = useProjectTree((s) => s.options);
|
||
const unity = useProjectTree((s) => s.mode === "unity");
|
||
return [
|
||
{ kind: "header", label: "Appearance" },
|
||
...(unity
|
||
? [
|
||
option("showUnityMeta", "Show Meta Files", options),
|
||
option("showUnityGenerated", "Show Generated Files", options),
|
||
]
|
||
: []),
|
||
...OPTION_LABELS.slice(0, 5).map(([key, label]) => option(key, label, options)),
|
||
{ kind: "separator" },
|
||
...SORT_LABELS.map(([sortBy, label]): MenuItem => ({
|
||
id: `sort.${sortBy}`,
|
||
label,
|
||
checked: options.sortBy === sortBy,
|
||
run: () => setViewOption("sortBy", sortBy),
|
||
})),
|
||
{ kind: "separator" },
|
||
{ kind: "header", label: "Behavior" },
|
||
...OPTION_LABELS.slice(5).map(([key, label]) => option(key, label, options)),
|
||
];
|
||
}
|
||
|
||
function option(key: ToggleOption, label: string, options: ViewOptions): MenuItem {
|
||
return { id: key, label, checked: options[key], run: () => setViewOption(key, !options[key]) };
|
||
}
|