Файли
openidea/src/features/project-tree/HeaderActions.tsx
T
arookieofcтаa-rookie-of-C-language 95e79116d1 feat(project-tree): show a file's members below it (#624)
Finding a declaration in a file meant opening the Structure view. A new Project view option, Show Members, lets files expand into their declarations, including nested ones, and clicking or activating a member opens the file at that symbol. It is off by default.

Outlines load when a file expands, including expansion restored on reopening a project or by turning the option on later. They refresh on save and on changes on disk, with stale in-flight results discarded. Files with no outline lose their chevron. File operations, drag and the context menu skip member rows. Also removes a duplicate Sort Folders First menu entry.

Co-authored-by: a-rookie-of-C-language <[email protected]>
2026-11-01 07:31:26 +08:00

76 рядки
2.9 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
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);
return {
label: VIEW_MODES.find(([id]) => id === mode)?.[1] ?? "Project",
items: VIEW_MODES.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"],
["autoscrollToSource", "Autoscroll to Source"],
["autoscrollFromSource", "Autoscroll from 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() {
return (
<>
<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);
return [
{ kind: "header", label: "Appearance" },
...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]) };
}