diff --git a/desktop/internal/settingswindow/plugin_settings_view.go b/desktop/internal/settingswindow/plugin_settings_view.go index 667640bc44..0d1163f31b 100644 --- a/desktop/internal/settingswindow/plugin_settings_view.go +++ b/desktop/internal/settingswindow/plugin_settings_view.go @@ -3,6 +3,7 @@ package settingswindow import ( "errors" "strconv" + "strings" "github.com/1lck/Lithe-IDEA/desktop/internal/configfile" "github.com/1lck/Lithe-IDEA/desktop/internal/core" @@ -199,6 +200,18 @@ func (w *window) readOnlyField(c ui.C, label, value string) { }) } +// readOnlyList shows a list value that cannot be edited one item per line, as the TextArea +// shows it while it can be, so a read-only list is not cut down to its first item. +func (w *window) readOnlyList(c ui.C, label, value string) { + ui.Column(c).FillWidth().MinWidth(0).PadX(10).PadY(6).Gap(2).Border(1, w.pal.line).Radius(6). + HitWith(ui.ID(c), label, gfx.HitOptions{Role: gfx.RoleTextField, Value: value, ReadOnly: true, Disabled: true}). + Children(func() { + for index, line := range strings.Split(value, "\n") { + ui.Text(c.Key(strconv.Itoa(index)), line).FontSize(13).Color(w.pal.muted).FillWidth().Ellipsis() + } + }) +} + // pluginSettingRow declares one setting on one line: its title on the leading side, and on // the trailing side the control for its kind and Reset, so the controls of a page line up // down its trailing edge. A text, path or list takes most of the line, and moves under the diff --git a/desktop/internal/settingswindow/source_settings_view.go b/desktop/internal/settingswindow/source_settings_view.go index fbd7a01fec..ea391f4229 100644 --- a/desktop/internal/settingswindow/source_settings_view.go +++ b/desktop/internal/settingswindow/source_settings_view.go @@ -268,7 +268,8 @@ func (w *window) sourceSettingsPanel(c ui.C, p *sourceSettingsForm) { if field.EffectiveSource != "" { ui.Text(row.C, field.EffectiveSource).FontSize(11).Color(w.pal.muted) } - if 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() { + // 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) @@ -374,9 +375,12 @@ func (w *window) sourceSettingsControl(c ui.C, p *sourceSettingsForm, source cor p.changed(source.ID, field.ID) } default: - if disabled { + list := field.Kind == "stringList" || field.Kind == "fileList" + if disabled && list { + w.readOnlyList(c, field.Title, control.input.Text) + } else if disabled { w.readOnlyField(c, field.Title, control.input.Text) - } else if field.Kind == "stringList" || field.Kind == "fileList" { + } else if list { if ui.TextArea(c, &control.input.Text, field.Title, "").FillWidth().Height(100).Changed() { control.input.Inherit = false p.changed(source.ID, field.ID) @@ -387,7 +391,7 @@ func (w *window) sourceSettingsControl(c ui.C, p *sourceSettingsForm, source cor p.changed(source.ID, field.ID) } } - if field.Kind == "fileList" && ui.Button(c, i18n.Shared(language, "desktop.pluginSettings.browse")).Outline().Disabled(disabled).Clicked() { + if field.Kind == "fileList" && source.Writable && ui.Button(c, i18n.Shared(language, "desktop.pluginSettings.browse")).Outline().Disabled(disabled).Clicked() { c.After(func() { paths, err := app.OpenFiles(app.OpenFileOptions{Title: field.Title}) // log-exempt: 用户取消:文件选择器取消不修改依赖草稿。 diff --git a/desktop/internal/settingswindow/source_settings_view_test.go b/desktop/internal/settingswindow/source_settings_view_test.go index 77f6686c8e..e5763b42b4 100644 --- a/desktop/internal/settingswindow/source_settings_view_test.go +++ b/desktop/internal/settingswindow/source_settings_view_test.go @@ -37,7 +37,7 @@ func (s *nativeFormFixture) SaveSources(ctx context.Context, _ pluginservice.Set s.saves <- edits return editor, s.failure } -func nativeFormSource(t *testing.T) *nativeFormFixture { +func nativeFormSource(t *testing.T, adjust ...func(*core.SourceSettingsSnapshot)) *nativeFormFixture { t.Helper() manifest, err := os.ReadFile(contractfixture.Path("fixtures/settings/source-editor.plugin.json")) if err != nil { @@ -62,6 +62,9 @@ func nativeFormSource(t *testing.T) *nativeFormFixture { t.Fatal(err) } fixture.Snapshot.Sources[1].Revision = fmt.Sprintf("sha256:%x", sha256.Sum256(contents)) + for _, fn := range adjust { + fn(&fixture.Snapshot) + } raw, err := json.Marshal(fixture.Snapshot) if err != nil { t.Fatal(err) @@ -161,3 +164,35 @@ func TestNativeCompilerPageRequiresAnExplicitRead(t *testing.T) { t.Fatal("the explicit read did not query exactly once") } } + +// A source the plugin projects read-only shows every item of a list, one per line, and +// offers no Reset: an ellipsized single line hid all but the first item. +func TestNativeSettingsFormShowsReadOnlyListsInFull(t *testing.T) { + items := []string{"web/lib/*.jar", "Server Runtime — 2 JARs", "Global Utils — IDE library"} + source := nativeFormSource(t, func(snapshot *core.SourceSettingsSnapshot) { + snapshot.Sources[0].Writable = false + for index := range snapshot.Sources[0].Fields { + if field := &snapshot.Sources[0].Fields[index]; field.ID == "files" { + value, _ := json.Marshal(items) + field.Value, field.EffectiveValue = value, value + } + } + }) + w := nativeFormWindow(t, source, i18n.English, "light") + d := openWindow(t, w, func(config *app.Config) { config.Height = 1100 }) + openNativeForm(t, w, d) + d.pump() + for _, item := range items { + if !d.text(item) { + t.Fatalf("read-only list item %q is not shown", item) + } + } + if hit := d.hit("Referenced files"); !hit.ReadOnly { + t.Fatalf("the read-only list accepts input: %+v", hit) + } + for _, action := range []string{"desktop.pluginSettings.reset", "desktop.pluginSettings.browse"} { + if d.has(i18n.Shared(i18n.English, action)) { + t.Fatalf("a read-only source offers %s", action) + } + } +}