diff --git a/desktop/internal/core/chrome.go b/desktop/internal/core/chrome.go index ef2d1ffddf..b92c58a088 100644 --- a/desktop/internal/core/chrome.go +++ b/desktop/internal/core/chrome.go @@ -69,13 +69,17 @@ type Placement struct { // an empty layout and is a valid input: the kernel completes it from the catalog. // // A layout returned by ReduceChromeLayout lists every catalog item exactly once, zone by zone in -// the order of the Zone constants, and Open names at most one panel item per zone, also in zone -// order. +// the order of the Zone constants, Open names at most one panel item per zone, also in zone +// order, and Hidden lists the hidden tool stripe items in the order of Placements. type ChromeLayout struct { - // Placements is every item with its zone. + // Placements is every item with its zone. A hidden item keeps its placement, so showing it + // again puts it back where it was. Placements []Placement `json:"placements"` - // Open lists the panel items whose panel is shown. + // Open lists the panel items whose panel is shown. A hidden item's panel can be open: a + // shortcut or command opens it without showing the button. Open []string `json:"open"` + // Hidden lists the tool stripe items whose button the user hid from the stripe. + Hidden []string `json:"hidden"` } // MarshalJSON encodes the layout with empty lists as [] instead of null, because the kernel @@ -84,8 +88,9 @@ func (l ChromeLayout) MarshalJSON() ([]byte, error) { type wire struct { Placements []Placement `json:"placements"` Open []string `json:"open"` + Hidden []string `json:"hidden"` } - return json.Marshal(wire{Placements: nonNil(l.Placements), Open: nonNil(l.Open)}) + return json.Marshal(wire{Placements: nonNil(l.Placements), Open: nonNil(l.Open), Hidden: nonNil(l.Hidden)}) } // chromeKind names the variants of a ChromeAction. The values are the "kind" tags of the Rust @@ -98,17 +103,19 @@ const ( chromeMove chromeKind = "move" chromeToggle chromeKind = "toggle" chromeSetOpen chromeKind = "setOpen" + chromeSetHidden chromeKind = "setHidden" ) // ChromeAction is one transition of the chrome layout. Build it with NormalizeChrome, -// ResetChrome, MoveChrome, ToggleChrome or SetChromeOpen; the zero value is not a valid action -// and cannot be encoded. +// ResetChrome, MoveChrome, ToggleChrome, SetChromeOpen or SetChromeHidden; the zero value is not +// a valid action and cannot be encoded. type ChromeAction struct { kind chromeKind id string zone Zone before string open bool + hidden bool } // NormalizeChrome repairs a saved layout against the catalog without changing anything else: @@ -118,7 +125,8 @@ func NormalizeChrome() ChromeAction { return ChromeAction{kind: chromeNormalize} } -// ResetChrome replaces the layout with the default layout of the catalog. +// ResetChrome replaces the layout with the default layout of the catalog, which shows every +// item. func ResetChrome() ChromeAction { return ChromeAction{kind: chromeReset} } @@ -142,8 +150,15 @@ func SetChromeOpen(id string, open bool) ChromeAction { return ChromeAction{kind: chromeSetOpen, id: id, open: open} } -// chromeKindWire, chromeMoveWire, chromeIDWire and chromeSetOpenWire are the exact JSON shapes -// of the action variants. The kernel rejects unknown fields, so each variant encodes only its +// SetChromeHidden hides or shows the tool stripe button of the item id. Hiding closes the item's +// panel; showing leaves the panel as it is. A hidden item keeps its zone and position. Only tool +// stripe items can be hidden; a title or status bar item fails with CodeInvalidRequest. +func SetChromeHidden(id string, hidden bool) ChromeAction { + return ChromeAction{kind: chromeSetHidden, id: id, hidden: hidden} +} + +// chromeKindWire, chromeMoveWire, chromeIDWire, chromeSetOpenWire and chromeSetHiddenWire are +// the exact JSON shapes of the action variants. The kernel rejects unknown fields, so each variant encodes only its // own fields. type chromeKindWire struct { Kind chromeKind `json:"kind"` @@ -167,6 +182,12 @@ type chromeSetOpenWire struct { Open bool `json:"open"` } +type chromeSetHiddenWire struct { + Kind chromeKind `json:"kind"` + ID string `json:"id"` + Hidden bool `json:"hidden"` +} + // MarshalJSON encodes the action as the exact object of its variant. func (a ChromeAction) MarshalJSON() ([]byte, error) { switch a.kind { @@ -178,8 +199,10 @@ func (a ChromeAction) MarshalJSON() ([]byte, error) { return json.Marshal(chromeIDWire{Kind: a.kind, ID: a.id}) case chromeSetOpen: return json.Marshal(chromeSetOpenWire{Kind: a.kind, ID: a.id, Open: a.open}) + case chromeSetHidden: + return json.Marshal(chromeSetHiddenWire{Kind: a.kind, ID: a.id, Hidden: a.hidden}) } - return nil, errors.New("core: zero ChromeAction; build one with NormalizeChrome, ResetChrome, MoveChrome, ToggleChrome or SetChromeOpen") + return nil, errors.New("core: zero ChromeAction; build one with NormalizeChrome, ResetChrome, MoveChrome, ToggleChrome, SetChromeOpen or SetChromeHidden") } // chromeLayoutRequest is the payload of workbench.chromeLayout.reduce. The kernel rejects @@ -209,8 +232,8 @@ type chromeLayoutResponse struct { // // The kernel answers CodeInvalidRequest for a malformed catalog (an empty or repeated id, a // panel outside the tool stripes, a default-open item that is not a panel) and for an action -// that names an unknown item, moves an item to another surface or opens an item that is not a -// panel. +// that names an unknown item, moves an item to another surface, opens an item that is not a +// panel or hides an item outside the tool stripes. // // The call only computes over its arguments and is fast enough for an event handler. func (c *Client) ReduceChromeLayout(ctx context.Context, catalog []ChromeItem, state ChromeLayout, action ChromeAction) (ChromeLayout, bool, error) { @@ -226,5 +249,6 @@ func (c *Client) ReduceChromeLayout(ctx context.Context, catalog []ChromeItem, s return ChromeLayout{ Placements: nonNil(response.State.Placements), Open: nonNil(response.State.Open), + Hidden: nonNil(response.State.Hidden), }, response.Changed, nil } diff --git a/desktop/internal/core/core_test.go b/desktop/internal/core/core_test.go index 5ea3a6fd6c..95681f2580 100644 --- a/desktop/internal/core/core_test.go +++ b/desktop/internal/core/core_test.go @@ -703,6 +703,30 @@ func TestReduceChromeLayout(t *testing.T) { } }) + // A hidden button keeps its place and its panel closes; showing it again leaves the panel + // closed, and a shortcut can still open the panel of a hidden button. + t.Run("hide and show a stripe button", func(t *testing.T) { + layout, changed := reduce(t, defaults, SetChromeHidden("project", true)) + if !changed || !slices.Equal(layout.Hidden, []string{"project"}) || len(layout.Open) != 0 { + t.Fatalf("hide project: hidden %q, open %q, changed %v, want [project], [], true", layout.Hidden, layout.Open, changed) + } + if !slices.Equal(layout.Placements, defaults.Placements) { + t.Errorf("hide project: placements %+v, want them unchanged", layout.Placements) + } + layout, _ = reduce(t, layout, SetChromeOpen("project", true)) + if !slices.Equal(layout.Hidden, []string{"project"}) || !slices.Equal(layout.Open, []string{"project"}) { + t.Errorf("open hidden project: hidden %q, open %q, want [project], [project]", layout.Hidden, layout.Open) + } + layout, changed = reduce(t, layout, SetChromeHidden("project", false)) + if !changed || len(layout.Hidden) != 0 || layout.Hidden == nil || !slices.Equal(layout.Open, []string{"project"}) { + t.Errorf("show project: hidden %#v, open %q, changed %v, want a non-nil empty list, [project], true", layout.Hidden, layout.Open, changed) + } + _, _, err := client.ReduceChromeLayout(ctx, catalog, defaults, SetChromeHidden("run", true)) + requireCode(t, err, CodeInvalidRequest) + _, _, err = client.ReduceChromeLayout(ctx, catalog, defaults, SetChromeHidden("missing", true)) + requireCode(t, err, CodeInvalidRequest) + }) + t.Run("only known panels open", func(t *testing.T) { _, _, err := client.ReduceChromeLayout(ctx, catalog, defaults, ToggleChrome("run")) requireCode(t, err, CodeInvalidRequest) @@ -812,8 +836,10 @@ func TestChromeJSON(t *testing.T) { {"move before", MoveChrome("git", ZoneRightTop, "run"), `{"kind":"move","id":"git","zone":"rightTop","before":"run"}`}, {"toggle", ToggleChrome("git"), `{"kind":"toggle","id":"git"}`}, {"set open", SetChromeOpen("git", false), `{"kind":"setOpen","id":"git","open":false}`}, - {"empty layout", ChromeLayout{}, `{"placements":[],"open":[]}`}, - {"layout", ChromeLayout{Placements: []Placement{{ID: "a", Zone: ZoneLeftTop}}, Open: []string{"a"}}, `{"placements":[{"id":"a","zone":"leftTop"}],"open":["a"]}`}, + {"hide", SetChromeHidden("git", true), `{"kind":"setHidden","id":"git","hidden":true}`}, + {"show", SetChromeHidden("git", false), `{"kind":"setHidden","id":"git","hidden":false}`}, + {"empty layout", ChromeLayout{}, `{"placements":[],"open":[],"hidden":[]}`}, + {"layout", ChromeLayout{Placements: []Placement{{ID: "a", Zone: ZoneLeftTop}}, Open: []string{"a"}, Hidden: []string{"a"}}, `{"placements":[{"id":"a","zone":"leftTop"}],"open":["a"],"hidden":["a"]}`}, {"plain item", ChromeItem{ID: "a", DefaultZone: ZoneLeftTop}, `{"id":"a","defaultZone":"leftTop"}`}, {"panel item", ChromeItem{ID: "a", DefaultZone: ZoneLeftTop, Panel: true, OpenByDefault: true}, `{"id":"a","defaultZone":"leftTop","panel":true,"openByDefault":true}`}, } diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 5b3cbb54a5..1d22e9013e 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1941,6 +1941,7 @@ var sharedCatalogs = map[string]map[string]string{ "logs.window.verboseDiagnosticsOn": "verbose diagnostics on", "logs.window.viewClearedFilesOnDiskAreUntouchedNewRecordsWillAppearHere": "View cleared — files on disk are untouched; new records will appear here", "logs.window.visibleCount": "{visible} / {total} rows · line {line}", + "mac.workbench.unhide": "Unhide", "menu.closeTab": "Close Tab", "menu.copy": "Copy", "menu.paste": "Paste", @@ -2077,6 +2078,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.groups": "Groups", "native.head": "HEAD", "native.hiddenInTheProjectTreeNotRecorded": "Hidden in the project tree, not recorded", + "native.hideEntry": "Hide Entry", "native.hideToolWindow": "Hide {arg1} tool window", "native.history": "History", "native.homepage": "Homepage", @@ -2355,6 +2357,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.thisWorktreeHasNoUncommittedChanges": "This worktree has no uncommitted changes.", "native.timeToExit": "Time to exit", "native.toolWindow": "Tool Window", + "native.toolWindows": "Tool Windows", "native.trackingBranch": "Tracking Branch", "native.treeConflict": "Tree conflict", "native.tryABranchNameOrCheckoutPath": "Try a branch name or checkout path.", @@ -4411,6 +4414,7 @@ var sharedCatalogs = map[string]map[string]string{ "logs.window.verboseDiagnosticsOn": "详细诊断已开启", "logs.window.viewClearedFilesOnDiskAreUntouchedNewRecordsWillAppearHere": "已清空显示,磁盘上的日志文件不受影响;新记录会继续出现在这里", "logs.window.visibleCount": "{visible} / {total} 条 · 第 {line} 行", + "mac.workbench.unhide": "取消隐藏", "menu.closeTab": "关闭标签页", "menu.copy": "复制", "menu.paste": "粘贴", @@ -4547,6 +4551,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.groups": "组合", "native.head": "HEAD", "native.hiddenInTheProjectTreeNotRecorded": "已在项目树中隐藏,不记录", + "native.hideEntry": "隐藏入口", "native.hideToolWindow": "隐藏 {arg1} 工具窗口", "native.history": "历史", "native.homepage": "主页", @@ -4825,6 +4830,7 @@ var sharedCatalogs = map[string]map[string]string{ "native.thisWorktreeHasNoUncommittedChanges": "此工作树没有未提交的更改。", "native.timeToExit": "等待退出时间", "native.toolWindow": "工具窗口", + "native.toolWindows": "工具窗口", "native.trackingBranch": "跟踪的分支", "native.treeConflict": "树冲突", "native.tryABranchNameOrCheckoutPath": "请尝试输入分支名称或检出路径。", diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 52403bfffa..b5dcabbf96 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -474,6 +474,9 @@ type App struct { // is whether this workbench's stripe shows its popover (workbench_background.go). backdrop *workbenchBackground backdropOpen bool + // hiddenListOpen is whether the "…" button under the left stripe's top group shows the + // list of the hidden stripe buttons (chrome_view.go hiddenToolWindows). + hiddenListOpen bool // shownTitle is the system title last given to the window (window_title.go). shownTitle string // updates is the update check, download and install, which every tab of the window @@ -964,6 +967,36 @@ func (a *App) saveSettings() { // resetLayout puts every rearrangeable button back where the catalog puts it. func (a *App) resetLayout() { a.reduceChrome(core.ResetChrome()) } +// hideEntry takes the stripe button of catalog item index off its stripe. The kernel keeps its +// zone and position and closes its tool window; the background button's popover closes with +// it, because it hangs off the button. +func (a *App) hideEntry(index int) { + id := a.chrome.catalog[index].id + if id == itemBackground { + a.backdropOpen = false + } + a.reduceChrome(core.SetChromeHidden(id, true)) +} + +// showEntry puts the hidden stripe button of catalog item index back where it was and, when +// open is set, opens what the button opens, as a click on it does: its tool window, or the +// background button's popover. A tool window that is already open, from a shortcut, stays +// open. +func (a *App) showEntry(index int, open bool) { + it := a.chrome.catalog[index] + a.reduceChrome(core.SetChromeHidden(it.id, false)) + if !open || a.chrome.isHidden(index) { + // The kernel refused, which reduceChrome reported. + return + } + switch { + case it.id == itemBackground: + a.backdropOpen = true + case it.panel && !a.chrome.isOpen(index): + a.activate(index) + } +} + // activate is a click on the rearrangeable button of catalog item index: a tool // button opens or closes its tool window, the settings button opens or closes its menu // and the commands that need a provider that is not connected yet say so. diff --git a/desktop/internal/workbench/catalog.go b/desktop/internal/workbench/catalog.go index 4e76b3e96d..eadd3b8ffc 100644 --- a/desktop/internal/workbench/catalog.go +++ b/desktop/internal/workbench/catalog.go @@ -219,6 +219,10 @@ func stripeLucide(icon gfx.Icon) *gfx.Icon { return &icon } +// hiddenToolWindowsIcon is the glyph of the left stripe's "…" button, which lists the stripe +// buttons the user hid, at the weight of the other stripe icons. +var hiddenToolWindowsIcon = stripeLucide(icons.Ellipsis) + // catalog is every rearrangeable button, in the default order of each zone. The // kernel owns the layout rules; this is only the host's list of what exists. A tool // stripe button shows the IntelliJ New UI icon of its window (toolicons), or a Lucide icon @@ -290,8 +294,16 @@ type chromeState struct { // places the tool windows of plugins that are not enabled now, so they come back where // the user left them. saved core.ChromeLayout - // items lists the catalog indices of each zone in display order. + // items lists the catalog indices of the shown buttons of each zone in display order. items [zoneCount][]int + // zones is the zone each catalog item sits in, by catalog index. A hidden stripe button + // keeps its zone: its tool window still opens in that zone's slot, and showing the button + // again puts it back there. + zones []zone + // hidden lists the catalog indices of the stripe buttons the user hid, in layout order, + // and hiddenMark marks them by catalog index. + hidden []int + hiddenMark []bool // open is the catalog index of the open tool window of each slot, -1 for none. open [slotCount]int @@ -328,6 +340,12 @@ func (c *chromeState) setItems(items []item) { c.coreItems[i] = core.ChromeItem{ID: it.id, DefaultZone: zoneNames[it.zone], Panel: it.panel, OpenByDefault: it.open} c.index[it.id] = i } + c.zones = make([]zone, len(items)) + for i, it := range items { + c.zones[i] = it.zone + } + c.hidden = c.hidden[:0] + c.hiddenMark = make([]bool, len(items)) c.ids = make([]gfx.ID, len(items)) c.rects = make([]gfx.Rect, len(items)) c.rectHooks = make([]func(*ui.DrawContext), len(items)) @@ -337,11 +355,13 @@ func (c *chromeState) setItems(items []item) { } // withAbsent is layout with the saved places of plugin tool windows the catalog does not -// list now, which the kernel leaves out of every layout it returns. +// list now, which the kernel leaves out of every layout it returns, and whether they are open +// or hidden. func (c *chromeState) withAbsent(layout core.ChromeLayout) core.ChromeLayout { merged := core.ChromeLayout{ Placements: append([]core.Placement(nil), layout.Placements...), Open: append([]string(nil), layout.Open...), + Hidden: append([]string(nil), layout.Hidden...), } for _, placement := range c.saved.Placements { if _, known := c.index[placement.ID]; !known && isPluginItem(placement.ID) { @@ -353,6 +373,11 @@ func (c *chromeState) withAbsent(layout core.ChromeLayout) core.ChromeLayout { merged.Open = append(merged.Open, id) } } + for _, id := range c.saved.Hidden { + if _, known := c.index[id]; !known && isPluginItem(id) { + merged.Hidden = append(merged.Hidden, id) + } + } return merged } @@ -366,6 +391,7 @@ func (c *chromeState) restated() core.ChromeLayout { restated := core.ChromeLayout{ Placements: append([]core.Placement(nil), c.saved.Placements...), Open: append([]string(nil), c.saved.Open...), + Hidden: append([]string(nil), c.saved.Hidden...), } saved := make(map[string]bool, len(c.saved.Placements)) for _, placement := range c.saved.Placements { @@ -376,6 +402,11 @@ func (c *chromeState) restated() core.ChromeLayout { restated.Placements = append(restated.Placements, placement) } } + for _, id := range c.layout.Hidden { + if !saved[id] { + restated.Hidden = append(restated.Hidden, id) + } + } return restated } @@ -397,8 +428,9 @@ func defaultLayout() core.ChromeLayout { } // apply makes layout the current arrangement. Placements of unknown items or zones are -// skipped; the kernel never returns them. An open item that is not a tool window, such as the -// background button an earlier layout saved as open, takes no slot. +// skipped; the kernel never returns them. A hidden button keeps its zone but is left out of +// the zone's shown buttons. An open item that is not a tool window, such as the background +// button an earlier layout saved as open, takes no slot. func (c *chromeState) apply(layout core.ChromeLayout) { c.layout = layout for z := range c.items { @@ -407,12 +439,27 @@ func (c *chromeState) apply(layout core.ChromeLayout) { for s := range c.open { c.open[s] = -1 } + for i := range c.catalog { + c.zones[i] = c.catalog[i].zone + } + clear(c.hiddenMark) + c.hidden = c.hidden[:0] + for _, id := range layout.Hidden { + if index, known := c.index[id]; known { + c.hiddenMark[index] = true + } + } for _, placement := range layout.Placements { index, known := c.index[placement.ID] z, valid := zoneFromCore(placement.Zone) if !known || !valid { continue } + c.zones[index] = z + if c.hiddenMark[index] { + c.hidden = append(c.hidden, index) + continue + } c.items[z] = append(c.items[z], index) } for _, id := range layout.Open { @@ -426,16 +473,21 @@ func (c *chromeState) apply(layout core.ChromeLayout) { } } -// zoneOf returns the zone catalog item index sits in now. -func (c *chromeState) zoneOf(index int) zone { - for z := range c.items { - for _, candidate := range c.items[z] { - if candidate == index { - return zone(z) - } +// zoneOf returns the zone catalog item index sits in now, whether its button is shown or +// hidden. +func (c *chromeState) zoneOf(index int) zone { return c.zones[index] } + +// isHidden reports whether the user hid the stripe button of catalog item index. +func (c *chromeState) isHidden(index int) bool { return c.hiddenMark[index] } + +// hiddenOpen reports whether the tool window of a hidden stripe button is open. +func (c *chromeState) hiddenOpen() bool { + for _, index := range c.hidden { + if c.isOpen(index) { + return true } } - return c.catalog[index].zone + return false } // isOpen reports whether the tool window of catalog item index is open. diff --git a/desktop/internal/workbench/chrome.go b/desktop/internal/workbench/chrome.go index 9a6a670d69..d824d840e4 100644 --- a/desktop/internal/workbench/chrome.go +++ b/desktop/internal/workbench/chrome.go @@ -11,6 +11,10 @@ import ( // and their shortcuts. const gearMenuWidth = 224 +// hiddenListWidth is the width of the list of hidden stripe buttons, which holds a tool +// window's name and its shortcut. +const hiddenListWidth = 240 + const ( // chromeIconButton is the side of a title bar icon button and the height of the // other title bar controls. It is even and fits its bar with a whole pixel above and diff --git a/desktop/internal/workbench/chrome_menu_test.go b/desktop/internal/workbench/chrome_menu_test.go index 871ee4cd99..091b717012 100644 --- a/desktop/internal/workbench/chrome_menu_test.go +++ b/desktop/internal/workbench/chrome_menu_test.go @@ -1,6 +1,7 @@ package workbench import ( + "slices" "testing" "github.com/1lck/Lithe-IDEA/desktop/internal/core" @@ -78,3 +79,148 @@ func TestToolWindowMoveSubmenuUsesCoreLayout(t *testing.T) { t.Fatalf("move submenu left Project in zone %v", got) } } + +// A hidden stripe button is listed under the "…" button below the left stripe's top group, +// as the earlier client and IDEA list it: a click on its row puts the button back where it +// was and opens its tool window. The "…" button is there only while a button is hidden. +func TestHiddenStripeButtonIsListedUnderTheEllipsisAndComesBack(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + h.open(t.TempDir()) + more := h.shared("native.toolWindows") + if _, shown := h.findPageHit(more); shown { + t.Fatal("the stripe shows the hidden tool windows button with nothing hidden") + } + commit := catalogIndex[itemCommit] + before := slices.Clone(h.app.chrome.items[zoneLeftTop]) + label := h.app.chrome.catalog[commit].label(h.app.text) + + h.rightClickAt(h.button(itemCommit)) + h.click(center(h.popupHit(h.shared("native.hideEntry")))) + h.settle() + if slices.Contains(h.app.chrome.items[zoneLeftTop], commit) || !h.app.chrome.isHidden(commit) { + t.Fatalf("after Hide Entry the top left zone shows %v, want Commit hidden", h.app.chrome.items[zoneLeftTop]) + } + if got := h.app.chrome.zoneOf(commit); got != zoneLeftTop { + t.Fatalf("hidden Commit sits in zone %v, want it to keep the top left zone", got) + } + if r := h.app.chrome.rects[commit]; r.Width != 0 { + t.Fatalf("hidden Commit is still laid out at %v", r) + } + var saved core.ChromeLayout + if _, err := h.store.Load(layoutFile, &saved); err != nil || !slices.Equal(saved.Hidden, []string{itemCommit}) { + t.Fatalf("saved hidden = %q, %v; want [commit]", saved.Hidden, err) + } + + // The "…" button is laid out as one more button of the top group and, as they do, names + // itself in a tip on the stripe's inner side. + shown := h.app.chrome.items[zoneLeftTop] + last := h.button(h.app.chrome.catalog[shown[len(shown)-1]].id) + ellipsis := h.pageHit(more).Bounds + if ellipsis.Width != 30 || ellipsis.Height != 30 || ellipsis.X != last.X || ellipsis.Y-last.Y != 40 { + t.Fatalf("the hidden tool windows button is at %+v, want 30x30, 40 below the last top button at %+v", ellipsis, last) + } + at := center(ellipsis) + if err := h.driver.Move(at.X, at.Y); err != nil { + t.Fatal(err) + } + h.settle() + if tips := h.tooltips(); len(tips) != 1 || tips[0].Value != more || tips[0].Bounds.X < ellipsis.Right() { + t.Fatalf("resting on the hidden tool windows button shows the tips %+v, want only %q on its right", tips, more) + } + + h.clickNamed(more) + if !h.app.hiddenListOpen { + t.Fatal("the hidden tool windows button did not open its list") + } + if tips := h.tooltips(); len(tips) != 0 { + t.Fatalf("the open list of hidden tool windows is covered by the tips %+v", tips) + } + h.click(center(h.popupHit(label))) + h.settle() + if h.app.chrome.isHidden(commit) || !slices.Equal(h.app.chrome.items[zoneLeftTop], before) { + t.Fatalf("after its row was clicked the zone shows %v, want %v", h.app.chrome.items[zoneLeftTop], before) + } + if !h.app.chrome.isOpen(commit) { + t.Fatal("the row of a hidden button did not open its tool window") + } + if h.app.hiddenListOpen { + t.Fatal("the list stayed open after a row was chosen") + } + if _, shown := h.findPageHit(more); shown { + t.Fatal("the hidden tool windows button stayed with nothing hidden") + } +} + +// Hiding the button of an open tool window closes it. A shortcut still opens the window of a +// hidden button, and then the "…" button takes the open look; Unhide in the row's context +// menu only puts the button back. +func TestUnhidePutsTheButtonBackWithoutTouchingItsToolWindow(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + h.open(t.TempDir()) + project := catalogIndex[itemProject] + label := h.app.chrome.catalog[project].label(h.app.text) + if !h.app.chrome.isOpen(project) { + t.Fatal("the Project tool window is not open by default") + } + h.rightClickAt(h.button(itemProject)) + h.click(center(h.popupHit(h.shared("native.hideEntry")))) + h.settle() + if h.app.chrome.isOpen(project) || !h.app.chrome.isHidden(project) { + t.Fatal("Hide Entry left the Project tool window open or its button shown") + } + + more := h.shared("native.toolWindows") + if h.pageHit(more).Selected { + t.Fatal("the hidden tool windows button looks open with every hidden window closed") + } + h.app.post(func(a *App) { a.reduceChrome(core.SetChromeOpen(itemProject, true)) }) + h.settle() + if !h.app.chrome.isOpen(project) || !h.app.chrome.isHidden(project) { + t.Fatal("opening the tool window of a hidden button did not keep the button hidden") + } + if !h.pageHit(more).Selected { + t.Fatal("the hidden tool windows button does not show that a hidden window is open") + } + + h.clickNamed(more) + h.rightClickAt(h.popupHit(label)) + h.click(center(h.popupHit(h.shared("mac.workbench.unhide")))) + h.settle() + if h.app.chrome.isHidden(project) || h.app.chrome.items[zoneLeftTop][0] != project { + t.Fatalf("after Unhide the top left zone shows %v, want Project first", h.app.chrome.items[zoneLeftTop]) + } + if !h.app.chrome.isOpen(project) { + t.Fatal("Unhide closed the Project tool window") + } + if h.app.hiddenListOpen { + t.Fatal("the list stayed open after its last button came back") + } +} + +// The arrangement keeps a hidden button's zone and leaves it out of the zone's shown buttons; +// the tool window of a hidden button still opens in its zone's slot. +func TestChromeStateKeepsTheZoneOfAHiddenButton(t *testing.T) { + c := newChromeState() + layout := defaultLayout() + for i, placement := range layout.Placements { + if placement.ID == itemTerminal { + layout.Placements[i].Zone = core.ZoneRightBottom + } + } + layout.Open = append(layout.Open, itemTerminal) + layout.Hidden = []string{itemTerminal} + c.apply(layout) + terminal := c.index[itemTerminal] + if !c.isHidden(terminal) || !slices.Equal(c.hidden, []int{terminal}) { + t.Fatalf("hidden = %v, want [%d]", c.hidden, terminal) + } + if got := c.zoneOf(terminal); got != zoneRightBottom { + t.Fatalf("zone of the hidden terminal = %v, want right bottom", got) + } + if len(c.items[zoneRightBottom]) != 0 { + t.Fatalf("right bottom shows %v, want no buttons", c.items[zoneRightBottom]) + } + if c.open[slotRightBottom] != terminal || !c.hiddenOpen() { + t.Fatalf("open slots = %v, want the hidden terminal in the right bottom slot", c.open) + } +} diff --git a/desktop/internal/workbench/chrome_view.go b/desktop/internal/workbench/chrome_view.go index 56e99950a2..212c63e5c8 100644 --- a/desktop/internal/workbench/chrome_view.go +++ b/desktop/internal/workbench/chrome_view.go @@ -5,6 +5,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/vivaui/viva/app" + "github.com/vivaui/viva/components" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" "runtime" @@ -242,6 +243,9 @@ func (a *App) chromeTitleButton(c ui.C, i int) bool { // While a tool button is dragged, every zone gets at least the height of a button, so an // empty zone remains visible and can be hit. No separator is needed between the top and // split groups: the flexible space makes their placement clear. +// +// While the user has hidden a button, the left stripe has a "…" button under its top group +// that lists the hidden ones (hiddenToolWindows). func (a *App) stripe(c ui.C, left bool) { top, split, end := zoneLeftTop, zoneLeftBottom, zoneBottomLeft if !left { @@ -254,6 +258,11 @@ func (a *App) stripe(c ui.C, left bool) { if i := a.stripeZone(c, top, left, dragging); i >= 0 { clicked = i } + if left { + // The "…" button follows the top group a gap below, as one more of its buttons; + // while a button is dragged the group is a button high even when empty. + a.hiddenToolWindows(c, dragging || len(a.chrome.items[top]) > 0) + } ui.Spacer(c) if i := a.stripeZone(c, split, left, dragging); i >= 0 { clicked = i @@ -325,6 +334,137 @@ func (a *App) stripeZone(c ui.C, z zone, left, dragging bool) int { return clicked } +// hiddenToolWindows declares the "…" button under the left stripe's top group and, while it is +// open, the list of the stripe buttons the user hid, as the earlier client and IDEA put them +// there. The button is there only while a button is hidden, so a hidden button can always be +// found again. While the tool window of a hidden button is open, the "…" button takes the open +// look of a stripe button, because that window has no button of its own to show it. The +// button is laid out as a stripe button (stripeGlyph), below is whether the top group has +// buttons above it, and as they do it names itself in a tip, except while its list is open +// beside it on the same side. +func (a *App) hiddenToolWindows(c ui.C, below bool) { + if len(a.chrome.hidden) == 0 { + // The last hidden button came back, and the list went with its button. + a.hiddenListOpen = false + return + } + k := c.Part("hiddenToolWindows") + listOpen := a.hiddenListOpen + shown := a.chrome.hiddenOpen() + layout := stripeGlyph(true) + name := i18n.Shared(a.language(), "native.toolWindows") + button := ui.Row(k).Size(layout.side, layout.side).Shrink(0).Center(). + Radius(a.theme.Metrics.RadiusItem()). + HitWith(ui.ID(k), name, gfx.HitOptions{ + Role: gfx.RoleButton, + Cursor: gfx.PointerCursorHand, + Selected: shown, + Expandable: true, + Expanded: listOpen, + }). + Pressed(ui.Look{}.Background(a.colors.Active)) + if below { + button = button.MarginTop(chromeToolGap) + } + if !listOpen { + button = button.Tooltip(name).TooltipOn(layout.tooltip) + } + rest, hover := a.colors.Subtle, a.colors.Text + switch { + case shown: + button = button.Background(a.theme.Primary) + rest, hover = a.theme.PrimaryForeground, a.theme.PrimaryForeground + case listOpen: + button = button.Background(a.colors.Active) + default: + button = button.Hover(ui.Look{}.Background(a.colors.Hover)) + } + button.Children(func() { + ui.Icon(k, *hiddenToolWindowsIcon).Size(layout.icon, layout.icon).Color(rest). + StateFrom(button).Hover(ui.Look{}.Color(hover)) + }) + clicked := button.Clicked() + if listOpen { + a.hiddenToolWindowList(c, button) + } + // As the background button: the press on the button that dismisses the open list must not + // open it again. + if clicked && !listOpen { + a.hiddenListOpen = true + } +} + +// hiddenToolWindowList declares the list of the hidden stripe buttons beside anchor, the "…" +// button, in layout order. A click on a row puts the button back where it was and opens what +// it opens, as a click on the button would; Unhide in the row's context menu only puts the +// button back and leaves the list open on the others. +func (a *App) hiddenToolWindowList(c ui.C, anchor ui.Box) { + language := a.language() + unhide := i18n.Shared(language, "mac.workbench.unhide") + shown, restored := -1, -1 + open := true + spec := ui.PopoverSpec{Side: components.PopoverRight, Align: ui.Start, Offset: chromeMenuOffset, Width: hiddenListWidth, ConsumeOutsidePress: true} + ui.PopoverWith(c, anchor, spec, &open, func() { + ui.Column(c).FillWidth().Gap(chromeMenuItems).Children(func() { + for _, i := range a.chrome.hidden { + row, clicked := a.hiddenToolWindowRow(c.KeyInt(i), i) + if clicked { + shown = i + } + ui.ContextMenu(c.Part("unhide").KeyInt(i), row, func(menu *ui.MenuItems) { + if menu.Item(unhide).Clicked() { + restored = i + } + }) + } + }) + }) + switch { + case shown >= 0: + a.hiddenListOpen = false + c.After(func() { + a.performed("workbench.toolWindow.showHidden", surfaceMenu) + a.showEntry(shown, true) + }) + case restored >= 0: + c.After(func() { + a.performed("workbench.toolWindow.unhide", surfaceMenu) + a.showEntry(restored, false) + }) + case !open: + a.hiddenListOpen = false + } +} + +// hiddenToolWindowRow declares the row of the hidden stripe button of catalog item i: its +// icon, its name and the shortcut that shows its tool window. The row of an open tool window +// is marked as selected. It returns the row, for its context menu, and whether it was clicked. +func (a *App) hiddenToolWindowRow(c ui.C, i int) (ui.Box, bool) { + it := a.chrome.catalog[i] + label := it.label(a.text) + open := a.chrome.isOpen(i) + row := ui.Row(c).FillWidth().Height(chromeMenuRow).Shrink(0).Items(ui.Center).Gap(chromeMenuGap).PadX(chromeEdge). + Radius(a.theme.Metrics.RadiusItem()). + HitWith(ui.ID(c), label, gfx.HitOptions{Role: gfx.RoleMenuItem, Cursor: gfx.PointerCursorHand, Selected: open}) + if open { + row = row.Background(a.colors.Selection) + } else { + row = a.chromeHover(row) + } + row.Children(func() { + if it.icon != nil { + ui.Icon(c, *it.icon).Size(chromeIconSize, chromeIconSize).Shrink(0).Color(a.colors.Subtle) + } + ui.Text(c, label).Grow(1).Color(a.colors.Text).LineHeight(chromeLineHeight).Ellipsis() + if it.panel { + if keys := a.settings.Keymap.Label(toolCommandPrefix + it.id); keys != "" { + ui.Text(c, keys).Shrink(0).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).LineHeight(chromeLineHeight) + } + } + }) + return row, row.Clicked() +} + // statusBar is the strip across the bottom of the workbench: the project on the left, and at // the trailing end the readouts the user can arrange. func (a *App) statusBar(c ui.C) { @@ -632,8 +772,9 @@ func stripeZoneMoveText(lang i18n.Language, z zone) string { } // stripeButtonMenu is the context menu of the stripe button of catalog item i, which sits -// in zone at: hiding its open tool window, and moving it to the end of another stripe zone, -// the keyboard and pointer alternative to dragging it. +// in zone at: hiding its open tool window, hiding the button itself, which the "…" button +// under the left stripe's top group then lists, and moving it to the end of another stripe +// zone, the keyboard and pointer alternative to dragging it. func (a *App) stripeButtonMenu(c ui.C, i int, at zone) func(*ui.MenuItems) { return func(menu *ui.MenuItems) { language := a.language() @@ -646,8 +787,14 @@ func (a *App) stripeButtonMenu(c ui.C, i int, at zone) func(*ui.MenuItems) { a.reduceChrome(core.SetChromeOpen(id, false)) }) } - menu.Separator() } + if menu.Item(i18n.Shared(language, "native.hideEntry")).Clicked() { + c.After(func() { + a.performed("workbench.toolWindow.hideEntry", surfaceMenu) + a.hideEntry(i) + }) + } + menu.Separator() menu.Sub(i18n.Shared(language, "desktop.tools.moveTo"), func(sub *ui.MenuItems) { for z := zoneLeftTop; z <= zoneBottomRight; z++ { if z == at { diff --git a/desktop/internal/workbench/commands.go b/desktop/internal/workbench/commands.go index 577ec652b6..0873c589a1 100644 --- a/desktop/internal/workbench/commands.go +++ b/desktop/internal/workbench/commands.go @@ -17,6 +17,11 @@ import ( // same function its button, menu item or shortcut calls, so running it by name // behaves exactly like those. +// toolCommandPrefix starts the id of the command that shows a tool window; the item id +// follows it. A shortcut bound to that id opens the window, and its label is shown beside the +// window's name in the hidden tool windows list. +const toolCommandPrefix = "tool." + // command is one action of the catalog. type command struct { id string @@ -135,7 +140,7 @@ func (a *App) commands() []command { } id := it.id open := a.chrome.isOpen(index) - add("tool."+id, t.GroupToolWindows, t.ShowTool(it.label(a.text)), "", !open, func() { + add(toolCommandPrefix+id, t.GroupToolWindows, t.ShowTool(it.label(a.text)), "", !open, func() { a.reduceChrome(core.SetChromeOpen(id, true)) }) } diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index ac18bb0166..0241adf09f 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -28,7 +28,9 @@ native_path() { } PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" -# Lithe-core-rust #33, squash-merged into main: build.detect and automatic run discovery skip +# Lithe-core-rust #34, squash-merged into main: workbench.chromeLayout.reduce setHidden hides a +# stripe entry and the layout keeps it in hidden. It is on top of #33, squash-merged into +# main: build.detect and automatic run discovery skip # directories Git ignores (the .gitignore files inside the workspace and the info/exclude of each # repository rooted there, a linked worktree's shared one included), so agent worktrees and local # copies are no longer build or run roots; fingerprint scans are unchanged. It is on top of #32 @@ -61,7 +63,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="29b35bfd7fd8efb53efaa86c62a2065f35a86aa3" +PINNED_CORE_REVISION="1d4556b09d156ad93724368750cddd32a49ca09f" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index deee339ac4..ae1c1a9e19 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -37504,7 +37504,8 @@ "id": "mac.workbench.unhide", "description": "Restore a hidden tool window rail entry without opening its panel", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Unhide", @@ -56460,7 +56461,8 @@ "id": "native.hideEntry", "description": "Native UI: Hide Entry", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Hide Entry", @@ -86922,7 +86924,8 @@ "id": "native.toolWindows", "description": "Native UI: Tool Windows", "platforms": [ - "macos" + "macos", + "desktop" ], "macos": { "key": "Tool Windows", diff --git a/shared/platform-feature-matrix/features/workbench-tool-window-docking.json b/shared/platform-feature-matrix/features/workbench-tool-window-docking.json index 565322e21f..17b5b2c2ef 100644 --- a/shared/platform-feature-matrix/features/workbench-tool-window-docking.json +++ b/shared/platform-feature-matrix/features/workbench-tool-window-docking.json @@ -11,7 +11,9 @@ "desktop/internal/workbench/dockdrag.go", "desktop/internal/workbench/visual_capture_test.go", "desktop/internal/workbench/root.go", - "desktop/internal/workbench/tabstrip.go" + "desktop/internal/workbench/tabstrip.go", + "desktop/internal/workbench/chrome_view.go", + "desktop/internal/workbench/chrome_menu_test.go" ] }, "windows": { @@ -22,7 +24,9 @@ "desktop/internal/workbench/dockdrag.go", "desktop/internal/workbench/visual_capture_test.go", "desktop/internal/workbench/root.go", - "desktop/internal/workbench/tabstrip.go" + "desktop/internal/workbench/tabstrip.go", + "desktop/internal/workbench/chrome_view.go", + "desktop/internal/workbench/chrome_menu_test.go" ] }, "owner": "Workbench", @@ -56,5 +60,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:catalog.go 定义六个停靠区,dockdrag.go 处理拖动落点与遮罩,布局经 loadChrome 保存;未核到组内排序、右键移动和多工作区布局恢复的完整实现。 全页对照恢复活动侧栏蓝色与焦点相关的标签边框;项目渐变由根容器在子元素前绘制,不覆盖不透明工具面板。首次打开仅展开 Project,Git 按需打开,已有保存布局保持优先。像素回归 TestVisualWorkbenchGradientStaysBehindPanels 证明修复前失败、修复后通过;Windows 原生验收仍待执行。" + "notes": "Viva:catalog.go 定义六个停靠区,dockdrag.go 处理拖动落点与遮罩,布局经 loadChrome 保存;组内排序和右键移动由 chrome_menu_test.go 覆盖;布局保存在全局 workbench-layout-v2.json,未按工作区分别恢复。 全页对照恢复活动侧栏蓝色与焦点相关的标签边框;项目渐变由根容器在子元素前绘制,不覆盖不透明工具面板。首次打开仅展开 Project,Git 按需打开,已有保存布局保持优先。像素回归 TestVisualWorkbenchGradientStaysBehindPanels 证明修复前失败、修复后通过;Windows 原生验收仍待执行。 侧栏按钮右键“隐藏入口”把按钮从侧栏收起,Core 布局状态记录 hidden 并保留原分区和位置;左侧栏上方组之后的“…”按钮只在有隐藏入口时出现,尺寸和间距与侧栏按钮一致、悬停显示名称,列出隐藏的工具窗口(图标、名称、快捷键,已打开的行高亮),点击行恢复按钮并打开窗口,行的右键“取消隐藏”只恢复按钮;隐藏按钮的窗口仍可由快捷键打开,此时“…”按钮高亮。TestHiddenStripeButtonIsListedUnderTheEllipsisAndComesBack、TestUnhidePutsTheButtonBackWithoutTouchingItsToolWindow 覆盖;macOS 与 Windows 实机验收待执行。" }