diff --git a/.agents/notes/implemented/architecture/2026-10-25-settings-native-configuration-editing.md b/.agents/notes/implemented/architecture/2026-10-25-settings-native-configuration-editing.md index 36cc0df587..335f3a43e5 100644 --- a/.agents/notes/implemented/architecture/2026-10-25-settings-native-configuration-editing.md +++ b/.agents/notes/implemented/architecture/2026-10-25-settings-native-configuration-editing.md @@ -107,6 +107,18 @@ Provider 读取实际生效值及已发布的源哈希;回读失败保留草 Maven 模型缓存版本 2 保存上游实际选中的来源,即使来源由带空格路径的 `.mvn/maven.config` 指定,外部编辑或删除也会使缓存失效;不以宿主猜测的默认路径代替上游事实。 +### 模块结构:侧栏、标签页和条目列表 + +2026-11-17(#2086)起宿主声明 `sourceSettings` 版本 1,对标 IDEA“项目结构 → 模块”:插件把每个模块投影成侧栏组里的一个来源(`parent` 表示父模块),字段按 `section` 分成“源 / 路径 / 依赖”等标签页,依赖、源目录这类有序列表用 `entryList` 字段。宿主只做通用渲染,不认识任何工具: + +- 模块列表在表单左侧,只显示所选模块;浏览模块和标签页不产生草稿,也不读写文件。只有一组字段时不显示标签。 +- 条目列表的添加菜单按插件声明的条目种类走:`file` / `directory` 打开原生选择器,返回绝对路径由插件换算成工具写法;`choice` 打开候选项对话框,只列尚未在列表中的项。导出、作用域等属性是条目行右侧的布尔/枚举列。 +- 条目的 `title` / `detail` 只用于显示。宿主比较草稿、Core 比较和规划写入时都忽略它们,写给插件的值里也会去掉。 +- 全部移除是显式的空列表,不等于“继承”;插件没有给出继承值时不提供“重置”,以免一次点击清空列表。 +- 只读来源(依赖由 Maven/Gradle/IDEA 文件决定的模块)只显示条目,没有工具栏和选中状态。 + +正确做法:Eclipse 模块的依赖在插件里改写 `.classpath`,保留未知条目和属性;宿主只把用户的顺序、增删和属性交给 Core。错误做法:宿主根据路径后缀猜测条目种类,或把标题写回工具文件。 + ## 考虑过的备选方案 - 只提示默认路径、要求用户重新填写:省去读取逻辑,但无法证明显示值与工具一致,也增加误操作,因此不作为非敏感配置的默认交互。 diff --git a/desktop/internal/core/source_settings.go b/desktop/internal/core/source_settings.go index 3ff050b505..7d7b9bcd9d 100644 --- a/desktop/internal/core/source_settings.go +++ b/desktop/internal/core/source_settings.go @@ -30,18 +30,61 @@ type SettingsSource struct { Revision string `json:"revision"` Writable bool `json:"writable"` Fields []SourceSettingField `json:"fields"` + // Parent names an earlier source of the same sidebar group under which + // the module list nests this one. + Parent string `json:"parent,omitempty"` } type SourceSettingField struct { - ID string `json:"id"` - Title string `json:"title"` - Description string `json:"description,omitempty"` + ID string `json:"id"` + Title string `json:"title"` + Description string `json:"description,omitempty"` + // Section is the tab (sidebar) or subheading (form) holding the field. + Section string `json:"section,omitempty"` Kind string `json:"kind"` Value json.RawMessage `json:"value"` InheritedValue json.RawMessage `json:"inheritedValue,omitempty"` EffectiveValue json.RawMessage `json:"effectiveValue"` EffectiveSource string `json:"effectiveSource"` Options []PluginSettingOption `json:"options,omitempty"` + // EntryKinds and Attributes describe an entryList's add menu and columns. + EntryKinds []SourceEntryKind `json:"entryKinds,omitempty"` + Attributes []SourceEntryAttribute `json:"attributes,omitempty"` +} + +// SourceEntryKind is one item of an entryList's add menu: a native file or +// directory picker, or a choice among values the plugin offers now. +type SourceEntryKind struct { + ID string `json:"id"` + Title string `json:"title"` + Input string `json:"input"` + Extensions []string `json:"extensions,omitempty"` + Choices []SourceEntryChoice `json:"choices,omitempty"` +} + +type SourceEntryChoice struct { + Value string `json:"value"` + Title string `json:"title"` + Detail string `json:"detail,omitempty"` +} + +// SourceEntryAttribute is a per-entry boolean or enum column. +type SourceEntryAttribute struct { + ID string `json:"id"` + Title string `json:"title"` + Kind string `json:"kind"` + Options []PluginSettingOption `json:"options,omitempty"` +} + +// SourceEntry is one ordered entryList item. Title and Detail are display text +// Core ignores when it compares and plans edits. +type SourceEntry struct { + Kind string `json:"kind"` + Value string `json:"value"` + Title string `json:"title,omitempty"` + Detail string `json:"detail,omitempty"` + // Attributes holds a bool or an option value per declared attribute ID. + Attributes map[string]any `json:"attributes,omitempty"` } // SourceSettingInput is the unparsed view draft projected by Core. Inherit @@ -51,6 +94,8 @@ type SourceSettingInput struct { Choice string `json:"choice"` On bool `json:"on"` Inherit bool `json:"inherit"` + // Entries is the ordered entryList draft; other kinds leave it empty. + Entries []SourceEntry `json:"entries"` } type SourceSettingsLimits struct { diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 90d4fea4c4..548ba36585 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1589,11 +1589,21 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.updates.waiting": "Lithe moves back to Stable with the first stable release after {version}.", "desktop.sourceSettings.add": "Add override", "desktop.sourceSettings.allEntriesShown": "All available entries are shown.", + "desktop.sourceSettings.cancel": "Cancel", + "desktop.sourceSettings.chooseNone": "Everything that can be added is already listed.", + "desktop.sourceSettings.chooseTitle": "Add {title}", "desktop.sourceSettings.close": "Back", "desktop.sourceSettings.compilerTitle": "{compiler} Compiler", "desktop.sourceSettings.effective": "Effective: {value}", + "desktop.sourceSettings.entryAdd": "Add", + "desktop.sourceSettings.entryDown": "Move down", + "desktop.sourceSettings.entryEmpty": "No entries", + "desktop.sourceSettings.entryKind": "{title}…", + "desktop.sourceSettings.entryRemove": "Remove", + "desktop.sourceSettings.entryUp": "Move up", "desktop.sourceSettings.fileCount": "{count} entries", "desktop.sourceSettings.inherit": "Inherit ({value})", + "desktop.sourceSettings.modules": "Modules", "desktop.sourceSettings.noValue": "Not determined", "desktop.sourceSettings.remove": "Inherit project defaults", "desktop.startupSweep.body": "{arg1} processes started by an earlier run of Lithe are still running. Ending them stops them.", @@ -4369,11 +4379,21 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.settings.updates.waiting": "正式版发布 {version} 之后的版本时切回正式版。", "desktop.sourceSettings.add": "添加覆盖", "desktop.sourceSettings.allEntriesShown": "所有可用条目已列出。", + "desktop.sourceSettings.cancel": "取消", + "desktop.sourceSettings.chooseNone": "可添加的项都已在列表中。", + "desktop.sourceSettings.chooseTitle": "添加{title}", "desktop.sourceSettings.close": "返回", "desktop.sourceSettings.compilerTitle": "{compiler} 编译器", "desktop.sourceSettings.effective": "当前生效:{value}", + "desktop.sourceSettings.entryAdd": "添加", + "desktop.sourceSettings.entryDown": "下移", + "desktop.sourceSettings.entryEmpty": "没有条目", + "desktop.sourceSettings.entryKind": "{title}…", + "desktop.sourceSettings.entryRemove": "移除", + "desktop.sourceSettings.entryUp": "上移", "desktop.sourceSettings.fileCount": "{count} 项", "desktop.sourceSettings.inherit": "继承({value})", + "desktop.sourceSettings.modules": "模块", "desktop.sourceSettings.noValue": "未确定", "desktop.sourceSettings.remove": "继承项目设置", "desktop.startupSweep.body": "上次运行 Lithe 启动的 {arg1} 个进程仍在运行。结束它们会停止这些进程。", diff --git a/desktop/internal/pluginhost/pluginhost.go b/desktop/internal/pluginhost/pluginhost.go index 4b9d746812..51745d672f 100644 --- a/desktop/internal/pluginhost/pluginhost.go +++ b/desktop/internal/pluginhost/pluginhost.go @@ -164,6 +164,9 @@ func Declared() Capabilities { for _, name := range baseline { declared[name] = []int{0} } + // Version 1 adds module sidebars, field sections and entry lists, which the + // settings window's source forms render. + declared["sourceSettings"] = []int{0, 1} return declared } diff --git a/desktop/internal/pluginhost/pluginhost_test.go b/desktop/internal/pluginhost/pluginhost_test.go index ea4dd715a7..0b3f291225 100644 --- a/desktop/internal/pluginhost/pluginhost_test.go +++ b/desktop/internal/pluginhost/pluginhost_test.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "runtime" + "slices" "testing" ) @@ -66,8 +67,14 @@ func TestDeclaredServesTheBaselineOfEveryWiredCapability(t *testing.T) { t.Fatalf("declared = %v", declared) } for _, name := range want { - if versions := declared[name]; len(versions) != 1 || versions[0] != 0 { - t.Fatalf("%s = %v, want [0]", name, versions) + wanted := []int{0} + // The settings window renders the module sidebars, sections and entry + // lists that version 1 adds. + if name == "sourceSettings" { + wanted = []int{0, 1} + } + if versions := declared[name]; !slices.Equal(versions, wanted) { + t.Fatalf("%s = %v, want %v", name, versions, wanted) } } // Capabilities nothing here serves stay absent so their plugins are not diff --git a/desktop/internal/settingswindow/source_settings_entries.go b/desktop/internal/settingswindow/source_settings_entries.go new file mode 100644 index 0000000000..850f4d0200 --- /dev/null +++ b/desktop/internal/settingswindow/source_settings_entries.go @@ -0,0 +1,310 @@ +package settingswindow + +import ( + "path/filepath" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/vivaui/viva/ui" +) + +// maximumSourceEntries is the contract's bound on one entryList; the add menu +// stops offering entries past it rather than letting Save fail. +const maximumSourceEntries = 256 + +// sourceRowKind says what a row of a source form's list shows. +type sourceRowKind uint8 + +const ( + sourceRowGroup sourceRowKind = iota // a group's heading (and a table's add control) + sourceRowTable // one source of a table group + sourceRowField // one field of a form or sidebar source + sourceRowEntry // one entry of the entryList field above it + sourceRowModule // the selected sidebar source's name and file + sourceRowTabs // the selected sidebar source's sections +) + +type sourceSettingsRow struct { + kind sourceRowKind + group int + source int + field int + entry int + // heading is the section a form field starts, shown above it. + heading string +} + +// sourceNavItem is a row of the module list beside a form with a sidebar group: +// a sidebar group's heading, one of its sources, or a whole other group. +type sourceNavItem struct { + group int + source int // -1 for a heading or a whole group + depth int + heading bool +} + +// sourceEntryChooser is the dialog that adds entries of a choice kind. +type sourceEntryChooser struct { + open bool + source, field string + kind int + picked []bool + list ui.ListState +} + +func cloneSourceInput(input core.SourceSettingInput) core.SourceSettingInput { + entries := make([]core.SourceEntry, len(input.Entries)) + for index, entry := range input.Entries { + entries[index] = cloneSourceEntry(entry) + } + input.Entries = entries + return input +} + +func cloneSourceEntry(entry core.SourceEntry) core.SourceEntry { + if entry.Attributes != nil { + attributes := make(map[string]any, len(entry.Attributes)) + for id, value := range entry.Attributes { + attributes[id] = value + } + entry.Attributes = attributes + } + return entry +} + +// sameSourceInput compares drafts as Core does: entry display text never makes +// two drafts differ. +func sameSourceInput(a, b core.SourceSettingInput) bool { + if a.Text != b.Text || a.Choice != b.Choice || a.On != b.On || a.Inherit != b.Inherit || len(a.Entries) != len(b.Entries) { + return false + } + for index := range a.Entries { + x, y := a.Entries[index], b.Entries[index] + if x.Kind != y.Kind || x.Value != y.Value || len(x.Attributes) != len(y.Attributes) { + return false + } + for id, value := range x.Attributes { + if other, ok := y.Attributes[id]; !ok || other != value { + return false + } + } + } + return true +} + +func entryKindIndex(field core.SourceSettingField, kind string) int { + for index, candidate := range field.EntryKinds { + if candidate.ID == kind { + return index + } + } + return -1 +} + +// entryLabel is what an entry's row shows: the plugin's title, else the value. +func entryLabel(entry core.SourceEntry) string { + if entry.Title != "" { + return entry.Title + } + return entry.Value +} + +// entryBool is a boolean attribute; absent, the plugin's default, shown as off. +// Core admits only booleans for a boolean attribute. +func entryBool(entry core.SourceEntry, id string) bool { + on, _ := entry.Attributes[id].(bool) + return on +} + +// entryChoice is an enum attribute's value; absent, the plugin's default, which +// the host shows as the first option. +func entryChoice(entry core.SourceEntry, attribute core.SourceEntryAttribute) string { + if value, ok := entry.Attributes[attribute.ID].(string); ok { + return value + } + if len(attribute.Options) > 0 { + return attribute.Options[0].Value + } + return "" +} + +func setEntryAttribute(entry *core.SourceEntry, id string, value any) { + if entry.Attributes == nil { + entry.Attributes = make(map[string]any) + } + entry.Attributes[id] = value +} + +func hasEntry(entries []core.SourceEntry, kind, value string) bool { + for _, entry := range entries { + if entry.Kind == kind && entry.Value == value { + return true + } + } + return false +} + +// pathEntries turns the paths a native picker returned into entries of kind, +// skipping ones the list already holds and any past the contract's bound. +func pathEntries(existing []core.SourceEntry, kind string, paths []string) []core.SourceEntry { + var added []core.SourceEntry + for _, path := range paths { + if path == "" || hasEntry(existing, kind, path) || hasEntry(added, kind, path) || len(existing)+len(added) >= maximumSourceEntries { + continue + } + added = append(added, core.SourceEntry{Kind: kind, Value: path, Title: filepath.Base(path), Detail: filepath.Dir(path)}) + } + return added +} + +// choiceEntries is the choices of kind the list does not hold yet, by index. +func choiceEntries(field core.SourceSettingField, kind int, entries []core.SourceEntry) []int { + var available []int + for index, choice := range field.EntryKinds[kind].Choices { + if !hasEntry(entries, field.EntryKinds[kind].ID, choice.Value) { + available = append(available, index) + } + } + return available +} + +// editEntries applies one change to an entryList draft. A draft that holds a +// list is an explicit value, even an empty one. +func (p *sourceSettingsForm) editEntries(source string, field core.SourceSettingField, edit func(*sourceSettingControl)) { + control := p.controls[source][field.ID] + edit(control) + control.input.Inherit = false + if control.entry >= len(control.input.Entries) { + control.entry = len(control.input.Entries) - 1 + } + control.syncAttributes(field) + p.changed(source, field.ID) + p.layoutDirty = true +} + +func (p *sourceSettingsForm) addEntries(source string, field core.SourceSettingField, entries []core.SourceEntry) { + if len(entries) == 0 { + return + } + p.editEntries(source, field, func(control *sourceSettingControl) { + control.input.Entries = append(control.input.Entries, entries...) + control.entry = len(control.input.Entries) - 1 + }) +} + +func (p *sourceSettingsForm) removeEntry(source string, field core.SourceSettingField) { + p.editEntries(source, field, func(control *sourceSettingControl) { + if index := control.entry; index >= 0 && index < len(control.input.Entries) { + control.input.Entries = append(control.input.Entries[:index], control.input.Entries[index+1:]...) + } + }) +} + +func (p *sourceSettingsForm) moveEntry(source string, field core.SourceSettingField, by int) { + p.editEntries(source, field, func(control *sourceSettingControl) { + from, to := control.entry, control.entry+by + if from < 0 || to < 0 || to >= len(control.input.Entries) { + return + } + entries := control.input.Entries + entries[from], entries[to] = entries[to], entries[from] + control.entry = to + }) +} + +// navigation lists the module list of a form that has a sidebar group, and keeps +// the selection on an item that still exists; a form without one has no list. +func (p *sourceSettingsForm) navigation() { + snapshot := &p.editor.State.Snapshot + p.nav = p.nav[:0] + sidebar := false + for _, section := range p.editor.State.Layout { + sidebar = sidebar || snapshot.Groups[section.Group].Layout == "sidebar" + } + if !sidebar { + return + } + depths := make(map[string]int) + for _, section := range p.editor.State.Layout { + if snapshot.Groups[section.Group].Layout != "sidebar" { + p.nav = append(p.nav, sourceNavItem{group: section.Group, source: -1}) + continue + } + p.nav = append(p.nav, sourceNavItem{group: section.Group, source: -1, heading: true}) + for _, index := range section.Sources { + source := snapshot.Sources[index] + depth := 0 + if parent, ok := depths[source.Parent]; ok && source.Parent != "" { + depth = parent + 1 + } + depths[source.ID] = depth + p.nav = append(p.nav, sourceNavItem{group: section.Group, source: index, depth: depth + 1}) + } + } + for _, item := range p.nav { + if !item.heading && p.navSelected(item) { + return + } + } + for _, item := range p.nav { + if !item.heading { + p.selectNav(item) + return + } + } +} + +func (p *sourceSettingsForm) navSelected(item sourceNavItem) bool { + snapshot := &p.editor.State.Snapshot + if snapshot.Groups[item.group].ID != p.selectedGroup { + return false + } + if item.source < 0 { + return p.selectedSource == "" + } + return snapshot.Sources[item.source].ID == p.selectedSource +} + +func (p *sourceSettingsForm) selectNav(item sourceNavItem) { + snapshot := &p.editor.State.Snapshot + p.selectedGroup, p.selectedSource = snapshot.Groups[item.group].ID, "" + if item.source >= 0 { + p.selectedSource = snapshot.Sources[item.source].ID + } + p.layoutDirty = true +} + +// sections is the tabs of a sidebar source, in order of first appearance. +func sourceSections(source core.SettingsSource) []string { + var sections []string + seen := make(map[string]bool) + for _, field := range source.Fields { + if field.Section != "" && !seen[field.Section] { + seen[field.Section] = true + sections = append(sections, field.Section) + } + } + return sections +} + +// fieldRows appends a source's fields, each entryList followed by its entries. +// A field that starts a section of a form carries it as its heading. +func (p *sourceSettingsForm) fieldRows(group, sourceIndex int, include func(core.SourceSettingField) bool, headings bool) { + source := p.editor.State.Snapshot.Sources[sourceIndex] + previous := "" + for fieldIndex, field := range source.Fields { + if !include(field) { + continue + } + row := sourceSettingsRow{kind: sourceRowField, group: group, source: sourceIndex, field: fieldIndex, entry: -1} + if headings && field.Section != previous { + row.heading = field.Section + } + previous = field.Section + p.rows = append(p.rows, row) + if field.Kind == "entryList" { + for entry := range p.controls[source.ID][field.ID].input.Entries { + p.rows = append(p.rows, sourceSettingsRow{kind: sourceRowEntry, group: group, source: sourceIndex, field: fieldIndex, entry: entry}) + } + } + } +} diff --git a/desktop/internal/settingswindow/source_settings_entries_view.go b/desktop/internal/settingswindow/source_settings_entries_view.go new file mode 100644 index 0000000000..ab480fbae9 --- /dev/null +++ b/desktop/internal/settingswindow/source_settings_entries_view.go @@ -0,0 +1,280 @@ +package settingswindow + +import ( + "errors" + "strings" + + "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/vivaui/viva/app" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// Widths of an entry list's attribute columns, shared by the heading and the rows. +const ( + entryFlagWidth = 64 + entryChoiceWidth = 120 +) + +func entryAttributeWidth(attribute core.SourceEntryAttribute) float32 { + if attribute.Kind == "boolean" { + return entryFlagWidth + } + return entryChoiceWidth +} + +func sourceEntriesDisabled(p *sourceSettingsForm, source core.SettingsSource) bool { + return p.busy || p.stale || !source.Writable +} + +// sourceEntryToolbar is the line above an entry list: add, remove, move up and +// down, and the headings of its attribute columns. A read-only list keeps only +// the headings. +func (w *window) sourceEntryToolbar(c ui.C, p *sourceSettingsForm, source core.SettingsSource, field core.SourceSettingField) { + language := w.marketLanguage() + control := p.controls[source.ID][field.ID] + disabled := sourceEntriesDisabled(p, source) + entries := control.input.Entries + // A read-only list without attribute columns has nothing to put on the line. + if !source.Writable && (len(field.Attributes) == 0 || len(entries) == 0) { + if len(entries) == 0 { + ui.Text(c, i18n.Shared(language, "desktop.sourceSettings.entryEmpty")).FontSize(12).Color(w.pal.muted).PadX(8) + } + return + } + ui.Row(c).FillWidth().Height(28).PadRight(8).Items(ui.Center).Gap(2).Children(func() { + if source.Writable { + addLabel := i18n.Shared(language, "desktop.sourceSettings.entryAdd") + add := ui.Button(c.Part("add"), addLabel).Icon(icons.Plus).IconOnly().Ghost().Size(26, 26). + Disabled(disabled || len(entries) >= maximumSourceEntries).Tooltip(addLabel) + if add.Clicked() { + control.menu = !control.menu + } + ui.Menu(c, add, &control.menu, func(menu *ui.MenuItems) { + for index, kind := range field.EntryKinds { + item := menu.Item(i18n.SharedFormat(language, "desktop.sourceSettings.entryKind", map[string]string{"title": kind.Title})) + if kind.Input == "choice" { + item = item.Disabled(len(choiceEntries(field, index, entries)) == 0) + } + if item.Clicked() { + w.addSourceEntries(c, p, source, field, index) + } + } + }) + buttons := []struct { + part, label string + icon gfx.Icon + off bool + run func() + }{ + {"remove", i18n.Shared(language, "desktop.sourceSettings.entryRemove"), icons.Minus, control.entry < 0, func() { p.removeEntry(source.ID, field) }}, + {"up", i18n.Shared(language, "desktop.sourceSettings.entryUp"), icons.ArrowUp, control.entry <= 0, func() { p.moveEntry(source.ID, field, -1) }}, + {"down", i18n.Shared(language, "desktop.sourceSettings.entryDown"), icons.ArrowDown, control.entry < 0 || control.entry >= len(entries)-1, func() { p.moveEntry(source.ID, field, 1) }}, + } + for _, button := range buttons { + if ui.Button(c.Part(button.part), button.label).Icon(button.icon).IconOnly().Ghost().Size(26, 26).Disabled(disabled || button.off).Tooltip(button.label).Clicked() { + button.run() + } + } + } + ui.Spacer(c) + if len(entries) > 0 { + for _, attribute := range field.Attributes { + ui.Text(c.Key(attribute.ID), attribute.Title).FontSize(11).Color(w.pal.muted).Width(entryAttributeWidth(attribute)).Shrink(0).Ellipsis() + } + } + }) + if len(entries) == 0 { + ui.Text(c, i18n.Shared(language, "desktop.sourceSettings.entryEmpty")).FontSize(12).Color(w.pal.muted).PadX(8) + } +} + +// sourceEntryRow is one entry: its kind's icon, its title and detail, and its +// attribute columns. A click selects it for remove and move. +func (w *window) sourceEntryRow(c ui.C, p *sourceSettingsForm, source core.SettingsSource, field core.SourceSettingField, index int) { + control := p.controls[source.ID][field.ID] + if index >= len(control.input.Entries) { + return + } + entry := control.input.Entries[index] + disabled := sourceEntriesDisabled(p, source) + selected := !disabled && control.entry == index + icon := icons.LayoutGrid + if kind := entryKindIndex(field, entry.Kind); kind >= 0 { + switch field.EntryKinds[kind].Input { + case "file": + icon = icons.Archive + case "directory": + icon = icons.Folder + } + } + label := entryLabel(entry) + row := ui.Row(c).FillWidth().Height(28).PadX(8).Gap(8).Items(ui.Center).Radius(4). + HitWith(ui.ID(c), label, gfx.HitOptions{Role: gfx.RoleOption, Selected: selected, Value: entry.Value, Disabled: disabled}) + if selected { + row = row.Background(w.pal.selectionIdle) + } + row.Children(func() { + ui.Icon(c, icon).Size(14, 14).Color(w.pal.muted) + // The title keeps its width up to most of the row; the detail takes + // what is left and is cut first. + ui.Text(c, label).FontSize(12).Color(w.pal.text).Shrink(0).MaxWidthPercent(60).Ellipsis() + ui.Text(c, entry.Detail).FontSize(11).Color(w.pal.muted).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + for column, attribute := range field.Attributes { + k := c.Key(attribute.ID) + title := attribute.Title + " " + label + if attribute.Kind == "boolean" { + on := entryBool(entry, attribute.ID) + ui.Row(k).Width(entryFlagWidth).Shrink(0).Items(ui.Center).Children(func() { + box := ui.Row(k).Size(16, 16).Radius(4).Border(1, w.pal.border).Center(). + HitWith(ui.ID(k), title, gfx.HitOptions{Role: gfx.RoleCheckbox, Checked: on, Disabled: disabled}) + if on { + box = box.Background(w.pal.accent) + } + box.Children(func() { + if on { + ui.Icon(k, icons.Check).Size(12, 12).Color(w.pal.white) + } + }) + if !disabled && box.Clicked() { + p.editEntries(source.ID, field, func(control *sourceSettingControl) { + setEntryAttribute(&control.input.Entries[index], attribute.ID, !on) + }) + } + }) + continue + } + if column >= len(control.attributes[index]) { + continue + } + choice := &control.attributes[index][column] + indices := make([]int, len(attribute.Options)) + for option := range indices { + indices[option] = option + } + optionTitle := func(option int) string { return attribute.Options[option].Title } + if disabled { + ui.Text(k, optionTitle(*choice)).FontSize(12).Color(w.pal.muted).Width(entryChoiceWidth).Shrink(0).Ellipsis() + continue + } + if ui.Select(k, choice, indices, optionTitle).Width(entryChoiceWidth).Shrink(0).Label(title).Changed() { + value := attribute.Options[*choice].Value + p.editEntries(source.ID, field, func(control *sourceSettingControl) { + setEntryAttribute(&control.input.Entries[index], attribute.ID, value) + }) + } + } + }) + if !disabled && row.Clicked() { + control.entry = index + } +} + +// addSourceEntries runs one add-menu item: a native picker for files or +// folders, or the dialog of the choices the list does not hold yet. +func (w *window) addSourceEntries(c ui.C, p *sourceSettingsForm, source core.SettingsSource, field core.SourceSettingField, kindIndex int) { + kind := field.EntryKinds[kindIndex] + control := p.controls[source.ID][field.ID] + if kind.Input == "choice" { + p.chooser = sourceEntryChooser{open: true, source: source.ID, field: field.ID, kind: kindIndex, picked: make([]bool, len(kind.Choices))} + return + } + c.After(func() { + var paths []string + var err error + if kind.Input == "directory" { + var path string + path, err = app.OpenDirectory(app.OpenDirectoryOptions{Title: kind.Title}) + paths = []string{path} + } else { + options := app.OpenFileOptions{Title: kind.Title, AllowMultiple: true} + if len(kind.Extensions) > 0 { + patterns := make([]string, len(kind.Extensions)) + for index, extension := range kind.Extensions { + patterns[index] = "*." + extension + } + options.Filters = []app.FileFilter{{Name: kind.Title, Pattern: strings.Join(patterns, ";")}} + } + paths, err = app.OpenFiles(options) + } + // log-exempt: 用户取消:关闭原生选择器不修改条目草稿。 + if errors.Is(err, app.ErrCanceled) { + return + } + if err != nil { + p.failed = err + if w.ctrl.opts.MarketplaceError != nil { + w.ctrl.opts.MarketplaceError(err) + } + return + } + if w.pluginSettings.sources != p || p.controls[source.ID][field.ID] != control { + return + } + p.addEntries(source.ID, field, pathEntries(control.input.Entries, kind.ID, paths)) + }) +} + +// sourceEntryChooser is the dialog that adds entries of a choice kind: the +// choices the list does not hold yet, each with a checkbox. +func (w *window) sourceEntryChooser(c ui.C, p *sourceSettingsForm) { + chooser := &p.chooser + if !chooser.open { + return + } + language := w.marketLanguage() + var source core.SettingsSource + var field core.SourceSettingField + found := false + for _, candidate := range p.editor.State.Snapshot.Sources { + if candidate.ID != chooser.source { + continue + } + for _, candidateField := range candidate.Fields { + if candidateField.ID == chooser.field && chooser.kind < len(candidateField.EntryKinds) { + source, field, found = candidate, candidateField, true + } + } + } + if !found { + chooser.open = false + return + } + control := p.controls[source.ID][field.ID] + kind := field.EntryKinds[chooser.kind] + available := choiceEntries(field, chooser.kind, control.input.Entries) + title := i18n.SharedFormat(language, "desktop.sourceSettings.chooseTitle", map[string]string{"title": kind.Title}) + ui.ModalWith(c, &chooser.open, title, ui.ModalSpec{Width: 480, Height: 440}, func() { + if len(available) == 0 { + ui.Wrap(c, i18n.Shared(language, "desktop.sourceSettings.chooseNone")).FontSize(12).Color(w.pal.muted) + return + } + ui.List(c, &chooser.list, len(available), func(row ui.ListRow) { + index := available[row.Index] + choice := kind.Choices[index] + row.Element.FillWidth().Children(func() { + ui.Row(row.C).FillWidth().Gap(8).Items(ui.Center).PadY(4).Children(func() { + ui.Checkbox(row.C, &chooser.picked[index], choice.Title).Shrink(0) + ui.Text(row.C, choice.Detail).FontSize(11).Color(w.pal.muted).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + }) + }) + }).Scrollbars().FillWidth().Grow(1).MinHeight(200).Label(title) + }, func() { + if ui.Button(c, i18n.Shared(language, "desktop.sourceSettings.cancel")).Outline().Clicked() { + chooser.open = false + } + var entries []core.SourceEntry + for _, index := range available { + if chooser.picked[index] && len(control.input.Entries)+len(entries) < maximumSourceEntries { + choice := kind.Choices[index] + entries = append(entries, core.SourceEntry{Kind: kind.ID, Value: choice.Value, Title: choice.Title, Detail: choice.Detail}) + } + } + if ui.Button(c, i18n.Shared(language, "desktop.sourceSettings.entryAdd")).Disabled(len(entries) == 0).Clicked() { + p.addEntries(source.ID, field, entries) + chooser.open = false + } + }) +} diff --git a/desktop/internal/settingswindow/source_settings_modules_test.go b/desktop/internal/settingswindow/source_settings_modules_test.go new file mode 100644 index 0000000000..161e853a1b --- /dev/null +++ b/desktop/internal/settingswindow/source_settings_modules_test.go @@ -0,0 +1,212 @@ +package settingswindow + +import ( + "context" + "encoding/json" + "reflect" + "testing" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/app" +) + +func openModuleForm(t *testing.T, source *nativeFormFixture) (*windowDriver, *sourceSettingsForm) { + t.Helper() + w := nativeFormWindow(t, source, i18n.English, "light") + d := openWindow(t, w, func(config *app.Config) { config.Width, config.Height = 1120, 1100 }) + openNativeForm(t, w, d) + d.pump() + return d, w.pluginSettings.sources +} + +func entryValues(entries []core.SourceEntry) []string { + values := make([]string, len(entries)) + for index, entry := range entries { + values[index] = entry.Kind + ":" + entry.Value + } + return values +} + +// A sidebar group lists its modules nested by parent; only the selected one is +// shown beside the list, one section per tab, and other groups stay one item. +func TestSourceModuleListShowsTheSelectedModuleOneTabAtATime(t *testing.T) { + d, p := openModuleForm(t, moduleFormSource(t)) + for _, item := range []string{"example", "app", "core", "Workspace"} { + if !d.has(item) { + t.Fatalf("the module list has no %q", item) + } + } + if p.selectedSource != "root" || !d.text("Runtime") { + t.Fatalf("the first module is not shown: %q", p.selectedSource) + } + depths := map[string]int{} + for _, item := range p.nav { + if item.source >= 0 { + depths[p.editor.State.Snapshot.Sources[item.source].ID] = item.depth + } + } + if depths["root"] != 1 || depths["app"] != 2 || depths["core"] != 2 { + t.Fatalf("modules are not nested by parent: %v", depths) + } + d.click("app") + d.pump() + if !d.has("Sources") || !d.has("Paths") || !d.has("Dependencies") { + t.Fatal("the module's sections are not tabs") + } + if !d.has("src") || !d.has("test") || d.has("one.zip") { + t.Fatal("the first tab does not show only the source folders") + } + d.click("Dependencies") + d.pump() + // Entry rows are named by their full title, though a narrow row ellipsizes it. + if !d.has("one.zip") || !d.has("Legacy library") || d.has("src") { + t.Fatal("the dependencies tab does not show only its fields") + } + d.click("Workspace") + d.pump() + if !d.text("Referenced files") || !d.text("Libraries") || d.text("Legacy library") { + t.Fatal("a form group is not shown as one item with its section heading") + } + if len(p.pending) != 0 { + t.Fatalf("navigating created drafts: %+v", p.pending) + } +} + +// Reordering, flagging and adding offered choices edits only the draft; Save +// sends the list in order, and Core drops the display text before the plugin. +func TestSourceEntryListEditsReachThePluginWithoutDisplayText(t *testing.T) { + source := moduleFormSource(t) + d, p := openModuleForm(t, source) + d.click("app") + d.pump() + d.click("Dependencies") + d.pump() + d.click("one.zip") + d.pump() + d.click(i18n.Shared(i18n.English, "desktop.sourceSettings.entryDown")) + d.pump() + d.click("Export one.zip") + d.pump() + d.click(i18n.Shared(i18n.English, "desktop.sourceSettings.entryAdd")) + d.pump() + d.click(i18n.SharedFormat(i18n.English, "desktop.sourceSettings.entryKind", map[string]string{"title": "Library"})) + d.until("library chooser", func() bool { return p.chooser.open }) + if !d.text("3 archives") { + t.Fatal("the chooser does not show the choice's detail") + } + d.click("Shared library") + d.pump() + d.click(i18n.Shared(i18n.English, "desktop.sourceSettings.entryAdd")) + d.until("chooser closed", func() bool { return !p.chooser.open }) + control := p.controls["app"]["dependencies"] + if got := entryValues(control.input.Entries); len(got) != 3 || got[0] != "library:lib:legacy" || got[1] != "archive:lib/one.zip" || got[2] != "library:lib:shared" { + t.Fatalf("draft entries = %v", got) + } + if !entryBool(control.input.Entries[1], "exported") { + t.Fatal("the Export column did not flag the entry") + } + if len(p.pending) != 1 || len(p.pending["app"]) != 1 { + t.Fatalf("drafts touched other fields: %+v", p.pending) + } + d.click(i18n.Shared(i18n.English, "desktop.pluginSettings.save")) + var edits []core.SourceSettingsEdits + select { + case edits = <-source.saves: + case <-time.After(5 * time.Second): + t.Fatal("explicit save did not reach the native adapter") + } + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + writes, err := core.NewClient().PlanSourceSettingsEdits(ctx, p.editor.State.Snapshot, edits, true) + if err != nil { + t.Fatal(err) + } + if len(writes) != 1 || writes[0].Path != "app/tool.xml" { + t.Fatalf("writes = %+v", writes) + } + var written, want any + if err := json.Unmarshal(writes[0].Values["dependencies"], &written); err != nil { + t.Fatal(err) + } + if err := json.Unmarshal([]byte(`[{"kind":"library","value":"lib:legacy","attributes":{"exported":true}},{"kind":"archive","value":"lib/one.zip","attributes":{"exported":true}},{"kind":"library","value":"lib:shared"}]`), &want); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(written, want) { + t.Fatalf("written = %s", writes[0].Values["dependencies"]) + } +} + +// Removing every entry is an explicit empty list, shown as such. Reset is offered +// only when the plugin knows the inherited list, and restores it. +func TestSourceEntryListRemovesToAnExplicitEmptyListAndResets(t *testing.T) { + reset := i18n.Shared(i18n.English, "desktop.pluginSettings.reset") + d, p := openModuleForm(t, moduleFormSource(t)) + d.click("app") + d.pump() + if d.has(reset) { + t.Fatal("a list without a known inherited value offers Reset, which would empty it") + } + d, p = openModuleForm(t, moduleFormSource(t, func(snapshot *core.SourceSettingsSnapshot) { + snapshot.Sources[1].Fields[0].InheritedValue = json.RawMessage(`[{"kind":"folder","value":"src"}]`) + })) + d.click("app") + d.pump() + for _, folder := range []string{"src", "test"} { + d.click(folder) + d.pump() + d.click(i18n.Shared(i18n.English, "desktop.sourceSettings.entryRemove")) + d.pump() + } + control := p.controls["app"]["roots"] + if len(control.input.Entries) != 0 || control.input.Inherit || !d.text(i18n.Shared(i18n.English, "desktop.sourceSettings.entryEmpty")) { + t.Fatalf("removing every folder: %+v", control.input) + } + if _, ok := p.pending["app"]["roots"]; !ok { + t.Fatal("an emptied list is not a draft") + } + d.click(reset) + d.pump() + if got := entryValues(control.input.Entries); len(got) != 1 || got[0] != "folder:src" || !control.input.Inherit { + t.Fatalf("reset: %v %+v", got, control.input) + } +} + +// A module whose dependencies belong to its build file shows them without the +// controls that would edit them. +func TestReadOnlyModuleShowsEntriesWithoutEditing(t *testing.T) { + d, p := openModuleForm(t, moduleFormSource(t)) + d.click("core") + d.pump() + if p.selectedSource != "core" || !d.text("library-1.0.zip") { + t.Fatal("the read-only module's entries are not shown") + } + for _, key := range []string{"desktop.sourceSettings.entryAdd", "desktop.sourceSettings.entryRemove", "desktop.pluginSettings.reset"} { + if d.has(i18n.Shared(i18n.English, key)) { + t.Fatalf("a read-only module offers %s", key) + } + } + d.click("library-1.0.zip") + d.pump() + if p.controls["core"]["dependencies"].entry != -1 { + t.Fatal("a read-only entry can be selected for editing") + } +} + +func TestEntryDraftsCompareWithoutDisplayTextAndSkipDuplicatePaths(t *testing.T) { + a := core.SourceSettingInput{Entries: []core.SourceEntry{{Kind: "archive", Value: "lib/a.zip", Title: "a.zip", Attributes: map[string]any{"exported": true}}}} + b := cloneSourceInput(a) + b.Entries[0].Title, b.Entries[0].Detail = "", "elsewhere" + if !sameSourceInput(a, b) { + t.Fatal("display text made two drafts differ") + } + b.Entries[0].Attributes["exported"] = false + if sameSourceInput(a, b) || a.Entries[0].Attributes["exported"] != true { + t.Fatal("a cloned draft shares its attributes, or a changed attribute went unnoticed") + } + added := pathEntries(a.Entries, "archive", []string{"lib/a.zip", "/abs/b.jar", "/abs/b.jar", ""}) + if len(added) != 1 || added[0].Value != "/abs/b.jar" || added[0].Title != "b.jar" { + t.Fatalf("picker paths = %+v", added) + } +} diff --git a/desktop/internal/settingswindow/source_settings_view.go b/desktop/internal/settingswindow/source_settings_view.go index ea391f4229..396e4c0566 100644 --- a/desktop/internal/settingswindow/source_settings_view.go +++ b/desktop/internal/settingswindow/source_settings_view.go @@ -3,6 +3,7 @@ package settingswindow import ( "context" "errors" + "slices" "strconv" "strings" "time" @@ -10,6 +11,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/configfile" "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/pluginsettings" "github.com/vivaui/viva/app" @@ -23,12 +25,12 @@ type sourceSettingControl struct { inherited core.SourceSettingInput choices []int selected int -} - -type sourceSettingsRow struct { - group int - source int - field int + // entry is the selected entry of an entryList, -1 for none; menu whether its + // add menu is open; attributes the option index of each entry's enum columns, + // which its drop-downs bind to. + entry int + menu bool + attributes [][]int } // A source form owns only presentation drafts. The worker receives a captured @@ -53,10 +55,19 @@ type sourceSettingsForm struct { reload bool busy, stale, saved bool failed error + // The module list of a form with a sidebar group, the item it shows (by + // group and source ID, so a reload keeps it) and each source's open tab. + nav []sourceNavItem + navTree ui.TreeState + selectedGroup string + selectedSource string + tabs map[string]*string + chooser sourceEntryChooser } func newSourceSettingsForm(loader PluginSettingsLoader, owner pluginservice.SettingsEditor, action string, editor pluginsettings.SourceEditor) *sourceSettingsForm { - p := &sourceSettingsForm{loader: loader, owner: owner, action: action} + p := &sourceSettingsForm{loader: loader, owner: owner, action: action, tabs: make(map[string]*string)} + p.navTree.Node, p.navTree.RowHeight, p.navTree.Indent = p.navNode, 28, 14 p.effect = ui.NewEffect[pluginsettings.SourceEditor, int](func(parent context.Context) (pluginsettings.SourceEditor, error) { ctx, cancel := context.WithTimeout(parent, 120*time.Second) defer cancel() @@ -82,6 +93,7 @@ func (p *sourceSettingsForm) apply(editor pluginsettings.SourceEditor) { p.add = make(map[string]*int) p.pending = make(map[string]map[string]core.SourceSettingInput) p.tableSources = make(map[string]bool) + p.chooser.open = false for _, section := range editor.State.Layout { if editor.State.Snapshot.Groups[section.Group].Layout == "table" { for _, index := range section.Sources { @@ -93,7 +105,7 @@ func (p *sourceSettingsForm) apply(editor pluginsettings.SourceEditor) { fields := make(map[string]*sourceSettingControl) for _, field := range source.Fields { input := editor.State.Inputs[source.ID][field.ID] - control := &sourceSettingControl{input: input, base: input, inherited: editor.State.InheritedInputs[source.ID][field.ID]} + control := &sourceSettingControl{input: cloneSourceInput(input), base: cloneSourceInput(input), inherited: editor.State.InheritedInputs[source.ID][field.ID], entry: -1} control.choices = make([]int, len(field.Options)+1) for index := range control.choices { control.choices[index] = index @@ -101,6 +113,7 @@ func (p *sourceSettingsForm) apply(editor pluginsettings.SourceEditor) { control.selected = index } } + control.syncAttributes(field) fields[field.ID] = control } p.controls[source.ID] = fields @@ -109,34 +122,86 @@ func (p *sourceSettingsForm) apply(editor pluginsettings.SourceEditor) { p.layout() } +// syncAttributes points each enum column's drop-down at its entry's value. +func (control *sourceSettingControl) syncAttributes(field core.SourceSettingField) { + control.attributes = control.attributes[:0] + for _, entry := range control.input.Entries { + row := make([]int, len(field.Attributes)) + for column, attribute := range field.Attributes { + value := entryChoice(entry, attribute) + for index, option := range attribute.Options { + if option.Value == value { + row[column] = index + } + } + } + control.attributes = append(control.attributes, row) + } +} + func (p *sourceSettingsForm) layout() { p.rows = p.rows[:0] p.available = make(map[string][]int) p.layoutDirty = false + p.navigation() + snapshot := &p.editor.State.Snapshot + all := func(core.SourceSettingField) bool { return true } for _, section := range p.editor.State.Layout { groupIndex := section.Group - group := p.editor.State.Snapshot.Groups[groupIndex] - p.rows = append(p.rows, sourceSettingsRow{group: groupIndex, source: -1, field: -1}) + group := snapshot.Groups[groupIndex] + // With a module list only the selected item is shown beside it. + if len(p.nav) > 0 && group.ID != p.selectedGroup { + continue + } + if group.Layout == "sidebar" { + for _, sourceIndex := range section.Sources { + source := snapshot.Sources[sourceIndex] + if source.ID != p.selectedSource { + continue + } + p.rows = append(p.rows, sourceSettingsRow{kind: sourceRowModule, group: groupIndex, source: sourceIndex, field: -1, entry: -1}) + sections := sourceSections(source) + tab := p.tabs[source.ID] + if tab == nil { + tab = new(string) + p.tabs[source.ID] = tab + } + if !slices.Contains(sections, *tab) { + *tab = "" + if len(sections) > 0 { + *tab = sections[0] + } + } + // One section needs no tab to choose it. + if len(sections) > 1 { + p.rows = append(p.rows, sourceSettingsRow{kind: sourceRowTabs, group: groupIndex, source: sourceIndex, field: -1, entry: -1}) + } + current := *tab + p.fieldRows(groupIndex, sourceIndex, func(field core.SourceSettingField) bool { + return field.Section == "" || field.Section == current + }, false) + } + continue + } + p.rows = append(p.rows, sourceSettingsRow{kind: sourceRowGroup, group: groupIndex, source: -1, field: -1, entry: -1}) if p.add[group.ID] == nil { p.add[group.ID] = new(int) } for _, sourceIndex := range section.Sources { - source := p.editor.State.Snapshot.Sources[sourceIndex] + source := snapshot.Sources[sourceIndex] if group.Layout == "table" { visible := false for _, control := range p.controls[source.ID] { visible = visible || !control.input.Inherit } if visible { - p.rows = append(p.rows, sourceSettingsRow{group: groupIndex, source: sourceIndex, field: -1}) + p.rows = append(p.rows, sourceSettingsRow{kind: sourceRowTable, group: groupIndex, source: sourceIndex, field: -1, entry: -1}) } if !visible && source.Writable { p.available[group.ID] = append(p.available[group.ID], sourceIndex) } } else { - for fieldIndex := range source.Fields { - p.rows = append(p.rows, sourceSettingsRow{group: groupIndex, source: sourceIndex, field: fieldIndex}) - } + p.fieldRows(groupIndex, sourceIndex, all, true) } } if available := p.available[group.ID]; len(available) > 0 { @@ -166,7 +231,7 @@ func (p *sourceSettingsForm) edits() []core.SourceSettingsEdits { func (p *sourceSettingsForm) changed(source, field string) { control := p.controls[source][field] - if control.input == control.base { + if sameSourceInput(control.input, control.base) { delete(p.pending[source], field) if len(p.pending[source]) == 0 { delete(p.pending, source) @@ -236,63 +301,166 @@ func (w *window) sourceSettingsPanel(c ui.C, p *sourceSettingsForm) { if p.saved { ui.Text(c, i18n.Shared(language, "desktop.pluginSettings.saved")).FontSize(12).Color(w.pal.muted) } - ui.List(c, &p.list, len(p.rows), func(row ui.ListRow) { - item := p.rows[row.Index] - group := p.editor.State.Snapshot.Groups[item.group] - row.Element.FillWidth().Children(func() { - if item.source < 0 { - w.sourceSettingsGroup(row.C, p, group) - return - } - source := p.editor.State.Snapshot.Sources[item.source] - if item.field >= 0 { - field := source.Fields[item.field] - ui.Column(row.C).FillWidth().Gap(5).PadY(6).Children(func() { - ui.Row(row.C).FillWidth().Items(ui.Center).Gap(8).Children(func() { - if field.Kind == "boolean" { - w.sourceSettingsControl(row.C, p, source, field) - } else { - ui.Text(row.C, field.Title).FontSize(12).Weight(gfx.WeightSemibold).Color(w.pal.text) - } - if field.Description != "" { - w.infoButton(row.C, field.Description) - } - ui.Spacer(row.C) - if item.field == 0 { - ui.Text(row.C, source.Path).FontSize(11).Color(w.pal.muted).Ellipsis() - } - }) - if field.Kind != "boolean" { - w.sourceSettingsControl(row.C, p, source, field) - } - if field.EffectiveSource != "" { - ui.Text(row.C, field.EffectiveSource).FontSize(11).Color(w.pal.muted) - } - // A source the plugin projects read-only has nothing to reset. - if source.Writable && field.Kind != "enum" && !controlInherits(p, source.ID, field.ID) && ui.Button(row.C, i18n.Shared(language, "desktop.pluginSettings.reset")).Link().Disabled(p.busy || p.stale || !source.Writable || controlInherits(p, source.ID, field.ID)).Clicked() { - control := p.controls[source.ID][field.ID] - control.input = control.inherited - p.changed(source.ID, field.ID) - } - }) - } else { - ui.Row(row.C).FillWidth().MinHeight(36).Items(ui.Center).Gap(8).Children(func() { - ui.Text(row.C, source.Title).FontSize(12).Color(w.pal.text).Grow(1).Ellipsis() - w.infoButton(row.C, source.Path) - for _, field := range source.Fields { - w.sourceSettingsControl(row.C.Key(field.ID), p, source, field) - } - if ui.Button(row.C, i18n.Shared(language, "desktop.sourceSettings.remove")).Outline().Disabled(p.busy || !source.Writable).Clicked() { - for id, control := range p.controls[source.ID] { - control.input = control.inherited - control.selected = 0 - p.changed(source.ID, id) - } - } - }) + rows := func() { + ui.List(c, &p.list, len(p.rows), func(row ui.ListRow) { + row.Element.FillWidth().Children(func() { w.sourceSettingsRow(row.C, p, p.rows[row.Index]) }) + }).Scrollbars().FillWidth().Grow(1).MinHeight(settingsListMinHeight).Label(p.editor.State.Snapshot.Title) + } + if len(p.nav) == 0 { + rows() + return + } + ui.Row(c).FillWidth().Grow(1).MinHeight(settingsListMinHeight).Children(func() { + ui.Tree(c, &p.navTree, len(p.nav), p.navLabel, func(i int) { w.sourceNavContent(c, p, i) }). + Scrollbars().Width(sourceNavWidth).FillHeight().Shrink(0).Label(i18n.Shared(language, "desktop.sourceSettings.modules")) + if i, ok := p.navTree.Chosen(); ok && i < len(p.nav) && !p.nav[i].heading { + p.selectNav(p.nav[i]) + } + ui.Column(c).Width(1).FillHeight().Shrink(0).Background(w.pal.line) + ui.Column(c).Grow(1).MinWidth(0).FillHeight().PadLeft(14).Children(rows) + }) + }) + w.sourceEntryChooser(c, p) + // A click that selected a module or tab or changed an entry list changed the + // rows being declared; lay them out again before the next paint. + if p.layoutDirty { + c.After(func() { + if p.layoutDirty { + p.layout() + } + }) + } +} + +// sourceNavWidth is the width of the module list beside a sidebar form. +const sourceNavWidth = 168 + +func (p *sourceSettingsForm) navNode(i int) ui.TreeNode { + if i < 0 || i >= len(p.nav) { + return ui.TreeNode{} + } + item := p.nav[i] + return ui.TreeNode{Depth: item.depth, Selected: !item.heading && p.navSelected(item)} +} + +func (p *sourceSettingsForm) navLabel(i int) string { + if i < 0 || i >= len(p.nav) { + return "" + } + if item := p.nav[i]; item.source >= 0 { + return p.editor.State.Snapshot.Sources[item.source].Title + } + return p.editor.State.Snapshot.Groups[p.nav[i].group].Title +} + +func (w *window) sourceNavContent(c ui.C, p *sourceSettingsForm, i int) { + if i < 0 || i >= len(p.nav) { + return + } + item := p.nav[i] + if item.heading { + ui.Text(c, p.navLabel(i)).FontSize(11).Weight(gfx.WeightSemibold).Color(w.pal.muted).Grow(1).MinWidth(0).Ellipsis() + return + } + icon := icons.LayoutGrid + if item.source >= 0 { + icon = icons.Folder + } + ui.Row(c).Grow(1).MinWidth(0).Gap(6).Items(ui.Center).Children(func() { + ui.Icon(c, icon).Size(14, 14).Color(w.pal.muted) + ui.Text(c, p.navLabel(i)).FontSize(13).Color(w.pal.text).Grow(1).MinWidth(0).Ellipsis() + }) +} + +// sourceSettingsRow declares one row of a source form's list. +func (w *window) sourceSettingsRow(c ui.C, p *sourceSettingsForm, item sourceSettingsRow) { + language := w.marketLanguage() + snapshot := &p.editor.State.Snapshot + group := snapshot.Groups[item.group] + switch item.kind { + case sourceRowGroup: + w.sourceSettingsGroup(c, p, group) + return + case sourceRowModule: + source := snapshot.Sources[item.source] + ui.Row(c).FillWidth().Items(ui.Center).Gap(8).PadY(6).Children(func() { + ui.Text(c, source.Title).FontSize(15).Weight(gfx.WeightSemibold).Color(w.pal.text).Shrink(0) + ui.Spacer(c) + ui.Text(c, source.Path).FontSize(11).Color(w.pal.muted).Shrink(1).MinWidth(0).Ellipsis() + }) + return + case sourceRowTabs: + source := snapshot.Sources[item.source] + tab := p.tabs[source.ID] + before := *tab + ui.Tabs(c, tab, sourceSections(source), func(section string) string { return section }) + if *tab != before { + p.layoutDirty = true + } + return + case sourceRowEntry: + w.sourceEntryRow(c, p, snapshot.Sources[item.source], snapshot.Sources[item.source].Fields[item.field], item.entry) + return + } + source := snapshot.Sources[item.source] + if item.kind == sourceRowTable { + ui.Row(c).FillWidth().MinHeight(36).Items(ui.Center).Gap(8).Children(func() { + ui.Text(c, source.Title).FontSize(12).Color(w.pal.text).Grow(1).Ellipsis() + w.infoButton(c, source.Path) + for _, field := range source.Fields { + w.sourceSettingsControl(c.Key(field.ID), p, source, field) + } + if ui.Button(c, i18n.Shared(language, "desktop.sourceSettings.remove")).Outline().Disabled(p.busy || !source.Writable).Clicked() { + for id, control := range p.controls[source.ID] { + control.input = cloneSourceInput(control.inherited) + control.selected = 0 + p.changed(source.ID, id) } - }) - }).Scrollbars().FillWidth().Grow(1).MinHeight(settingsListMinHeight).Label(p.editor.State.Snapshot.Title) + } + }) + return + } + field := source.Fields[item.field] + ui.Column(c).FillWidth().Gap(5).PadY(6).Children(func() { + if item.heading != "" { + ui.Text(c, item.heading).FontSize(13).Weight(gfx.WeightSemibold).Color(w.pal.text).PadTop(6) + } + ui.Row(c).FillWidth().Items(ui.Center).Gap(8).Children(func() { + if field.Kind == "boolean" { + w.sourceSettingsControl(c, p, source, field) + } else { + ui.Text(c, field.Title).FontSize(12).Weight(gfx.WeightSemibold).Color(w.pal.text) + } + if field.Description != "" { + w.infoButton(c, field.Description) + } + ui.Spacer(c) + // An entry list's rows follow it, so its origin goes beside its title. + if field.Kind == "entryList" && field.EffectiveSource != "" { + ui.Text(c, field.EffectiveSource).FontSize(11).Color(w.pal.muted).Shrink(1).MinWidth(0).Ellipsis() + } else if item.field == 0 && group.Layout != "sidebar" { + ui.Text(c, source.Path).FontSize(11).Color(w.pal.muted).Ellipsis() + } + }) + if field.Kind == "entryList" { + w.sourceEffectiveHint(c, p, source, field) + w.sourceEntryToolbar(c, p, source, field) + } else if field.Kind != "boolean" { + w.sourceSettingsControl(c, p, source, field) + } + if field.EffectiveSource != "" && field.Kind != "entryList" { + ui.Text(c, field.EffectiveSource).FontSize(11).Color(w.pal.muted) + } + // A source the plugin projects read-only has nothing to reset, and an entry + // list only resets to an inherited list the plugin knows. + if source.Writable && field.Kind != "enum" && (field.Kind != "entryList" || inheritedKnown(field)) && !controlInherits(p, source.ID, field.ID) && ui.Button(c, i18n.Shared(language, "desktop.pluginSettings.reset")).Link().Disabled(p.busy || p.stale).Clicked() { + control := p.controls[source.ID][field.ID] + control.input = cloneSourceInput(control.inherited) + control.entry = -1 + control.syncAttributes(field) + p.changed(source.ID, field.ID) + p.layoutDirty = true + } }) } @@ -419,6 +587,12 @@ func (w *window) sourceSettingsControl(c ui.C, p *sourceSettingsForm, source cor }) } } + w.sourceEffectiveHint(c, p, source, field) +} + +// sourceEffectiveHint shows the value the tool uses when it differs from the draft or is inherited. +func (w *window) sourceEffectiveHint(c ui.C, p *sourceSettingsForm, source core.SettingsSource, field core.SourceSettingField) { + language := w.marketLanguage() if display, ok := p.editor.State.EffectiveDisplays[source.ID][field.ID]; ok { value := display.Text switch display.Kind { @@ -438,7 +612,12 @@ func (w *window) sourceSettingsControl(c ui.C, p *sourceSettingsForm, source cor } ui.Text(c, hint).FontSize(11).Color(w.pal.muted).Ellipsis() } +} +// inheritedKnown reports whether the plugin projected the value a field takes +// without its override. +func inheritedKnown(field core.SourceSettingField) bool { + return len(field.InheritedValue) > 0 && string(field.InheritedValue) != "null" } func controlInherits(p *sourceSettingsForm, source, field string) bool { diff --git a/desktop/internal/settingswindow/source_settings_view_test.go b/desktop/internal/settingswindow/source_settings_view_test.go index e5763b42b4..1dd9118f17 100644 --- a/desktop/internal/settingswindow/source_settings_view_test.go +++ b/desktop/internal/settingswindow/source_settings_view_test.go @@ -38,20 +38,27 @@ func (s *nativeFormFixture) SaveSources(ctx context.Context, _ pluginservice.Set return editor, s.failure } func nativeFormSource(t *testing.T, adjust ...func(*core.SourceSettingsSnapshot)) *nativeFormFixture { + t.Helper() + return sourceFormFixture(t, "plugins/settings-sources.json", map[string]string{"child/tool.json": `{"target":"two"}`}, adjust...) +} + +// moduleFormSource is the module structure fixture: a sidebar of nested modules +// with tabs, entry lists and a read-only module. +func moduleFormSource(t *testing.T, adjust ...func(*core.SourceSettingsSnapshot)) *nativeFormFixture { + t.Helper() + return sourceFormFixture(t, "plugins/settings-sources-modules.json", map[string]string{"app/tool.xml": "", "core/build.file": "core"}, adjust...) +} + +// sourceFormFixture captures a Core fixture snapshot over a workspace holding +// files, each source's revision set to the bytes written for it. +func sourceFormFixture(t *testing.T, name string, files map[string]string, adjust ...func(*core.SourceSettingsSnapshot)) *nativeFormFixture { t.Helper() manifest, err := os.ReadFile(contractfixture.Path("fixtures/settings/source-editor.plugin.json")) if err != nil { t.Fatal(err) } root := t.TempDir() - if err := os.Mkdir(filepath.Join(root, "child"), 0700); err != nil { - t.Fatal(err) - } - contents := []byte(`{"target":"two"}`) - if err := os.WriteFile(filepath.Join(root, "child/tool.json"), contents, 0600); err != nil { - t.Fatal(err) - } - data, err := os.ReadFile(contractfixture.CoreFixture("plugins/settings-sources.json")) + data, err := os.ReadFile(contractfixture.CoreFixture(name)) if err != nil { t.Fatal(err) } @@ -61,7 +68,19 @@ func nativeFormSource(t *testing.T, adjust ...func(*core.SourceSettingsSnapshot) if err := json.Unmarshal(data, &fixture); err != nil { t.Fatal(err) } - fixture.Snapshot.Sources[1].Revision = fmt.Sprintf("sha256:%x", sha256.Sum256(contents)) + for path, contents := range files { + if err := os.MkdirAll(filepath.Join(root, filepath.Dir(path)), 0700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(root, path), []byte(contents), 0600); err != nil { + t.Fatal(err) + } + for index := range fixture.Snapshot.Sources { + if fixture.Snapshot.Sources[index].Path == path { + fixture.Snapshot.Sources[index].Revision = fmt.Sprintf("sha256:%x", sha256.Sum256([]byte(contents))) + } + } + } for _, fn := range adjust { fn(&fixture.Snapshot) } diff --git a/desktop/internal/settingswindow/source_settings_visual_test.go b/desktop/internal/settingswindow/source_settings_visual_test.go index 25d903e58e..10d90146f3 100644 --- a/desktop/internal/settingswindow/source_settings_visual_test.go +++ b/desktop/internal/settingswindow/source_settings_visual_test.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "testing" + "time" ) func TestVisualNativeSettingsForm(t *testing.T) { @@ -46,3 +47,63 @@ func TestVisualNativeSettingsForm(t *testing.T) { } } } + +// TestVisualModuleStructureForm captures the module list beside a module's +// tabs: the dependencies with their Export and scope columns, the source +// folders, a read-only module and the library chooser. +func TestVisualModuleStructureForm(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + for _, language := range []i18n.Language{i18n.Chinese, i18n.English} { + for _, theme := range []string{"dark", "light"} { + t.Run(language.Code()+"-"+theme, func(t *testing.T) { + source := moduleFormSource(t) + w := nativeFormWindow(t, source, language, theme) + config := w.config() + config.Width, config.Height = 1120, 820 + session, err := headless.Open(config, nil, headless.Options{}) + if err != nil { + t.Fatal(err) + } + t.Cleanup(session.Close) + d := &windowDriver{t: t, w: w, driver: session.Driver()} + openNativeForm(t, w, d) + shot := func(name string) { + d.pump() + // Menus and dialogs open with an animation; let it finish. + if err := session.Advance(300 * time.Millisecond); err != nil { + t.Fatal(err) + } + if err := session.Screenshot(filepath.Join(out, "module-structure-"+name+"-"+language.Code()+"-"+theme+".png")); err != nil { + t.Fatal(err) + } + } + d.click("app") + d.pump() + d.click("Dependencies") + d.pump() + d.click("one.zip") + shot("dependencies") + d.click("Sources") + shot("sources") + d.click("core") + shot("read-only") + d.click("app") + d.pump() + d.click("Dependencies") + d.pump() + d.click(i18n.Shared(language, "desktop.sourceSettings.entryAdd")) + d.pump() + shot("add-menu") + d.click(i18n.SharedFormat(language, "desktop.sourceSettings.entryKind", map[string]string{"title": "Library"})) + d.until("library chooser", func() bool { return w.pluginSettings.sources.chooser.open }) + shot("chooser") + }) + } + } +} diff --git a/docs/assets/module-structure-settings/add-menu-en-light.png b/docs/assets/module-structure-settings/add-menu-en-light.png new file mode 100644 index 0000000000..8beabf1bac Binary files /dev/null and b/docs/assets/module-structure-settings/add-menu-en-light.png differ diff --git a/docs/assets/module-structure-settings/chooser-zh-Hans-light.png b/docs/assets/module-structure-settings/chooser-zh-Hans-light.png new file mode 100644 index 0000000000..6f65257db6 Binary files /dev/null and b/docs/assets/module-structure-settings/chooser-zh-Hans-light.png differ diff --git a/docs/assets/module-structure-settings/dependencies-en-dark.png b/docs/assets/module-structure-settings/dependencies-en-dark.png new file mode 100644 index 0000000000..474a4fd263 Binary files /dev/null and b/docs/assets/module-structure-settings/dependencies-en-dark.png differ diff --git a/docs/assets/module-structure-settings/dependencies-zh-Hans-light.png b/docs/assets/module-structure-settings/dependencies-zh-Hans-light.png new file mode 100644 index 0000000000..659de2908c Binary files /dev/null and b/docs/assets/module-structure-settings/dependencies-zh-Hans-light.png differ diff --git a/docs/assets/module-structure-settings/read-only-zh-Hans-dark.png b/docs/assets/module-structure-settings/read-only-zh-Hans-dark.png new file mode 100644 index 0000000000..4439f889aa Binary files /dev/null and b/docs/assets/module-structure-settings/read-only-zh-Hans-dark.png differ diff --git a/docs/assets/module-structure-settings/sources-zh-Hans-light.png b/docs/assets/module-structure-settings/sources-zh-Hans-light.png new file mode 100644 index 0000000000..793f1b652e Binary files /dev/null and b/docs/assets/module-structure-settings/sources-zh-Hans-light.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 1a34ccf8d3..77a557daa3 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -178,7 +178,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="6a29169d030d18709563780db317ab96dcad0f87" +PINNED_CORE_REVISION="788e61eb62177dff4cb0bfe11a48eed0a1083fb3" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index 717af38606..8fd1f51394 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -11399,6 +11399,16 @@ "desktop.marketplace.failureHelp": "The package could not be downloaded, verified or installed. Retry; if it fails again, open Diagnostics to view the error details.", "desktop.sourceSettings.effective": "Effective: {value}", "desktop.sourceSettings.fileCount": "{count} entries", + "desktop.sourceSettings.entryAdd": "Add", + "desktop.sourceSettings.entryKind": "{title}…", + "desktop.sourceSettings.entryRemove": "Remove", + "desktop.sourceSettings.entryUp": "Move up", + "desktop.sourceSettings.entryDown": "Move down", + "desktop.sourceSettings.entryEmpty": "No entries", + "desktop.sourceSettings.chooseTitle": "Add {title}", + "desktop.sourceSettings.chooseNone": "Everything that can be added is already listed.", + "desktop.sourceSettings.cancel": "Cancel", + "desktop.sourceSettings.modules": "Modules", "desktop.toolchains.global": "Global defaults", "desktop.toolchains.globalHelp": "Manage detected and manually added SDKs for all projects. Save writes to the application’s user settings; projects can override the default. Existing processes use the new SDK after restarting.", "desktop.toolchains.project": "Current project" diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index f37a70e927..5db2d566af 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -11399,6 +11399,16 @@ "desktop.marketplace.failureHelp": "插件包下载、校验或安装失败。请重试;若仍失败,可打开诊断查看错误详情。", "desktop.sourceSettings.effective": "当前生效:{value}", "desktop.sourceSettings.fileCount": "{count} 项", + "desktop.sourceSettings.entryAdd": "添加", + "desktop.sourceSettings.entryKind": "{title}…", + "desktop.sourceSettings.entryRemove": "移除", + "desktop.sourceSettings.entryUp": "上移", + "desktop.sourceSettings.entryDown": "下移", + "desktop.sourceSettings.entryEmpty": "没有条目", + "desktop.sourceSettings.chooseTitle": "添加{title}", + "desktop.sourceSettings.chooseNone": "可添加的项都已在列表中。", + "desktop.sourceSettings.cancel": "取消", + "desktop.sourceSettings.modules": "模块", "desktop.toolchains.global": "全局默认", "desktop.toolchains.globalHelp": "统一管理自动识别和手动添加的 SDK,保存到应用的用户设置。项目可单独覆盖默认版本;已启动的进程需重启后使用新版本。", "desktop.toolchains.project": "当前项目" diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index eb46ace780..7a9a1dcf38 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -107953,6 +107953,82 @@ "count": "string" } }, + { + "id": "desktop.sourceSettings.entryAdd", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.sourceSettings.entryKind", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ], + "parameters": { + "title": "string" + } + }, + { + "id": "desktop.sourceSettings.entryRemove", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.sourceSettings.entryUp", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.sourceSettings.entryDown", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.sourceSettings.entryEmpty", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.sourceSettings.chooseTitle", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ], + "parameters": { + "title": "string" + } + }, + { + "id": "desktop.sourceSettings.chooseNone", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.sourceSettings.cancel", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.sourceSettings.modules", + "description": "Generic source-backed settings module list and entry list editor.", + "platforms": [ + "desktop" + ] + }, { "id": "desktop.toolchains.global", "description": "Machine-wide toolchain scope selector.", diff --git a/shared/platform-feature-matrix/features/declarative-plugin-settings.json b/shared/platform-feature-matrix/features/declarative-plugin-settings.json index 587e37367c..ccd3af2091 100644 --- a/shared/platform-feature-matrix/features/declarative-plugin-settings.json +++ b/shared/platform-feature-matrix/features/declarative-plugin-settings.json @@ -2,7 +2,7 @@ "id": "declarative-plugin-settings", "area": "插件", "group": "插件管理", - "capability": "声明式插件通过 Core 校验的设置声明提供整数、枚举、布尔、多选、文本、文件和目录设置,支持全局/项目继承、真实来源保存、通用界面、页面/动作注册及 restart/immediate/reload/nextRun 生效;实际启动与运行消费者必须读取同一来源。 声明动作经显式确认、安装/工作区身份复查与 Core 同工作区函数会话选择后调用;支持取消和完成状态,保留未保存草稿。 已启用插件动态贡献语言/构建系统页,同一应用内窗口按原生目录身份接收全局/项目保存通知,独立保留项目覆盖值与未保存草稿。 插件包可自带 l10n/<语言>.json 翻译设置文字,Core 按界面语言挑选文件并逐条回退到清单原文;切换界面语言后重读文字,但保留未保存草稿。 支持 Core 来源表单、编译器页面、有效/继承值和显式条件原子保存;读取项目工具须点击读取按钮。", + "capability": "声明式插件通过 Core 校验的设置声明提供整数、枚举、布尔、多选、文本、文件和目录设置,支持全局/项目继承、真实来源保存、通用界面、页面/动作注册及 restart/immediate/reload/nextRun 生效;实际启动与运行消费者必须读取同一来源。 声明动作经显式确认、安装/工作区身份复查与 Core 同工作区函数会话选择后调用;支持取消和完成状态,保留未保存草稿。 已启用插件动态贡献语言/构建系统页,同一应用内窗口按原生目录身份接收全局/项目保存通知,独立保留项目覆盖值与未保存草稿。 插件包可自带 l10n/<语言>.json 翻译设置文字,Core 按界面语言挑选文件并逐条回退到清单原文;切换界面语言后重读文字,但保留未保存草稿。 支持 Core 来源表单、编译器页面、有效/继承值和显式条件原子保存;读取项目工具须点击读取按钮。 来源表单支持 sourceSettings 1:模块侧栏(按父子缩进)、字段分组标签页,以及带添加/移除/排序、文件/目录/候选项三种添加方式和布尔/枚举属性列的条目列表;只读模块只显示条目。", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -48,7 +48,10 @@ "desktop/internal/pluginsettings/sources_test.go", "desktop/internal/settingswindow/source_settings_view.go", "desktop/internal/settingswindow/source_settings_view_test.go", - "desktop/internal/workbench/settings_plugin_sources.go" + "desktop/internal/workbench/settings_plugin_sources.go", + "desktop/internal/settingswindow/source_settings_entries.go", + "desktop/internal/settingswindow/source_settings_entries_view.go", + "desktop/internal/settingswindow/source_settings_modules_test.go" ] }, "windows": { @@ -96,11 +99,14 @@ "desktop/internal/pluginsettings/sources_test.go", "desktop/internal/settingswindow/source_settings_view.go", "desktop/internal/settingswindow/source_settings_view_test.go", - "desktop/internal/workbench/settings_plugin_sources.go" + "desktop/internal/workbench/settings_plugin_sources.go", + "desktop/internal/settingswindow/source_settings_entries.go", + "desktop/internal/settingswindow/source_settings_entries_view.go", + "desktop/internal/settingswindow/source_settings_modules_test.go" ] }, "owner": "Plugin Platform", - "verification": "Viva:共享 settings-documents fixture 经真实 Core C ABI 验证类型、作用层、整批拒绝及文档保留;原生来源覆盖权限/元数据、冲突、取消、捕获来源回读、提交后回读失败。Build/Debug 读取实际文件,明确失效路径不能静默回退;Build 全局专属程序不能被项目文件替换。LSP 启动同时传全局/项目设置、初始化选项与 Core 展开的 workspaceConfiguration。真实协议子进程在同一 Core 会话接收更新通知并重新拉取值;保存来源后服务层回读、展开并更新现有会话,损坏来源不推空配置。macOS 有定向测试与真实子进程证据;此前设置动作节点已在 Lithe-dev 通过完整消费者与定向 race;本节点结果按独立报告记录。已安装本地目录独立于商店网络,Core 绑定注册 ID/版本;原生快照拒绝安装替换。七种控件与全局/项目草稿已接线,macOS 无头驱动验证原生文本输入、明确保存回读、冲突保留、重新加载;共享模型验证七种类型及非法整数原文。保存后的即时通知与所属插件模型刷新已接线,旧模型回包不会覆盖待刷新状态,运行任务及无关模型保持。动作原生窗体、重启与完整生效状态、目标平台原生 UI 及正式市场准入尚未验收,宿主仍不声明 settings 2。 动作节点增加:实际按钮确认/取消,草稿不保存;真实提供方函数成功与取消、原进程复用、会话关闭后不可用;拒绝不同工作区/版本/未注册函数,显示版本不可替代私有身份,项目同路径重开不能接受过期动作。 动态页面节点验证 Core 启用过滤、多个贡献者、动作独立页面、搜索保留父节点、作用域/版本通知规则;Viva 验证页面/动作筛选与切页草稿保留;多工作台驱动验证同偏好目录全局通知、同项目通知、项目覆盖隔离、私有身份及旧生命周期拒绝。同一应用进程内通知不代表独立进程实时同步,也不新增多工作台创建入口。 设置列表填满表单标题下的高度、最少 160 像素,窗口放不下时滚动整页而不截断;Viva 无头驱动在最小窗口、800、1000 高度下验证语言页与已安装插件“设置”标签页的列表随窗口等量增长、底部与确定按钮间距不变、最后一项完整显示。 插件语言文件:契约 localization-cases 的 13 个用例经真实 Core 逐条比对 applied/rejected;保存回读保留译文;从已安装包读取前后,文件清单与字节不变;Viva 无头驱动验证切换界面语言、有草稿时不重读、确认弹窗用译后的按钮标题;读不了或被拒绝的语言文件各记一条 WARN。", + "verification": "Viva:共享 settings-documents fixture 经真实 Core C ABI 验证类型、作用层、整批拒绝及文档保留;原生来源覆盖权限/元数据、冲突、取消、捕获来源回读、提交后回读失败。Build/Debug 读取实际文件,明确失效路径不能静默回退;Build 全局专属程序不能被项目文件替换。LSP 启动同时传全局/项目设置、初始化选项与 Core 展开的 workspaceConfiguration。真实协议子进程在同一 Core 会话接收更新通知并重新拉取值;保存来源后服务层回读、展开并更新现有会话,损坏来源不推空配置。macOS 有定向测试与真实子进程证据;此前设置动作节点已在 Lithe-dev 通过完整消费者与定向 race;本节点结果按独立报告记录。已安装本地目录独立于商店网络,Core 绑定注册 ID/版本;原生快照拒绝安装替换。七种控件与全局/项目草稿已接线,macOS 无头驱动验证原生文本输入、明确保存回读、冲突保留、重新加载;共享模型验证七种类型及非法整数原文。保存后的即时通知与所属插件模型刷新已接线,旧模型回包不会覆盖待刷新状态,运行任务及无关模型保持。动作原生窗体、重启与完整生效状态、目标平台原生 UI 及正式市场准入尚未验收,宿主仍不声明 settings 2。 动作节点增加:实际按钮确认/取消,草稿不保存;真实提供方函数成功与取消、原进程复用、会话关闭后不可用;拒绝不同工作区/版本/未注册函数,显示版本不可替代私有身份,项目同路径重开不能接受过期动作。 动态页面节点验证 Core 启用过滤、多个贡献者、动作独立页面、搜索保留父节点、作用域/版本通知规则;Viva 验证页面/动作筛选与切页草稿保留;多工作台驱动验证同偏好目录全局通知、同项目通知、项目覆盖隔离、私有身份及旧生命周期拒绝。同一应用进程内通知不代表独立进程实时同步,也不新增多工作台创建入口。 设置列表填满表单标题下的高度、最少 160 像素,窗口放不下时滚动整页而不截断;Viva 无头驱动在最小窗口、800、1000 高度下验证语言页与已安装插件“设置”标签页的列表随窗口等量增长、底部与确定按钮间距不变、最后一项完整显示。 插件语言文件:契约 localization-cases 的 13 个用例经真实 Core 逐条比对 applied/rejected;保存回读保留译文;从已安装包读取前后,文件清单与字节不变;Viva 无头驱动验证切换界面语言、有草稿时不重读、确认弹窗用译后的按钮标题;读不了或被拒绝的语言文件各记一条 WARN。 模块结构节点:Core settings-sources-modules fixture 经真实 C ABI 读取;Viva 无头驱动验证模块侧栏按父子缩进且只显示所选模块、标签页只显示本组字段、浏览不产生草稿;排序、勾选导出、从候选项对话框添加后保存,Core 规划的写入按顺序且去掉显示文字;全部移除为显式空列表,插件给出继承值时才提供重置;只读模块无编辑控件且条目不可选。自动化:TestSourceModuleListShowsTheSelectedModuleOneTabAtATime、TestSourceEntryListEditsReachThePluginWithoutDisplayText、TestSourceEntryListRemovesToAnExplicitEmptyListAndResets、TestReadOnlyModuleShowsEntriesWithoutEditing、TestEntryDraftsCompareWithoutDisplayTextAndSkipDuplicatePaths;截图 TestVisualModuleStructureForm(中英、深浅主题)。原生文件/目录选择器只在实机验收,Windows 实机未执行。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -132,5 +138,5 @@ "verificationStatus": "pending" } }, - "notes": "partial 包含原生双层存储、运行消费、离线目录、七类控件、声明动作、动态页面及同一应用内跨窗口通知。语言状态卡、完整 settings v2、独立进程同步及原生产品验收仍 pending;宿主现已声明 settings 2。 Viva 2026-11-14:设置页每项是标题行(标题、ⓘ 说明、重置)加控件行,开关不再重复标题,标题只作无障碍名称;去掉每行常驻的“继承值”说明,作用范围的说明收进范围选择旁的 ⓘ;无效值和仅全局可改两条状态提示保留;自动化:TestPluginSettingsFormEditsOnlyOnExplicitSaveAndPreservesConflictDraft,截图场景 TestVisualPluginSettingsForm。 Viva 2026-11-14:插件设置文字由包内 l10n/<语言>.json 翻译(API-37)。宿主经 configfile 从已安装插件目录只读地取文件,由 Core 选候选并逐条回退。自动化:TestPresentedLoadFollowsContractLocalizationCases、TestInstalledSettingsEditorTranslatesFromThePackageWithoutWritingIt、TestPluginSettingsTextFollowsTheWindowLanguageWithoutDiscardingDrafts、TestPluginSettingsLoadLogsSkippedAndRefusedTranslations;目标平台真机界面验收仍 pending。 Viva 2026-11-16:设置项改为单行,左侧标题与 ⓘ,右侧开关/下拉/输入框与重置按钮;窗格放不下时控件与重置整体换到标题下方,多选、整数范围和状态提示仍在行下。取代 2026-11-14 的标题行加控件行布局。截图 TestVisualPluginSettingsPage(宽页面与插件详情窄窗格、深浅主题)。原生验收仍 pending。" + "notes": "partial 包含原生双层存储、运行消费、离线目录、七类控件、声明动作、动态页面及同一应用内跨窗口通知。语言状态卡、完整 settings v2、独立进程同步及原生产品验收仍 pending;宿主现已声明 settings 2。 Viva 2026-11-14:设置页每项是标题行(标题、ⓘ 说明、重置)加控件行,开关不再重复标题,标题只作无障碍名称;去掉每行常驻的“继承值”说明,作用范围的说明收进范围选择旁的 ⓘ;无效值和仅全局可改两条状态提示保留;自动化:TestPluginSettingsFormEditsOnlyOnExplicitSaveAndPreservesConflictDraft,截图场景 TestVisualPluginSettingsForm。 Viva 2026-11-14:插件设置文字由包内 l10n/<语言>.json 翻译(API-37)。宿主经 configfile 从已安装插件目录只读地取文件,由 Core 选候选并逐条回退。自动化:TestPresentedLoadFollowsContractLocalizationCases、TestInstalledSettingsEditorTranslatesFromThePackageWithoutWritingIt、TestPluginSettingsTextFollowsTheWindowLanguageWithoutDiscardingDrafts、TestPluginSettingsLoadLogsSkippedAndRefusedTranslations;目标平台真机界面验收仍 pending。 Viva 2026-11-16:设置项改为单行,左侧标题与 ⓘ,右侧开关/下拉/输入框与重置按钮;窗格放不下时控件与重置整体换到标题下方,多选、整数范围和状态提示仍在行下。取代 2026-11-14 的标题行加控件行布局。截图 TestVisualPluginSettingsPage(宽页面与插件详情窄窗格、深浅主题)。原生验收仍 pending。 Viva 2026-11-17:宿主声明 sourceSettings [0,1](#2086)。侧栏布局的来源组在表单左侧显示模块列表,其他组各占一项;所选模块的字段按 section 分标签页(只有一组时不显示标签),条目列表的工具栏为 + − ↑ ↓ 图标按钮和属性列标题,添加菜单按条目种类调用原生文件/目录选择器或候选项对话框。" }