Compare commits

...
Author SHA1 Message Date
l0ng-ai da65920f2d feat(workbench): let users move the More Tool Windows button 2026-11-22 22:19:15 +08:00
6 changed files with 157 additions and 64 deletions

No files matched your search

+3
View File
@@ -625,6 +625,9 @@
"Folded unchanged fragments › Wave": "Folded unchanged fragments › Wave",
"Error stripe mark": "Error stripe mark",
"Dock Pinned": "Dock Pinned",
"Move More Tool Windows Button": "Move More Tool Windows Button",
"Move to Right": "Move to Right",
"Move to Left": "Move to Left",
"Dock Unpinned": "Dock Unpinned",
"Undock": "Undock",
"The program ended by itself, so no garbage collection ran before the profile was written: objects that were already unreachable may show as live.": "The program ended by itself, so no garbage collection ran before the profile was written: objects that were already unreachable may show as live.",
+1
View File
@@ -2276,6 +2276,7 @@
"More Actions": "更多操作",
"More Run/Debug": "更多运行/调试",
"More Tool Windows": "更多工具窗口",
"Move More Tool Windows Button": "移动“更多工具窗口”按钮",
"Most recently opened tab": "最近打开的标签页",
"Mouse Control": "鼠标控制",
"Mouse reporting": "鼠标报告",
+51 -1
View File
@@ -1,8 +1,9 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { act, fireEvent, render, screen } from "@testing-library/react";
import { act, fireEvent, render, screen, within } from "@testing-library/react";
import { emitLocalIdeEvent } from "@/platform/ipc";
import { setLocale } from "@/platform/i18n";
import { useProject } from "@/platform/project";
import { ContextMenuHost, hideContextMenu } from "@/ui/Menu";
import { registerStatusItem, registerToolWindow, type StatusItemContribution } from "./contributions";
import { orderStatusItems, StatusBar, TaskStatus } from "./StatusBar";
import { orderTitleItems } from "./TitleBar";
@@ -18,6 +19,7 @@ import {
} from "./notificationStore";
import { installTaskEvents, useTasks } from "./tasks";
import { ToolWindowLayout, ToolWindowStripe } from "./toolwindows/ToolWindows";
import { installToolWindowActions } from "./toolwindows/actions";
import {
isToolWindowVisible,
loadToolWindowLayout,
@@ -277,6 +279,54 @@ describe("notifications", () => {
});
describe("tool window stripe", () => {
it("moves More Tool Windows to an empty right stripe and back", () => {
const disposeActions = installToolWindowActions();
const disposeWindow = registerToolWindow({
id: "hidden-tool",
title: "Hidden Tool",
icon: "folder",
anchor: "left",
stripe: "onUse",
requiresProject: false,
component: () => null,
});
loadToolWindowLayout("/stripe-more");
const { unmount } = render(
<>
<ToolWindowLayout editor={null} />
<ContextMenuHost />
</>,
);
const button = () => screen.getByRole("button", { name: "More Tool Windows" });
const move = (label: string) => {
fireEvent.contextMenu(button());
fireEvent.click(screen.getByRole("menuitem", { name: label }));
};
try {
expect(button().closest("[data-stripe-side]")).toHaveAttribute("data-stripe-side", "left");
expect(screen.queryByRole("toolbar", { name: "Right tool windows" })).not.toBeInTheDocument();
move("Move to Right");
expect(button().closest("[data-stripe-side]")).toHaveAttribute("data-stripe-side", "right");
expect(screen.queryByRole("toolbar", { name: "Tool windows" })).not.toBeInTheDocument();
fireEvent.click(button());
const menu = screen.getByRole("menu", { name: "Tool windows" });
fireEvent.click(within(menu).getByRole("menuitem", { name: "Hidden Tool" }));
expect(isToolWindowVisible("hidden-tool")).toBe(true);
expect(screen.getByRole("button", { name: "Hidden Tool" }).closest("[data-stripe-side]")).toHaveAttribute(
"data-stripe-side",
"left",
);
move("Move to Left");
expect(button().closest("[data-stripe-side]")).toHaveAttribute("data-stripe-side", "left");
expect(screen.queryByRole("toolbar", { name: "Right tool windows" })).not.toBeInTheDocument();
} finally {
unmount();
hideContextMenu();
disposeWindow();
disposeActions();
}
});
it("renders left + bottom windows on the left stripe and toggles on click", () => {
const C = () => null;
const disposers = [
+34 -63
View File
@@ -61,6 +61,7 @@ import {
type ToolWindowViewMode,
} from "./store";
import { contentTabRegistry } from "./content";
import { resetStripeNames, setStripe, STRIPE_MAX, STRIPE_MIN, useStripes, type StripeSide } from "./stripes";
import { toolWindowTitle } from "./title";
import styles from "./ToolWindows.module.css";
import { tx, useI18n } from "@/platform/i18n";
@@ -188,53 +189,6 @@ async function setShowToolWindowNames(on: boolean) {
useProject.setState({ settings });
}
/** Stripe button widths with names; icons only follow `--stripe-icon-button` (smaller in compact mode). */
const STRIPE_MIN = 44;
const STRIPE_DEFAULT = 56;
const STRIPE_MAX = 96;
const STRIPE_KEY = "openidea.stripes.v1";
type StripeSide = "left" | "right";
/** Per stripe: button width with names, and names shown or hidden by a drag (unset: the setting decides). */
interface StripeSize {
width: number;
names?: boolean;
}
function readStripes(): Record<StripeSide, StripeSize> {
const out: Record<StripeSide, StripeSize> = { left: { width: STRIPE_DEFAULT }, right: { width: STRIPE_DEFAULT } };
try {
const raw = JSON.parse(localStorage.getItem(STRIPE_KEY) ?? "null");
for (const side of ["left", "right"] as const) {
const v = raw?.[side];
if (typeof v?.width === "number") out[side].width = Math.min(STRIPE_MAX, Math.max(STRIPE_MIN, v.width));
if (typeof v?.names === "boolean") out[side].names = v.names;
}
} catch {
/* storage unavailable */
}
return out;
}
const useStripes = create<Record<StripeSide, StripeSize>>(readStripes);
function setStripe(side: StripeSide, size: StripeSize) {
useStripes.setState({ [side]: size });
try {
localStorage.setItem(STRIPE_KEY, JSON.stringify(useStripes.getState()));
} catch {
/* storage unavailable */
}
}
/** "Show Tool Window Names" (menu or settings) applies to both stripes again. */
function resetStripeNames() {
const s = useStripes.getState();
if (s.left.names === undefined && s.right.names === undefined) return;
setStripe("left", { width: s.left.width });
setStripe("right", { width: s.right.width });
}
/**
* Resize handle on a stripe's inner edge. Dragging sets the stripe's button width;
* narrower than halfway to the named minimum shows icons only.
@@ -484,7 +438,7 @@ function StripeButton({
}
/** Stripe "…": tool windows without a stripe button; opening one adds its button (IDEA). */
function StripeMore({ windows }: { windows: ToolWindowContribution[] }) {
function StripeMore({ side, windows }: { side: StripeSide; windows: ToolWindowContribution[] }) {
const iconSize = useChromeIconSize();
const [open, setOpen] = useState(false);
const ref = useRef<HTMLButtonElement>(null);
@@ -512,7 +466,18 @@ function StripeMore({ windows }: { windows: ToolWindowContribution[] }) {
aria-haspopup="menu"
aria-expanded={open}
onClick={() => setOpen((v) => !v)}
data-tooltip-stripe="left"
onContextMenu={(e) => {
e.preventDefault();
setOpen(false);
showContextMenu(e, [
{
kind: "action",
action: "toolwindow.moveMore",
label: side === "left" ? "Move to Right" : "Move to Left",
},
]);
}}
data-tooltip-stripe={side}
{...tooltipAttrs("More Tool Windows")}
>
<Icon name="more-horizontal" size={iconSize} />
@@ -522,7 +487,7 @@ function StripeMore({ windows }: { windows: ToolWindowContribution[] }) {
onClose={() => setOpen(false)}
anchor={ref}
items={items}
placement="right-start"
placement={side === "left" ? "right-start" : "left-start"}
aria-label="Tool windows"
/>
</>
@@ -560,6 +525,7 @@ export function ToolWindowStripe({
const primary = inSlot(side);
const split = inSlot(`${side}-split`);
const lower = inSlot(lowerSlot(side));
const moreSide = useStripes((s) => s.moreSide);
const moreWindows = windows.filter((w) => !onStripe.includes(w));
const focused = useToolWindowLayout((s) => s.focused);
const drop = useStripeDrag((s) => s.drop);
@@ -599,7 +565,7 @@ export function ToolWindowStripe({
{renderGroup(side, primary)}
{dragging && <div className={styles.stripeSeparator} data-stripe-separator="" role="separator" />}
{(split.length > 0 || dragging) && renderGroup(`${side}-split`, split)}
{side === "left" && <StripeMore windows={moreWindows} />}
{side === moreSide && <StripeMore side={side} windows={moreWindows} />}
<div className={styles.stripeSpacer} data-stripe-spacer="" />
{renderGroup(lowerSlot(side), lower)}
</nav>
@@ -1315,16 +1281,21 @@ export function ToolWindowLayout({ editor }: { editor: ReactNode }) {
);
const sizes = useToolWindowLayout((s) => s.sizes);
const stripeButtons = useToolWindowLayout((s) => s.stripeButtons);
// The right stripe holds the right side's windows and Bottom Right.
const hasRight = windows.some((w) => {
const slot = slotOf(w);
return (
(w.anchor === "right" || slot === "bottom-split") && (hasStripeButton(w, stripeButtons) || visible[slot] === w.id)
);
});
// While a stripe button is dragged, an empty right stripe shows as a drop target.
// Keep the overflow button reachable and show empty stripes as drop targets while dragging.
const dragging = useStripeDrag((s) => !!s.id);
const rightStripe = bars && (hasRight || dragging);
const showStripe = (side: StripeSide) =>
bars &&
(stripes.moreSide === side ||
dragging ||
windows.some((w) => {
const slot = slotOf(w);
return (
(w.anchor === side || slot === lowerSlot(side)) &&
(hasStripeButton(w, stripeButtons) || visible[slot] === w.id)
);
}));
const leftStripe = showStripe("left");
const rightStripe = showStripe("right");
const gridRef = useRef<HTMLDivElement>(null);
const editorRef = useRef<HTMLDivElement>(null);
// Undocked windows take no track: the editor keeps its size under them.
@@ -1357,10 +1328,10 @@ export function ToolWindowLayout({ editor }: { editor: ReactNode }) {
return (
<div
ref={frameRef}
className={clsx(styles.frame, !rightStripe && styles.frameNoRight, !bars && styles.frameNoLeft)}
className={clsx(styles.frame, !rightStripe && styles.frameNoRight, !leftStripe && styles.frameNoLeft)}
>
{bars && stripe("left")}
{bars && stripeHandle("left")}
{leftStripe && stripe("left")}
{leftStripe && stripeHandle("left")}
<div
ref={gridRef}
className={clsx(styles.grid, widescreen && styles.widescreen)}
+7
View File
@@ -18,6 +18,7 @@ import {
useToolWindowLayouts,
} from "./layouts";
import { closeSelectedContent } from "./content";
import { toggleMoreToolWindowsSide } from "./stripes";
import {
activateToolWindow,
hideActiveToolWindow,
@@ -217,6 +218,12 @@ export function installToolWindowActions(): () => void {
};
const disposeStatic = registerActions([
{
id: "toolwindow.moveMore",
title: "Move More Tool Windows Button",
category: "Window",
run: toggleMoreToolWindowsSide,
},
{
id: "toolwindow.hideAll",
title: "Hide All Tool Windows",
+61
View File
@@ -0,0 +1,61 @@
import { create } from "zustand";
export type StripeSide = "left" | "right";
/** Stripe button widths with names; icons only follow `--stripe-icon-button`. */
export const STRIPE_MIN = 44;
export const STRIPE_MAX = 96;
const STRIPE_DEFAULT = 56;
const STRIPE_KEY = "openidea.stripes.v1";
interface StripeSize {
width: number;
/** Names shown or hidden by a resize. Unset follows the appearance setting. */
names?: boolean;
}
interface Stripes extends Record<StripeSide, StripeSize> {
moreSide: StripeSide;
}
function readStripes(): Stripes {
const out: Stripes = { left: { width: STRIPE_DEFAULT }, right: { width: STRIPE_DEFAULT }, moreSide: "left" };
try {
const raw = JSON.parse(localStorage.getItem(STRIPE_KEY) ?? "null");
for (const side of ["left", "right"] as const) {
const v = raw?.[side];
if (typeof v?.width === "number") out[side].width = Math.min(STRIPE_MAX, Math.max(STRIPE_MIN, v.width));
if (typeof v?.names === "boolean") out[side].names = v.names;
}
if (raw?.moreSide === "right") out.moreSide = "right";
} catch {
/* storage unavailable */
}
return out;
}
export const useStripes = create<Stripes>(readStripes);
function saveStripes(next: Partial<Stripes>) {
useStripes.setState(next);
try {
localStorage.setItem(STRIPE_KEY, JSON.stringify(useStripes.getState()));
} catch {
/* storage unavailable */
}
}
export function setStripe(side: StripeSide, size: StripeSize) {
saveStripes({ [side]: size });
}
/** "Show Tool Window Names" (menu or settings) applies to both stripes again. */
export function resetStripeNames() {
const s = useStripes.getState();
if (s.left.names === undefined && s.right.names === undefined) return;
saveStripes({ left: { width: s.left.width }, right: { width: s.right.width } });
}
export function toggleMoreToolWindowsSide() {
saveStripes({ moreSide: useStripes.getState().moreSide === "left" ? "right" : "left" });
}