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
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.

2 changes: 2 additions & 0 deletions desktop/internal/pluginview/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Node struct {
Columns []Column `json:"columns,omitempty"`
Rows [][]string `json:"rows,omitempty"`
Tool string `json:"tool,omitempty"`
// Choose makes a tool row in a settings region also the tool's picker.
Choose bool `json:"choose,omitempty"`
// Height, ViewBox, Pan, Zoom, On and Nodes describe a canvas.
Height float64 `json:"height,omitempty"`
ViewBox [4]float64 `json:"viewBox,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions desktop/internal/pluginview/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type SettingsHost interface {
// Row draws the page's own row for a declared setting, exactly as the page draws it.
// It reports false when the page has no such row.
Row(c ui.C, setting string) bool
// Tool draws the toolchain pages' row for a tool the plugin defines or requires.
// It reports false when the host has no row for it.
Tool(c ui.C, tool string) bool
// Tool draws the toolchain pages' row for a tool the plugin defines or requires; with
// choose the row is also the tool's picker, whose choice edits the page's toolchain
// draft. It reports false when the host has no row for it.
Tool(c ui.C, tool string, choose bool) bool
// Binding is the draft of a declared setting for a control bound to it.
Binding(setting string) (Binding, bool)
// Action runs a setting action through the page's confirmation flow. It runs
Expand Down Expand Up @@ -254,7 +255,7 @@ func (r *renderer) node(c ui.C, n *Node) {
}
case "tool":
if r.host.Settings != nil {
r.host.Settings.Tool(c, n.Tool)
r.host.Settings.Tool(c, n.Tool, n.Choose)
}
case "tree":
r.tree(c, n)
Expand Down
120 changes: 112 additions & 8 deletions desktop/internal/settingswindow/plugin_region_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/1lck/Lithe-IDEA/desktop/internal/icons"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginview"
"github.com/1lck/Lithe-IDEA/desktop/internal/toolchain"
"github.com/vivaui/viva/ui"
)

Expand Down Expand Up @@ -48,8 +50,18 @@ type regionView struct {
// sent is the settings, encoded, that the paint before found, so a paint that finds
// them changed tells the view.
sent string
// picker is the tool whose picker is open, empty when none is; pickerShown says this
// paint drew it, so a picker whose row the view no longer shows closes.
picker string
pickerShown bool
}

// The tool picker's width, and the height its choices scroll beyond.
const (
toolPickerWidth = 560
toolPickerMaxHeight = 320
)

// pluginRegionOf is the region the form's plugin placed on the page on screen: on a page
// under Build or a contributed page the contributor's, on the plugin's own Settings tab the
// editor's. It is nil when the plugin placed none there.
Expand Down Expand Up @@ -98,7 +110,11 @@ func (w *window) pluginRegion(c ui.C, p *pluginSettingsForm, hasSource bool) {
}
v.host.Palette, v.host.Language = w.regionPalette(), language
v.host.Settings = regionSettings{w: w, p: p, hasSource: hasSource}
v.pickerShown = false
pluginview.Draw(c.Key("plugin-region:"+region.ID), v.session, &v.host, false)
if !v.pickerShown {
v.picker = ""
}
}

// openRegion makes and opens the view of key. Its calls carry the editor the form holds now,
Expand Down Expand Up @@ -194,16 +210,31 @@ func (s regionSettings) Row(c ui.C, setting string) bool {
return true
}

// Tool draws the toolchains list's row for the tool, in the scope the toolchain pages show.
// Choosing it opens the Toolchains page with the tool chosen, where it is configured.
func (s regionSettings) Tool(c ui.C, tool string) bool {
// toolScope is the toolchain scope beside the scope the page shows: the project's pins beside
// the project's settings, the machine's defaults beside the global ones. A window without the
// two scopes has the one it has.
func (s regionSettings) toolScope(t *toolchainState) *toolchainScope {
name := scopeGlobal
if s.p.scope == 1 {
name = scopeProject
}
if scope := t.scopes[name]; scope != nil {
return scope
}
return t.current()
}

// Tool draws the toolchains list's row for the tool, in the toolchain scope beside the scope
// the page shows. Pressing it opens the Toolchains page in that scope with the tool chosen;
// with choose, a tool the user may pin opens its picker instead (toolPicker).
func (s regionSettings) Tool(c ui.C, tool string, choose bool) bool {
w := s.w
t := w.toolchains
if t == nil || !t.available() {
return false
}
t.ensureLoaded()
scope := t.current()
scope := s.toolScope(t)
if scope == nil || !scope.loaded {
return false
}
Expand All @@ -213,16 +244,89 @@ func (s regionSettings) Tool(c ui.C, tool string) bool {
}
b := &w.bp
language := w.marketLanguage()
v := w.region
// Only a tool the scope holds and the user may pin has choices; any other row stays the
// way to the Toolchains page, which says why.
fresh := scope.tool(tool)
picks := choose && v != nil && fresh != nil && !fresh.ManagedOnly
open := picks && v.picker == tool
row := ui.ButtonBase(c, entry.tool.DisplayName).FillWidth().Height(toolchainToolRow).PadSides(0, 12, 0, 14).
Gap(9).Items(ui.Center).Radius(6).Border(1, b.line).Hover(ui.Look{}.Background(b.hover))
if row.Clicked() {
t.reveal(tool, t.view.group(tool))
w.openBuildChild(pageToolchains)
if open {
row = row.Border(1, b.accent)
}
clicked := row.Clicked()
row.Children(func() {
w.toolchainToolContent(c, language, scope, entry, "")
if picks {
ui.Icon(c, icons.ChevronDown).Size(14, 14).Color(b.sub).Shrink(0)
}
})
if !picks {
if clicked {
s.revealTool(t, scope, tool)
}
return true
}
if open {
v.pickerShown = true
s.toolPicker(c.Part("picker"), row, language, scope, fresh, &open)
} else if clicked {
// The add-directory field checks in the Toolchains page's scope, so the page follows
// the picker's.
t.setScope(scope.name)
open, v.pickerShown = true, true
}
switch {
case open:
v.picker = tool
case v.picker == tool:
v.picker = ""
}
row.Children(func() { w.toolchainToolContent(c, language, scope, entry, "") })
return true
}

// revealTool opens the Toolchains page in the scope with the tool chosen.
func (s regionSettings) revealTool(t *toolchainState, scope *toolchainScope, tool string) {
t.setScope(scope.name)
t.reveal(tool, t.view.group(tool))
s.w.openBuildChild(pageToolchains)
}

// toolPicker is the menu a tool row with choose opens, like an IDE's interpreter menu: the
// Toolchains page's choices for the tool in the scope (the automatic or inherited choice, then
// every home the scope knows with its version and sources), the field that adds a directory,
// and the way to the page. A choice is the scope's draft, which the footer's Apply writes and
// Cancel drops, and it closes the menu.
func (s regionSettings) toolPicker(c ui.C, row ui.Box, language i18n.Language, scope *toolchainScope, tool *toolchain.Tool, open *bool) {
w := s.w
t := w.toolchains
title := i18n.Shared(language, "desktop.buildSettings.optionsGlobal")
if scope.name == scopeProject {
title = i18n.Shared(language, "desktop.buildSettings.optionsProject")
}
spec := ui.PopoverSpec{Align: ui.Start, Width: toolPickerWidth, ConsumeOutsidePress: true, Title: title}
ui.PopoverWith(c, row, spec, open, func() {
before := scope.wanted(tool.ID)
current := toolchainCurrent(tool)
ui.Scroll(c.Part("choices")).Scrollbars().FillWidth().MaxHeight(toolPickerMaxHeight).Children(func() {
for _, option := range t.options(language, scope, tool) {
w.toolchainOption(c.Key("option:"+option.home), language, scope, tool, option, option.home == before, current)
}
})
w.toolchainAddRow(c.Part("add"), language, scope, tool)
ui.Row(c).FillWidth().PadX(8).PadY(4).Items(ui.Center).Children(func() {
if w.button(c.Part("toolchains"), buttonLinkSmall, i18n.Shared(language, "desktop.pluginView.toolPickerToolchains"), false) {
*open = false
s.revealTool(t, scope, tool.ID)
}
})
if scope.wanted(tool.ID) != before {
*open = false
}
})
}

// Binding is the draft of a declared setting a control can edit: a text, file, directory or
// integer setting's text, a boolean's switch and an enum's choice.
func (s regionSettings) Binding(setting string) (pluginview.Binding, bool) {
Expand Down
92 changes: 92 additions & 0 deletions desktop/internal/settingswindow/plugin_region_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/1lck/Lithe-IDEA/desktop/internal/marketplace"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginsettings"
"github.com/1lck/Lithe-IDEA/desktop/internal/toolchain"
)

// regionPlugin is the synthetic plugin whose settings page carries a region view.
Expand Down Expand Up @@ -408,3 +409,94 @@ func TestSearchFindsAPluginPageByItsRegionKeywords(t *testing.T) {
w.searchField.SetText("no such words")
d.until("a search no region matches", func() bool { return w.query == foldQuery("no such words") && !listed() })
}

// regionToolWindow opens the synthetic plugin's Settings tab, its region one row of the fixture
// tool the loader serves, the tool's picker with choose, and waits for the row.
func regionToolWindow(t *testing.T, loader ToolchainLoader, choose bool) (*window, *windowDriver) {
t.Helper()
view, _ := json.Marshal([]map[string]any{{"type": "tool", "tool": fixtureTool, "choose": choose}})
source := &regionSource{calls: make(chan regionCall, 32), view: view}
fetch := func(context.Context) (marketplace.Snapshot, error) {
return marketplace.Snapshot{Index: core.MarketplaceIndex{Plugins: []core.MarketplacePlugin{{ID: regionPlugin, Name: "Region Fixture", LatestVersion: "1.0.0"}}}}, nil
}
w := newWindow(NewController(Options{
Marketplace: fetch, MarketplaceInstalled: fetch, PluginSettings: source, Toolchains: loader,
PluginState: func(string) PluginState { return PluginState{Installed: true, Enabled: true, Version: "1.0.0"} },
InstalledPlugins: func() []PluginFacts {
return []PluginFacts{{ID: regionPlugin, Name: "Region Fixture", Version: "1.0.0", Settings: len(regionEditor().Snapshot.State.Rows)}}
},
}), Values{})
w.sess.page = pagePlugins
w.installed.tab = installedSettings
d := openWindow(t, w)
d.until("the region's tool row", func() bool { return d.has("Compiler") })
d.pump()
return w, d
}

// A tool row with choose opens the tool's choices under it in the plugin page's scope; a
// choice is a draft of that scope that closes the choices and waits for the footer's Apply.
func TestRegionToolPickerChoosesIntoTheToolchainDraft(t *testing.T) {
loader := &scopedToolchainLoader{fakeToolchainLoader{snapshot: fixtureSnapshot(), saved: make(chan []toolchain.Edit, 1)}}
w, d := regionToolWindow(t, loader, true)
manage := en("desktop.pluginView.toolPickerToolchains")
if d.has(manage) || d.has("/fixture/compiler") {
t.Fatal("the tool's choices show before the row is pressed")
}
// The plugin page shows the global settings, and the project scope is the one the
// Toolchains page shows; the picker follows the plugin page.
w.toolchains.setScope(scopeProject)
d.click("Compiler")
d.until("the tool's choices", func() bool { return d.has(manage) && d.has("/fixture/compiler") })
if w.toolchains.scope != scopeGlobal {
t.Fatalf("the picker opened with the Toolchains page in the %s scope, want the plugin page's", w.toolchains.scope)
}
d.click("/fixture/compiler")
d.pump()
global := w.toolchains.scopes[scopeGlobal]
if global.draft[fixtureTool] != "/fixture/compiler" || w.toolchains.drafts(scopeProject) != 0 {
t.Fatalf("the choice drafted %v globally and %d in the project, want the installation globally", global.draft, w.toolchains.drafts(scopeProject))
}
if d.has(manage) || w.region.picker != "" {
t.Fatal("the choices stayed open after a choice")
}
select {
case edits := <-loader.saved:
t.Fatalf("choosing wrote %+v before Apply", edits)
default:
}
d.applyBuild()
select {
case edits := <-loader.saved:
if len(edits) != 1 || edits[0].Tool != fixtureTool || edits[0].Pin == nil || edits[0].Pin.Home != "/fixture/compiler" {
t.Fatalf("Apply wrote %+v, want the chosen installation pinned", edits)
}
default:
t.Fatal("Apply did not write the choice")
}
if len(global.draft) != 0 {
t.Fatalf("the applied choice is still a draft: %v", global.draft)
}
}

// The picker's way to the Toolchains page, and a press on a row without choose, open the page
// in the plugin page's scope with the tool chosen.
func TestRegionToolRowOpensTheToolchainsPage(t *testing.T) {
for _, choose := range []bool{true, false} {
w, d := regionToolWindow(t, &scopedToolchainLoader{fakeToolchainLoader{snapshot: fixtureSnapshot()}}, choose)
w.toolchains.setScope(scopeProject)
d.click("Compiler")
if choose {
manage := en("desktop.pluginView.toolPickerToolchains")
d.until("the tool's choices", func() bool { return d.has(manage) })
d.click(manage)
}
d.until("the Toolchains page", func() bool { return w.sess.page == pageToolchains })
if w.toolchains.scope != scopeGlobal || w.toolchains.selected != fixtureTool {
t.Fatalf("choose %v: the Toolchains page opened in the %s scope on %q, want the global scope on the tool", choose, w.toolchains.scope, w.toolchains.selected)
}
if w.region != nil && w.region.picker != "" {
t.Fatalf("choose %v: the picker stayed open after leaving for the Toolchains page", choose)
}
}
}
Loading
Loading