дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Attach adds a trusted folder to the current project without reopening it or moving its root. Attachments live in the primary project's private .openidea/workspace.json, and detaching the last one restores a plain project. ProjectInfo.name stays the primary project's name; displayName supplies window titles, project tabs and Recent Projects. Attach is no longer a remembered opening policy, and File > Attach Project is available when the policy is not Ask. Attached folders must be trusted, and Restricted Mode names any attached folder that blocks trust. Explicit workspaces keep their behaviour and still cannot be created in or inside a linked project.
58 рядки
2.0 KiB
TypeScript
58 рядки
2.0 KiB
TypeScript
/**
|
||
* Window title, IDEA style: `<project> – <file>`; with Settings › Appearance ›
|
||
* "Always show full path in window header" the file's full path. A remote
|
||
* project names its host: `<project> [<user@host>] – <file>`.
|
||
*/
|
||
import { useEditorRegistry } from "@/editor/api";
|
||
import { t, useI18n } from "@/platform/i18n";
|
||
import { isTauri } from "@/platform/ipc";
|
||
import { basename, useProject } from "@/platform/project";
|
||
import { useRemote } from "@/platform/remote";
|
||
|
||
export function windowTitle(
|
||
project: string | null | undefined,
|
||
file: string | null | undefined,
|
||
fullPath = false,
|
||
host: string | null = null,
|
||
): string {
|
||
const name = file ? (fullPath ? file : basename(file)) : null;
|
||
if (!project) return name ?? t("app.title.default");
|
||
const where = host ? `${project} [${host}]` : project;
|
||
return name ? `${where} – ${name}` : where;
|
||
}
|
||
|
||
export function installWindowTitle(): () => void {
|
||
let last: string | null = null;
|
||
let setNative: ((title: string) => void) | null = null;
|
||
if (isTauri()) {
|
||
void import("@tauri-apps/api/window").then(({ getCurrentWindow }) => {
|
||
const w = getCurrentWindow();
|
||
setNative = (title) => void w.setTitle(title).catch(() => {});
|
||
if (last !== null) setNative(last);
|
||
});
|
||
}
|
||
const update = () => {
|
||
const { project, settings } = useProject.getState();
|
||
const fullPath = settings?.appearance?.fullPathInTitle === true;
|
||
const host = useRemote.getState().session?.host ?? null;
|
||
const title = windowTitle(
|
||
project?.displayName || project?.name,
|
||
useEditorRegistry.getState().active?.ctx.path,
|
||
fullPath,
|
||
host,
|
||
);
|
||
if (title === last) return;
|
||
last = title;
|
||
if (typeof document !== "undefined") document.title = title;
|
||
setNative?.(title);
|
||
};
|
||
update();
|
||
const unsubs = [
|
||
useProject.subscribe(update),
|
||
useEditorRegistry.subscribe(update),
|
||
useI18n.subscribe(update),
|
||
useRemote.subscribe(update),
|
||
];
|
||
return () => unsubs.forEach((u) => u());
|
||
}
|