Файли
openidea/src/workbench/activate.ts
T
Mansur Akhmadiтаmansur-akhmadi 92b5b5306f feat(workbench): Enter / Exit Zen Mode (#6039)
View › Appearance › Enter Zen Mode turns on Distraction Free Mode and full screen with one action. Zen Mode is on while both are on; the action sets both to the opposite, touching only the one that differs, and a second run while one is in progress joins it. Full screen is tracked from the window's events (macOS) or resizes (Windows, Linux), and the title flips between Enter and Exit Zen Mode. The item is in the native View › Appearance menu after Enter Distraction Free Mode and in Quick Switch Scheme › View Mode.

Co-authored-by: mansur-akhmadi <[email protected]>
2026-11-27 01:49:04 +08:00

109 рядки
4.7 KiB
TypeScript

/**
* Shell services and built-in contributions. Call before `activateFeatures()`
* so features can rely on the tool window and notification services.
*/
import { openPolicy } from "./projectWindow";
import { setContext } from "@/platform/context";
import { isRemoteWindow, projectLocation, useRemote } from "@/platform/remote";
import { useProject } from "@/platform/project";
import {
provideNotificationService,
provideToolWindowService,
registerOverlay,
registerStatusItem,
registerToolWindow,
registerWorkbenchBanner,
} from "./contributions";
import { installBrowserGuards } from "./browserGuards";
import { installDistractionFree } from "./distractionFree";
import { installZenMode } from "./zenMode";
import { installNarrowWindow } from "./narrowWindow";
import { installFileDrop } from "./fileDrop";
import { installFocusTracking } from "./focus";
import { installFocusScopeTracking } from "@/ui/focusScope";
import { clearProjectNotifications, installNotifyEvents, notificationServiceImpl } from "./notificationStore";
import { NOTIFICATIONS_TOOL_WINDOW, NotificationsToolWindow, useUnreadNotifications } from "./Notifications";
import { loadPlatformInfo } from "@/platform/platformInfo";
import { registerShellActions } from "./shellActions";
import { MainToolbarDialogHost } from "./MainToolbarDialog";
import { BackgroundTasksHost, StatusInfo, TaskStatus } from "./StatusBar";
import { installTaskEvents } from "./tasks";
import { installToolWindowActions } from "./toolwindows/actions";
import {
installToolWindowLayoutSync,
loadToolWindowLayout,
setFocusedToolWindow,
toolWindowServiceImpl,
} from "./toolwindows/store";
import { TabColorPicker } from "./TabColorPicker";
import { WebConnectionBanner } from "./WebConnectionBanner";
import { installWebSessionGuard } from "./webSessionGuard";
export function activateWorkbench(): () => void {
provideToolWindowService(toolWindowServiceImpl);
provideNotificationService(notificationServiceImpl);
void loadPlatformInfo();
const syncProjectContext = () => {
const project = useProject.getState().project;
setContext("projectLocal", !!project && !isRemoteWindow() && !useProject.getState().lightEdit);
setContext("projectRemote", !!project && isRemoteWindow());
setContext("workspaceOpen", !!project?.workspace);
setContext("projectAttached", !!project?.workspace && project.workspace.projects[0] === project.root);
setContext("workspaceContainer", !!project?.workspace && project.workspace.projects[0] !== project.root);
setContext("projectOpenAsk", openPolicy() === "ask");
};
// Synchronous so the frame's first render after opening already has the project's layout.
let prevLocation = projectLocation(useProject.getState().project?.root);
const onProject = (scope: string | null) => {
setContext("projectOpen", scope !== null);
syncProjectContext();
setContext("lightEdit", useProject.getState().lightEdit);
if (scope !== null) loadToolWindowLayout(scope);
};
onProject(prevLocation);
const unsubProject = useProject.subscribe((s, prev) => {
syncProjectContext();
const nextLocation = projectLocation(s.project?.root);
if (nextLocation === prevLocation && s.lightEdit === prev.lightEdit) return;
prevLocation = nextLocation;
// The previous project's notifications (and their actions) no longer apply.
if (prev.project) clearProjectNotifications();
onProject(nextLocation);
});
const disposers = [
unsubProject,
useRemote.subscribe(syncProjectContext),
registerShellActions(),
installToolWindowActions(),
installToolWindowLayoutSync(),
installDistractionFree(),
installZenMode(),
installNarrowWindow(),
installFocusTracking(setFocusedToolWindow),
installFocusScopeTracking(),
installTaskEvents(),
installNotifyEvents(),
installBrowserGuards(),
installWebSessionGuard(),
installFileDrop(),
registerWorkbenchBanner({ id: "workbench.webConnection", component: WebConnectionBanner }),
registerOverlay({ id: "workbench.customizeToolbar", component: MainToolbarDialogHost }),
registerOverlay({ id: "workbench.backgroundTasks", component: BackgroundTasksHost }),
registerOverlay({ id: "workbench.projectColor", component: TabColorPicker }),
registerStatusItem({ id: "workbench.tasks", align: "right", priority: 0, component: TaskStatus, lightEdit: true }),
registerStatusItem({ id: "workbench.info", align: "left", priority: 5, component: StatusInfo, lightEdit: true }),
registerToolWindow({
id: NOTIFICATIONS_TOOL_WINDOW,
title: "Notifications",
icon: "bell",
anchor: "right",
order: 0,
component: NotificationsToolWindow,
useBadge: useUnreadNotifications,
}),
];
return () => disposers.reverse().forEach((d) => d());
}