Файли
openidea/src/workbench/Workbench.tsx
T
l0ng-ai 2d7726cf53 feat(workbench): Edit single files without opening a project (#145)
Files can now be opened without a project. A file dropped on the Welcome screen, picked with File › Open File…, or passed on the command line or to a second instance opens in a lightweight window: editor tabs only, with no project tree, indexing, language servers, VCS or project tool windows. Syntax highlighting, find, save, undo and Local History still work. More files opened later join the same window as new tabs. Open as Project in the status bar opens the file's directory as a full project, following the open-project policy, and reopens the file there.

Backend: a light session reuses Project with an unindexed index, no LSP or VCS, and a flat watch on each opened file's directory. It is never reused as a project for the same root. Previously a file passed at launch opened its parent directory as a project.
2026-10-28 22:06:35 +08:00

66 рядки
2.4 KiB
TypeScript

/**
* 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 { useEditorRegistry } from "@/editor/api";
import { basename, useProject } from "@/platform/project";
import { useDistractionFree } from "./distractionFree";
import { EditorArea } from "./EditorArea";
import { OverlayHost } from "./OverlayHost";
import { projectColorVars } from "./projectColor";
import { StatusBar } from "./StatusBar";
import { TitleBar } from "./TitleBar";
import { useApplyTheme } from "./theme";
import { ToolWindowLayout } from "./toolwindows/ToolWindows";
import { Welcome } from "./Welcome";
import styles from "./Workbench.module.css";
/** LightEdit: editor tabs only; no tool windows, toolbar widgets or project status items. */
function LightEditFrame() {
const path = useEditorRegistry((s) => s.active?.ctx.path);
const distractionFree = useDistractionFree((s) => s.active);
return (
<>
<TitleBar lightEdit bare={distractionFree} title={path ? basename(path) : "LightEdit"} />
<main className={styles.lightEdit} data-light-edit>
<div className={styles.lightEditIsland}>
<EditorArea />
</div>
</main>
{!distractionFree && <StatusBar lightEdit />}
</>
);
}
export function Workbench() {
useApplyTheme();
const project = useProject((s) => s.project);
const lightEdit = useProject((s) => s.lightEdit);
const root = project?.root ?? null;
const distractionFree = useDistractionFree((s) => s.active);
const frame = project ? styles.framed : lightEdit ? styles.lightEditFrame : undefined;
return (
<div
className={frame ? `${styles.workbench} ${frame}` : styles.workbench}
style={project ? projectColorVars(project.name) : undefined}
>
{project ? (
<>
{/* Distraction Free Mode keeps the bar for the traffic lights and window dragging only. */}
<TitleBar bare={distractionFree} />
<ToolWindowLayout key={root} editor={<EditorArea />} />
{!distractionFree && <StatusBar />}
</>
) : lightEdit ? (
<LightEditFrame />
) : (
<Welcome />
)}
<OverlayHost />
</div>
);
}