Compare commits

...
Author SHA1 Message Date
l0ng-ai f92efa83cd feat(workbench): keep rarely used tool windows off the stripe by default
Bookmarks and TODO are listed under the stripe's "…" until first opened. The Database
window is on the stripe by default only while the project has data sources. Of the
Flutter DevTools windows only Flutter Inspector has a stripe button; Deep Links,
DevTools and DevTools Extensions wait under "…". A user's own stripe choice still wins.
2026-11-24 11:28:46 +08:00
7 changed files with 117 additions and 8 deletions

No files matched your search

+3 -1
View File
@@ -5,8 +5,10 @@ test("keeps the file count visible beside a long directory in the TODO pane", as
await page.evaluate(async () => {
const projectModule = "/src/platform/project.ts";
const todoModule = "/src/features/todo/store.ts";
const layoutModule = "/src/workbench/toolwindows/store.ts";
const { useProject } = await import(/* @vite-ignore */ projectModule);
const { useTodos } = await import(/* @vite-ignore */ todoModule);
const { showToolWindow } = await import(/* @vite-ignore */ layoutModule);
const directory = "src/features/checkout/shared/services/with-a-long-directory-name/for-order-processing";
const path = `${useProject.getState().project.root}/${directory}/orders.ts`;
useTodos.setState({
@@ -14,9 +16,9 @@ test("keeps the file count visible beside a long directory in the TODO pane", as
error: null,
scanned: new Map([[path, [{ path, line: 8, col: 3, keyword: "TODO", text: "TODO: validate orders" }]]]),
});
showToolWindow("todo", true);
});
await page.getByRole("button", { name: "TODO" }).click();
const pane = page.locator('[data-toolwindow="todo"]');
const toolbar = pane.getByRole("toolbar", { name: "TODO actions" });
await expect(toolbar).toHaveAttribute("aria-orientation", "vertical");
+44 -7
View File
@@ -7,7 +7,7 @@
import { lazyComponent, lazyWhen, type MenuItem } from "@/ui";
import { activeEditor, lazyEditorExtension, registerEditorContribution } from "@/editor/api";
import { tx } from "@/platform/i18n";
import { onIdeEvent } from "@/platform/ipc";
import { call, commands, onIdeEvent } from "@/platform/ipc";
import { registerActions, type ActionContext } from "@/platform/actions";
import { activeCellGrid } from "./cellActions";
import {
@@ -81,21 +81,58 @@ function tableTarget(arg: unknown): TableCommandTarget {
return { rows: activeCellGrid()?.selectedRows() ?? [], editor: null };
}
export function activate(): () => void {
const disposers = [
onIdeEvent("dbSourcesChanged", () => {
void loadSources();
}),
registerToolWindow({
/** The Database window, on the stripe by default only while the project has data sources. */
function registerDatabaseWindow(): () => void {
let withSources: boolean | null = null;
let dispose = () => {};
const sync = (next: boolean) => {
if (next === withSources) return;
withSources = next;
// Registering the same id again replaces the contribution in place.
dispose = registerToolWindow({
id: DB_TOOL_WINDOW,
title: "Database",
icon: "toolwindow-database",
anchor: "right",
order: 20,
...(next ? {} : { stripe: "onUse" as const }),
component: lazyComponent(() => import("./DatabaseView").then((m) => m.DatabaseView)),
headerMenu: useDatabaseHeaderMenu,
headerActions: lazyComponent(() => import("./DatabaseView").then((m) => m.DatabaseHeaderActions)),
});
};
// Until the window loads the sources, a quiet probe decides; a failed one leaves it under "…".
let probe = 0;
const check = () => {
const seq = ++probe;
sync(false);
if (!useProject.getState().project) return;
call(commands.dbSources()).then(
(sources) => seq === probe && !useDatabase.getState().loaded && sync(sources.length > 0),
() => {},
);
};
check();
const offSources = useDatabase.subscribe((s) => {
if (s.loaded) sync(s.sources.length > 0);
});
const offProject = useProject.subscribe((s, prev) => {
if (s.project?.root !== prev.project?.root) check();
});
return () => {
probe++;
offSources();
offProject();
dispose();
};
}
export function activate(): () => void {
const disposers = [
onIdeEvent("dbSourcesChanged", () => {
void loadSources();
}),
registerDatabaseWindow(),
registerServiceView({
id: RESULTS_VIEW,
title: "Database",
+56
View File
@@ -0,0 +1,56 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { waitFor } from "@testing-library/react";
import { useContributions } from "@/workbench/contributions";
import { useProject } from "@/platform/project";
import type { DataSource } from "@/platform/ipc";
const mocks = vi.hoisted(() => ({ sources: vi.fn(async (): Promise<unknown> => []) }));
vi.mock("@/platform/ipc", async (original) => {
const actual = await original<typeof import("@/platform/ipc")>();
return {
...actual,
commands: { ...actual.commands, dbSources: () => "dbSources" },
call: (request: unknown) => (request === "dbSources" ? mocks.sources() : Promise.reject(new Error("unmocked"))),
};
});
import { activate } from "./index";
import { DB_TOOL_WINDOW, useDatabase } from "./store";
const stripe = () => useContributions.getState().toolWindows.get(DB_TOOL_WINDOW)?.stripe;
describe("Database tool window", () => {
let dispose = () => {};
afterEach(() => {
dispose();
dispose = () => {};
useProject.setState({ project: null });
useDatabase.setState({ sources: [], loaded: false });
});
it("is on the stripe by default only while there are data sources", () => {
dispose = activate();
expect(stripe()).toBe("onUse");
useDatabase.setState({ sources: [{ id: "pg" } as DataSource], loaded: true });
expect(stripe()).toBeUndefined();
useDatabase.setState({ sources: [] });
expect(stripe()).toBe("onUse");
dispose();
dispose = () => {};
expect(useContributions.getState().toolWindows.has(DB_TOOL_WINDOW)).toBe(false);
});
it("asks for the sources quietly when a project opens, before the window loads them", async () => {
dispose = activate();
mocks.sources.mockResolvedValueOnce([{ id: "pg" }]);
useProject.setState({ project: { root: "/app" } as never });
await waitFor(() => expect(stripe()).toBeUndefined());
mocks.sources.mockRejectedValueOnce(new Error("no backend"));
useProject.setState({ project: { root: "/other" } as never });
await waitFor(() => expect(mocks.sources).toHaveBeenCalledTimes(2));
expect(stripe()).toBe("onUse");
expect(useDatabase.getState().loaded).toBe(false);
});
});
@@ -76,6 +76,16 @@ describe("Flutter DevTools windows", () => {
const dispose = registerDevToolsWindows();
await waitFor(() => expect(ids()).toEqual(expect.arrayContaining(DEVTOOLS_WINDOWS.map((w) => w.id))));
expect(getContext().flutterDevTools).toBe(true);
// One stripe button: the others wait under "…" until first opened.
const stripes = Object.fromEntries(
DEVTOOLS_WINDOWS.map((w) => [w.id, useContributions.getState().toolWindows.get(w.id)?.stripe]),
);
expect(stripes).toEqual({
"flutter-deep-links": "onUse",
"flutter-devtools": "onUse",
"flutter-devtools-extensions": "onUse",
"flutter-inspector": undefined,
});
useProject.setState({ project: { root: "/tool" } as never });
await waitFor(() => expect(ids()).not.toContain("flutter-inspector"));
@@ -114,6 +114,8 @@ export function registerDevToolsWindows(): () => void {
icon: w.icon,
anchor: "right",
order: 40 + i,
// Only the Inspector is on the stripe until the others are first opened.
...(w.id === "flutter-inspector" ? {} : { stripe: "onUse" as const }),
component: view("FlutterDevToolsView"),
headerActions: view("FlutterDevToolsRefresh"),
...(w.app === "each" ? { headerContent: view("FlutterDevToolsTabs") } : {}),
+1
View File
@@ -218,6 +218,7 @@ export function activate(): void | (() => void) {
anchor: "left",
secondary: true,
order: 30,
stripe: "onUse",
component: lazyComponent(() => import("./bookmarks/BookmarksView").then((m) => m.BookmarksView)),
headerActions: lazyComponent(() => import("./bookmarks/BookmarksView").then((m) => m.BookmarksActions)),
useBadge: () => null,
+1
View File
@@ -21,6 +21,7 @@ export function activate(): () => void {
icon: hasIcon("toolwindow-todo") ? "toolwindow-todo" : "list",
anchor: "bottom",
order: 40,
stripe: "onUse",
component: TodoView,
headerContent: TodoTabs,
headerMenu: useTodoHeaderMenu,