Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions desktop/internal/core/chrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ type ChromeItem struct {
// ID is the stable host identifier, persisted in placements. It must be unique and not
// empty.
ID string `json:"id"`
// DefaultZone is the zone of the default layout. Its surface (the tool stripes, the title
// bar or the status bar) is the only surface the item may ever sit in.
// DefaultZone is the zone of the default layout. The item may sit only in zones of its
// surface (the tool stripes, the title bar or the status bar), unless AlsoOnToolStripes adds
// the stripe zones.
DefaultZone Zone `json:"defaultZone"`
// Panel reports that the button opens a tool panel in its zone's panel slot. Only the six
// tool stripe zones can host a panel.
Panel bool `json:"panel,omitempty"`
// OpenByDefault reports that the panel is open in the default layout. It requires Panel.
OpenByDefault bool `json:"openByDefault,omitempty"`
// AlsoOnToolStripes lets a title bar item sit in the six tool stripe zones too and come back
// to the title bar. On a stripe the item still opens no panel and cannot be hidden. Only
// title bar items may set it.
AlsoOnToolStripes bool `json:"alsoOnToolStripes,omitempty"`
}

// Placement is the zone of one item. The order of the placements that share a zone is the
Expand Down Expand Up @@ -133,8 +138,8 @@ func ResetChrome() ChromeAction {

// MoveChrome moves the item id into zone, in front of the item before when that item sits in
// zone and at the end of the zone otherwise. An empty before always means the end. The zone
// must belong to the item's own surface; moving a stripe button into the status bar fails with
// CodeInvalidRequest.
// must belong to the item's own surface, or be a stripe zone for an item marked
// AlsoOnToolStripes; moving a stripe button into the status bar fails with CodeInvalidRequest.
func MoveChrome(id string, zone Zone, before string) ChromeAction {
return ChromeAction{kind: chromeMove, id: id, zone: zone, before: before}
}
Expand All @@ -152,7 +157,8 @@ func SetChromeOpen(id string, open bool) ChromeAction {

// 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.
// stripe items can be hidden; a title or status bar item fails with CodeInvalidRequest, also
// when it is a title bar item that sits on a stripe.
func SetChromeHidden(id string, hidden bool) ChromeAction {
return ChromeAction{kind: chromeSetHidden, id: id, hidden: hidden}
}
Expand Down Expand Up @@ -231,9 +237,10 @@ type chromeLayoutResponse struct {
// moving an open panel takes its open state into the target zone.
//
// 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, opens an item that is not a
// panel or hides an item outside the tool stripes.
// panel outside the tool stripes, a default-open item that is not a panel, AlsoOnToolStripes on
// an item outside the title bar) and for an action that names an unknown item, moves an item to
// a zone it may not sit in, opens an item that is not a panel or hides an item whose default
// zone is not on a tool stripe.
//
// 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) {
Expand Down
38 changes: 37 additions & 1 deletion desktop/internal/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,15 @@ func TestReduceRecentProjectsRejectsInvalidInput(t *testing.T) {
}

// chromeCatalog returns the catalog the chrome layout tests use: two panels on the upper left,
// one at the bottom left, and one plain button each on the title bar and the status bar.
// one at the bottom left, two plain title bar buttons, the second of which may also sit on the
// stripes, and one plain status bar button.
func chromeCatalog() []ChromeItem {
return []ChromeItem{
{ID: "project", DefaultZone: ZoneLeftTop, Panel: true, OpenByDefault: true},
{ID: "commit", DefaultZone: ZoneLeftTop, Panel: true},
{ID: "git", DefaultZone: ZoneBottomLeft, Panel: true},
{ID: "run", DefaultZone: ZoneTitleTrailing},
{ID: "settings", DefaultZone: ZoneTitleTrailing, AlsoOnToolStripes: true},
{ID: "caret", DefaultZone: ZoneStatusTrailing},
}
}
Expand Down Expand Up @@ -602,6 +604,7 @@ func TestReduceChromeLayout(t *testing.T) {
{ID: "commit", Zone: ZoneLeftTop},
{ID: "git", Zone: ZoneBottomLeft},
{ID: "run", Zone: ZoneTitleTrailing},
{ID: "settings", Zone: ZoneTitleTrailing},
{ID: "caret", Zone: ZoneStatusTrailing},
},
Open: []string{"project"},
Expand Down Expand Up @@ -679,6 +682,35 @@ func TestReduceChromeLayout(t *testing.T) {
requireCode(t, err, CodeInvalidRequest)
})

// A title bar item marked AlsoOnToolStripes moves onto a stripe and back, keeps the title bar
// rules there (it cannot be hidden or go into the status bar), and normalize keeps it there.
t.Run("a marked title item moves onto a stripe and back", func(t *testing.T) {
layout, changed := reduce(t, defaults, MoveChrome("settings", ZoneLeftTop, "commit"))
if !changed {
t.Error("changed = false, want true")
}
if got := zoneIDs(layout, ZoneLeftTop); !slices.Equal(got, []string{"project", "settings", "commit"}) {
t.Errorf("left top = %q, want [project settings commit]", got)
}
if got := zoneIDs(layout, ZoneTitleTrailing); !slices.Equal(got, []string{"run"}) {
t.Errorf("title = %q, want [run]", got)
}
if _, changed := reduce(t, layout, NormalizeChrome()); changed {
t.Error("normalizing a stripe placement of settings: changed = true, want false")
}
_, _, err := client.ReduceChromeLayout(ctx, catalog, layout, SetChromeHidden("settings", true))
requireCode(t, err, CodeInvalidRequest)
_, _, err = client.ReduceChromeLayout(ctx, catalog, layout, MoveChrome("settings", ZoneStatusTrailing, ""))
requireCode(t, err, CodeInvalidRequest)
back, _ := reduce(t, layout, MoveChrome("settings", ZoneTitleTrailing, "run"))
if got := zoneIDs(back, ZoneTitleTrailing); !slices.Equal(got, []string{"settings", "run"}) {
t.Errorf("title after moving back = %q, want [settings run]", got)
}
if got := zoneIDs(back, ZoneLeftTop); !slices.Equal(got, []string{"project", "commit"}) {
t.Errorf("left top after moving back = %q, want [project commit]", got)
}
})

t.Run("toggle and set open", func(t *testing.T) {
layout, changed := reduce(t, defaults, ToggleChrome("git"))
if !changed || !slices.Equal(layout.Open, []string{"project", "git"}) {
Expand Down Expand Up @@ -772,6 +804,9 @@ func TestReduceChromeLayout(t *testing.T) {
}
_, _, err := client.ReduceChromeLayout(ctx, repeated, ChromeLayout{}, ResetChrome())
requireCode(t, err, CodeInvalidRequest)
stripeOnStripe := []ChromeItem{{ID: "a", DefaultZone: ZoneLeftTop, AlsoOnToolStripes: true}}
_, _, err = client.ReduceChromeLayout(ctx, stripeOnStripe, ChromeLayout{}, ResetChrome())
requireCode(t, err, CodeInvalidRequest)
})

t.Run("zero action", func(t *testing.T) {
Expand Down Expand Up @@ -842,6 +877,7 @@ func TestChromeJSON(t *testing.T) {
{"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}`},
{"title item also on the stripes", ChromeItem{ID: "a", DefaultZone: ZoneTitleTrailing, AlsoOnToolStripes: true}, `{"id":"a","defaultZone":"titleTrailing","alsoOnToolStripes":true}`},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/i18n/shared.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion desktop/internal/workbench/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,15 @@ func (a *App) performedIn(ctx context.Context, action string, surface actionSurf
return core.WithOrigin(ctx, core.Origin{Operation: id, Trigger: action})
}

// chromeSurface is the surface a click on the rearrangeable button of catalog item index
// comes from: the toolbar while the button sits in the title bar, a button on a stripe.
func (a *App) chromeSurface(index int) actionSurface {
if a.chrome.zoneOf(index).surface() == surfaceTitle {
return surfaceToolbar
}
return surfaceButton
}

// titleBarHeight is the height of the title bar on both screens; the system's window
// buttons sit in it.
const titleBarHeight = 40
Expand Down Expand Up @@ -1344,7 +1353,7 @@ func (a *App) activate(index int) {
a.titleDebug(a.project)
case it.id == itemTitleSearch:
if a.project != nil {
a.performed("workspace.searchEverywhere.open", surfaceToolbar)
a.performed("workspace.searchEverywhere.open", a.chromeSurface(index))
a.openEverywhere(a.project)
}
case it.id == itemCaret:
Expand Down
21 changes: 16 additions & 5 deletions desktop/internal/workbench/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const (
// item is one button the workbench can show in its rearrangeable chrome.
type item struct {
id string
zone zone // the default zone; its surface is the only one the item may sit in
zone zone // the default zone; the item sits only in its surface's zones unless stripes is set
// icon is the glyph of the button; nil for a status item that is text only.
icon *gfx.Icon
// label is the button's name, read by assistive technology and, on a button that is only
Expand All @@ -204,6 +204,9 @@ type item struct {
panel bool
// open reports that the tool window is open in the default layout.
open bool
// stripes lets a title bar item also sit in the six tool stripe zones. It does the same thing
// there, opens no tool window and still cannot be hidden.
stripes bool
// tool is the plugin tool window the item shows; nil for a built-in item.
tool *pluginservice.ToolWindow
// vcs is the plugin version control provider whose window the item shows (vcs.go); nil for
Expand Down Expand Up @@ -252,9 +255,9 @@ var catalog = []item{

{id: itemRunConfig, zone: zoneTitle, icon: &icons.FileCode, label: func(m *i18n.Messages) string { return m.Title.RunConfiguration }},
{id: itemTitleRun, zone: zoneTitle, icon: &icons.Play, label: func(m *i18n.Messages) string { return m.Title.Run }},
{id: itemTitleDebug, zone: zoneTitle, icon: &icons.Bug, label: func(m *i18n.Messages) string { return m.Title.Debug }},
{id: itemTitleSearch, zone: zoneTitle, icon: &icons.Search, label: func(m *i18n.Messages) string { return m.Title.Search }, shortcut: "search.everywhere"},
{id: itemTitleSettings, zone: zoneTitle, icon: &icons.Settings, label: func(m *i18n.Messages) string { return m.Title.Settings }},
{id: itemTitleDebug, zone: zoneTitle, icon: &icons.Bug, label: func(m *i18n.Messages) string { return m.Title.Debug }, stripes: true},
{id: itemTitleSearch, zone: zoneTitle, icon: &icons.Search, label: func(m *i18n.Messages) string { return m.Title.Search }, shortcut: "search.everywhere", stripes: true},
{id: itemTitleSettings, zone: zoneTitle, icon: &icons.Settings, label: func(m *i18n.Messages) string { return m.Title.Settings }, stripes: true},

{id: itemCaret, zone: zoneStatus, label: func(m *i18n.Messages) string { return m.Status.Caret }},
{id: itemLock, zone: zoneStatus, icon: &icons.LockOpen, label: func(m *i18n.Messages) string { return m.Status.Writable }},
Expand Down Expand Up @@ -341,7 +344,7 @@ func (c *chromeState) setItems(items []item) {
c.index = make(map[string]int, len(items))
c.coreItems = make([]core.ChromeItem, len(items))
for i, it := range items {
c.coreItems[i] = core.ChromeItem{ID: it.id, DefaultZone: zoneNames[it.zone], Panel: it.panel, OpenByDefault: it.open}
c.coreItems[i] = core.ChromeItem{ID: it.id, DefaultZone: zoneNames[it.zone], Panel: it.panel, OpenByDefault: it.open, AlsoOnToolStripes: it.stripes}
c.index[it.id] = i
}
c.zones = make([]zone, len(items))
Expand Down Expand Up @@ -490,6 +493,14 @@ func (c *chromeState) apply(layout core.ChromeLayout) {
// hidden.
func (c *chromeState) zoneOf(index int) zone { return c.zones[index] }

// allowed reports whether catalog item index may sit in zone z: a zone of the surface of its
// default zone, or a stripe zone for a title bar item that may also sit on the stripes. The
// kernel enforces the same rule; the drag asks it where the button may land.
func (c *chromeState) allowed(index int, z zone) bool {
it := c.catalog[index]
return z.surface() == it.zone.surface() || it.stripes && z.surface() == surfaceStripes
}

// isHidden reports whether the user hid the stripe button of catalog item index.
func (c *chromeState) isHidden(index int) bool { return c.hiddenMark[index] }

Expand Down
Loading
Loading