Файли
openidea/src/workbench/quickSwitch.ts
T
l0ng-ai 9cc83c77b8 feat(plugins): plugin contributions in the IDE's own settings and menus; official plugins published with releases
- Themes: a plugin theme is an `appearance.theme` value
  (`plugin:<id>/<theme>`), offered by Settings › Appearance (and the
  preferred themes of Sync with OS), Quick Switch, the toolbar gear menu and
  Welcome › Customize. The project window selects it in the plugin host;
  picking a built-in theme clears it. While its plugin is off, the built-in
  theme of its kind shows and the choice is kept.
- File icon themes: chosen in Settings › Appearance › File icon theme and
  kept in `appearance.fileIconTheme`, so every window follows.
- Keymap: plugins' default shortcuts show in Settings › Keymap as the
  defaults of their actions: removable, changeable, resettable and part of
  conflict checks.
- Problems: a plugin's problems are withdrawn when it stops, fails, is
  disabled or uninstalled. Settings › Inspections lists them under Plugins by
  plugin name; stored overrides of `plugin:` producers parse correctly.
- Status bar items of plugins are named in the status bar menu and can be
  hidden.
- Languages added or removed by plugins refresh Override File Type, the
  Code Style pages and Inspections without a restart.
- Uninstalling a plugin deletes the secrets it declared.
- The Settings window follows plugin changes made elsewhere.
- The plugin system is marked Preview (Settings › Plugins, README); Harbor
  Night is versioned 0.1.0 like the other official plugins.
- Release: the official plugins are packed, signed (secret
  PLUGIN_SIGNING_KEY) and indexed into the release as
  `plugins-index.json`; released builds use it as the default marketplace.
  Without the key the step is skipped.
2026-11-04 02:41:46 +08:00

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

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* Theme / color scheme / keymap / view mode switches shared by the main
* toolbar's gear menu and View › Quick Switch Scheme… (⌃`).
*/
import { call, commands, isTauri } from "@/platform/ipc";
import { listSchemes } from "@/platform/colorScheme";
import { editorPrefs } from "@/platform/editorSettings";
import { PRESET_TITLES, useKeymap } from "@/platform/keymap";
import { useProject } from "@/platform/project";
import type { MenuItem } from "@/ui";
import { themeChoices } from "@/platform/themes";
import { currentThemeChoice, setTheme } from "./theme";
async function setGlobal(key: string, value: unknown, what: string) {
if (!isTauri()) return;
try {
useProject.setState({ settings: await call(commands.settingsSet("global", key, JSON.stringify(value))) });
} catch (e) {
console.warn(`cannot switch ${what}`, e);
}
}
export const selectKeymap = (id: string) => setGlobal("keymap", id, "keymap");
export function themeItems(themeId: string = currentThemeChoice()): MenuItem[] {
return themeChoices().map<MenuItem>((c) => ({
id: `theme.${c.id}`,
label: c.label,
// Plugin themes keep their own names.
verbatim: !!c.origin,
checked: c.id === themeId,
run: () => void setTheme(c.id),
}));
}
export function keymapItems(keymapId: string, customKeymaps: string[]): MenuItem[] {
return [...Object.keys(PRESET_TITLES), ...customKeymaps].map<MenuItem>((id) => ({
id: `keymap.${id}`,
label: PRESET_TITLES[id] ?? id,
verbatim: !PRESET_TITLES[id],
checked: id === keymapId,
run: () => void selectKeymap(id),
}));
}
export function colorSchemeItems(current: string | undefined): MenuItem[] {
const schemes = listSchemes(editorPrefs().customSchemes);
const value = current && schemes.some((s) => s.id === current) ? current : "theme-default";
return [
{
id: "scheme.theme-default",
label: "Theme default",
checked: value === "theme-default",
run: () => void setGlobal("editor.colorScheme", "theme-default", "color scheme"),
},
...schemes.map<MenuItem>((s) => ({
id: `scheme.${s.id}`,
label: s.name,
checked: s.id === value,
run: () => void setGlobal("editor.colorScheme", s.id, "color scheme"),
})),
];
}
/** The existing view modes: Distraction Free Mode and Full Screen. */
export const VIEW_MODE_ITEMS: MenuItem[] = [
{ kind: "action", action: "editor.toggleZen" },
{ kind: "action", action: "window.toggleFullScreen" },
];
/** The keymap in effect and the user's custom keymaps. */
export function keymapState(): { keymapId: string; customs: string[] } {
const settings = useProject.getState().settings;
const customs = settings?.customKeymaps;
return {
keymapId: typeof settings?.keymap === "string" ? settings.keymap : useKeymap.getState().preset,
customs: customs && typeof customs === "object" ? Object.keys(customs) : [],
};
}
/** View › Quick Switch Scheme…: IDEA's popup of the switchable schemes. */
export function quickSwitchItems(): MenuItem[] {
const { keymapId, customs } = keymapState();
return [
{
id: "qs.scheme",
label: "Editor Color Scheme",
submenu: colorSchemeItems(useProject.getState().settings?.editor?.colorScheme),
},
{ id: "qs.keymap", label: "Keymap", submenu: keymapItems(keymapId, customs) },
{ id: "qs.viewMode", label: "View Mode", submenu: VIEW_MODE_ITEMS },
{ id: "qs.theme", label: "Theme", submenu: themeItems() },
];
}