Skip to content

Commit 3be45fb

Browse files
1lckclaude
andauthored
fix(settings): 只读来源的列表逐行显示,不再显示重置和浏览 (#2081)
插件以只读方式投影的来源(writable:false)中,stringList/fileList 字段 原先渲染成单行省略的只读框,只能看到第一项;同时仍显示禁用的“重置” 和“浏览…”。现在只读列表每项一行显示,只读来源不显示这两个操作。 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b09093c commit 3be45fb

3 files changed

Lines changed: 57 additions & 5 deletions

File tree

‎desktop/internal/settingswindow/plugin_settings_view.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package settingswindow
33
import (
44
"errors"
55
"strconv"
6+
"strings"
67

78
"github.com/1lck/Lithe-IDEA/desktop/internal/configfile"
89
"github.com/1lck/Lithe-IDEA/desktop/internal/core"
@@ -199,6 +200,18 @@ func (w *window) readOnlyField(c ui.C, label, value string) {
199200
})
200201
}
201202

203+
// readOnlyList shows a list value that cannot be edited one item per line, as the TextArea
204+
// shows it while it can be, so a read-only list is not cut down to its first item.
205+
func (w *window) readOnlyList(c ui.C, label, value string) {
206+
ui.Column(c).FillWidth().MinWidth(0).PadX(10).PadY(6).Gap(2).Border(1, w.pal.line).Radius(6).
207+
HitWith(ui.ID(c), label, gfx.HitOptions{Role: gfx.RoleTextField, Value: value, ReadOnly: true, Disabled: true}).
208+
Children(func() {
209+
for index, line := range strings.Split(value, "\n") {
210+
ui.Text(c.Key(strconv.Itoa(index)), line).FontSize(13).Color(w.pal.muted).FillWidth().Ellipsis()
211+
}
212+
})
213+
}
214+
202215
// pluginSettingRow declares one setting on one line: its title on the leading side, and on
203216
// the trailing side the control for its kind and Reset, so the controls of a page line up
204217
// down its trailing edge. A text, path or list takes most of the line, and moves under the

‎desktop/internal/settingswindow/source_settings_view.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ func (w *window) sourceSettingsPanel(c ui.C, p *sourceSettingsForm) {
268268
if field.EffectiveSource != "" {
269269
ui.Text(row.C, field.EffectiveSource).FontSize(11).Color(w.pal.muted)
270270
}
271-
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() {
271+
// A source the plugin projects read-only has nothing to reset.
272+
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() {
272273
control := p.controls[source.ID][field.ID]
273274
control.input = control.inherited
274275
p.changed(source.ID, field.ID)
@@ -374,9 +375,12 @@ func (w *window) sourceSettingsControl(c ui.C, p *sourceSettingsForm, source cor
374375
p.changed(source.ID, field.ID)
375376
}
376377
default:
377-
if disabled {
378+
list := field.Kind == "stringList" || field.Kind == "fileList"
379+
if disabled && list {
380+
w.readOnlyList(c, field.Title, control.input.Text)
381+
} else if disabled {
378382
w.readOnlyField(c, field.Title, control.input.Text)
379-
} else if field.Kind == "stringList" || field.Kind == "fileList" {
383+
} else if list {
380384
if ui.TextArea(c, &control.input.Text, field.Title, "").FillWidth().Height(100).Changed() {
381385
control.input.Inherit = false
382386
p.changed(source.ID, field.ID)
@@ -387,7 +391,7 @@ func (w *window) sourceSettingsControl(c ui.C, p *sourceSettingsForm, source cor
387391
p.changed(source.ID, field.ID)
388392
}
389393
}
390-
if field.Kind == "fileList" && ui.Button(c, i18n.Shared(language, "desktop.pluginSettings.browse")).Outline().Disabled(disabled).Clicked() {
394+
if field.Kind == "fileList" && source.Writable && ui.Button(c, i18n.Shared(language, "desktop.pluginSettings.browse")).Outline().Disabled(disabled).Clicked() {
391395
c.After(func() {
392396
paths, err := app.OpenFiles(app.OpenFileOptions{Title: field.Title})
393397
// log-exempt: 用户取消:文件选择器取消不修改依赖草稿。

‎desktop/internal/settingswindow/source_settings_view_test.go‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *nativeFormFixture) SaveSources(ctx context.Context, _ pluginservice.Set
3737
s.saves <- edits
3838
return editor, s.failure
3939
}
40-
func nativeFormSource(t *testing.T) *nativeFormFixture {
40+
func nativeFormSource(t *testing.T, adjust ...func(*core.SourceSettingsSnapshot)) *nativeFormFixture {
4141
t.Helper()
4242
manifest, err := os.ReadFile(contractfixture.Path("fixtures/settings/source-editor.plugin.json"))
4343
if err != nil {
@@ -62,6 +62,9 @@ func nativeFormSource(t *testing.T) *nativeFormFixture {
6262
t.Fatal(err)
6363
}
6464
fixture.Snapshot.Sources[1].Revision = fmt.Sprintf("sha256:%x", sha256.Sum256(contents))
65+
for _, fn := range adjust {
66+
fn(&fixture.Snapshot)
67+
}
6568
raw, err := json.Marshal(fixture.Snapshot)
6669
if err != nil {
6770
t.Fatal(err)
@@ -161,3 +164,35 @@ func TestNativeCompilerPageRequiresAnExplicitRead(t *testing.T) {
161164
t.Fatal("the explicit read did not query exactly once")
162165
}
163166
}
167+
168+
// A source the plugin projects read-only shows every item of a list, one per line, and
169+
// offers no Reset: an ellipsized single line hid all but the first item.
170+
func TestNativeSettingsFormShowsReadOnlyListsInFull(t *testing.T) {
171+
items := []string{"web/lib/*.jar", "Server Runtime — 2 JARs", "Global Utils — IDE library"}
172+
source := nativeFormSource(t, func(snapshot *core.SourceSettingsSnapshot) {
173+
snapshot.Sources[0].Writable = false
174+
for index := range snapshot.Sources[0].Fields {
175+
if field := &snapshot.Sources[0].Fields[index]; field.ID == "files" {
176+
value, _ := json.Marshal(items)
177+
field.Value, field.EffectiveValue = value, value
178+
}
179+
}
180+
})
181+
w := nativeFormWindow(t, source, i18n.English, "light")
182+
d := openWindow(t, w, func(config *app.Config) { config.Height = 1100 })
183+
openNativeForm(t, w, d)
184+
d.pump()
185+
for _, item := range items {
186+
if !d.text(item) {
187+
t.Fatalf("read-only list item %q is not shown", item)
188+
}
189+
}
190+
if hit := d.hit("Referenced files"); !hit.ReadOnly {
191+
t.Fatalf("the read-only list accepts input: %+v", hit)
192+
}
193+
for _, action := range []string{"desktop.pluginSettings.reset", "desktop.pluginSettings.browse"} {
194+
if d.has(i18n.Shared(i18n.English, action)) {
195+
t.Fatalf("a read-only source offers %s", action)
196+
}
197+
}
198+
}

0 commit comments

Comments
 (0)