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
13 changes: 13 additions & 0 deletions desktop/internal/settingswindow/plugin_settings_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions desktop/internal/settingswindow/source_settings_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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: 用户取消:文件选择器取消不修改依赖草稿。
Expand Down
37 changes: 36 additions & 1 deletion desktop/internal/settingswindow/source_settings_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Loading