feat(plugins): link an icon theme's settings page from the plugin details (#7691)

Each File Icon Themes row in a plugin's details gets a Settings… button while that theme's settings page is registered; it opens Settings at the page through file.settings.

Part of #7688.

Co-authored-by: Bruno0416 <[email protected]>
Цей коміт міститься в:
Bruno Valladares authored and GitHub committed 2026-12-03 20:53:31 +08:00
1 джерело 1877d8c1a1
коміт 7f9a618cac
13 files changed
+84 -6

No files matched your search

+2 -1
Переглянути файл
@@ -143,7 +143,8 @@ handlers, external references, `url()` or entities.
## A settings page
`settings` describes the theme's page under **Settings › Plugins**, named after the theme's
label. A theme without `settings` has no page.
label. A theme without `settings` has no page. The plugin's details pane in **Settings › Plugins**
links to the page with a **Settings…** button next to **Apply**.
```json
{
+1 -1
Переглянути файл
@@ -120,7 +120,7 @@ path = "icons/theme.json"
## 设置页面
`settings` 描述主题在 **设置 › 插件** 下的页面,页面以主题的 label 命名。没有 `settings` 的主题没有设置页面。
`settings` 描述主题在 **设置 › 插件** 下的页面,页面以主题的 label 命名。没有 `settings` 的主题没有设置页面。插件详情窗格中,主题行的 **应用** 按钮旁会有一个 **设置…** 按钮,点击即可跳转到该页面。
```json
{
+47
Переглянути файл
@@ -15,6 +15,7 @@ import {
searchCategories,
onEndpointsChanged,
provideNotificationService,
registerSettingsPage,
searchEndpoints,
type NotificationService,
} from "@/workbench/contributions";
@@ -33,6 +34,7 @@ import {
} from "../bridge";
import { iconResolver, selectedIconTheme, useIconThemes } from "../iconThemes";
import { markerIcon, placeMarkers } from "../lineMarkerGutter";
import { IconThemesDetails } from "../corePoints";
import { SecretsDetails } from "../secrets";
import { handleRuntimeEvent, startRuntimeUi, statusMenuItems, usePluginStatusItems } from "../runtimeUi";
import { evaluateWhen, getContext } from "@/platform/context";
@@ -2142,6 +2144,51 @@ describe("icon themes", () => {
}
});
describe("details pane", () => {
const items = [iconThemeUi("acme.icons", "atom.dark"), iconThemeUi("acme.icons", "plain")];
const PAGE = "plugins.acme-icons.atom-dark";
const settingsButton = (label: string) =>
screen.queryByRole("button", { name: `Settings for icon theme ${label}` });
const renderDetails = () => render(<IconThemesDetails plugin={plugin({ id: "acme.icons" })} items={items} />);
const registerPage = (id: string) => registerSettingsPage({ id, title: id, component: () => null });
it("links a theme to its settings page once that page is registered", async () => {
renderDetails();
expect(settingsButton("ATOM.DARK")).toBeNull();
let unregister = () => {};
act(() => {
unregister = registerPage(PAGE);
});
expect(settingsButton("ATOM.DARK")).not.toBeNull();
expect(settingsButton("PLAIN")).toBeNull();
act(() => unregister());
expect(settingsButton("ATOM.DARK")).toBeNull();
});
it("opens Settings at the theme's page", async () => {
const run = vi.fn();
const offAction = registerAction({ id: "file.settings", title: "Settings…", run });
const offPage = registerPage(PAGE);
try {
renderDetails();
await userEvent.setup().click(settingsButton("ATOM.DARK")!);
expect(run).toHaveBeenCalledTimes(1);
expect(run.mock.calls[0]?.[0].arg).toBe(PAGE);
} finally {
offPage();
offAction();
}
});
it("leaves themes without a settings page as before", () => {
renderDetails();
expect(screen.queryAllByRole("button").map((b) => b.getAttribute("aria-label") ?? b.textContent)).toEqual([
"Apply icon theme ATOM.DARK",
"Apply icon theme PLAIN",
]);
});
});
it("adopts nothing for plugins without icon themes", async () => {
useIconThemes.setState({ override: undefined });
usePlugins.setState({ ui: [iconThemeUi("q", "other")] });
+25 -4
Переглянути файл
@@ -3,10 +3,15 @@
* secrets, endpoints), shared by the workbench and the Settings window without
* pulling in CodeMirror-backed plugin editors.
*/
import { registerEndpointProvider, registerSearchCategory, type EndpointEntry } from "@/workbench/contributions";
import {
registerEndpointProvider,
registerSearchCategory,
useSettingsPages,
type EndpointEntry,
} from "@/workbench/contributions";
import type { PluginInfo, ThemeDef } from "@/bindings";
import { pluginIconName } from "./pluginIcon";
import { registerAction } from "@/platform/actions";
import { executeAction, registerAction } from "@/platform/actions";
import { tx } from "@/platform/i18n";
import { addContributedTheme, pluginThemeRef } from "@/platform/themes";
import { currentThemeChoice, setTheme, useThemeOverride } from "@/workbench/theme";
@@ -122,16 +127,32 @@ interface IconThemeDecl {
icons: number;
}
function IconThemesDetails({ plugin, items }: { plugin: PluginInfo; items: UiItem<IconThemeDecl>[] }) {
const iconThemeSettingsPage = (pluginId: string, themeId: string) =>
`${pluginSettingsPageId(pluginId)}.${themeId.replace(/\./g, "-")}`;
export function IconThemesDetails({ plugin, items }: { plugin: PluginInfo; items: UiItem<IconThemeDecl>[] }) {
const selected = useSelectedIconTheme();
// Theme pages register once the theme's details load, so the link follows the registry.
const pages = useSettingsPages((s) => s.pages);
return (
<ul className={styles.items}>
{items.map(({ decl: t }) => {
const key = iconThemeKey(plugin.id, t.id);
const settingsPage = iconThemeSettingsPage(plugin.id, t.id);
return (
<li key={t.id} className={styles.item}>
<span className={styles.itemMain}>{t.label}</span>
<span className={styles.muted}>{tx`${t.icons} icons`}</span>
{pages.has(settingsPage) && (
<Button
size="small"
variant="ghost"
onClick={() => void executeAction("file.settings", settingsPage)}
aria-label={tx`Settings for icon theme ${t.label}`}
>
<T>Settings…</T>
</Button>
)}
{selected === key ? (
<Button size="small" variant="secondary" onClick={() => void selectIconTheme(null)}>
<T>Use Default Icons</T>
@@ -291,7 +312,7 @@ export function defineCoreUiPoints(): () => void {
id: decl.id,
label: decl.label,
origin: plugin.name,
settingsPage: `${pluginSettingsPageId(pluginId)}.${decl.id.replace(/\./g, "-")}`,
settingsPage: iconThemeSettingsPage(pluginId, decl.id),
}),
Details: IconThemesDetails,
}),
+1
Переглянути файл
@@ -5838,6 +5838,7 @@
"{icons} icons": "{icons} iconos",
"Use Default Icons": "Usar iconos predeterminados",
"Apply icon theme {label}": "Aplicar tema de iconos {label}",
"Settings for icon theme {label}": "Configuración del tema de iconos {label}",
"File Icon Themes": "Temas de iconos de archivo",
"File Icons": "Iconos de archivo",
"File Templates": "Plantillas de archivo",
+1
Переглянути файл
@@ -5582,6 +5582,7 @@
"{icons} icons": "{icons} icônes",
"Use Default Icons": "Utiliser les icônes par défaut",
"Apply icon theme {label}": "Appliquer le thème d'icônes {label}",
"Settings for icon theme {label}": "Paramètres du thème d'icônes {label}",
"File Icon Themes": "Thèmes d'icônes de fichiers",
"Secrets": "Secrets",
"Stored": "Enregistré",
+1
Переглянути файл
@@ -5904,6 +5904,7 @@
"{icons} icons": "아이콘 {icons}개",
"Use Default Icons": "기본 아이콘 사용",
"Apply icon theme {label}": "아이콘 테마 {label} 적용",
"Settings for icon theme {label}": "아이콘 테마 {label} 설정",
"File Icon Themes": "파일 아이콘 테마",
"File Icons": "파일 아이콘",
"File Templates": "파일 템플릿",
+1
Переглянути файл
@@ -5748,6 +5748,7 @@
"{icons} icons": "Ikony: {icons}",
"Use Default Icons": "Użyj ikon domyślnych",
"Apply icon theme {label}": "Zastosuj motyw ikon {label}",
"Settings for icon theme {label}": "Ustawienia motywu ikon {label}",
"File Icon Themes": "Motywy ikon plików",
"File Icons": "Ikony plików",
"File Templates": "Szablony plików",
+1
Переглянути файл
@@ -5763,6 +5763,7 @@
"{icons} icons": "{icons} ícones",
"Use Default Icons": "Usar ícones padrão",
"Apply icon theme {label}": "Aplicar tema de ícones {label}",
"Settings for icon theme {label}": "Configurações do tema de ícones {label}",
"File Icon Themes": "Temas de ícones de arquivo",
"File Icons": "Ícones de arquivo",
"File Templates": "Modelos de arquivo",
+1
Переглянути файл
@@ -7417,6 +7417,7 @@
"{icons} icons": "Значков: {icons}",
"Use Default Icons": "Использовать значки по умолчанию",
"Apply icon theme {label}": "Применить тему значков {label}",
"Settings for icon theme {label}": "Настройки темы значков {label}",
"File Icon Themes": "Темы значков файлов",
"File Icons": "Значки файлов",
"File Templates": "Шаблоны файлов",
+1
Переглянути файл
@@ -8481,6 +8481,7 @@
"{icons} icons": "{icons} simge",
"Use Default Icons": "Varsayılan Simgeleri Kullan",
"Apply icon theme {label}": "{label} simge temasını uygula",
"Settings for icon theme {label}": "{label} simge temasının ayarları",
"File Icon Themes": "Dosya Simge Temaları",
"File Icons": "Dosya Simgeleri",
"File Templates": "Dosya Şablonları",
+1
Переглянути файл
@@ -7025,6 +7025,7 @@
"{icons} icons": "{icons} 個圖示",
"Use Default Icons": "使用預設圖示",
"Apply icon theme {label}": "應用圖示主題 {label}",
"Settings for icon theme {label}": "圖示主題 {label} 的設定",
"File Icon Themes": "檔案圖示主題",
"File Icons": "檔案圖示",
"File Templates": "檔案範本",
+1
Переглянути файл
@@ -7966,6 +7966,7 @@
"{icons} icons": "{icons} 个图标",
"Use Default Icons": "使用默认图标",
"Apply icon theme {label}": "应用图标主题 {label}",
"Settings for icon theme {label}": "图标主题 {label} 的设置",
"File Icon Themes": "文件图标主题",
"File Icons": "文件图标",
"File Templates": "文件模板",