diff --git a/docs/en/plugins/guides/icon-themes.mdx b/docs/en/plugins/guides/icon-themes.mdx index ca316d90ed..1250a849f3 100644 --- a/docs/en/plugins/guides/icon-themes.mdx +++ b/docs/en/plugins/guides/icon-themes.mdx @@ -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 { diff --git a/docs/zh/plugins/guides/icon-themes.mdx b/docs/zh/plugins/guides/icon-themes.mdx index 19d2e3cf4d..160ac6b23b 100644 --- a/docs/zh/plugins/guides/icon-themes.mdx +++ b/docs/zh/plugins/guides/icon-themes.mdx @@ -120,7 +120,7 @@ path = "icons/theme.json" ## 设置页面 -`settings` 描述主题在 **设置 › 插件** 下的页面,页面以主题的 label 命名。没有 `settings` 的主题没有设置页面。 +`settings` 描述主题在 **设置 › 插件** 下的页面,页面以主题的 label 命名。没有 `settings` 的主题没有设置页面。插件详情窗格中,主题行的 **应用** 按钮旁会有一个 **设置…** 按钮,点击即可跳转到该页面。 ```json { diff --git a/src/features/plugins/__tests__/plugins.test.tsx b/src/features/plugins/__tests__/plugins.test.tsx index 41b0b5352e..d983e68409 100644 --- a/src/features/plugins/__tests__/plugins.test.tsx +++ b/src/features/plugins/__tests__/plugins.test.tsx @@ -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(); + 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")] }); diff --git a/src/features/plugins/corePoints.tsx b/src/features/plugins/corePoints.tsx index c8e7404466..e1d9cfceaf 100644 --- a/src/features/plugins/corePoints.tsx +++ b/src/features/plugins/corePoints.tsx @@ -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[] }) { +const iconThemeSettingsPage = (pluginId: string, themeId: string) => + `${pluginSettingsPageId(pluginId)}.${themeId.replace(/\./g, "-")}`; + +export function IconThemesDetails({ plugin, items }: { plugin: PluginInfo; items: UiItem[] }) { 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 (
    {items.map(({ decl: t }) => { const key = iconThemeKey(plugin.id, t.id); + const settingsPage = iconThemeSettingsPage(plugin.id, t.id); return (
  • {t.label} {tx`${t.icons} icons`} + {pages.has(settingsPage) && ( + + )} {selected === key ? (