Файли
openidea/src/workbench/Workbench.tsx
T
l0ng-ai 197c7d6141 fix(workbench): centre the project colour gradient on the Project widget (#5975)
The frame's project colour gradient was pinned to the top-left corner, so it stayed there when the Project widget was moved to the Center or Right toolbar group. The title bar now measures the widget's icon whenever the bar or its entries change size and writes its centre to the frame as --project-gradient-x. Without the widget the gradient keeps the corner.
2026-11-26 05:08:33 +08:00

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

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* The IDEA-style shell (Islands): title bar, tool window stripes and island
* panels around the editor area on the frame background, status bar, and the
* overlay layer. Without an open project the welcome view replaces the frame,
* or, editing loose files (LightEdit), a frame with the editor only.
*/
import { useSyncExternalStore } from "react";
import { useEditorRegistry } from "@/editor/api";
import { Breadcrumbs } from "@/editor/core";
import { basename, useProject } from "@/platform/project";
import { isUntitledUri, untitledTitle } from "@/platform/virtualDocs";
import { useT } from "@/platform/i18n";
import { ProgressBar } from "@/ui";
import projectMark from "../../src-tauri/icons/source/openidea-mark.svg";
import { useDistractionFree } from "./distractionFree";
import { EditorArea } from "./EditorArea";
import { OverlayHost } from "./OverlayHost";
import { subscribeTabColors, tabColorOverride, tabColorVars, tabColorsVersion } from "./tabColors";
import { StatusBar } from "./StatusBar";
import { TitleBar } from "./TitleBar";
import { WindowGroupTabs } from "./WindowGroupTabs";
import { useApplyTheme } from "./theme";
import { ToolWindowLayout } from "./toolwindows/ToolWindows";
import { Welcome } from "./Welcome";
import { WindowResizeHandles } from "./WindowResizeHandles";
import { useContributions, useStandaloneEditor } from "./contributions";
import styles from "./Workbench.module.css";
/** View › Appearance switches (`appearance.showMainToolbar`, `appearance.showStatusBar`), shown by default. */
function useAppearanceFlag(key: "showMainToolbar" | "showStatusBar"): boolean {
return useProject((s) => s.settings?.appearance?.[key] !== false);
}
/** Where View › Appearance › Navigation Bar puts the file path breadcrumbs. */
type NavigationBarPosition = "top" | "statusBar" | "hidden";
function useNavigationBarPosition(): NavigationBarPosition {
const position = useProject((s) => s.settings?.appearance?.navigationBar);
// Nothing loaded yet, or a malformed value: match the backend default (`statusBar`).
return position === "top" || position === "statusBar" || position === "hidden" ? position : "statusBar";
}
/** LightEdit: editor tabs only; no tool windows, toolbar widgets or project status items. */
function LightEditFrame({ title }: { title?: string }) {
const path = useEditorRegistry((s) => s.active?.ctx.path);
const distractionFree = useDistractionFree((s) => s.active);
const statusBar = useAppearanceFlag("showStatusBar");
const name = path ? (isUntitledUri(path) ? untitledTitle(path) : basename(path)) : "LightEdit";
return (
<>
<TitleBar lightEdit compact={distractionFree} title={title ?? name} />
<main className={styles.lightEdit} data-light-edit>
<div className={styles.lightEditIsland}>
<EditorArea />
</div>
</main>
{!distractionFree && statusBar && <StatusBar lightEdit />}
</>
);
}
function ProjectOpening({ path }: { path: string }) {
const t = useT();
const label = t("app.project.opening", { name: basename(path) || path });
return (
<div className={styles.opening} data-project-opening>
<TitleBar />
<WindowGroupTabs />
<div className={styles.openingBody} role="status" aria-label={label}>
<div className={styles.openingBrand} aria-hidden="true">
<img className={styles.openingLogo} src={projectMark} alt="" draggable={false} />
<span>OpenIDEA</span>
</div>
<ProgressBar className={styles.openingProgress} aria-label={label} />
<div className={styles.openingTitle}>{label}</div>
<div className={styles.openingPath} title={path}>
{path}
</div>
</div>
</div>
);
}
export function Workbench() {
useApplyTheme();
useSyncExternalStore(subscribeTabColors, tabColorsVersion);
const banners = useContributions((s) => s.workbenchBanners);
const project = useProject((s) => s.project);
const lightEdit = useProject((s) => s.lightEdit);
const standaloneTitle = useStandaloneEditor((s) => s.title);
const openingPath = useProject((s) => s.openingPath);
const root = project?.root ?? null;
const distractionFree = useDistractionFree((s) => s.active);
const mainToolbar = useAppearanceFlag("showMainToolbar");
const statusBar = useAppearanceFlag("showStatusBar");
const navBarPosition = useNavigationBarPosition();
const frame = project ? styles.framed : lightEdit || standaloneTitle ? styles.lightEditFrame : undefined;
const tintName = openingPath ? basename(openingPath) || openingPath : project?.name;
const tintRoot = openingPath ?? root;
return (
<div
className={frame ? `${styles.workbench} ${frame}` : styles.workbench}
data-project-frame=""
style={tintName ? tabColorVars(tintName, tintRoot ? tabColorOverride(tintRoot) : null) : undefined}
>
<div className={styles.content} inert={openingPath !== null} aria-hidden={openingPath ? true : undefined}>
{project ? (
<>
<TitleBar compact={distractionFree || !mainToolbar} />
{!distractionFree && navBarPosition === "top" && <Breadcrumbs className={styles.navigationBar} />}
{!distractionFree && <WindowGroupTabs />}
{[...banners.values()].map(({ id, component: Banner }) => (
<Banner key={id} />
))}
<ToolWindowLayout key={root} editor={<EditorArea />} />
{!distractionFree && statusBar && <StatusBar />}
</>
) : lightEdit || standaloneTitle ? (
<LightEditFrame title={standaloneTitle ?? undefined} />
) : (
<Welcome />
)}
</div>
{openingPath && <ProjectOpening path={openingPath} />}
<OverlayHost />
<WindowResizeHandles />
</div>
);
}