diff --git a/.agents/notes/implemented/architecture/2026-11-18-builtin-process-runs-and-run-file-formats.md b/.agents/notes/implemented/architecture/2026-11-18-builtin-process-runs-and-run-file-formats.md index 71fce0f138..564c9bf098 100644 --- a/.agents/notes/implemented/architecture/2026-11-18-builtin-process-runs-and-run-file-formats.md +++ b/.agents/notes/implemented/architecture/2026-11-18-builtin-process-runs-and-run-file-formats.md @@ -60,10 +60,29 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 对话框参照 IDEA 的同名窗口(`runconfig_dialog.go`、`runconfig_dialog_view.go`),在应用窗口内以模态层显示,不开系统窗口。入口有三个:标题栏运行下拉的“新建运行配置…”和“编辑运行配置…”,以及构建窗口配置列表表头的“+”。列表里的编辑按钮也打开它,并选中那一条。 -- 左侧工具栏是“+”(按类型新建)、“−”(删除)和复制。配置树按类型分组,分组可以折叠,折叠状态在再次打开时保留。 -- 每条被选中过的配置都有自己的草稿。新建、修改和删除都先记在草稿里:“应用”先删除,再按配置树的顺序保存有改动的草稿,完成后留在对话框;“确定”保存后关闭;“取消”丢弃全部改动;“运行”保存后关闭,并运行选中的配置。 +- 左侧工具栏依次是“+”(按类型新建)、“−”(删除)、复制、新建文件夹和“按字母顺序排序”开关。配置树按类型分组,类型下面先列文件夹,再列不在文件夹里的配置;分组和文件夹都可以折叠,折叠状态在再次打开时保留。 +- 焦点在配置树上时,macOS 按 ⌫ 或 ⌦、其他平台按 Delete 删除选中的配置(选中文件夹时解散文件夹),和“−”一样只记进草稿。macOS 按 ⌃N、其他平台按 Alt+Insert 打开新建菜单;这两个快捷键只挂在左侧一列上,右侧编辑器里的文本框照常用 ⌃N 换行。 +- 没有配置时和 IDEA 一样:左侧写“未添加运行配置。”和链接“添加新… ⌃N”,右侧是链接“添加新的运行配置…”和“或选择要编辑的运行配置”,两个链接都打开类型菜单。有配置但没选中时,右侧也是这一页。 +- 每条被选中过的配置都有自己的草稿。新建、修改、复制、删除、文件夹和顺序都先记在草稿里:“应用”依次保存有改动的草稿、复制品,再删除,最后保存文件夹和顺序,完成后留在对话框;“确定”保存后关闭;“取消”丢弃全部改动;“运行”保存后关闭,并运行选中的配置。 - 新建的配置第一次保存后换成 Core 给的 `user:` ID;只有 `user:` 配置能删除。第一处失败就停下,选中出错的那条配置并在它的编辑器里显示原因,对话框不关闭;失败前已保存的部分照常生效。 - 构建插件提供的运行也在这个对话框里编辑,用的是 `runconfig_edit.go` 的编辑器;内置运行用 Core 描述的表单。 +- 树的行在 Viva 的 `ui.Tree` 里没有自己的标识,挂悬停提示会直接 panic,所以不可运行的行只带警告图标,原因写在行的无障碍标签和右侧编辑器顶部。 + +### 文件夹、顺序和复制 + +文件夹参照 IDEA 的 `folderName`,存在配置本身的 `folder` 字段里:项目层的配置写进 `configurations.yaml`,跟团队共享;本机配置和插件生成的配置写进 `local.yaml`(生成的配置只写一条 `{id, folder}` 覆盖)。文件夹只属于一个类型,没有单独的文件夹列表:一个文件夹里的配置都移走或删掉以后,文件夹就没了;刚建的空文件夹只在对话框打开期间存在。 + +列表的顺序和“按字母排序”是这台机器上的选择,只存在 `local.yaml` 的 `arrangement` 里(`sortAlphabetically`、`order`),不进项目文件,避免团队成员互相改写。默认按名称排序(忽略大小写)。关掉排序后才能把配置拖到别的位置;重新打开排序时,保存的手动顺序保留,下次关掉还能恢复。`order` 里不再存在的 ID 跳过,没列进去的配置按名称排在后面。`runConfig.resolve` 按这个顺序返回配置,并带回 `sortAlphabetically`,所以标题栏下拉、构建窗口和对话框的顺序一致。这些规则都在 Core 的 `execution/src/configuration/arrangement.rs`,宿主用 `runConfig.arrange` 提交 `{folders, order, sortAlphabetically}`,拿回的仍是 `changes`。 + +复制分两种: + +- 内置运行按表单当前显示的值复制,新草稿名为“<原名>(副本)”、留在原来的文件夹,保存位置跟着表单里的“存为项目文件”。 +- 其他配置(包括构建插件生成的运行)在“应用”时由 Core 的 `runConfig.copyConfiguration` 复制,保留原配置保存的全部选择。复制品是用户配置,生成的运行复制后存进 `.lithe/run/plugin/<插件 ID>.local.toml`,原来那条照常列出、不被遮住。保存前复制品的编辑器只提示“按应用或确定后生成副本”,不能运行,也不能再复制。 + +### 正确做法(文件夹与顺序) + +- 新的排列方式(比如按类型以外的维度分组)先在 Core 的 `Arrangement` 里定义和存储,再让宿主画;宿主不自己排序或记顺序。 +- 只要改了名字或新建了配置,而列表又是手动顺序,就把配置树当前显示的顺序一起保存,否则新 ID 会掉到列表末尾。 ### 从界面按下运行时打开 Run 窗口 @@ -96,6 +115,14 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 实现简单,点两下就能新建。没有采用:用户要求参照 IDEA,在一个窗口里同时看到全部配置、切换着编辑,改完一起应用;子菜单也放不下“仅 Windows”这类说明和以后更多的类型。 +### 文件夹单独存一份列表,或连顺序一起存进项目文件 + +单独的文件夹列表能保留空文件夹,顺序进项目文件能让全队看到同样的列表。没有采用:IDEA 把文件夹记在配置上,顺序记在 workspace 里,用户要的就是这种行为;文件夹列表和配置分开存,会出现指向已删除配置的文件夹。顺序是个人习惯,放进项目文件后,每个人拖一下都会在版本控制里产生冲突。 + +### 复制插件生成的运行时只复制表单值 + +和内置运行的复制走同一条路。没有采用:插件运行没有 Core 描述的表单,宿主只拿得到界面上显示的部分,会丢掉插件保存的目标、执行方式等不透明字段。交给 Core 复制,才能保留全部选择,并按插件拆分的 TOML 规则落盘。 + ### 全部配置都用 YAML,或都用 TOML 一种格式更简单。没有采用:内置配置只有通用字段,YAML 适合手写和代码评审;插件配置要带一个“依赖哪个插件、哪个版本”的头,TOML 的 `[plugin]` 表把元数据和配置分得清楚。按插件拆文件后,卸载插件或插件出错只影响一份文件。 @@ -121,9 +148,9 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 ## 验证 -- `scripts/desktop/desktop-go.sh test ./internal/core/... ./internal/buildprocess/... ./internal/workbench/...`:`runconfig_process_test.go` 用系统 shell 真实运行脚本,并断言 Run 窗口打开、输出进入控制台;`runconfig_dialog_test.go` 覆盖对话框的应用、取消、删除、复制、分组折叠,以及批处理在非 Windows 上能编辑、能保存、不能运行;`runconfig_browser_test.go`、`title_run_test.go`、`runconfig_edit_test.go` 覆盖列表、标题栏和插件运行的编辑。 +- `scripts/desktop/desktop-go.sh test ./internal/core/... ./internal/buildprocess/... ./internal/workbench/...`:`runconfig_process_test.go` 用系统 shell 真实运行脚本,并断言 Run 窗口打开、输出进入控制台;`runconfig_dialog_test.go` 覆盖对话框的应用、取消、删除(含 ⌫/Delete 键)、复制(含插件运行复制进 `<插件 ID>.local.toml`)、文件夹的新建、重命名和解散、手动顺序与排序开关、IDEA 式空白页和 ⌃N/Alt+Insert、分组折叠,以及批处理在非 Windows 上能编辑、能保存、不能运行;`runconfig_browser_test.go`、`title_run_test.go`、`runconfig_edit_test.go` 覆盖列表、标题栏和插件运行的编辑。 - `scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/workbench -run '^(TestVisualBuiltInProcessRuns|TestVisualTitleRunWithoutConfigurations)$'`:设置 `LITHE_VISUAL_OUTPUT_DIR` 后生成 `docs/assets/builtin-process-runs/` 和 `docs/assets/run-config-empty/` 的截图。 -- Core 仓库的 `cargo test -p lithe-execution -p lithe-core`:覆盖表单、校验、启动计划、YAML/TOML 读写、旧 JSON 和插件可用性。 +- Core 仓库的 `cargo test -p lithe-execution -p lithe-core`:覆盖表单、校验、启动计划、YAML/TOML 读写、旧 JSON、插件可用性,以及 `run_configuration_arrangement.rs` 里文件夹写入哪一层、顺序只进本机、复制保留全部选择。 - `./scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:确认运行不写发行目录。 ## 适用范围 @@ -138,4 +165,4 @@ Shell 脚本、PowerShell 脚本、cmd 批处理(只能在 Windows 上运行 - `desktop/internal/workbench/runconfig.go` - `desktop/internal/core/run_process.go` - `desktop/internal/buildprocess/` -- Core 仓库的内置运行与文件格式:[process.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/rust/crates/execution/src/configuration/process.rs)、[storage.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/rust/crates/execution/src/configuration/storage.rs)、[plugin_document.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/rust/crates/execution/src/configuration/plugin_document.rs) +- Core 仓库的内置运行与文件格式:[process.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/rust/crates/execution/src/configuration/process.rs)、[storage.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/rust/crates/execution/src/configuration/storage.rs)、[plugin_document.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/rust/crates/execution/src/configuration/plugin_document.rs)、[arrangement.rs](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/rust/crates/execution/src/configuration/arrangement.rs) diff --git a/desktop/internal/core/run_config.go b/desktop/internal/core/run_config.go index a437999d85..df4f728969 100644 --- a/desktop/internal/core/run_config.go +++ b/desktop/internal/core/run_config.go @@ -32,8 +32,11 @@ type RunProviderRun struct { // detected, team and local layers. Extensions stay raw except for the build // reference the host needs to find the provider instance. type RunConfiguration struct { - ID string `json:"id"` - Name string `json:"name"` + ID string `json:"id"` + Name string `json:"name"` + // Folder is the folder the configuration is listed in within its kind; "" when + // it is in none. It is display only. + Folder string `json:"folder,omitempty"` Provider string `json:"provider"` Execution string `json:"execution"` Category string `json:"category,omitempty"` @@ -150,6 +153,9 @@ type RunConfigResolution struct { Message string `json:"message"` } `json:"diagnostics"` DefaultRunConfiguration *string `json:"defaultRunConfiguration"` + // SortAlphabetically says Configurations are listed by name; otherwise they come in + // the order the user placed them on this machine. + SortAlphabetically bool `json:"sortAlphabetically"` } // ResolveRunConfigurations merges the workspace's run configuration layers diff --git a/desktop/internal/core/run_process.go b/desktop/internal/core/run_process.go index 2bf5fe3ffe..a54e309353 100644 --- a/desktop/internal/core/run_process.go +++ b/desktop/internal/core/run_process.go @@ -141,6 +141,46 @@ func (c *Client) DeleteRunConfiguration(ctx context.Context, root, configuration return result.Changes, err } +// CopyRunConfiguration returns the new `user:` ID of a copy of configuration +// configurationID named name, and the file changes that save it. Any configuration +// can be copied; copying a generated build provider run also saves the original in +// the local layer, so the copy does not take its place. +func (c *Client) CopyRunConfiguration(ctx context.Context, root, configurationID, name string, plugins []RunInstalledPlugin) (string, []RunConfigChange, error) { + var result struct { + ID string `json:"id"` + Changes []RunConfigChange `json:"changes"` + } + err := c.Execute(ctx, "runConfig.copyConfiguration", struct { + Root string `json:"root"` + ConfigurationID string `json:"configurationId"` + Name string `json:"name"` + Plugins []RunInstalledPlugin `json:"plugins,omitempty"` + }{root, configurationID, name, plugins}, &result) + return result.ID, result.Changes, err +} + +// RunConfigArrangement is a `runConfig.arrange` request. Folders maps configuration +// IDs to the folder each moves to, nil taking it out of its folder; Order replaces +// the saved manual order and SortAlphabetically the sort choice when set. +type RunConfigArrangement struct { + Root string `json:"root"` + Folders map[string]*string `json:"folders,omitempty"` + Order []string `json:"order,omitempty"` + SortAlphabetically *bool `json:"sortAlphabetically,omitempty"` + Plugins []RunInstalledPlugin `json:"plugins,omitempty"` +} + +// ArrangeRunConfigurations returns the file changes that move configurations between +// folders and save the list's order. A folder is saved with the configuration, the +// order on this machine only. +func (c *Client) ArrangeRunConfigurations(ctx context.Context, request RunConfigArrangement) ([]RunConfigChange, error) { + var result struct { + Changes []RunConfigChange `json:"changes"` + } + err := c.Execute(ctx, "runConfig.arrange", request, &result) + return result.Changes, err +} + // RunPlanExecutable is the program a launch plan starts: Command, a name looked // up on the PATH of the launch environment; Path, a native absolute path; or // Toolchain, a runtime the host resolves from its toolchain registry. diff --git a/desktop/internal/fileicons/NOTICE b/desktop/internal/fileicons/NOTICE index 9a884b0325..2bc6c14f1d 100644 --- a/desktop/internal/fileicons/NOTICE +++ b/desktop/internal/fileicons/NOTICE @@ -38,9 +38,10 @@ client's NOTICE.txt records the source paths and revisions of the restored icons platform/icons/src/expui/nodes/; task.svg from platform/external-system-impl/resources/icons/newui/. -license.svg and makefile.svg (and their _dark siblings) are original Lithe icons, -because the Community set has no LICENSE or Makefile glyph; they follow the Lithe -repository license. +license.svg, makefile.svg, powershell.svg, batch.svg and executable.svg (and their _dark +siblings) are original Lithe icons, because the Community set has no LICENSE, Makefile, +PowerShell, Windows batch file or Windows program glyph; they follow the Lithe repository +license. The icons of the languages whose grammars the editor bundles but the Community set has no glyph for were copied from these sources: diff --git a/desktop/internal/fileicons/fileicons.go b/desktop/internal/fileicons/fileicons.go index 163b3d54b7..c78cdcf715 100644 --- a/desktop/internal/fileicons/fileicons.go +++ b/desktop/internal/fileicons/fileicons.go @@ -55,6 +55,10 @@ const ( kindShell // kindPowerShell identifies a PowerShell script. kindPowerShell + // kindBatch identifies a Windows batch file. + kindBatch + // kindExecutable identifies a Windows program. + kindExecutable // kindLua identifies a Lua file. kindLua // kindZig identifies a Zig source or ZON file. @@ -150,6 +154,8 @@ var kindIcons = [kindCount][2]*gfx.Icon{ kindCSharp: {&Csharp, &CsharpDark}, kindShell: {&Shell, &ShellDark}, kindPowerShell: {&Powershell, &PowershellDark}, + kindBatch: {&Batch, &BatchDark}, + kindExecutable: {&Executable, &ExecutableDark}, kindLua: {&Lua, nil}, kindZig: {&Zig, nil}, kindProtobuf: {&ProtoFile, &ProtoFileDark}, @@ -420,6 +426,10 @@ func fileKind(name string) kind { return kindShell case "ps1", "psm1", "psd1", "ps1xml", "psc1", "pssc": return kindPowerShell + case "bat", "cmd": + return kindBatch + case "exe": + return kindExecutable case "lua": return kindLua case "zig", "zon": diff --git a/desktop/internal/fileicons/fileicons_test.go b/desktop/internal/fileicons/fileicons_test.go index 16f1606640..f9fd284810 100644 --- a/desktop/internal/fileicons/fileicons_test.go +++ b/desktop/internal/fileicons/fileicons_test.go @@ -58,6 +58,11 @@ func TestFileKind(t *testing.T) { {"file.", kindUnknown}, {"App.TSX", kindJavaScript}, {"archive.tar.gz", kindBinary}, + {"deploy.sh", kindShell}, + {"deploy.ps1", kindPowerShell}, + {"deploy.cmd", kindBatch}, + {"DEPLOY.BAT", kindBatch}, + {"tool.exe", kindExecutable}, } for _, test := range tests { diff --git a/desktop/internal/fileicons/icons.go b/desktop/internal/fileicons/icons.go index a2f899161e..664526e2f3 100644 --- a/desktop/internal/fileicons/icons.go +++ b/desktop/internal/fileicons/icons.go @@ -39,9 +39,10 @@ // platform/icons/src/expui/nodes/; task.svg from // platform/external-system-impl/resources/icons/newui/. // -// license.svg and makefile.svg (and their _dark siblings) are original Lithe icons, -// because the Community set has no LICENSE or Makefile glyph; they follow the Lithe -// repository license. +// license.svg, makefile.svg, powershell.svg, batch.svg and executable.svg (and their _dark +// siblings) are original Lithe icons, because the Community set has no LICENSE, Makefile, +// PowerShell, Windows batch file or Windows program glyph; they follow the Lithe repository +// license. // // The icons of the languages whose grammars the editor bundles but the Community set has no // glyph for were copied from these sources: @@ -515,6 +516,130 @@ var ArtifactDark = gfx.Icon{ }, } +// batch is a compiled vector icon. +var Batch = gfx.Icon{ + ViewBox: 16.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Layers: []gfx.IconLayer{ + {Fill: gfx.Color{Red: 0.286275, Green: 0.294118, Blue: 0.341176, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 2.5), + gfx.LineTo(13.0, 2.5), + gfx.CubicTo(13.8284, 2.5, 14.5, 3.17157, 14.5, 4.0), + gfx.LineTo(14.5, 12.0), + gfx.CubicTo(14.5, 12.8284, 13.8284, 13.5, 13.0, 13.5), + gfx.LineTo(3.0, 13.5), + gfx.CubicTo(2.17157, 13.5, 1.5, 12.8284, 1.5, 12.0), + gfx.LineTo(1.5, 4.0), + gfx.CubicTo(1.5, 3.17157, 2.17157, 2.5, 3.0, 2.5), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 0.286275, Green: 0.294118, Blue: 0.341176, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 2.0), + gfx.LineTo(13.0, 2.0), + gfx.QuadTo(15.0, 2.0, 15.0, 4.0), + gfx.LineTo(15.0, 12.0), + gfx.QuadTo(15.0, 14.0, 13.0, 14.0), + gfx.LineTo(3.0, 14.0), + gfx.QuadTo(1.0, 14.0, 1.0, 12.0), + gfx.LineTo(1.0, 4.0), + gfx.QuadTo(1.0, 3.172, 1.586, 2.586), + gfx.QuadTo(2.172, 2.0, 3.0, 2.0), + gfx.ClosePath(), + gfx.MoveTo(3.0, 3.0), + gfx.QuadTo(2.586, 3.0, 2.293, 3.293), + gfx.QuadTo(2.0, 3.586, 2.0, 4.0), + gfx.LineTo(2.0, 12.0), + gfx.QuadTo(2.0, 13.0, 3.0, 13.0), + gfx.LineTo(13.0, 13.0), + gfx.QuadTo(14.0, 13.0, 14.0, 12.0), + gfx.LineTo(14.0, 4.0), + gfx.QuadTo(14.0, 3.0, 13.0, 3.0), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 1.0, Green: 1.0, Blue: 1.0, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(4.424, 5.576), + gfx.LineTo(6.849, 8.0), + gfx.LineTo(4.424, 10.424), + gfx.LineTo(3.576, 9.576), + gfx.LineTo(5.151, 8.0), + gfx.LineTo(3.576, 6.424), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 1.0, Green: 1.0, Blue: 1.0, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(7.5, 9.9), + gfx.LineTo(11.5, 9.9), + gfx.LineTo(11.5, 11.1), + gfx.LineTo(7.5, 11.1), + gfx.LineTo(7.5, 9.9), + gfx.ClosePath(), + }}, + }, +} + +// batch-dark is a compiled vector icon. +var BatchDark = gfx.Icon{ + ViewBox: 16.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Layers: []gfx.IconLayer{ + {Fill: gfx.Color{Red: 0.87451, Green: 0.882353, Blue: 0.898039, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 2.5), + gfx.LineTo(13.0, 2.5), + gfx.CubicTo(13.8284, 2.5, 14.5, 3.17157, 14.5, 4.0), + gfx.LineTo(14.5, 12.0), + gfx.CubicTo(14.5, 12.8284, 13.8284, 13.5, 13.0, 13.5), + gfx.LineTo(3.0, 13.5), + gfx.CubicTo(2.17157, 13.5, 1.5, 12.8284, 1.5, 12.0), + gfx.LineTo(1.5, 4.0), + gfx.CubicTo(1.5, 3.17157, 2.17157, 2.5, 3.0, 2.5), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 0.87451, Green: 0.882353, Blue: 0.898039, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 2.0), + gfx.LineTo(13.0, 2.0), + gfx.QuadTo(15.0, 2.0, 15.0, 4.0), + gfx.LineTo(15.0, 12.0), + gfx.QuadTo(15.0, 14.0, 13.0, 14.0), + gfx.LineTo(3.0, 14.0), + gfx.QuadTo(1.0, 14.0, 1.0, 12.0), + gfx.LineTo(1.0, 4.0), + gfx.QuadTo(1.0, 3.172, 1.586, 2.586), + gfx.QuadTo(2.172, 2.0, 3.0, 2.0), + gfx.ClosePath(), + gfx.MoveTo(3.0, 3.0), + gfx.QuadTo(2.586, 3.0, 2.293, 3.293), + gfx.QuadTo(2.0, 3.586, 2.0, 4.0), + gfx.LineTo(2.0, 12.0), + gfx.QuadTo(2.0, 13.0, 3.0, 13.0), + gfx.LineTo(13.0, 13.0), + gfx.QuadTo(14.0, 13.0, 14.0, 12.0), + gfx.LineTo(14.0, 4.0), + gfx.QuadTo(14.0, 3.0, 13.0, 3.0), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 0.168627, Green: 0.176471, Blue: 0.188235, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(4.424, 5.576), + gfx.LineTo(6.849, 8.0), + gfx.LineTo(4.424, 10.424), + gfx.LineTo(3.576, 9.576), + gfx.LineTo(5.151, 8.0), + gfx.LineTo(3.576, 6.424), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 0.168627, Green: 0.176471, Blue: 0.188235, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(7.5, 9.9), + gfx.LineTo(11.5, 9.9), + gfx.LineTo(11.5, 11.1), + gfx.LineTo(7.5, 11.1), + gfx.LineTo(7.5, 9.9), + gfx.ClosePath(), + }}, + }, +} + // c is a compiled vector icon. var C = gfx.Icon{ ViewBox: 16.0, @@ -2173,6 +2298,116 @@ var ExcludeRootDark = gfx.Icon{ }, } +// executable is a compiled vector icon. +var Executable = gfx.Icon{ + ViewBox: 16.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Layers: []gfx.IconLayer{ + {Fill: gfx.Color{Red: 1.0, Green: 1.0, Blue: 1.0, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 2.5), + gfx.LineTo(13.0, 2.5), + gfx.CubicTo(13.8284, 2.5, 14.5, 3.17157, 14.5, 4.0), + gfx.LineTo(14.5, 12.0), + gfx.CubicTo(14.5, 12.8284, 13.8284, 13.5, 13.0, 13.5), + gfx.LineTo(3.0, 13.5), + gfx.CubicTo(2.17157, 13.5, 1.5, 12.8284, 1.5, 12.0), + gfx.LineTo(1.5, 4.0), + gfx.CubicTo(1.5, 3.17157, 2.17157, 2.5, 3.0, 2.5), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 0.207843, Green: 0.454902, Blue: 0.941176, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(2.0, 6.5), + gfx.LineTo(2.0, 4.0), + gfx.CubicTo(2.0, 3.448, 2.448, 3.0, 3.0, 3.0), + gfx.LineTo(13.0, 3.0), + gfx.CubicTo(13.552, 3.0, 14.0, 3.448, 14.0, 4.0), + gfx.LineTo(14.0, 6.5), + gfx.LineTo(2.0, 6.5), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 0.423529, Green: 0.439216, Blue: 0.494118, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 2.0), + gfx.LineTo(13.0, 2.0), + gfx.QuadTo(15.0, 2.0, 15.0, 4.0), + gfx.LineTo(15.0, 12.0), + gfx.QuadTo(15.0, 14.0, 13.0, 14.0), + gfx.LineTo(3.0, 14.0), + gfx.QuadTo(1.0, 14.0, 1.0, 12.0), + gfx.LineTo(1.0, 4.0), + gfx.QuadTo(1.0, 3.172, 1.586, 2.586), + gfx.QuadTo(2.172, 2.0, 3.0, 2.0), + gfx.ClosePath(), + gfx.MoveTo(3.0, 3.0), + gfx.QuadTo(2.586, 3.0, 2.293, 3.293), + gfx.QuadTo(2.0, 3.586, 2.0, 4.0), + gfx.LineTo(2.0, 12.0), + gfx.QuadTo(2.0, 13.0, 3.0, 13.0), + gfx.LineTo(13.0, 13.0), + gfx.QuadTo(14.0, 13.0, 14.0, 12.0), + gfx.LineTo(14.0, 4.0), + gfx.QuadTo(14.0, 3.0, 13.0, 3.0), + gfx.ClosePath(), + }}, + }, +} + +// executable-dark is a compiled vector icon. +var ExecutableDark = gfx.Icon{ + ViewBox: 16.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Layers: []gfx.IconLayer{ + {Fill: gfx.Color{Red: 0.262745, Green: 0.270588, Blue: 0.290196, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 2.5), + gfx.LineTo(13.0, 2.5), + gfx.CubicTo(13.8284, 2.5, 14.5, 3.17157, 14.5, 4.0), + gfx.LineTo(14.5, 12.0), + gfx.CubicTo(14.5, 12.8284, 13.8284, 13.5, 13.0, 13.5), + gfx.LineTo(3.0, 13.5), + gfx.CubicTo(2.17157, 13.5, 1.5, 12.8284, 1.5, 12.0), + gfx.LineTo(1.5, 4.0), + gfx.CubicTo(1.5, 3.17157, 2.17157, 2.5, 3.0, 2.5), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 0.329412, Green: 0.541176, Blue: 0.968627, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(2.0, 6.5), + gfx.LineTo(2.0, 4.0), + gfx.CubicTo(2.0, 3.448, 2.448, 3.0, 3.0, 3.0), + gfx.LineTo(13.0, 3.0), + gfx.CubicTo(13.552, 3.0, 14.0, 3.448, 14.0, 4.0), + gfx.LineTo(14.0, 6.5), + gfx.LineTo(2.0, 6.5), + gfx.ClosePath(), + }}, + {Fill: gfx.Color{Red: 0.807843, Green: 0.815686, Blue: 0.839216, Alpha: 1.0}, Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 2.0), + gfx.LineTo(13.0, 2.0), + gfx.QuadTo(15.0, 2.0, 15.0, 4.0), + gfx.LineTo(15.0, 12.0), + gfx.QuadTo(15.0, 14.0, 13.0, 14.0), + gfx.LineTo(3.0, 14.0), + gfx.QuadTo(1.0, 14.0, 1.0, 12.0), + gfx.LineTo(1.0, 4.0), + gfx.QuadTo(1.0, 3.172, 1.586, 2.586), + gfx.QuadTo(2.172, 2.0, 3.0, 2.0), + gfx.ClosePath(), + gfx.MoveTo(3.0, 3.0), + gfx.QuadTo(2.586, 3.0, 2.293, 3.293), + gfx.QuadTo(2.0, 3.586, 2.0, 4.0), + gfx.LineTo(2.0, 12.0), + gfx.QuadTo(2.0, 13.0, 3.0, 13.0), + gfx.LineTo(13.0, 13.0), + gfx.QuadTo(14.0, 13.0, 14.0, 12.0), + gfx.LineTo(14.0, 4.0), + gfx.QuadTo(14.0, 3.0, 13.0, 3.0), + gfx.ClosePath(), + }}, + }, +} + // folder is a compiled vector icon. var Folder = gfx.Icon{ ViewBox: 16.0, diff --git a/desktop/internal/fileicons/icons_tree.go b/desktop/internal/fileicons/icons_tree.go index f2f5f387ef..19002be5a2 100644 --- a/desktop/internal/fileicons/icons_tree.go +++ b/desktop/internal/fileicons/icons_tree.go @@ -39,9 +39,10 @@ // platform/icons/src/expui/nodes/; task.svg from // platform/external-system-impl/resources/icons/newui/. // -// license.svg and makefile.svg (and their _dark siblings) are original Lithe icons, -// because the Community set has no LICENSE or Makefile glyph; they follow the Lithe -// repository license. +// license.svg, makefile.svg, powershell.svg, batch.svg and executable.svg (and their _dark +// siblings) are original Lithe icons, because the Community set has no LICENSE, Makefile, +// PowerShell, Windows batch file or Windows program glyph; they follow the Lithe repository +// license. // // The icons of the languages whose grammars the editor bundles but the Community set has no // glyph for were copied from these sources: diff --git a/desktop/internal/fileicons/svg/batch.svg b/desktop/internal/fileicons/svg/batch.svg new file mode 100644 index 0000000000..bfeef73c41 --- /dev/null +++ b/desktop/internal/fileicons/svg/batch.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/desktop/internal/fileicons/svg/batch_dark.svg b/desktop/internal/fileicons/svg/batch_dark.svg new file mode 100644 index 0000000000..a8281f2fd4 --- /dev/null +++ b/desktop/internal/fileicons/svg/batch_dark.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/desktop/internal/fileicons/svg/executable.svg b/desktop/internal/fileicons/svg/executable.svg new file mode 100644 index 0000000000..6e2293b97c --- /dev/null +++ b/desktop/internal/fileicons/svg/executable.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/desktop/internal/fileicons/svg/executable_dark.svg b/desktop/internal/fileicons/svg/executable_dark.svg new file mode 100644 index 0000000000..bba59c2d73 --- /dev/null +++ b/desktop/internal/fileicons/svg/executable_dark.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 354fda11aa..02ba2011e7 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1350,9 +1350,12 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.statusRunning": "Running", "desktop.run.statusStopped": "Stopped", "desktop.run.statusSucceeded": "Succeeded", + "desktop.runConfig.addNew": "Add New…", + "desktop.runConfig.addNewConfiguration": "Add New Run Configuration…", "desktop.runConfig.apply": "Apply", "desktop.runConfig.arguments": "Program arguments", "desktop.runConfig.argumentsPlaceholder": "Arguments for the program, e.g. --port 8080; separate with spaces and quote one that contains spaces", + "desktop.runConfig.arrangeFailed": "Could not save the folders and order: {reason}", "desktop.runConfig.automaticValue": "Automatic ({value})", "desktop.runConfig.beforeLaunch.confirmBody": "Before {name} starts, the project's run configuration file asks to run these commands. Run them only if you trust this project.", "desktop.runConfig.beforeLaunch.confirmRun": "Run Steps", @@ -1379,15 +1382,17 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.chooseFailed": "Could not open the file chooser.", "desktop.runConfig.conflict": "The file changed on disk while saving. Close the editor, reopen it and try again.", "desktop.runConfig.copyConfiguration": "Copy Configuration", + "desktop.runConfig.copyFailed": "Could not copy the run configuration: {reason}", "desktop.runConfig.copyName": "{name} (Copy)", + "desktop.runConfig.copyPendingHint": "The copy is made when you press Apply or OK; its options can be edited after that.", "desktop.runConfig.delete": "Delete", "desktop.runConfig.deleteBody": "Delete “{name}”? It is removed from the run configuration file it is saved in.", "desktop.runConfig.deleteFailed": "Could not delete the run configuration: {reason}", "desktop.runConfig.deleteTitle": "Delete Run Configuration", - "desktop.runConfig.dialogHint": "Select a run configuration on the left to edit it, or create one:", "desktop.runConfig.dialogTitle": "Run/Debug Configurations", "desktop.runConfig.documentIgnored": "Not read: {file}", "desktop.runConfig.emptyHint": "No run configurations yet. Click + to add a script or program run.", + "desktop.runConfig.emptyTree": "No run configurations added.", "desktop.runConfig.entrypoint": "Entrypoint", "desktop.runConfig.entrypointPlaceholder": "Provider default", "desktop.runConfig.environment": "Environment variables", @@ -1416,6 +1421,10 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.fieldSource": "Execute", "desktop.runConfig.fieldStoreAsProjectFile": "Store as project file", "desktop.runConfig.fieldText": "Script text", + "desktop.runConfig.folderHint": "Folders only organize the list and are saved with the configurations in them; an empty folder is not saved.", + "desktop.runConfig.folderNameEmpty": "Enter a folder name.", + "desktop.runConfig.folderNameInvalid": "A folder name can be at most 256 bytes and cannot contain control characters.", + "desktop.runConfig.folderNameTaken": "This kind already has a folder with this name.", "desktop.runConfig.formTooNew": "Editing this run configuration needs a newer version of Lithe.", "desktop.runConfig.interpreterArgumentsHelp": "Options placed before the script path and handled by the interpreter itself, such as bash's -x, which prints each command as it runs. The script does not see them. Left empty, the automatic options shown in brackets are used.", "desktop.runConfig.interpreterArgumentsPlaceholder": "Options for the interpreter, e.g. -x", @@ -1423,11 +1432,14 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.loadFailed": "Run configurations are unavailable: {reason}", "desktop.runConfig.newConfiguration": "New Configuration", "desktop.runConfig.newConfigurationEllipsis": "New Run Configuration…", + "desktop.runConfig.newFolder": "New Folder", + "desktop.runConfig.newFolderName": "New Folder", "desktop.runConfig.notEditable": "This run configuration can be edited once its plugin is available.", "desktop.runConfig.noteWindowsOnly": "Takes effect on Windows only; other systems ignore it.", "desktop.runConfig.ok": "OK", "desktop.runConfig.optionDefault": "Default", "desktop.runConfig.optionReadOnly": "Not editable here", + "desktop.runConfig.orSelectToEdit": "or select a run configuration to edit", "desktop.runConfig.programArgumentsHelp": "Command-line arguments placed after the program path when it starts. Separate them with spaces; quote an argument that contains spaces.", "desktop.runConfig.programArgumentsPlaceholder": "Arguments for the program, e.g. --port 8080", "desktop.runConfig.programNotFound": "“{program}” was not found on PATH. Enter the full path of the interpreter or program.", @@ -1443,6 +1455,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.scriptOptionsHelpPowerShell": "Arguments placed after the script path and passed to the script, which reads them through $args or param(). Separate them with spaces; quote an argument that contains spaces.", "desktop.runConfig.scriptOptionsHelpShell": "Arguments placed after the script path and passed to the script, which reads them as $1, $2… Separate them with spaces; quote an argument that contains spaces.", "desktop.runConfig.scriptOptionsPlaceholder": "Arguments for the script, e.g. --verbose input.txt", + "desktop.runConfig.sortAlphabetically": "Sort Alphabetically", "desktop.runConfig.sourceFile": "Script file", "desktop.runConfig.sourceText": "Script text", "desktop.runConfig.storeAsProjectFileHelp": "Checked, the configuration is saved in .lithe/run/configurations.yaml and can be committed with the project; unchecked, it stays on this machine in .lithe/run/local.yaml.", @@ -4291,9 +4304,12 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.run.statusRunning": "正在运行", "desktop.run.statusStopped": "已停止", "desktop.run.statusSucceeded": "成功", + "desktop.runConfig.addNew": "添加新…", + "desktop.runConfig.addNewConfiguration": "添加新的运行配置…", "desktop.runConfig.apply": "应用", "desktop.runConfig.arguments": "程序参数", "desktop.runConfig.argumentsPlaceholder": "传给程序的参数,例如 --port 8080;多个参数用空格分隔,含空格的参数用引号括起来", + "desktop.runConfig.arrangeFailed": "无法保存文件夹和排序:{reason}", "desktop.runConfig.automaticValue": "自动({value})", "desktop.runConfig.beforeLaunch.confirmBody": "启动 {name} 前,项目的运行配置文件要求先运行以下命令。只有信任此项目时才运行。", "desktop.runConfig.beforeLaunch.confirmRun": "运行步骤", @@ -4320,15 +4336,17 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.chooseFailed": "无法打开文件选择器。", "desktop.runConfig.conflict": "保存期间文件已在磁盘上被修改,请关闭编辑器重新打开后再试。", "desktop.runConfig.copyConfiguration": "复制配置", + "desktop.runConfig.copyFailed": "无法复制运行配置:{reason}", "desktop.runConfig.copyName": "{name}(副本)", + "desktop.runConfig.copyPendingHint": "按“应用”或“确定”后生成这个副本,之后就可以编辑它的选项。", "desktop.runConfig.delete": "删除", "desktop.runConfig.deleteBody": "确定删除“{name}”吗?它会从保存它的运行配置文件中移除。", "desktop.runConfig.deleteFailed": "无法删除运行配置:{reason}", "desktop.runConfig.deleteTitle": "删除运行配置", - "desktop.runConfig.dialogHint": "在左侧选择一个运行配置进行编辑,或新建一个:", "desktop.runConfig.dialogTitle": "运行/调试配置", "desktop.runConfig.documentIgnored": "未读取 {file} 中的运行配置", "desktop.runConfig.emptyHint": "还没有运行配置,点 + 新建脚本或程序运行", + "desktop.runConfig.emptyTree": "未添加运行配置。", "desktop.runConfig.entrypoint": "入口", "desktop.runConfig.entrypointPlaceholder": "提供方默认值", "desktop.runConfig.environment": "环境变量", @@ -4357,6 +4375,10 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.fieldSource": "执行", "desktop.runConfig.fieldStoreAsProjectFile": "存为项目文件", "desktop.runConfig.fieldText": "脚本文本", + "desktop.runConfig.folderHint": "文件夹只用来整理列表,随其中的配置一起保存;空文件夹不会保存。", + "desktop.runConfig.folderNameEmpty": "请输入文件夹名称。", + "desktop.runConfig.folderNameInvalid": "文件夹名称不能超过 256 字节,也不能包含控制字符。", + "desktop.runConfig.folderNameTaken": "这一类配置中已经有同名文件夹。", "desktop.runConfig.formTooNew": "这个运行配置需要更新版本的 Lithe 才能编辑。", "desktop.runConfig.interpreterArgumentsHelp": "写在脚本路径前面、交给解释器本身的选项,例如 bash 的 -x(逐行打印执行的命令);脚本读不到这些值。留空时使用括号里显示的自动选项。", "desktop.runConfig.interpreterArgumentsPlaceholder": "传给解释器的选项,例如 -x", @@ -4364,11 +4386,14 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.loadFailed": "无法读取运行配置:{reason}", "desktop.runConfig.newConfiguration": "新建运行配置", "desktop.runConfig.newConfigurationEllipsis": "新建运行配置…", + "desktop.runConfig.newFolder": "新建文件夹", + "desktop.runConfig.newFolderName": "新建文件夹", "desktop.runConfig.notEditable": "插件可用后才能编辑这个运行配置。", "desktop.runConfig.noteWindowsOnly": "只在 Windows 上生效,其他系统会忽略。", "desktop.runConfig.ok": "确定", "desktop.runConfig.optionDefault": "默认", "desktop.runConfig.optionReadOnly": "此处无法编辑", + "desktop.runConfig.orSelectToEdit": "或选择要编辑的运行配置", "desktop.runConfig.programArgumentsHelp": "启动程序时附在程序路径后面的命令行参数。多个参数用空格分隔,含空格的参数用引号括起来。", "desktop.runConfig.programArgumentsPlaceholder": "传给程序的参数,例如 --port 8080", "desktop.runConfig.programNotFound": "在 PATH 中找不到“{program}”,请填写解释器或程序的完整路径。", @@ -4384,6 +4409,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.runConfig.scriptOptionsHelpPowerShell": "写在脚本路径后面、传给脚本的参数,脚本里用 $args 或 param() 读取。多个参数用空格分隔,含空格的参数用引号括起来。", "desktop.runConfig.scriptOptionsHelpShell": "写在脚本路径后面、传给脚本的参数,脚本里用 $1、$2… 读取。多个参数用空格分隔,含空格的参数用引号括起来。", "desktop.runConfig.scriptOptionsPlaceholder": "传给脚本的参数,例如 --verbose input.txt", + "desktop.runConfig.sortAlphabetically": "按字母顺序排序", "desktop.runConfig.sourceFile": "脚本文件", "desktop.runConfig.sourceText": "脚本文本", "desktop.runConfig.storeAsProjectFileHelp": "勾选后保存到 .lithe/run/configurations.yaml,可随项目提交共享;不勾选则只保存在本机的 .lithe/run/local.yaml。", diff --git a/desktop/internal/icons/icons.go b/desktop/internal/icons/icons.go index db5dfd612a..897ca62ef2 100644 --- a/desktop/internal/icons/icons.go +++ b/desktop/internal/icons/icons.go @@ -85,6 +85,32 @@ var ArrowDown = gfx.Icon{ }, } +// arrow-down-a-z is a compiled vector icon. +var ArrowDownAZ = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(3.0, 16.0), + gfx.LineTo(7.0, 20.0), + gfx.LineTo(11.0, 16.0), + gfx.MoveTo(7.0, 20.0), + gfx.LineTo(7.0, 4.0), + gfx.MoveTo(20.0, 8.0), + gfx.LineTo(15.0, 8.0), + gfx.MoveTo(15.0, 10.0), + gfx.LineTo(15.0, 6.5), + gfx.CubicTo(15.0, 5.11929, 16.1193, 4.0, 17.5, 4.0), + gfx.CubicTo(18.8807, 4.0, 20.0, 5.11929, 20.0, 6.5), + gfx.LineTo(20.0, 10.0), + gfx.MoveTo(15.0, 14.0), + gfx.LineTo(20.0, 14.0), + gfx.LineTo(15.0, 20.0), + gfx.LineTo(20.0, 20.0), + }, +} + // arrow-down-left is a compiled vector icon. var ArrowDownLeft = gfx.Icon{ ViewBox: 24.0, @@ -983,6 +1009,33 @@ var FolderOpen = gfx.Icon{ }, } +// folder-plus is a compiled vector icon. +var FolderPlus = gfx.Icon{ + ViewBox: 24.0, + Stroke: 2.0, + Cap: gfx.CapRound, + Join: gfx.JoinRound, + Commands: []gfx.PathCommand{ + gfx.MoveTo(12.0, 10.0), + gfx.LineTo(12.0, 16.0), + gfx.MoveTo(9.0, 13.0), + gfx.LineTo(15.0, 13.0), + gfx.MoveTo(20.0, 20.0), + gfx.CubicTo(21.1046, 20.0, 22.0, 19.1046, 22.0, 18.0), + gfx.LineTo(22.0, 8.0), + gfx.CubicTo(22.0, 6.89543, 21.1046, 6.0, 20.0, 6.0), + gfx.LineTo(12.1, 6.0), + gfx.CubicTo(11.4203, 6.00666, 10.7838, 5.66768, 10.41, 5.1), + gfx.LineTo(9.6, 3.9), + gfx.CubicTo(9.23008, 3.33828, 8.60259, 3.00011, 7.93, 3.0), + gfx.LineTo(4.0, 3.0), + gfx.CubicTo(2.89543, 3.0, 2.0, 3.89543, 2.0, 5.0), + gfx.LineTo(2.0, 18.0), + gfx.CubicTo(2.0, 19.1046, 2.89543, 20.0, 4.0, 20.0), + gfx.ClosePath(), + }, +} + // folder-tree is a compiled vector icon. var FolderTree = gfx.Icon{ ViewBox: 24.0, diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 22f0718c75..7388347674 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -110,6 +110,10 @@ type Kernel interface { SaveRunConfiguration(ctx context.Context, request core.RunConfigurationSave) (core.RunConfigurationSaved, error) DeleteRunConfiguration(ctx context.Context, root, configurationID string, plugins []core.RunInstalledPlugin) ([]core.RunConfigChange, error) CreateRunLaunchPlan(ctx context.Context, root, configurationID, inlineScriptBase string) (core.RunLaunchPlan, error) + // CopyRunConfiguration and ArrangeRunConfigurations copy any configuration and save the + // folders and order of the list (runconfig_dialog.go). + CopyRunConfiguration(ctx context.Context, root, configurationID, name string, plugins []core.RunInstalledPlugin) (string, []core.RunConfigChange, error) + ArrangeRunConfigurations(ctx context.Context, request core.RunConfigArrangement) ([]core.RunConfigChange, error) // RunBeforeLaunch expands the steps a configuration runs before it starts (runconfig_before_launch.go). RunBeforeLaunch(ctx context.Context, root, configurationID string) (core.RunBeforeLaunch, error) RunArgumentText(ctx context.Context, lists [][]string) ([]string, error) diff --git a/desktop/internal/workbench/runconfig.go b/desktop/internal/workbench/runconfig.go index 50928415a0..30545c4cf0 100644 --- a/desktop/internal/workbench/runconfig.go +++ b/desktop/internal/workbench/runconfig.go @@ -38,6 +38,9 @@ type runConfigState struct { // they are asked for. types []core.RunConfigurationType typesLoading bool + // manualOrder says list is in the order the user gave it on this machine rather than by + // name; Core keeps the choice locally and lists the configurations in that order. + manualOrder bool // dialog is the Run/Debug Configurations window that creates, edits and removes // configurations (runconfig_dialog.go). dialog runConfigDialog @@ -186,6 +189,8 @@ func (a *App) finishRunConfigurations(p *project, generation uint64, resolved co } return !ok || c.Disabled }) + s.manualOrder = !resolved.SortAlphabetically + a.settleRunConfigDialog(p) if s.reveal != "" && s.configuration(s.reveal) != nil { s.selected = s.reveal } diff --git a/desktop/internal/workbench/runconfig_dialog.go b/desktop/internal/workbench/runconfig_dialog.go index 862a50e470..a548105343 100644 --- a/desktop/internal/workbench/runconfig_dialog.go +++ b/desktop/internal/workbench/runconfig_dialog.go @@ -2,11 +2,13 @@ package workbench import ( "cmp" + "context" "encoding/json" "maps" "slices" "strconv" "strings" + "unicode" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" @@ -16,58 +18,131 @@ import ( ) // This file holds the Run/Debug Configurations dialog, after IDEA's: the configurations as a -// tree by kind on the left under the buttons that add, remove and copy one, the editor of the -// selected one on the right, and Run, Cancel, Apply and OK under them. Every configuration the -// user selects gets its own draft, so edits to several configurations, the configurations -// added and the ones removed all wait for Apply or OK, and Cancel drops them together. -// Drawing is in runconfig_dialog_view.go. +// tree by kind on the left, under the buttons that add, remove and copy one, make a folder and +// sort the list by name; the editor of the selected one on the right; and Run, Cancel, Apply and +// OK under them. Every configuration the user selects gets its own draft, so edits to several +// configurations, the configurations added, copied and removed, and the folders and order the +// user gave the list all wait for Apply or OK, and Cancel drops them together. Drawing is in +// runconfig_dialog_view.go. +// +// A folder lives in the configurations it holds, as IDEA's folderName does: Core saves it with +// each one, so a folder with nothing in it is not saved. The manual order and the choice to sort +// by name are this machine's and Core keeps them in the local layer. // runConfigNewKey starts the draft key of a configuration created in the dialog and not saved // yet. No configuration ID starts with it, since Core's IDs start with their layer. const runConfigNewKey = "new:" +// runConfigFolderBytes is the longest folder name Core takes, in bytes. +const runConfigFolderBytes = 256 + +// runConfigNewMenu is where the menu of kinds a new configuration can take shows. +type runConfigNewMenu uint8 + +const ( + runConfigNewMenuClosed runConfigNewMenu = iota + // runConfigNewMenuToolbar is under the + button, and opens from the keyboard too. + runConfigNewMenuToolbar + // runConfigNewMenuTree is under the link of the empty tree. + runConfigNewMenuTree + // runConfigNewMenuPane is under the link the pane shows while no configuration is selected. + runConfigNewMenuPane +) + // runConfigDialog is the state of the Run/Debug Configurations dialog. Only the window thread // reads or writes it. type runConfigDialog struct { open bool // generation rejects the answer of a save chain whose dialog was closed or reopened since. generation uint64 - // selected is the draft key of the selected configuration, and group the key of the - // selected group row while a group rather than a configuration is selected. - selected, group string + // selected is the draft key of the selected configuration, and node the group or folder + // row selected while one of those rather than a configuration is. + selected string + node runConfigDialogNode // drafts are the editors of the configurations the user selected, by configuration ID, or // by a runConfigNewKey key until a new configuration's first save names it. drafts map[string]*runConfigDraft - // added are the keys of the configurations created in the dialog, in creation order. A - // saved one stays until the list shows it, so it does not vanish while the list refreshes. + // added are the keys of the configurations created or copied in the dialog, in creation + // order. A saved one stays until the list shows it, so it does not vanish while the list + // refreshes. added []string // removed are the listed configurations to delete on Apply, and hidden the IDs a save - // replaced, such as by renaming, kept out of the tree until the list stops showing them. + // replaced, such as by renaming, or deleted, kept out of the tree until the list stops + // showing them. removed, hidden map[string]bool // next numbers the next new configuration's key. next int - // newMenu says the menu of kinds the + button opens is showing. - newMenu bool - // saving says Apply, OK or Run is saving the drafts; failure is a removal that failed. + // newMenu says where the menu of kinds is showing, if anywhere. + newMenu runConfigNewMenu + // saving says Apply, OK or Run is saving the drafts; failure is a step of the save that + // failed outside every editor: a removal, a copy or the arrangement. saving bool failure string - // closed are the groups the user closed, by key. They stay closed across openings. - closed map[string]bool + // closed are the groups and folders the user closed. They stay closed across openings. + closed map[runConfigDialogNode]bool + // folders are the folders the user moved configurations to, by draft key, "" for none; + // emptyFolders are the folders made in the dialog with nothing in them yet, by group key. + folders map[string]string + emptyFolders map[string][]string + // sort is the choice to sort by name the user made in the dialog, nil while the list's + // stands; order is the manual order the user made, by draft key, nil while the list's + // stands. rearranged says the folders, the order or the sort changed since Apply. + sort *bool + order []string + rearranged bool + // folderName is the text of the selected folder's name field, and folderError why it + // cannot name the folder. + folderName, folderError string // groups, rows and ids are the tree as it shows, collected on each paint; ids give every - // draft key a row key of its own for the list's state. - groups []runConfigDialogGroup - rows []runConfigDialogRow - ids map[string]int - view ui.ListState + // row a key of its own for the tree's state, the same across paints. selectedRow is the + // row of the selection in the last paint, -1 when none shows, and painted the number of + // rows the tree last painted. + groups []runConfigDialogGroup + rows []runConfigDialogRow + ids map[string]int + selectedRow, painted int + // focus is the keyboard focus the tree last saw, so a row the arrow keys move to is + // selected. reveal scrolls the selection into view on the next paint, and refocus also + // gives it the keyboard, as after Delete took out the focused row. + focus gfx.ID + reveal, refocus bool + view ui.TreeState } // runConfigDraft is the editor of one configuration in the dialog: the form of a built-in -// process run, or the options editor of a build provider run. A provider run whose plugin -// cannot resolve has neither, and the dialog says why it cannot be edited. +// process run, the options editor of a build provider run, or the name of a copy Core makes on +// Apply. A provider run whose plugin cannot resolve has none of them, and the dialog says why it +// cannot be edited. type runConfigDraft struct { key string form *runConfigForm editor *runConfigEditor + // folder is the folder the configuration is saved in, for while the list does not show it + // under this key: after a rename, or for a copy. + folder string + // copyOf is the configuration a copy not saved yet copies, and copyName the copy's name. + // Core copies it on Apply, every saved choice and the folder included; copied then says it + // did, and the draft gives way to the configuration's own editor once the list shows it. + // A built-in run is copied from its form instead, with what the form shows. + copyOf, copyName string + copied bool + // group and icon are where and how a copy shows until the list shows it. + group runConfigDialogGroup + icon gfx.Icon +} + +// runConfigDialogNode names a group row of the tree by the group's key, or a folder row by its +// group's key and its name. +type runConfigDialogNode struct { + group, folder string +} + +// id is the node's key among the tree's row keys. +func (n runConfigDialogNode) id() string { + if n.folder == "" { + return "g\x00" + n.group + } + return "f\x00" + n.group + "\x00" + n.folder } // runConfigDialogGroup is one kind of configuration in the tree: a built-in kind, or the build @@ -77,14 +152,25 @@ type runConfigDialogGroup struct { icon gfx.Icon // order places the built-in kinds first, in the order Core lists them. order int - keys []string + // folders are the group's folders by name, and keys the configurations outside them, each + // in the order the list shows them. + folders []runConfigDialogFolder + keys []string +} + +// runConfigDialogFolder is one folder of a group and the configurations in it. +type runConfigDialogFolder struct { + name string + keys []string } -// runConfigDialogRow is one row of the tree: a group's, with an empty key, or a configuration -// under it. +// runConfigDialogRow is one row of the tree: a group's or a folder's, with an empty key, or a +// configuration's. node is the row's group or folder, or the one the configuration is in. type runConfigDialogRow struct { group int + node runConfigDialogNode key string + depth int } // runConfigDialogStep is the button that saves the drafts. @@ -113,7 +199,7 @@ func (a *App) openRunConfigDialog(p *project, id string) { d := &p.runConfigs.dialog d.dropDrafts() *d = runConfigDialog{ - open: true, generation: d.generation + 1, closed: d.closed, + open: true, generation: d.generation + 1, closed: d.closed, selectedRow: -1, reveal: true, drafts: map[string]*runConfigDraft{}, removed: map[string]bool{}, hidden: map[string]bool{}, ids: map[string]int{}, } a.title.runConfigOpen = false @@ -121,7 +207,9 @@ func (a *App) openRunConfigDialog(p *project, id string) { a.loadRunConfigTypes(p) if configuration := p.runConfigs.configuration(id); configuration != nil { a.selectRunConfigDraft(p, id) - delete(d.closed, p.runConfigDialogGroupKey(id)) + group := p.runConfigDialogGroupKey(id) + delete(d.closed, runConfigDialogNode{group: group}) + delete(d.closed, runConfigDialogNode{group: group, folder: configuration.Folder}) } } @@ -130,7 +218,7 @@ func (a *App) closeRunConfigDialog(p *project) { d := &p.runConfigs.dialog d.dropDrafts() d.generation++ - d.open, d.saving, d.newMenu = false, false, false + d.open, d.saving, d.newMenu = false, false, runConfigNewMenuClosed } // dropDrafts closes every draft's editor. @@ -151,8 +239,11 @@ func (draft *runConfigDraft) close() { } } +// pendingCopy says the draft is a copy Core has not made yet. +func (draft *runConfigDraft) pendingCopy() bool { return draft.copyOf != "" && !draft.copied } + // dirty says the draft holds something Apply would save: an edited configuration, or a new -// one not saved yet. +// one or a copy not saved yet. func (draft *runConfigDraft) dirty() bool { switch { case draft.form != nil: @@ -160,7 +251,7 @@ func (draft *runConfigDraft) dirty() bool { case draft.editor != nil: return draft.editor.dirty() } - return false + return draft.pendingCopy() } // busy says the draft is being read or saved, so Apply cannot save it yet. @@ -177,7 +268,7 @@ func (draft *runConfigDraft) busy() bool { // selectRunConfigDraft selects configuration key and reads its editor the first time. func (a *App) selectRunConfigDraft(p *project, key string) { d := &p.runConfigs.dialog - d.selected, d.group, d.newMenu = key, "", false + d.selected, d.node, d.newMenu, d.folderError = key, runConfigDialogNode{}, runConfigNewMenuClosed, "" if d.drafts[key] != nil { return } @@ -185,7 +276,7 @@ func (a *App) selectRunConfigDraft(p *project, key string) { if configuration == nil { return } - draft := &runConfigDraft{key: key} + draft := &runConfigDraft{key: key, folder: configuration.Folder} switch { case configuration.IsProcess(): draft.form = a.openRunConfigForm(p, configuration.Provider, key, nil) @@ -195,35 +286,128 @@ func (a *App) selectRunConfigDraft(p *project, key string) { d.drafts[key] = draft } +// selectRunConfigDialogNode selects a group or folder row; a folder's name field starts with +// its name. +func (d *runConfigDialog) selectRunConfigDialogNode(node runConfigDialogNode) { + d.selected, d.node, d.newMenu = "", node, runConfigNewMenuClosed + d.folderName, d.folderError = node.folder, "" +} + +// selectRunConfigDialogRow selects the configuration, group or folder of a row of the tree. +func (a *App) selectRunConfigDialogRow(p *project, row runConfigDialogRow) { + if row.key != "" { + a.selectRunConfigDraft(p, row.key) + return + } + d := &p.runConfigs.dialog + if d.selected != "" || d.node != row.node { + d.selectRunConfigDialogNode(row.node) + } +} + // addRunConfigDraft creates a new configuration of provider, seeded with values when they are -// set, opens its group and selects it. +// set, opens its group and selects it. With a folder of that kind selected, or a configuration +// in one, the new configuration goes in that folder, as in IDEA. func (a *App) addRunConfigDraft(p *project, provider string, values map[string]json.RawMessage) { d := &p.runConfigs.dialog + group := runProcessKindKey(provider) + folder := d.node.folder + if d.selected != "" { + folder = p.runConfigDialogFolder(d.selected) + if p.runConfigDialogGroupKey(d.selected) != group { + folder = "" + } + } else if d.node.group != group { + folder = "" + } d.next++ key := runConfigNewKey + strconv.Itoa(d.next) draft := &runConfigDraft{key: key, form: a.openRunConfigForm(p, provider, "", values)} d.drafts[key] = draft d.added = append(d.added, key) - delete(d.closed, runProcessKindKey(provider)) - d.selected, d.group, d.newMenu, d.failure = key, "", false, "" + if folder != "" { + d.moveToFolder(key, folder) + } + delete(d.closed, runConfigDialogNode{group: group}) + delete(d.closed, runConfigDialogNode{group: group, folder: folder}) + d.selected, d.node, d.newMenu, d.failure, d.reveal = key, runConfigDialogNode{}, runConfigNewMenuClosed, "", true } -// copyRunConfigDraft creates a copy of the selected built-in run with the values its form shows, -// named as a copy. +// runConfigCopyable says copy can copy configuration key: the form of a built-in run once it +// is read, or any other listed configuration. A copy is not copied again before it is saved. +func (p *project) runConfigCopyable(key string) bool { + d := &p.runConfigs.dialog + draft := d.drafts[key] + switch { + case key == "" || d.saving || draft == nil: + return false + case draft.form != nil: + return draft.form.ready() + case draft.copyOf != "": + return false + } + return p.runConfigs.configuration(key) != nil +} + +// copyRunConfigDraft creates a copy of the selected configuration, named as a copy, in its +// folder. A built-in run is copied with the values its form shows; any other configuration, +// such as a build provider run, is copied by Core on Apply with every choice it saved. func (a *App) copyRunConfigDraft(p *project) { d := &p.runConfigs.dialog - draft := d.drafts[d.selected] - if draft == nil || draft.form == nil || !draft.form.ready() { + key := d.selected + if !p.runConfigCopyable(key) { return } - values := draft.form.collect() - name, _ := json.Marshal(i18n.SharedFormat(a.language(), "desktop.runConfig.copyName", map[string]string{"name": a.runConfigDraftLabel(p, d.selected)})) - values["name"] = name - a.addRunConfigDraft(p, draft.form.provider, values) + draft := d.drafts[key] + name := i18n.SharedFormat(a.language(), "desktop.runConfig.copyName", map[string]string{"name": a.runConfigDraftLabel(p, key)}) + folder := p.runConfigDialogFolder(key) + if draft.form != nil { + values := draft.form.collect() + values["name"], _ = json.Marshal(name) + a.addRunConfigDraft(p, draft.form.provider, values) + d.moveToFolder(d.selected, folder) + return + } + group := runConfigDialogGroup{key: p.runConfigDialogGroupKey(key)} + if g := slices.IndexFunc(d.groups, func(existing runConfigDialogGroup) bool { return existing.key == group.key }); g >= 0 { + group = runConfigDialogGroup{key: d.groups[g].key, title: d.groups[g].title, icon: d.groups[g].icon, order: d.groups[g].order} + } + d.next++ + copied := &runConfigDraft{ + key: runConfigNewKey + strconv.Itoa(d.next), folder: folder, + copyOf: key, copyName: name, group: group, icon: a.runConfigDraftIcon(p, key), + } + d.drafts[copied.key] = copied + d.added = append(d.added, copied.key) + d.selected, d.node, d.newMenu, d.failure, d.reveal = copied.key, runConfigDialogNode{}, runConfigNewMenuClosed, "", true } -// removeRunConfigDraft takes the selected configuration out of the tree: a new one is dropped, -// a saved one is deleted on Apply. The selection moves to the row that takes its place. +// removeRunConfigSelection is − and Delete: the selected configuration leaves the tree, and a +// selected folder lets go of its configurations, which stay in its group. +func (a *App) removeRunConfigSelection(p *project) { + d := &p.runConfigs.dialog + switch { + case d.saving: + case d.selected != "": + a.removeRunConfigDraft(p) + case d.node.folder != "": + p.ungroupRunConfigFolder() + } +} + +// runConfigDialogRemovable says − has something to take out: a configuration it can remove, +// or a folder. +func (p *project) runConfigDialogRemovable() bool { + d := &p.runConfigs.dialog + if d.selected == "" { + return !d.saving && d.node.folder != "" + } + return p.runConfigRemovable(d.selected) +} + +// removeRunConfigDraft takes the selected configuration out of the tree: a new one or a copy +// not saved yet is dropped, a saved one is deleted on Apply. The selection moves to the +// configuration that takes its place. func (a *App) removeRunConfigDraft(p *project) { d := &p.runConfigs.dialog key := d.selected @@ -236,13 +420,15 @@ func (a *App) removeRunConfigDraft(p *project) { delete(d.drafts, key) } d.added = slices.DeleteFunc(d.added, func(added string) bool { return added == key }) - if !strings.HasPrefix(key, runConfigNewKey) { + if strings.HasPrefix(key, runConfigNewKey) { + delete(d.folders, key) + } else { d.removed[key] = true } - d.selected, d.failure = "", "" + d.selected, d.failure, d.reveal = "", "", true p.collectRunConfigDialogRows(a) for index := min(at, len(d.rows)-1); index >= 0; index-- { - if index < len(d.rows) && d.rows[index].key != "" { + if d.rows[index].key != "" { a.selectRunConfigDraft(p, d.rows[index].key) return } @@ -255,9 +441,9 @@ func (a *App) removeRunConfigDraft(p *project) { } } -// runConfigRemovable says − can take configuration key out: a new one, or a saved user -// configuration that does not run. Generated configurations come back on the next detection, -// so they are never removed. +// runConfigRemovable says − can take configuration key out: a new one or a copy, or a saved +// user configuration that does not run. Generated configurations come back on the next +// detection, so they are never removed. func (p *project) runConfigRemovable(key string) bool { d := &p.runConfigs.dialog switch { @@ -283,30 +469,67 @@ func (p *project) runConfigDialogGroupKey(key string) string { } return runConfigGroupKey(configuration) } - if draft := p.runConfigs.dialog.drafts[key]; draft != nil && draft.form != nil { - return runProcessKindKey(draft.form.provider) + if draft := p.runConfigs.dialog.drafts[key]; draft != nil { + if draft.form != nil { + return runProcessKindKey(draft.form.provider) + } + return draft.group.key } return "" } +// runConfigDialogFolder is the folder configuration or draft key shows in: the one the user +// moved it to in the dialog, else the one it is saved in, "" for none. +func (p *project) runConfigDialogFolder(key string) string { + d := &p.runConfigs.dialog + if folder, ok := d.folders[key]; ok { + return folder + } + if configuration := p.runConfigs.configuration(key); configuration != nil { + return configuration.Folder + } + if draft := d.drafts[key]; draft != nil { + return draft.folder + } + return "" +} + +// moveToFolder moves configuration key to folder, or out of every folder for "", on Apply. +func (d *runConfigDialog) moveToFolder(key, folder string) { + if d.folders == nil { + d.folders = map[string]string{} + } + d.folders[key] = folder + d.rearranged = true +} + +// runConfigDialogSorted says the tree lists configurations by name rather than in the order +// the user gave them: the choice made in the dialog, else the saved one. +func (p *project) runConfigDialogSorted() bool { + if sort := p.runConfigs.dialog.sort; sort != nil { + return *sort + } + return !p.runConfigs.manualOrder +} + // collectRunConfigDialogRows lists the tree as it shows: the listed configurations the user did -// not remove and the ones created in the dialog, each under its kind, the built-in kinds first -// in Core's order and the build systems by title, the configurations of a kind by name. A -// closed group shows its row only. +// not remove and the ones created or copied in the dialog, each under its kind, the built-in +// kinds first in Core's order and the build systems by title. In a kind, its folders come first +// by name, then the configurations outside them; configurations are listed by name, or in the +// order the user gave them. A closed group or folder shows its row only. func (p *project) collectRunConfigDialogRows(a *App) { s := &p.runConfigs d := &s.dialog language := a.language() d.groups, d.rows = d.groups[:0], d.rows[:0] - place := func(key, group, title string, icon gfx.Icon, order int) { - g := slices.IndexFunc(d.groups, func(existing runConfigDialogGroup) bool { return existing.key == group }) - if g < 0 { - g = len(d.groups) - d.groups = append(d.groups, runConfigDialogGroup{key: group, title: title, icon: icon, order: order}) + members := map[string][]string{} + place := func(key string, group runConfigDialogGroup) { + if !slices.ContainsFunc(d.groups, func(existing runConfigDialogGroup) bool { return existing.key == group.key }) { + d.groups = append(d.groups, group) } - d.groups[g].keys = append(d.groups[g].keys, key) + members[group.key] = append(members[group.key], key) } - processGroup := func(provider string) (string, string, gfx.Icon, int) { + processGroup := func(provider string) runConfigDialogGroup { title, ok := runConfigTypeLabel(language, provider) if !ok { title = i18n.Shared(language, "desktop.runConfig.builtInGroup") @@ -315,7 +538,7 @@ func (p *project) collectRunConfigDialogRows(a *App) { if order < 0 { order = len(s.types) } - return runProcessKindKey(provider), title, runConfigTypeIcon(provider), order + return runConfigDialogGroup{key: runProcessKindKey(provider), title: title, icon: runConfigTypeIcon(provider, a.colors.Dark), order: order} } listed := map[string]bool{} for index := range s.list { @@ -325,57 +548,314 @@ func (p *project) collectRunConfigDialogRows(a *App) { continue } if configuration.IsProcess() { - group, title, icon, order := processGroup(configuration.Provider) - place(configuration.ID, group, title, icon, order) + place(configuration.ID, processGroup(configuration.Provider)) continue } - place(configuration.ID, runConfigGroupKey(configuration), p.runConfigGroupTitle(language, configuration), icons.Wrench, len(s.types)+1) + place(configuration.ID, runConfigDialogGroup{ + key: runConfigGroupKey(configuration), title: p.runConfigGroupTitle(language, configuration), icon: icons.Wrench, order: len(s.types) + 1, + }) } for _, key := range d.added { draft := d.drafts[key] - if listed[key] || draft == nil || draft.form == nil { - continue + switch { + case listed[key] || draft == nil: + case draft.form != nil: + place(key, processGroup(draft.form.provider)) + case draft.copyOf != "": + place(key, draft.group) } - group, title, icon, order := processGroup(draft.form.provider) - place(key, group, title, icon, order) } slices.SortStableFunc(d.groups, func(x, y runConfigDialogGroup) int { return cmp.Or(cmp.Compare(x.order, y.order), strings.Compare(strings.ToLower(x.title), strings.ToLower(y.title)), strings.Compare(x.key, y.key)) }) + // The manual order ranks configurations: the dialog's, else the list's, which Core keeps in + // the saved order; configurations it does not place come after it. + rank := map[string]int{} + for index, key := range d.order { + rank[key] = index + } + for index := range s.list { + if _, ok := rank[s.list[index].ID]; !ok { + rank[s.list[index].ID] = len(d.order) + index + } + } + for index, key := range d.added { + if _, ok := rank[key]; !ok { + rank[key] = len(d.order) + len(s.list) + index + } + } + sorted := p.runConfigDialogSorted() for g := range d.groups { group := &d.groups[g] - labels := make(map[string]string, len(group.keys)) - for _, key := range group.keys { + keys := members[group.key] + labels := make(map[string]string, len(keys)) + for _, key := range keys { labels[key] = strings.ToLower(a.runConfigDraftLabel(p, key)) } - slices.SortStableFunc(group.keys, func(x, y string) int { - return cmp.Or(strings.Compare(labels[x], labels[y]), strings.Compare(x, y)) + slices.SortStableFunc(keys, func(x, y string) int { + if sorted { + return cmp.Or(strings.Compare(labels[x], labels[y]), strings.Compare(x, y)) + } + return cmp.Or(cmp.Compare(rank[x], rank[y]), strings.Compare(x, y)) }) - d.rows = append(d.rows, runConfigDialogRow{group: g}) - if d.closed[group.key] { + folders := map[string][]string{} + for _, name := range d.emptyFolders[group.key] { + folders[name] = nil + } + for _, key := range keys { + if folder := p.runConfigDialogFolder(key); folder != "" { + folders[folder] = append(folders[folder], key) + } else { + group.keys = append(group.keys, key) + } + } + for _, name := range slices.SortedFunc(maps.Keys(folders), func(x, y string) int { + return cmp.Or(strings.Compare(strings.ToLower(x), strings.ToLower(y)), strings.Compare(x, y)) + }) { + group.folders = append(group.folders, runConfigDialogFolder{name: name, keys: folders[name]}) + } + node := runConfigDialogNode{group: group.key} + d.rows = append(d.rows, runConfigDialogRow{group: g, node: node}) + if d.closed[node] { continue } + for _, folder := range group.folders { + inside := runConfigDialogNode{group: group.key, folder: folder.name} + d.rows = append(d.rows, runConfigDialogRow{group: g, node: inside, depth: 1}) + if d.closed[inside] { + continue + } + for _, key := range folder.keys { + d.rows = append(d.rows, runConfigDialogRow{group: g, node: inside, key: key, depth: 2}) + } + } for _, key := range group.keys { - d.rows = append(d.rows, runConfigDialogRow{group: g, key: key}) + d.rows = append(d.rows, runConfigDialogRow{group: g, node: node, key: key, depth: 1}) + } + } +} + +// displayOrder is every configuration of the tree in the order it lists them, the ones in +// closed groups and folders too, as of the last paint. +func (d *runConfigDialog) displayOrder() []string { + var keys []string + for _, group := range d.groups { + for _, folder := range group.folders { + keys = append(keys, folder.keys...) + } + keys = append(keys, group.keys...) + } + return keys +} + +// runConfigDialogFolderKeys are the configurations in folder node as of the last paint. +func (d *runConfigDialog) runConfigDialogFolderKeys(node runConfigDialogNode) []string { + for _, group := range d.groups { + if group.key != node.group { + continue + } + for _, folder := range group.folders { + if folder.name == node.folder { + return slices.Clone(folder.keys) + } + } + } + return nil +} + +// runConfigDialogFolderTaken says group has a folder called name as of the last paint. +func (d *runConfigDialog) runConfigDialogFolderTaken(group, name string) bool { + for _, existing := range d.groups { + if existing.key == group { + return slices.ContainsFunc(existing.folders, func(folder runConfigDialogFolder) bool { return folder.name == name }) + } + } + return false +} + +// addRunConfigFolder makes a folder in the group of the selection, named New Folder or the +// first New Folder N its group does not have: with a configuration selected the folder takes it +// in, else it is empty until a configuration moves in. The folder is selected so it can be +// renamed. +func (a *App) addRunConfigFolder(p *project) { + d := &p.runConfigs.dialog + group := d.node.group + if d.selected != "" { + group = p.runConfigDialogGroupKey(d.selected) + } + if group == "" || d.saving { + return + } + base := i18n.Shared(a.language(), "desktop.runConfig.newFolderName") + name := base + for number := 2; d.runConfigDialogFolderTaken(group, name); number++ { + name = base + " " + strconv.Itoa(number) + } + if d.selected != "" { + d.moveToFolder(d.selected, name) + } else { + if d.emptyFolders == nil { + d.emptyFolders = map[string][]string{} + } + d.emptyFolders[group] = append(d.emptyFolders[group], name) + } + delete(d.closed, runConfigDialogNode{group: group}) + d.selectRunConfigDialogNode(runConfigDialogNode{group: group, folder: name}) + d.reveal = true +} + +// renameRunConfigFolder names the selected folder after its name field, without the spaces +// around it, moving every configuration in it. A name Core cannot save, or that another folder +// of the group has, is not taken and the field says why. +func (a *App) renameRunConfigFolder(p *project) { + d := &p.runConfigs.dialog + node := d.node + if node.folder == "" || d.selected != "" || d.saving { + return + } + language := a.language() + name := strings.TrimSpace(d.folderName) + switch { + case name == "": + d.folderError = i18n.Shared(language, "desktop.runConfig.folderNameEmpty") + return + case len(name) > runConfigFolderBytes || strings.ContainsFunc(name, unicode.IsControl): + d.folderError = i18n.Shared(language, "desktop.runConfig.folderNameInvalid") + return + case name == node.folder: + d.folderError = "" + return + case d.runConfigDialogFolderTaken(node.group, name): + d.folderError = i18n.Shared(language, "desktop.runConfig.folderNameTaken") + return + } + d.folderError = "" + for _, key := range d.runConfigDialogFolderKeys(node) { + d.moveToFolder(key, name) + } + if empty := d.emptyFolders[node.group]; slices.Contains(empty, node.folder) { + d.emptyFolders[node.group] = append(slices.DeleteFunc(empty, func(folder string) bool { return folder == node.folder }), name) + } + renamed := runConfigDialogNode{group: node.group, folder: name} + if d.closed[node] { + delete(d.closed, node) + d.closed[renamed] = true + } + // The row keeps its key, so it keeps the keyboard while it is renamed. + if id, ok := d.ids[node.id()]; ok { + d.ids[renamed.id()] = id + } + d.node = renamed +} + +// ungroupRunConfigFolder takes the configurations out of the selected folder, which then no +// longer shows, and selects its group. +func (p *project) ungroupRunConfigFolder() { + d := &p.runConfigs.dialog + node := d.node + if node.folder == "" { + return + } + for _, key := range d.runConfigDialogFolderKeys(node) { + d.moveToFolder(key, "") + } + if empty := d.emptyFolders[node.group]; empty != nil { + d.emptyFolders[node.group] = slices.DeleteFunc(empty, func(folder string) bool { return folder == node.folder }) + } + d.selectRunConfigDialogNode(runConfigDialogNode{group: node.group}) + d.reveal = true +} + +// toggleRunConfigDialogSort switches between listing by name and the order the user gives the +// list. The first manual order is the one the tree shows, so turning sorting off moves nothing. +func (p *project) toggleRunConfigDialogSort() { + d := &p.runConfigs.dialog + sorted := !p.runConfigDialogSorted() + if !sorted && d.order == nil { + d.order = d.displayOrder() + } + d.sort, d.rearranged, d.reveal = &sorted, true, true +} + +// runConfigDialogCanDrop says a dragged row can be let go where it is: only a configuration, in +// its own group. Into the group's row takes it out of its folder and into a folder's row puts it +// there; before or after another configuration places it in that one's folder and, when the list +// is not sorted by name, at that place. +func (p *project) runConfigDialogCanDrop(from, to int, where ui.TreeDrop) bool { + d := &p.runConfigs.dialog + if d.saving || from == to || from < 0 || to < 0 || from >= len(d.rows) || to >= len(d.rows) { + return false + } + source, target := d.rows[from], d.rows[to] + if source.key == "" || source.group != target.group { + return false + } + if target.key == "" { + return where == ui.TreeDropInside && target.node.folder != source.node.folder + } + if where == ui.TreeDropInside { + return false + } + return !p.runConfigDialogSorted() || target.node.folder != source.node.folder +} + +// dropRunConfigDialogRow moves a configuration where it was dropped and selects it. +func (a *App) dropRunConfigDialogRow(p *project, move ui.TreeMove) { + d := &p.runConfigs.dialog + if !p.runConfigDialogCanDrop(move.From, move.To, move.Where) { + return + } + source, target := d.rows[move.From], d.rows[move.To] + key := source.key + d.moveToFolder(key, target.node.folder) + if !p.runConfigDialogSorted() { + order := d.displayOrder() + at := slices.Index(order, key) + order = slices.Delete(order, at, at+1) + if target.key != "" { + at = slices.Index(order, target.key) + if move.Where == ui.TreeDropAfter { + at++ + } + } else { + // Into a group or folder goes after the configurations already there. + var section []string + if target.node.folder != "" { + section = d.runConfigDialogFolderKeys(target.node) + } else { + section = d.groups[target.group].keys + } + for index, existing := range order { + if existing != key && slices.Contains(section, existing) { + at = index + 1 + } + } } + d.order = slices.Insert(order, max(0, min(at, len(order))), key) } + a.selectRunConfigDraft(p, key) + d.reveal = true } -// runConfigDraftLabel is the name a configuration shows in the tree: the name its form holds, -// else the name it gets while the field is empty, else its saved name. +// runConfigDraftLabel is the name a configuration shows in the tree: the name its form or copy +// holds, else the name it gets while the field is empty, else its saved name. func (a *App) runConfigDraftLabel(p *project, key string) string { - if draft := p.runConfigs.dialog.drafts[key]; draft != nil && draft.form != nil { - f := draft.form - if name := f.texts["name"]; name != nil && strings.TrimSpace(*name) != "" { - return strings.TrimSpace(*name) - } - for _, field := range f.fields { - if field.ID == "name" && field.Automatic != nil && *field.Automatic != "" { - return *field.Automatic + if draft := p.runConfigs.dialog.drafts[key]; draft != nil { + if f := draft.form; f != nil { + if name := f.texts["name"]; name != nil && strings.TrimSpace(*name) != "" { + return strings.TrimSpace(*name) + } + for _, field := range f.fields { + if field.ID == "name" && field.Automatic != nil && *field.Automatic != "" { + return *field.Automatic + } + } + if f.name != "" { + return f.name } } - if f.name != "" { - return f.name + if name := strings.TrimSpace(draft.copyName); draft.copyOf != "" && name != "" { + return name } } if configuration := p.runConfigs.configuration(key); configuration != nil { @@ -404,11 +884,12 @@ func (a *App) runConfigDraftUnavailable(p *project, key string) string { return "" } -// runConfigDialogRunnable says Run can run the selected configuration once it is saved. +// runConfigDialogRunnable says Run can run the selected configuration once it is saved. A copy +// runs once the list shows it. func (a *App) runConfigDialogRunnable(p *project) bool { d := &p.runConfigs.dialog draft := d.drafts[d.selected] - if draft == nil || a.runConfigDraftUnavailable(p, d.selected) != "" { + if draft == nil || draft.copyOf != "" || a.runConfigDraftUnavailable(p, d.selected) != "" { return false } if draft.form != nil { @@ -418,9 +899,9 @@ func (a *App) runConfigDialogRunnable(p *project) bool { return configuration != nil && p.runConfigurationReady(*configuration) } -// runConfigDialogDirty says Apply has something to save. +// dirty says Apply has something to save. func (d *runConfigDialog) dirty() bool { - if len(d.removed) > 0 { + if len(d.removed) > 0 || d.rearranged { return true } for _, draft := range d.drafts { @@ -447,12 +928,13 @@ func (d *runConfigDialog) busy() bool { // runConfigDialogTask is one save of the chain Apply runs; done gets whether it succeeded. type runConfigDialogTask func(done func(ok bool)) -// applyRunConfigDialog saves what the dialog holds, one file change after another: the -// removals, then every draft with something to save. The first failure stops the chain and -// selects the configuration it belongs to, whose editor shows the reason. When every save -// succeeded, the selected configuration becomes the one the title bar runs; OK then closes the -// dialog, and Run closes it and runs the configuration once the list shows what was saved. The -// configurations are resolved again either way, so what was saved before a failure shows. +// applyRunConfigDialog saves what the dialog holds, one file change after another: every draft +// with something to save, the copies, the removals, then the folders, order and sort. The +// first failure stops the chain and selects the configuration it belongs to, whose editor or +// the pane shows the reason. When every step succeeded, the selected configuration becomes the +// one the title bar runs; OK then closes the dialog, and Run closes it and runs the +// configuration once the list shows what was saved. The configurations are resolved again +// either way, so what was saved before a failure shows. func (a *App) applyRunConfigDialog(p *project, step runConfigDialogStep) { d := &p.runConfigs.dialog if !d.open || d.busy() { @@ -462,39 +944,37 @@ func (a *App) applyRunConfigDialog(p *project, step runConfigDialogStep) { p.collectRunConfigDialogRows(a) d.saving, d.failure = true, "" generation := d.generation - var tasks []runConfigDialogTask - for _, id := range slices.Sorted(maps.Keys(d.removed)) { - tasks = append(tasks, func(done func(bool)) { - a.removeRunConfiguration(p, id, func(err error) { - if err != nil { - if d.generation == generation { - d.failure = i18n.SharedFormat(a.language(), "desktop.runConfig.deleteFailed", map[string]string{"reason": err.Error()}) - } - done(false) - return - } - delete(d.removed, id) - done(true) - }) - }) + current := func() bool { return d.generation == generation } + failedAt := func(key, failure string) { + if !current() { + return + } + if failure != "" { + d.failure = failure + } + d.selected, d.node, d.reveal = key, runConfigDialogNode{}, true + group := p.runConfigDialogGroupKey(key) + delete(d.closed, runConfigDialogNode{group: group}) + delete(d.closed, runConfigDialogNode{group: group, folder: p.runConfigDialogFolder(key)}) } - for _, key := range p.runConfigDialogSaveOrder() { + saves, copies := p.runConfigDialogSaveOrder() + // A renamed or new configuration gets an ID the saved order does not have yet, so in a + // list the user orders, the order the tree shows is saved with it and nothing moves. + if !p.runConfigDialogSorted() && len(saves)+len(copies) > 0 { + d.order, d.rearranged = d.displayOrder(), true + } + var tasks []runConfigDialogTask + for _, key := range saves { draft := d.drafts[key] tasks = append(tasks, func(done func(bool)) { - failed := func() { - if d.generation == generation { - d.selected, d.group = draft.key, "" - delete(d.closed, p.runConfigDialogGroupKey(draft.key)) - } - done(false) - } if draft.form != nil { a.saveRunConfigForm(p, draft.form, func(id string, ok bool) { if !ok { - failed() + failedAt(draft.key, "") + done(false) return } - if d.generation == generation { + if current() { d.rekey(draft, id) } done(true) @@ -503,15 +983,69 @@ func (a *App) applyRunConfigDialog(p *project, step runConfigDialogStep) { } a.saveRunConfigEditor(p, draft.editor, func(ok bool) { if !ok { - failed() + failedAt(draft.key, "") + } + done(ok) + }) + }) + } + for _, key := range copies { + draft := d.drafts[key] + tasks = append(tasks, func(done func(bool)) { + a.copyRunConfiguration(p, draft.copyOf, strings.TrimSpace(draft.copyName), func(id string, err error) { + if err != nil { + failedAt(draft.key, i18n.SharedFormat(a.language(), "desktop.runConfig.copyFailed", map[string]string{"reason": err.Error()})) + done(false) return } + if current() { + d.rekey(draft, id) + draft.copied = true + } done(true) }) }) } + for _, id := range slices.Sorted(maps.Keys(d.removed)) { + tasks = append(tasks, func(done func(bool)) { + a.removeRunConfiguration(p, id, func(err error) { + if err != nil { + if current() { + d.failure = i18n.SharedFormat(a.language(), "desktop.runConfig.deleteFailed", map[string]string{"reason": err.Error()}) + } + done(false) + return + } + delete(d.removed, id) + // It stays out of the tree until the list stops showing it. + d.hidden[id] = true + done(true) + }) + }) + } + tasks = append(tasks, func(done func(bool)) { + request, ok := p.runConfigDialogArrangement() + if !current() || !ok { + d.rearranged = d.rearranged && current() && ok + done(true) + return + } + a.arrangeRunConfigurations(p, request, func(err error) { + if err != nil { + if current() { + d.failure = i18n.SharedFormat(a.language(), "desktop.runConfig.arrangeFailed", map[string]string{"reason": err.Error()}) + } + done(false) + return + } + if current() { + d.rearranged = false + } + done(true) + }) + }) finish := func(ok bool) { - if d.generation != generation { + if !current() { a.refreshRunConfigurations(p) return } @@ -532,7 +1066,7 @@ func (a *App) applyRunConfigDialog(p *project, step runConfigDialogStep) { } var next func(index int) next = func(index int) { - if d.generation != generation { + if !current() { finish(false) return } @@ -551,25 +1085,129 @@ func (a *App) applyRunConfigDialog(p *project, step runConfigDialogStep) { next(0) } -// runConfigDialogSaveOrder is the drafts with something to save, as the tree shows them, so a -// failure stops at the first one the user sees. -func (p *project) runConfigDialogSaveOrder() []string { +// runConfigDialogSaveOrder is the drafts with something to save and the copies to make, as +// the tree shows them, so a failure stops at the first one the user sees. +func (p *project) runConfigDialogSaveOrder() (saves, copies []string) { d := &p.runConfigs.dialog - var keys []string - seen := map[string]bool{} - for _, group := range d.groups { - for _, key := range group.keys { - if draft := d.drafts[key]; draft != nil && !seen[key] && draft.dirty() { - keys, seen[key] = append(keys, key), true + for _, key := range d.displayOrder() { + draft := d.drafts[key] + switch { + case draft == nil || !draft.dirty() || slices.Contains(saves, key) || slices.Contains(copies, key): + case draft.pendingCopy(): + copies = append(copies, key) + default: + saves = append(saves, key) + } + } + return saves, copies +} + +// runConfigDialogArrangement is the arrange request that saves the folders, the manual order +// and the sort choice the user made, for saved configurations only; false when it holds +// nothing to save. +func (p *project) runConfigDialogArrangement() (core.RunConfigArrangement, bool) { + d := &p.runConfigs.dialog + request := core.RunConfigArrangement{Root: p.root} + if !d.rearranged { + return request, false + } + saved := func(key string) bool { + return !strings.HasPrefix(key, runConfigNewKey) && !d.removed[key] && !d.hidden[key] + } + for _, key := range slices.Sorted(maps.Keys(d.folders)) { + if !saved(key) { + continue + } + if request.Folders == nil { + request.Folders = map[string]*string{} + } + var folder *string + if name := d.folders[key]; name != "" { + folder = &name + } + request.Folders[key] = folder + } + if !p.runConfigDialogSorted() { + for _, key := range d.order { + if saved(key) && !slices.Contains(request.Order, key) { + request.Order = append(request.Order, key) } } } - return keys + if d.sort != nil { + sorted := *d.sort + request.SortAlphabetically = &sorted + } + return request, request.Folders != nil || request.Order != nil || request.SortAlphabetically != nil +} + +// copyRunConfiguration has Core copy configuration id under name and writes the copy; done gets +// the copy's ID. +func (a *App) copyRunConfiguration(p *project, id, name string, done func(string, error)) { + root, kernel := p.root, a.kernel + a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { + copied, changes, err := kernel.CopyRunConfiguration(ctx, root, id, name, a.runConfigPlugins(ctx)) + if err == nil { + err = applyRunConfigChanges(ctx, root, changes) + } + return func(a *App) { + if err != nil { + a.operationFailed("run_config_copy", err) + } + done(copied, err) + } + }) +} + +// arrangeRunConfigurations writes the folders, order and sort choice of request. +func (a *App) arrangeRunConfigurations(p *project, request core.RunConfigArrangement, done func(error)) { + kernel := a.kernel + a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) { + request.Plugins = a.runConfigPlugins(ctx) + changes, err := kernel.ArrangeRunConfigurations(ctx, request) + if err == nil { + err = applyRunConfigChanges(ctx, request.Root, changes) + } + return func(a *App) { + if err != nil { + a.operationFailed("run_config_arrange", err) + } + done(err) + } + }) +} + +// settleRunConfigDialog brings the open dialog up to date with a new list: a copy Apply saved +// gives way to the configuration's own editor once the list shows it, and an ID the list no +// longer shows stops being hidden, so a later configuration that takes it shows. +func (a *App) settleRunConfigDialog(p *project) { + s := &p.runConfigs + d := &s.dialog + if !d.open { + return + } + for id := range d.hidden { + if s.configuration(id) == nil { + delete(d.hidden, id) + } + } + for _, key := range slices.Sorted(maps.Keys(d.drafts)) { + draft := d.drafts[key] + if !draft.copied || s.configuration(key) == nil { + continue + } + draft.close() + delete(d.drafts, key) + if d.selected == key { + a.selectRunConfigDraft(p, key) + } + } } // rekey files a draft under the ID its save returned, when that differs from its key: a new -// configuration's first save, or a rename that gave it another ID. The old ID stays out of the -// tree until the list stops showing it. +// configuration's or a copy's first save, or a rename that gave it another ID. The old ID stays +// out of the tree until the list stops showing it; its folder, place in the order and the copies +// of it move to the new ID. func (d *runConfigDialog) rekey(draft *runConfigDraft, id string) { old := draft.key if id == "" || id == old { @@ -577,6 +1215,7 @@ func (d *runConfigDialog) rekey(draft *runConfigDraft, id string) { } delete(d.drafts, old) draft.key, d.drafts[id] = id, draft + delete(d.hidden, id) if !strings.HasPrefix(old, runConfigNewKey) { d.hidden[old] = true } @@ -585,6 +1224,18 @@ func (d *runConfigDialog) rekey(draft *runConfigDraft, id string) { } else { d.added = append(d.added, id) } + if folder, ok := d.folders[old]; ok { + delete(d.folders, old) + d.folders[id] = folder + } + if index := slices.Index(d.order, old); index >= 0 { + d.order[index] = id + } + for _, other := range d.drafts { + if other.copyOf == old { + other.copyOf = id + } + } if d.selected == old { d.selected = id } @@ -593,12 +1244,12 @@ func (d *runConfigDialog) rekey(draft *runConfigDraft, id string) { } } -// runConfigDialogRowID is the list key of a tree row, the same across paints: one per draft -// key and one per group key, numbered as they first show. +// runConfigDialogRowID is the tree key of a row, the same across paints: one per draft key and +// one per group and folder, numbered as they first show. func (d *runConfigDialog) runConfigDialogRowID(row runConfigDialogRow) int { key := "c\x00" + row.key if row.key == "" { - key = "g\x00" + d.groups[row.group].key + key = row.node.id() } id, ok := d.ids[key] if !ok { @@ -609,34 +1260,39 @@ func (d *runConfigDialog) runConfigDialogRowID(row runConfigDialogRow) int { } // runConfigDialogRowIndex is the index of the selected row among the rows as they show, -1 -// when nothing is selected or the selection is in a closed group. +// when nothing is selected or the selection is in a closed group or folder. func (d *runConfigDialog) runConfigDialogRowIndex() int { for index, row := range d.rows { - if row.key == "" { - if d.selected == "" && d.group != "" && d.groups[row.group].key == d.group { + if d.selected != "" { + if row.key == d.selected { return index } - } else if row.key == d.selected { + } else if row.key == "" && d.node.group != "" && row.node == d.node { return index } } return -1 } -// toggleRunConfigDialogGroup opens a closed group of the tree and closes an open one. -// Closing the group of the selected configuration leaves the selection on the group's row. -func (p *project) toggleRunConfigDialogGroup(key string) { +// toggleRunConfigDialogNode opens a closed group or folder of the tree and closes an open one. +// Closing the one that holds the selection leaves the selection on its row. +func (p *project) toggleRunConfigDialogNode(node runConfigDialogNode) { d := &p.runConfigs.dialog - if d.closed[key] { - delete(d.closed, key) + if d.closed[node] { + delete(d.closed, node) return } if d.closed == nil { - d.closed = map[string]bool{} + d.closed = map[runConfigDialogNode]bool{} } - d.closed[key] = true - if d.selected != "" && p.runConfigDialogGroupKey(d.selected) == key { - d.selected, d.group = "", key + d.closed[node] = true + switch { + case d.selected != "": + if p.runConfigDialogGroupKey(d.selected) == node.group && (node.folder == "" || p.runConfigDialogFolder(d.selected) == node.folder) { + d.selectRunConfigDialogNode(node) + } + case node.folder == "" && d.node.group == node.group && d.node.folder != "": + d.selectRunConfigDialogNode(node) } } diff --git a/desktop/internal/workbench/runconfig_dialog_test.go b/desktop/internal/workbench/runconfig_dialog_test.go index 0e1d6b988b..aa74ccf7b6 100644 --- a/desktop/internal/workbench/runconfig_dialog_test.go +++ b/desktop/internal/workbench/runconfig_dialog_test.go @@ -4,12 +4,15 @@ import ( "os" "path/filepath" "runtime" + "slices" "strings" "testing" "time" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" ) // emptyProcessRunHarness opens an empty project without any build plugin and waits until Core @@ -145,7 +148,12 @@ func TestRunConfigDialogCopiesAConfiguration(t *testing.T) { original := newRunConfigDraft(t, h, p, runProviderShell) fillScriptText(t, h, p, original, "Greet", "echo hello\n") h.settle() - h.app.post(func(a *App) { a.copyRunConfigDraft(p) }) + h.app.post(func(a *App) { + key := d.selected + a.addRunConfigFolder(p) + a.selectRunConfigDraft(p, key) + a.copyRunConfigDraft(p) + }) var copied *runConfigForm awaitStateWithin(t, h, 10*time.Second, "the copy's form", func() bool { if draft := d.drafts[d.selected]; draft != nil && draft.form != original { @@ -157,10 +165,20 @@ func TestRunConfigDialogCopiesAConfiguration(t *testing.T) { if *copied.texts["name"] != want || *copied.texts["text"] != "echo hello\n" || len(d.added) != 2 { t.Fatalf("copy = name %q text %q, added %v", *copied.texts["name"], *copied.texts["text"], d.added) } + // The copy goes in the original's folder, and both are saved there. + folder := i18n.Shared(h.app.language(), "desktop.runConfig.newFolderName") + if got := p.runConfigDialogFolder(d.selected); got != folder { + t.Fatalf("the copy is in folder %q, want %q", got, folder) + } applyDialog(t, h, p, runConfigDialogOK) if names := listedNames(p); len(names) != 2 { t.Fatalf("configurations %v, failure %q", names, d.failure) } + for _, configuration := range p.runConfigs.list { + if configuration.Folder != folder { + t.Fatalf("%s is in folder %q, want %q", configuration.Name, configuration.Folder, folder) + } + } } // Closing the group of the selected configuration leaves the selection on the group's row, and @@ -170,24 +188,349 @@ func TestRunConfigDialogGroupsClose(t *testing.T) { d := &p.runConfigs.dialog newRunConfigDraft(t, h, p, runProviderShell) h.settle() - group := runProcessKindKey(runProviderShell) + group := runConfigDialogNode{group: runProcessKindKey(runProviderShell)} if len(d.rows) != 2 || d.runConfigDialogRowIndex() != 1 { t.Fatalf("rows %+v, selected row %d", d.rows, d.runConfigDialogRowIndex()) } - h.app.post(func(*App) { p.toggleRunConfigDialogGroup(group) }) + h.app.post(func(*App) { p.toggleRunConfigDialogNode(group) }) h.settle() - if d.selected != "" || d.group != group || len(d.rows) != 1 || d.runConfigDialogRowIndex() != 0 { - t.Fatalf("selected %q group %q rows %+v", d.selected, d.group, d.rows) + if d.selected != "" || d.node != group || len(d.rows) != 1 || d.runConfigDialogRowIndex() != 0 { + t.Fatalf("selected %q node %+v rows %+v", d.selected, d.node, d.rows) } h.app.post(func(a *App) { a.closeRunConfigDialog(p) a.openRunConfigDialog(p, "") }) + h.settle() if !d.closed[group] { t.Fatal("the closed group opened again with the dialog") } } +// savedShellRuns saves shell runs of names through the dialog, which stays open on them. +func savedShellRuns(t *testing.T, h *harness, p *project, names ...string) map[string]string { + t.Helper() + d := &p.runConfigs.dialog + forms := make([]*runConfigForm, 0, len(names)) + for index, name := range names { + var f *runConfigForm + if index == 0 { + f = newRunConfigDraft(t, h, p, runProviderShell) + } else { + h.app.post(func(a *App) { + a.addRunConfigDraft(p, runProviderShell, nil) + f = d.drafts[d.selected].form + }) + awaitStateWithin(t, h, 10*time.Second, "the form of "+name, func() bool { return f != nil && f.ready() }) + } + fillScriptText(t, h, p, f, name, "echo "+name+"\n") + forms = append(forms, f) + } + h.settle() + applyDialog(t, h, p, runConfigDialogApply) + ids := map[string]string{} + for index, f := range forms { + if f.id == "" { + t.Fatalf("%s was not saved: dialog failure %q, form failure %q", names[index], d.failure, f.failure) + } + ids[names[index]] = f.id + } + if got := listedNames(p); len(got) != len(names) { + t.Fatalf("configurations %v, failure %q", got, d.failure) + } + return ids +} + +// dialogRowKeys is the configuration keys of the tree's rows, "" for a group's or folder's row. +func dialogRowKeys(d *runConfigDialog) []string { + keys := make([]string, 0, len(d.rows)) + for _, row := range d.rows { + keys = append(keys, row.key) + } + return keys +} + +// With no configuration, the dialog shows what IDEA does: that none was added and the link that +// adds one beside its keys in the tree, and the link that adds one over "or select one to edit" +// in the pane. Each link, and ⌃N or Alt+Insert, opens the menu of kinds. +func TestRunConfigDialogEmptyStateOffersToAdd(t *testing.T) { + h, p, _ := emptyProcessRunHarness(t) + d := &p.runConfigs.dialog + h.app.post(func(a *App) { a.openRunConfigDialog(p, "") }) + awaitStateWithin(t, h, 10*time.Second, "the list the dialog reads again", func() bool { + return d.open && !p.runConfigs.loading && p.runConfigs.types != nil + }) + h.settle() + language := h.app.language() + for _, key := range []string{"emptyTree", "addNew", "addNewConfiguration", "orSelectToEdit"} { + if text := i18n.Shared(language, "desktop.runConfig."+key); !h.shows(text) { + t.Fatalf("%q is not shown", text) + } + } + shell := i18n.Shared(language, "desktop.runConfig.typeShell") + if h.shows(shell) { + t.Fatal("the kinds show before the menu opens") + } + + // The keys open the menu while the keyboard is in the tree's column, as it is on opening. + if runtime.GOOS == "darwin" { + if _, err := h.driver.ShortcutChord(gfx.ModifierControl, 'n'); err != nil { + t.Fatal(err) + } + } else if err := h.driver.Key(gfx.KeyInsert, gfx.ModifierAlt); err != nil { + t.Fatal(err) + } + h.settle() + if d.newMenu != runConfigNewMenuToolbar || !h.shows(shell) { + t.Fatalf("menu %v, kinds shown %v after the add keys", d.newMenu, h.shows(shell)) + } + h.app.post(func(*App) { d.newMenu = runConfigNewMenuClosed }) + h.settle() + + for _, link := range []struct { + key string + menu runConfigNewMenu + }{{"addNew", runConfigNewMenuTree}, {"addNewConfiguration", runConfigNewMenuPane}} { + h.click(center(h.hitLabeled(i18n.Shared(language, "desktop.runConfig."+link.key)))) + if d.newMenu != link.menu || !h.shows(shell) { + t.Fatalf("%s: menu %v, kinds shown %v", link.key, d.newMenu, h.shows(shell)) + } + h.app.post(func(*App) { d.newMenu = runConfigNewMenuClosed }) + h.settle() + } + + h.click(center(h.hitLabeled(i18n.Shared(language, "desktop.runConfig.addNew")))) + h.popupClick(shell) + if draft := d.drafts[d.selected]; draft == nil || draft.form == nil || draft.form.provider != runProviderShell || d.newMenu != runConfigNewMenuClosed { + t.Fatalf("selected %q, menu %v after choosing a kind", d.selected, d.newMenu) + } +} + +// A folder holds the configuration selected when it is made and is selected to be renamed; the +// folder is saved in the configuration, so the list and the dialog show it again. Taking the +// folder away puts its configurations back in their kind. +func TestRunConfigDialogFoldersAreSavedInTheConfiguration(t *testing.T) { + h, p, root := emptyProcessRunHarness(t) + d := &p.runConfigs.dialog + ids := savedShellRuns(t, h, p, "Alpha", "Beta") + language := h.app.language() + h.app.post(func(a *App) { + a.selectRunConfigDraft(p, ids["Beta"]) + a.addRunConfigFolder(p) + }) + h.settle() + base := i18n.Shared(language, "desktop.runConfig.newFolderName") + folder := runConfigDialogNode{group: runProcessKindKey(runProviderShell), folder: base} + if d.node != folder || !slices.Equal(dialogRowKeys(d), []string{"", "", ids["Beta"], ids["Alpha"]}) { + t.Fatalf("node %+v rows %v", d.node, dialogRowKeys(d)) + } + if !h.shows(i18n.Shared(language, "desktop.runConfig.folderHint")) { + t.Fatal("the folder's pane is not shown") + } + + // A second folder takes the next free name; a name another folder has, or none, is refused. + h.app.post(func(a *App) { + a.selectRunConfigDraft(p, ids["Alpha"]) + a.addRunConfigFolder(p) + }) + h.settle() + if want := base + " 2"; d.node.folder != want { + t.Fatalf("second folder %q, want %q", d.node.folder, want) + } + for _, refused := range []struct{ name, key string }{{base, "folderNameTaken"}, {" ", "folderNameEmpty"}, {"a\tb", "folderNameInvalid"}} { + h.app.post(func(a *App) { + d.folderName = refused.name + a.renameRunConfigFolder(p) + }) + h.settle() + if want := i18n.Shared(language, "desktop.runConfig."+refused.key); d.folderError != want || d.node.folder != base+" 2" || !h.shows(want) { + t.Fatalf("%q: error %q node %+v", refused.name, d.folderError, d.node) + } + } + h.app.post(func(a *App) { + d.folderName = " Servers " + a.renameRunConfigFolder(p) + }) + h.settle() + if d.folderError != "" || d.node.folder != "Servers" || p.runConfigDialogFolder(ids["Alpha"]) != "Servers" { + t.Fatalf("rename: error %q node %+v", d.folderError, d.node) + } + + applyDialog(t, h, p, runConfigDialogApply) + for name, want := range map[string]string{"Alpha": "Servers", "Beta": base} { + if configuration := p.runConfigs.configuration(ids[name]); configuration == nil || configuration.Folder != want { + t.Fatalf("%s = %+v, failure %q", name, configuration, d.failure) + } + } + local := filepath.Join(root, ".lithe", "run", "local.yaml") + if data, err := os.ReadFile(local); err != nil || !strings.Contains(string(data), "folder: Servers") { + t.Fatalf("local.yaml = %s, %v", data, err) + } + if d.dirty() { + t.Fatal("the dialog shows something to save after Apply") + } + + // The folders show again when the dialog opens, and − on a folder takes it away. + h.app.post(func(a *App) { + a.closeRunConfigDialog(p) + a.openRunConfigDialog(p, "") + }) + h.settle() + if !h.shows("Servers") || !h.shows(base) { + t.Fatal("the saved folders are not shown") + } + h.app.post(func(a *App) { + d.selectRunConfigDialogNode(runConfigDialogNode{group: folder.group, folder: "Servers"}) + a.removeRunConfigSelection(p) + }) + h.settle() + if d.node != (runConfigDialogNode{group: folder.group}) || p.runConfigDialogFolder(ids["Alpha"]) != "" || h.shows("Servers") { + t.Fatalf("node %+v, Alpha in %q", d.node, p.runConfigDialogFolder(ids["Alpha"])) + } + applyDialog(t, h, p, runConfigDialogOK) + if configuration := p.runConfigs.configuration(ids["Alpha"]); d.open || configuration == nil || configuration.Folder != "" { + t.Fatalf("dialog open %v, Alpha = %+v, failure %q", d.open, configuration, d.failure) + } +} + +// Turning the sort off keeps the order the tree shows and lets a configuration be dragged to +// another place; the order is saved for this machine only, and the list follows it. +func TestRunConfigDialogOrdersTheListWhenNotSorted(t *testing.T) { + h, p, root := emptyProcessRunHarness(t) + d := &p.runConfigs.dialog + ids := savedShellRuns(t, h, p, "Alpha", "Beta", "Gamma") + if p.runConfigs.manualOrder || !p.runConfigDialogSorted() { + t.Fatal("a new project lists its configurations unsorted") + } + // Sorted, a configuration only moves between folders: before another one is refused. + if p.runConfigDialogCanDrop(3, 1, ui.TreeDropBefore) { + t.Fatal("a sorted list takes a new place") + } + h.app.post(func(*App) { p.toggleRunConfigDialogSort() }) + h.settle() + if !slices.Equal(dialogRowKeys(d), []string{"", ids["Alpha"], ids["Beta"], ids["Gamma"]}) || !d.dirty() { + t.Fatalf("turning the sort off moved the rows: %v", dialogRowKeys(d)) + } + h.app.post(func(a *App) { a.dropRunConfigDialogRow(p, ui.TreeMove{From: 3, To: 1, Where: ui.TreeDropBefore}) }) + h.settle() + if want := []string{"", ids["Gamma"], ids["Alpha"], ids["Beta"]}; !slices.Equal(dialogRowKeys(d), want) || d.selected != ids["Gamma"] { + t.Fatalf("rows %v selected %q, want %v", dialogRowKeys(d), d.selected, want) + } + applyDialog(t, h, p, runConfigDialogApply) + if names := listedNames(p); !slices.Equal(names, []string{"Gamma", "Alpha", "Beta"}) || !p.runConfigs.manualOrder { + t.Fatalf("configurations %v manual %v, failure %q", names, p.runConfigs.manualOrder, d.failure) + } + project := filepath.Join(root, ".lithe", "run", "configurations.yaml") + if data, err := os.ReadFile(project); err == nil && strings.Contains(string(data), "arrangement") { + t.Fatalf("the order went to the project file: %s", data) + } + local, err := os.ReadFile(filepath.Join(root, ".lithe", "run", "local.yaml")) + if err != nil || !strings.Contains(string(local), "sortAlphabetically: false") { + t.Fatalf("local.yaml = %s, %v", local, err) + } + + // A configuration added while the list is ordered goes after the others and keeps its place. + var added *runConfigForm + h.app.post(func(a *App) { + a.addRunConfigDraft(p, runProviderShell, nil) + added = d.drafts[d.selected].form + }) + awaitStateWithin(t, h, 10*time.Second, "the new form", func() bool { return added != nil && added.ready() }) + fillScriptText(t, h, p, added, "Delta", "echo delta\n") + h.settle() + applyDialog(t, h, p, runConfigDialogApply) + if names := listedNames(p); !slices.Equal(names, []string{"Gamma", "Alpha", "Beta", "Delta"}) { + t.Fatalf("configurations %v, failure %q", names, d.failure) + } + + // Sorting again lists by name. + h.app.post(func(*App) { p.toggleRunConfigDialogSort() }) + applyDialog(t, h, p, runConfigDialogOK) + if names := listedNames(p); !slices.Equal(names, []string{"Alpha", "Beta", "Delta", "Gamma"}) || p.runConfigs.manualOrder { + t.Fatalf("configurations %v manual %v, failure %q", names, p.runConfigs.manualOrder, d.failure) + } +} + +// ⌫ on macOS, and Delete elsewhere, takes the selected configuration out of the tree like −, and +// the keyboard stays in the tree on the row that took its place, so the key goes on removing. +func TestRunConfigDialogDeleteKeyRemovesTheSelection(t *testing.T) { + h, p, _ := emptyProcessRunHarness(t) + d := &p.runConfigs.dialog + ids := savedShellRuns(t, h, p, "One", "Two") + key := gfx.KeyDelete + if runtime.GOOS == "darwin" { + key = gfx.KeyBackspace + } + h.click(center(h.labelBounds("One"))) + if d.selected != ids["One"] { + t.Fatalf("selected %q after clicking One", d.selected) + } + for _, name := range []string{"One", "Two"} { + if err := h.driver.Key(key, 0); err != nil { + t.Fatal(err) + } + h.settle() + h.settle() + if !d.removed[ids[name]] || slices.Contains(dialogRowKeys(d), ids[name]) { + t.Fatalf("after the key: removed %v, rows %v", d.removed, dialogRowKeys(d)) + } + } + if len(d.rows) != 0 || len(p.runConfigs.list) != 2 { + t.Fatalf("rows %v, configurations %v", dialogRowKeys(d), listedNames(p)) + } + // Like −, the key only marks the removal: closing the dialog without Apply keeps both. + h.app.post(func(a *App) { + a.closeRunConfigDialog(p) + a.openRunConfigDialog(p, ids["One"]) + }) + h.settle() + if d.removed[ids["One"]] || len(d.rows) != 3 || d.selected != ids["One"] { + t.Fatalf("after Cancel: removed %v rows %v selected %q", d.removed, dialogRowKeys(d), d.selected) + } +} + +// A copy of a plugin run is made by Core on Apply with every choice the original saved, and the +// original stays listed. Until then the pane holds the copy's name only. +func TestRunConfigDialogCopiesAPluginRun(t *testing.T) { + root := t.TempDir() + h, p := loadedRunConfigs(t, &testKernel{Client: core.NewClient()}, root) + original := p.runConfigs.selected + d := &p.runConfigs.dialog + h.app.post(func(a *App) { a.openRunConfigDialog(p, original) }) + awaitStateWithin(t, h, 10*time.Second, "the original's editor", func() bool { + draft := d.drafts[original] + return draft != nil && draft.editor != nil && !draft.editor.loading + }) + h.app.post(func(a *App) { a.copyRunConfigDraft(p) }) + h.settle() + language := h.app.language() + draft := d.drafts[d.selected] + name := i18n.SharedFormat(language, "desktop.runConfig.copyName", map[string]string{"name": p.runConfigs.configuration(original).Name}) + if draft == nil || draft.copyOf != original || draft.copyName != name || !h.shows(i18n.Shared(language, "desktop.runConfig.copyPendingHint")) { + t.Fatalf("copy %+v", draft) + } + if h.app.runConfigDialogRunnable(p) || p.runConfigCopyable(d.selected) { + t.Fatal("a copy not made yet runs or copies") + } + applyDialog(t, h, p, runConfigDialogApply) + if names := listedNames(p); len(names) != 2 || !slices.Contains(names, name) { + t.Fatalf("configurations %v, failure %q", names, d.failure) + } + copied := d.selected + if copied == original || p.runConfigs.configuration(copied) == nil || p.runConfigs.configuration(original) == nil { + t.Fatalf("selected %q, original %q", copied, original) + } + document, err := os.ReadFile(filepath.Join(root, ".lithe", "run", "plugin", "dev.example.engine.local.toml")) + if err != nil || !strings.Contains(string(document), name) { + t.Fatalf("the plugin's local document = %s, %v", document, err) + } + // The copy then opens in its own editor, as any plugin run does. + awaitStateWithin(t, h, 10*time.Second, "the copy's editor", func() bool { + draft := d.drafts[copied] + return draft != nil && draft.copyOf == "" && draft.editor != nil && !draft.editor.loading + }) +} + // Off Windows a batch script is created, edited and saved like any other run, under a warning // that it cannot run here: the dialog's Run is off, the tree marks it, and the title bar's Run // says why instead of starting it. diff --git a/desktop/internal/workbench/runconfig_dialog_view.go b/desktop/internal/workbench/runconfig_dialog_view.go index a78f176b74..80b295d12e 100644 --- a/desktop/internal/workbench/runconfig_dialog_view.go +++ b/desktop/internal/workbench/runconfig_dialog_view.go @@ -1,11 +1,17 @@ package workbench import ( + "runtime" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/fileicons" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/1lck/Lithe-IDEA/desktop/internal/shortcuts" "github.com/1lck/Lithe-IDEA/desktop/internal/treelist" + "github.com/vivaui/viva/components" "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/keymap" "github.com/vivaui/viva/ui" ) @@ -18,10 +24,26 @@ const ( runConfigDialogHeight = 620 // runConfigDialogTreeWidth is the width of the tree and its toolbar. runConfigDialogTreeWidth = 260 - // runConfigDialogIndent indents a configuration under its group's arrow. - runConfigDialogIndent = treelist.Disclosure + 6 ) +// runConfigAddChord is the modifiers and key that add a configuration, as in IDEA: ⌃N on macOS +// and Alt+Insert elsewhere. +func runConfigAddChord() (gfx.Modifiers, string) { + if runtime.GOOS == "darwin" { + return gfx.ModifierControl, "n" + } + return gfx.ModifierAlt, "insert" +} + +// runConfigDeleteKeys are the keys that take the selection out of the tree: ⌫ and ⌦ on macOS, +// whose keyboards label ⌫ Delete, and Delete elsewhere, where Backspace only edits text. +func runConfigDeleteKeys() []string { + if runtime.GOOS == "darwin" { + return []string{"backspace", "delete"} + } + return []string{"delete"} +} + // drawRunConfigDialog declares the dialog while it is open: the toolbar and tree on the left, // the selected configuration's editor on the right, and Run, Cancel, Apply and OK below. // Escape and the close button end it like Cancel. @@ -49,40 +71,51 @@ func (a *App) drawRunConfigDialog(c ui.C, p *project) { } // drawRunConfigDialogTree declares the left column: the buttons that add, remove and copy a -// configuration over the tree of configurations by kind. +// configuration, make a folder and sort the list by name, over the tree of configurations. +// With the keyboard in it, ⌃N, or Alt+Insert off macOS, opens the menu of kinds a new +// configuration can take. The editor beside it keeps ⌃N, which moves down a line in a text +// field on macOS. func (a *App) drawRunConfigDialogTree(c ui.C, p *project) { s := &p.runConfigs d := &s.dialog language := a.language() k := c.Part("tree") - ui.Column(k).Width(runConfigDialogTreeWidth).FillHeight().Shrink(0).Children(func() { + column := ui.Column(k).Width(runConfigDialogTreeWidth).FillHeight().Shrink(0).Children(func() { ui.Row(k.Part("toolbar")).FillWidth().Height(panelHeaderHeight).Shrink(0).Items(ui.Center).Gap(2).PadX(6).Children(func() { label := i18n.Shared(language, "desktop.runConfig.newConfiguration") - add, clicked := a.gitToolButton(k.Part("add"), label, icons.Plus, d.newMenu, d.saving) + add, clicked := a.gitToolButton(k.Part("add"), label, icons.Plus, d.newMenu == runConfigNewMenuToolbar, d.saving) if clicked { - d.newMenu = !d.newMenu + c.After(func() { d.toggleNewMenu(runConfigNewMenuToolbar) }) } - ui.Menu(k.Part("add-menu"), add, &d.newMenu, func(menu *ui.MenuItems) { - menu.WidthRange(200, 300) - a.runConfigDialogTypeItems(k, menu, p) - }) - if a.gitIconButton(k.Part("remove"), i18n.Shared(language, "desktop.runConfig.removeConfiguration"), icons.Minus, false, !p.runConfigRemovable(d.selected)) { + a.drawRunConfigNewMenu(k.Part("add-menu"), p, add, runConfigNewMenuToolbar) + if a.gitIconButton(k.Part("remove"), i18n.Shared(language, "desktop.runConfig.removeConfiguration"), icons.Minus, false, !p.runConfigDialogRemovable()) { c.After(func() { a.performed("run.configuration.remove", surfaceButton) - a.removeRunConfigDraft(p) + a.removeRunConfigSelection(p) }) } - draft := d.drafts[d.selected] - copyable := !d.saving && draft != nil && draft.form != nil && draft.form.ready() - if a.gitIconButton(k.Part("copy"), i18n.Shared(language, "desktop.runConfig.copyConfiguration"), icons.Copy, false, !copyable) { + if a.gitIconButton(k.Part("copy"), i18n.Shared(language, "desktop.runConfig.copyConfiguration"), icons.Copy, false, !p.runConfigCopyable(d.selected)) { c.After(func() { a.performed("run.configuration.copy", surfaceButton) a.copyRunConfigDraft(p) }) } + folderable := !d.saving && (d.selected != "" || d.node.group != "") + if a.gitIconButton(k.Part("folder"), i18n.Shared(language, "desktop.runConfig.newFolder"), icons.FolderPlus, false, !folderable) { + c.After(func() { + a.performed("run.configuration.folder", surfaceButton) + a.addRunConfigFolder(p) + }) + } + if a.gitIconButton(k.Part("sort"), i18n.Shared(language, "desktop.runConfig.sortAlphabetically"), icons.ArrowDownAZ, p.runConfigDialogSorted(), d.saving) { + c.After(func() { + a.performed("run.configuration.sort", surfaceButton) + p.toggleRunConfigDialogSort() + }) + } }) ui.Row(k).FillWidth().Height(1).Shrink(0).Background(a.colors.Line) - ui.Column(k.Part("rows")).FillWidth().Grow(1).MinHeight(0).PadSides(4, 4, 4, 4).Children(func() { + ui.Column(k.Part("rows")).FillWidth().Grow(1).MinHeight(0).Children(func() { a.drawRunConfigDialogRows(k, p) }) if s.hidden > 0 { @@ -93,10 +126,35 @@ func (a *App) drawRunConfigDialogTree(c ui.C, p *project) { }) } }) + if modifiers, key := runConfigAddChord(); column.Shortcut(modifiers, key) && !d.saving { + c.After(func() { d.newMenu = runConfigNewMenuToolbar }) + } +} + +// toggleNewMenu opens the menu of kinds at at, or closes it when it shows there. +func (d *runConfigDialog) toggleNewMenu(at runConfigNewMenu) { + if d.newMenu == at { + d.newMenu = runConfigNewMenuClosed + return + } + d.newMenu = at +} + +// drawRunConfigNewMenu declares the menu of kinds under anchor while it shows at at. +func (a *App) drawRunConfigNewMenu(c ui.C, p *project, anchor ui.Box, at runConfigNewMenu) { + d := &p.runConfigs.dialog + open := d.newMenu == at + ui.Menu(c, anchor, &open, func(menu *ui.MenuItems) { + menu.WidthRange(200, 300) + a.runConfigDialogTypeItems(c, menu, p) + }) + if !open && d.newMenu == at { + d.newMenu = runConfigNewMenuClosed + } } -// runConfigDialogTypeItems adds an item per built-in kind to the + menu, each creating a new -// configuration of that kind. A kind this platform cannot run is still offered, saying so. +// runConfigDialogTypeItems adds an item per built-in kind to the menu of kinds, each creating a +// new configuration of that kind. A kind this platform cannot run is still offered, saying so. func (a *App) runConfigDialogTypeItems(c ui.C, menu *ui.MenuItems, p *project) { language := a.language() for _, kind := range p.runConfigs.types { @@ -105,7 +163,7 @@ func (a *App) runConfigDialogTypeItems(c ui.C, menu *ui.MenuItems, p *project) { continue } provider := kind.Provider - item := menu.Item(label).Icon(runConfigTypeIcon(provider)) + item := menu.Item(label).Icon(runConfigTypeIcon(provider, a.colors.Dark)) if kind.Unavailable() { item = item.Description(runConfigTypeNote(language, kind)) } @@ -129,143 +187,222 @@ func runConfigTypeNote(language i18n.Language, kind core.RunConfigurationType) s return i18n.Shared(language, "desktop.runConfig.typeNotRunnableHere") } -// drawRunConfigDialogRows declares the tree. Selecting a configuration shows its editor; -// Enter or a double click on a group opens or closes it. +// drawRunConfigDialogRows declares the tree, or while it has no rows, why: the list is being +// read, could not be read, or holds nothing yet, with the link that adds a configuration. +// Selecting a row shows its editor; Enter or a double click on a group or folder opens or +// closes it. A configuration can be dragged into another folder of its kind and, while the list +// is not sorted by name, to another place. Delete, or ⌫ on macOS, takes the selection out. func (a *App) drawRunConfigDialogRows(c ui.C, p *project) { s := &p.runConfigs d := &s.dialog language := a.language() if len(d.rows) == 0 { - message := i18n.Shared(language, "desktop.runConfig.emptyHint") - switch { - case s.failure != "": - message = i18n.SharedFormat(language, "desktop.runConfig.loadFailed", map[string]string{"reason": s.failure}) - case s.loading || s.generation == 0: - message = i18n.Shared(language, "native.loading") - } - // The message wraps inside the narrow column instead of centering one long line over it. - ui.Column(c.Part("empty")).Fill().Center().PadX(12).Children(func() { - ui.Paragraph(c, message, 4).TextCenter().FillWidth().Color(a.colors.Subtle) - }) + d.selectedRow = -1 + a.drawRunConfigDialogEmptyTree(c.Part("empty"), p) return } - if d.view.Key == nil { + if d.view.Node == nil { + d.view.Node = func(i int) ui.TreeNode { + row := d.rows[i] + return ui.TreeNode{Depth: row.depth, Branch: row.key == "", Expanded: row.key == "" && !d.closed[row.node], Selected: i == d.selectedRow} + } d.view.Key = func(i int) int { return d.runConfigDialogRowID(d.rows[i]) } - d.view.Label = func(i int) string { - if row := d.rows[i]; row.key != "" { - return a.runConfigDraftLabel(p, row.key) + d.view.Label = func(i int) string { return a.runConfigDialogRowLabel(p, d.rows[i]) } + d.view.RowHeight = treelist.RowHeight + d.view.Indent = treelist.Indent + d.view.CanDrop = p.runConfigDialogCanDrop + } + d.view.Disclosure = &components.TreeDisclosure{ + Collapsed: fileicons.TreeChevron(false, a.colors.Dark), + Expanded: fileicons.TreeChevron(true, a.colors.Dark), + Size: 16, + } + a.syncRunConfigDialogSelection(c.Canvas(), p) + title := i18n.Shared(language, "desktop.runConfig.dialogTitle") + tree := ui.Tree(c, &d.view, len(d.rows), d.view.Label, func(i int) { a.drawRunConfigDialogRow(c, p, i) }). + Scrollbars().Label(title).Grow(1).FillWidth().MinHeight(0).PadY(treelist.PadY) + d.painted = len(d.rows) + for _, key := range runConfigDeleteKeys() { + if tree.Shortcut(0, key) { + c.After(func() { + if p.runConfigDialogRemovable() { + a.performed("run.configuration.remove", surfaceShortcut) + a.removeRunConfigSelection(p) + d.refocus = true + } + }) + } + } + if i, ok := d.view.Toggled(); ok && i < len(d.rows) { + node := d.rows[i].node + c.After(func() { p.toggleRunConfigDialogNode(node) }) + } + if move, ok := d.view.Dropped(); ok { + c.After(func() { a.dropRunConfigDialogRow(p, move) }) + } + i, ok := d.view.Chosen() + if !ok || i >= len(d.rows) { + return + } + info, clicked := c.Canvas().ClickInfo() + repeated := clicked && info.Clicks >= 2 + row := d.rows[i] + // The row a click chose takes the keyboard, so the arrow keys and Delete go on from it. + c.Canvas().RequestFocus(d.view.RowID(i)) + c.After(func() { + a.selectRunConfigDialogRow(p, row) + if row.key == "" && (!clicked || repeated) { + p.toggleRunConfigDialogNode(row.node) + } + }) +} + +// syncRunConfigDialogSelection makes the selection follow the keyboard, as the Problems tree +// does: a row the arrow keys moved the focus to is selected. A selection asked to show is +// scrolled into view once the tree has painted its row, and takes the keyboard when the tree +// has it, or when Delete just took out the row that had it. +func (a *App) syncRunConfigDialogSelection(canvas *gfx.Canvas, p *project) { + d := &p.runConfigs.dialog + focused := canvas.Focused() + inTree := false + if focused != d.focus || d.reveal || d.refocus { + for i := range min(len(d.rows), d.painted) { + if focused != (gfx.ID{}) && d.view.RowID(i) == focused { + inTree = true + if focused != d.focus { + a.selectRunConfigDialogRow(p, d.rows[i]) + } + break } - return d.groups[d.rows[i].group].title } + d.focus = focused } selected := d.runConfigDialogRowIndex() - if !d.view.Changed() && d.view.Selected() != selected { - d.view.Select(selected) - } - title := i18n.Shared(language, "desktop.runConfig.dialogTitle") - ui.List(c, &d.view, len(d.rows), func(row ui.ListRow) { a.drawRunConfigDialogRow(p, row, row.Index == selected) }). - Scrollbars().Label(title).Grow(1).FillWidth() - if d.view.Changed() { - if i := d.view.Selected(); i >= 0 && i < len(d.rows) { - row := d.rows[i] - if row.key != "" { - key := row.key - c.After(func() { a.selectRunConfigDraft(p, key) }) - } else { - key := d.groups[row.group].key - c.After(func() { d.selected, d.group, d.newMenu = "", key, false }) + d.selectedRow = selected + if (d.reveal || d.refocus) && selected >= 0 { + if selected >= d.painted { + // The row has not painted yet, so the tree cannot scroll to it or focus it. + canvas.RequestFrame() + } else { + if first, last := d.view.Visible(); selected < first || selected > last { + d.view.ScrollTo(selected, ui.ListCenter) + canvas.RequestFrame() + } + if inTree || d.refocus { + canvas.RequestFocus(d.view.RowID(selected)) } + d.reveal, d.refocus = false, false } + } else if selected < 0 { + d.reveal, d.refocus = false, false } - if i, ok := d.view.Submitted(); ok && i >= 0 && i < len(d.rows) && d.rows[i].key == "" { - key := d.groups[d.rows[i].group].key - c.After(func() { p.toggleRunConfigDialogGroup(key) }) + if d.view.Selected() != selected { + d.view.Select(selected) } } -// drawRunConfigDialogRow declares one row of the tree: a group's arrow, icon and title, or a -// configuration's icon and name. A configuration this platform cannot run shows a warning -// icon and says why on hover. -func (a *App) drawRunConfigDialogRow(p *project, row ui.ListRow, selected bool) { +// runConfigDialogRowLabel names a row to assistive technology and to typing its start: the +// group's title, the folder's name or the configuration's, followed by why this platform +// cannot run it. +func (a *App) runConfigDialogRowLabel(p *project, row runConfigDialogRow) string { d := &p.runConfigs.dialog - c, r := row.C, d.rows[row.Index] - box := row.Element.Height(buildRowHeight).Items(ui.Center).Gap(6).PadX(6).Radius(a.theme.Metrics.RadiusItem()) - if selected { - box = box.Background(a.colors.Selection) - } else { - box = box.Hover(ui.Look{}.Background(a.colors.Hover)) + switch { + case row.key != "": + label := a.runConfigDraftLabel(p, row.key) + if unavailable := a.runConfigDraftUnavailable(p, row.key); unavailable != "" { + label += ", " + unavailable + } + return label + case row.node.folder != "": + return row.node.folder + case row.group < len(d.groups): + return d.groups[row.group].title } - group := d.groups[r.group] - if r.key == "" { - box.Children(func() { - a.drawRunConfigDialogArrow(c, p, group) - ui.Icon(c, group.icon).Size(14, 14).Shrink(0).Color(a.colors.Subtle) - ui.Text(c, group.title).Ellipsis().Shrink(1).MinWidth(0) - }) + return "" +} + +// drawRunConfigDialogRow declares what row i shows after its arrow: a group's icon and title, a +// folder's, or a configuration's icon and name. A configuration this platform cannot run shows +// a warning icon; the pane says why, and so does the row's label to assistive technology. A +// tree row takes every press in it, so nothing in it can carry a hover hint of its own. A +// configuration has no arrow, so it keeps the arrow's room empty and its icon lines up under +// its group's or folder's. +func (a *App) drawRunConfigDialogRow(c ui.C, p *project, i int) { + d := &p.runConfigs.dialog + if i >= len(d.rows) { return } - unavailable := a.runConfigDraftUnavailable(p, r.key) - if unavailable != "" { - box = box.Tooltip(unavailable) + row := d.rows[i] + k := c.KeyInt(i) + if row.key == "" { + icon := fileicons.ForDirectory("folder", a.colors.Dark) + if row.node.folder == "" { + icon = d.groups[row.group].icon + } + ui.Icon(k, icon).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(a.colors.Subtle) + ui.Text(k, a.runConfigDialogRowLabel(p, row)).FontSize(treeFontSize).Color(a.colors.Text).Shrink(1).MinWidth(0).Ellipsis() + return } - box.Children(func() { - ui.Row(c.Part("indent")).Size(runConfigDialogIndent, treelist.Icon).Shrink(0) - icon, color := a.runConfigDraftIcon(p, r.key), a.colors.Subtle + unavailable := a.runConfigDraftUnavailable(p, row.key) + ui.Row(k).Shrink(1).MinWidth(0).Items(ui.Center).Gap(c.Theme().Metrics.GapItem).PadLeft(treeChevron).Children(func() { + icon, color := a.runConfigDraftIcon(p, row.key), a.colors.Subtle if unavailable != "" { icon, color = icons.CircleAlert, a.colors.Warning } - ui.Icon(c, icon).Size(14, 14).Shrink(0).Color(color) - ui.Text(c, a.runConfigDraftLabel(p, r.key)).Ellipsis().Shrink(1).MinWidth(0) + ui.Icon(k, icon).Size(treelist.Icon, treelist.Icon).Shrink(0).Color(color) + ui.Text(k, a.runConfigDraftLabel(p, row.key)).FontSize(treeFontSize).Color(a.colors.Text).Shrink(1).MinWidth(0).Ellipsis() }) } -// runConfigDraftIcon is the icon of configuration key in the tree: its kind's for a built-in -// run, its execution's for a build provider run. -func (a *App) runConfigDraftIcon(p *project, key string) gfx.Icon { - if configuration := p.runConfigs.configuration(key); configuration != nil { - if configuration.IsProcess() { - return runConfigTypeIcon(configuration.Provider) +// drawRunConfigDialogEmptyTree declares the tree while it has no rows, as IDEA does: that no +// configuration was added, and the link that adds one with its keys; or that the list is being +// read or could not be read. +func (a *App) drawRunConfigDialogEmptyTree(c ui.C, p *project) { + s := &p.runConfigs + d := &s.dialog + language := a.language() + ui.Column(c).Fill().Center().Gap(6).PadX(12).Children(func() { + switch { + case s.failure != "": + ui.Paragraph(c, i18n.SharedFormat(language, "desktop.runConfig.loadFailed", map[string]string{"reason": s.failure}), 4).TextCenter().FillWidth().Color(a.colors.Subtle) + return + case s.loading || s.generation == 0: + ui.Text(c, i18n.Shared(language, "native.loading")).Color(a.colors.Subtle) + return } - return runExecutionIcon(configuration.Execution) - } - if draft := p.runConfigs.dialog.drafts[key]; draft != nil && draft.form != nil { - return runConfigTypeIcon(draft.form.provider) - } - return icons.FileCode -} - -// drawRunConfigDialogArrow declares the arrow that opens or closes a group of the tree. -func (a *App) drawRunConfigDialogArrow(c ui.C, p *project, group runConfigDialogGroup) { - open := !p.runConfigs.dialog.closed[group.key] - name, chevron := i18n.Shared(a.language(), "native.collapseSection"), icons.ChevronDown - if !open { - name, chevron = i18n.Shared(a.language(), "native.expandSection"), icons.ChevronRight - } - k := c.Part("arrow") - slot := ui.Row(k).Size(treelist.Disclosure, treelist.Icon).Shrink(0).Center(). - HitWith(ui.ID(k), name+" "+group.title, gfx.HitOptions{Role: gfx.RoleButton, Cursor: gfx.PointerCursorHand, Expandable: true, Expanded: open, SkipFocus: true}) - slot.Children(func() { - ui.Icon(k, chevron).Size(12, 12).Color(a.colors.Subtle) + ui.Paragraph(c, i18n.Shared(language, "desktop.runConfig.emptyTree"), 3).TextCenter().FillWidth().Color(a.colors.Subtle) + ui.Row(c.Part("add")).Items(ui.Center).Gap(6).Children(func() { + link := ui.Button(c.Part("add-link"), i18n.Shared(language, "desktop.runConfig.addNew")).Link().Disabled(d.saving) + if link.Clicked() { + c.After(func() { d.toggleNewMenu(runConfigNewMenuTree) }) + } + a.drawRunConfigNewMenu(c.Part("add-menu"), p, link, runConfigNewMenuTree) + modifiers, key := runConfigAddChord() + if chord, ok := keymap.Parse(modifiers, key); ok { + ui.Text(c, shortcuts.Keycaps(chord)).Color(a.colors.Subtle) + } + }) }) - if slot.Clicked() { - key := group.key - c.After(func() { p.toggleRunConfigDialogGroup(key) }) - } } // drawRunConfigDialogPane declares the right column: the editor of the selected -// configuration, under the reason this platform cannot run it, or, with nothing selected, the -// kinds a new configuration can take. +// configuration, under the reason this platform cannot run it; the name of the selected folder; +// or, with neither selected, the link that adds a configuration. func (a *App) drawRunConfigDialogPane(c ui.C, p *project) { d := &p.runConfigs.dialog k := c.Part("pane") ui.Column(k).Grow(1).FillHeight().MinWidth(0).Children(func() { draft := d.drafts[d.selected] + if draft == nil && d.node.folder == "" { + a.drawRunConfigDialogStart(k, p) + return + } ui.Scroll(k).Scrollbars().FillWidth().Grow(1).Children(func() { ui.Column(k).FillWidth().Gap(10).PadSides(14, 20, 14, 16).Children(func() { - if draft == nil { - a.drawRunConfigDialogStart(k, p) - } else { + switch { + case draft == nil: + a.drawRunConfigFolderPane(k, p) + default: if text := a.runConfigDraftUnavailable(p, d.selected); text != "" { a.drawRunConfigDialogBanner(k, text) } @@ -280,7 +417,8 @@ func (a *App) drawRunConfigDialogPane(c ui.C, p *project) { } // drawRunConfigDraft declares the editor of one configuration: the form of a built-in run, the -// options of a build provider run, or why a run whose plugin cannot resolve has no editor. +// options of a build provider run, the name of a copy Apply makes, or why a run whose plugin +// cannot resolve has no editor. func (a *App) drawRunConfigDraft(c ui.C, p *project, draft *runConfigDraft) { d := &p.runConfigs.dialog language := a.language() @@ -300,42 +438,85 @@ func (a *App) drawRunConfigDraft(c ui.C, p *project, draft *runConfigDraft) { ui.Text(c, i18n.Shared(language, "native.loading")).Color(a.colors.Subtle) } a.drawRunConfigEditorPane(c, p, draft.editor) + case draft.copyOf != "": + a.drawRunConfigNameRow(c.Part("copy"), func(k ui.C, label string) { + ui.TextField(k, &draft.copyName, label, "").Disabled(d.saving || draft.copied).FillWidth() + }) + ui.Paragraph(c, i18n.Shared(language, "desktop.runConfig.copyPendingHint"), 3).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) default: ui.Text(c, a.runConfigDraftLabel(p, draft.key)).Weight(gfx.WeightSemibold).Ellipsis().FillWidth() ui.Paragraph(c, i18n.Shared(language, "desktop.runConfig.notEditable"), 3).Color(a.colors.Subtle) } } -// drawRunConfigDialogStart declares the pane while nothing is selected: a hint and a button -// per built-in kind that creates a configuration of it. +// drawRunConfigFolderPane declares the pane of the selected folder: its name, which renames it +// as it is typed, why a name cannot be taken, and what a folder is. +func (a *App) drawRunConfigFolderPane(c ui.C, p *project) { + d := &p.runConfigs.dialog + language := a.language() + a.drawRunConfigNameRow(c.Part("folder"), func(k ui.C, label string) { + if ui.TextField(k, &d.folderName, label, "").Disabled(d.saving).FillWidth().Changed() { + c.After(func() { a.renameRunConfigFolder(p) }) + } + if d.folderError != "" { + ui.Text(k, d.folderError).FontSize(a.theme.Metrics.FontSizeS).Color(a.theme.Danger) + } + }) + ui.Paragraph(c, i18n.Shared(language, "desktop.runConfig.folderHint"), 3).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle) +} + +// drawRunConfigNameRow declares a Name row laid out as the form's are: the label in the form's +// label column and what field declares beside it. +func (a *App) drawRunConfigNameRow(c ui.C, field func(k ui.C, label string)) { + label, ok := runConfigFieldLabel(a.language(), "name") + if !ok { + label = "name" + } + ui.Row(c).FillWidth().Items(ui.Start).Gap(8).Children(func() { + ui.Row(c.Part("title")).Width(runConfigFormLabelWidth).MinHeight(28).Shrink(0).Items(ui.Center).Gap(4).Children(func() { + ui.Text(c, label) + }) + ui.Column(c.Part("value")).Grow(1).MinWidth(0).Gap(4).Children(func() { field(c.Part("field"), label) }) + }) +} + +// runConfigDraftIcon is the icon of configuration key in the tree: its kind's for a built-in +// run, its execution's for a build provider run, its original's for a copy not saved yet. +func (a *App) runConfigDraftIcon(p *project, key string) gfx.Icon { + if configuration := p.runConfigs.configuration(key); configuration != nil { + if configuration.IsProcess() { + return runConfigTypeIcon(configuration.Provider, a.colors.Dark) + } + return runExecutionIcon(configuration.Execution) + } + if draft := p.runConfigs.dialog.drafts[key]; draft != nil { + switch { + case draft.form != nil: + return runConfigTypeIcon(draft.form.provider, a.colors.Dark) + case draft.copyOf != "" && draft.icon.ViewBox > 0: + return draft.icon + } + } + return icons.FileCode +} + +// drawRunConfigDialogStart declares the pane while no configuration or folder is selected, as +// IDEA does: the link that adds a configuration, and that one can be selected to edit it. func (a *App) drawRunConfigDialogStart(c ui.C, p *project) { s := &p.runConfigs d := &s.dialog - language, small := a.language(), a.theme.Metrics.FontSizeS - ui.Paragraph(c, i18n.Shared(language, "desktop.runConfig.dialogHint"), 3).Color(a.colors.Subtle) - if len(s.types) == 0 { - ui.Text(c, i18n.Shared(language, "native.loading")).Color(a.colors.Subtle) - return - } - for index, kind := range s.types { - label, ok := runConfigTypeLabel(language, kind.Provider) - if !ok { - continue + language := a.language() + ui.Column(c.Part("start")).Fill().Center().Gap(4).PadX(16).Children(func() { + link := ui.Button(c.Part("add-link"), i18n.Shared(language, "desktop.runConfig.addNewConfiguration")).Link().Disabled(d.saving) + if link.Clicked() { + c.After(func() { d.toggleNewMenu(runConfigNewMenuPane) }) } - provider := kind.Provider - k := c.KeyInt(index) - ui.Row(k).FillWidth().Items(ui.Center).Gap(8).Children(func() { - if ui.Button(k, label).Icon(runConfigTypeIcon(provider)).Outline().Disabled(d.saving).Clicked() { - c.After(func() { - a.performed("run.configuration.new", surfaceButton) - a.addRunConfigDraft(p, provider, nil) - }) - } - if kind.Unavailable() { - ui.Text(k, runConfigTypeNote(language, kind)).FontSize(small).Color(a.colors.Subtle).Ellipsis().Shrink(1).MinWidth(0) - } - }) - } + a.drawRunConfigNewMenu(c.Part("add-menu"), p, link, runConfigNewMenuPane) + ui.Text(c, i18n.Shared(language, "desktop.runConfig.orSelectToEdit")).Color(a.colors.Subtle) + if d.failure != "" { + ui.Paragraph(c, d.failure, 4).TextCenter().FillWidth().FontSize(a.theme.Metrics.FontSizeS).Color(a.theme.Danger) + } + }) } // drawRunConfigDialogBanner declares the warning over an editor whose configuration this diff --git a/desktop/internal/workbench/runconfig_form_view.go b/desktop/internal/workbench/runconfig_form_view.go index b08d3b2aa7..2d2abf73bf 100644 --- a/desktop/internal/workbench/runconfig_form_view.go +++ b/desktop/internal/workbench/runconfig_form_view.go @@ -7,6 +7,7 @@ import ( "slices" "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/fileicons" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/vivaui/viva/gfx" @@ -45,10 +46,18 @@ func runConfigTypeLabel(language i18n.Language, provider string) (string, bool) return "", false } -// runConfigTypeIcon is the icon of a built-in kind: a script or a program. -func runConfigTypeIcon(provider string) gfx.Icon { - if provider == runProviderExecutable { - return icons.Cpu +// runConfigTypeIcon is the icon of a built-in kind: the colored project tree icon of the files +// it runs (.sh, .ps1, .cmd, .exe), so a kind looks like its files everywhere. +func runConfigTypeIcon(provider string, dark bool) gfx.Icon { + switch provider { + case runProviderShell: + return fileicons.ForFile("run.sh", dark) + case runProviderPowerShell: + return fileicons.ForFile("run.ps1", dark) + case runProviderBatch: + return fileicons.ForFile("run.cmd", dark) + case runProviderExecutable: + return fileicons.ForFile("run.exe", dark) } return icons.FileCode } diff --git a/desktop/internal/workbench/runconfig_process_visual_test.go b/desktop/internal/workbench/runconfig_process_visual_test.go index 0febd4d10f..a8dba90b4b 100644 --- a/desktop/internal/workbench/runconfig_process_visual_test.go +++ b/desktop/internal/workbench/runconfig_process_visual_test.go @@ -19,7 +19,8 @@ import ( // the Run/Debug Configurations dialog: the dialog with nothing yet, the editor of a shell // script with a script file and with script text, the Run window after the script ran, the + // menu of every kind, the editors of a PowerShell script, an executable and a batch script -// this platform cannot run, the title bar with that batch script chosen, and the title bar's +// this platform cannot run, the title bar with that batch script chosen, the shell script in a +// folder of the unsorted list, that folder's pane, a copy of the executable, and the title bar's // run menu marking that batch script and naming a run configuration file that was not read. The // script runs under the system's shell. It needs only LITHE_VISUAL_OUTPUT_DIR; the dark captures are in Chinese and the light ones in English. func TestVisualBuiltInProcessRuns(t *testing.T) { @@ -146,10 +147,10 @@ func TestVisualBuiltInProcessRuns(t *testing.T) { h.app.post(func(a *App) { a.openRunConfigDialog(p, p.runConfigs.selected) - d.newMenu = true + d.newMenu = runConfigNewMenuToolbar }) shot("new-menu") - h.app.post(func(a *App) { d.newMenu = false }) + h.app.post(func(*App) { d.newMenu = runConfigNewMenuClosed }) edit(runProviderPowerShell, map[string]string{"name": "Clean", "source": "file", "script": "scripts/clean.ps1"}, nil) shot("powershell") @@ -168,6 +169,46 @@ func TestVisualBuiltInProcessRuns(t *testing.T) { }) shot("title-unavailable") + // The toolbar's folder, copy and sort: Greet in a folder of its own, the list in the + // order it was made, the folder's pane, and a copy of Tool. + id := func(name string) string { + t.Helper() + for _, configuration := range p.runConfigs.list { + if configuration.Name == name { + return configuration.ID + } + } + t.Fatalf("no configuration %s in %v", name, listedNames(p)) + return "" + } + h.app.post(func(a *App) { + a.openRunConfigDialog(p, id("Greet")) + a.addRunConfigFolder(p) + }) + h.settle() + // The folder takes the name typed in its pane, as of the tree last painted. + h.app.post(func(a *App) { + d.folderName = "Scripts" + a.renameRunConfigFolder(p) + p.toggleRunConfigDialogSort() + a.selectRunConfigDraft(p, id("Greet")) + }) + shot("folders") + h.app.post(func(*App) { + d.selectRunConfigDialogNode(runConfigDialogNode{group: p.runConfigDialogGroupKey(id("Greet")), folder: "Scripts"}) + }) + shot("folder-pane") + tool := id("Tool") + h.app.post(func(a *App) { a.selectRunConfigDraft(p, tool) }) + awaitStateWithin(t, h, 10*time.Second, "Tool's editor", func() bool { return p.runConfigCopyable(tool) }) + h.app.post(func(a *App) { a.copyRunConfigDraft(p) }) + awaitStateWithin(t, h, 10*time.Second, "the copy's editor", func() bool { + draft := d.drafts[d.selected] + return d.selected != tool && draft != nil && draft.form != nil && draft.form.ready() + }) + shot("copy") + h.app.post(func(a *App) { a.closeRunConfigDialog(p) }) + plugins := filepath.Join(root, ".lithe", "run", "plugin") if err := os.MkdirAll(plugins, 0o755); err != nil { t.Fatal(err) diff --git a/desktop/internal/workbench/runconfig_view.go b/desktop/internal/workbench/runconfig_view.go index dbdf044eba..8d897a6a9e 100644 --- a/desktop/internal/workbench/runconfig_view.go +++ b/desktop/internal/workbench/runconfig_view.go @@ -179,7 +179,7 @@ func (a *App) drawRunConfigRow(p *project, row ui.ListRow, selected bool) { ui.Row(c.Part("arrow")).Size(treelist.Disclosure, treelist.Icon).Shrink(0) icon, name := runExecutionIcon(configuration.Execution), a.colors.Text if configuration.IsProcess() { - icon = runConfigTypeIcon(configuration.Provider) + icon = runConfigTypeIcon(configuration.Provider, a.colors.Dark) } if unavailable { icon, name = icons.CircleAlert, a.colors.Subtle diff --git a/desktop/internal/workbench/title_run_test.go b/desktop/internal/workbench/title_run_test.go index 3d49b6452b..f8552a25f2 100644 --- a/desktop/internal/workbench/title_run_test.go +++ b/desktop/internal/workbench/title_run_test.go @@ -235,7 +235,7 @@ func emptyRunConfigHarness(t *testing.T, root string) (*harness, *project) { // Edit Configuration on a project without configurations used to open a Run window that showed // nothing, which looked like no reaction (#2028). It now opens the Run/Debug Configurations -// dialog with nothing selected, whose pane offers a button per built-in kind. +// dialog with nothing selected, whose pane, as in IDEA, offers a link to the menu of kinds. func TestEditRunConfigurationsWithoutAnyOpensTheDialog(t *testing.T) { h, p := emptyRunConfigHarness(t, runConfigRoot(t)) h.app.post(func(a *App) { a.editRunConfigurations(p) }) @@ -248,13 +248,19 @@ func TestEditRunConfigurationsWithoutAnyOpensTheDialog(t *testing.T) { language := h.app.language() for _, text := range []string{ i18n.Shared(language, "desktop.runConfig.dialogTitle"), - i18n.Shared(language, "desktop.runConfig.dialogHint"), - i18n.Shared(language, "desktop.runConfig.typeShell"), + i18n.Shared(language, "desktop.runConfig.emptyTree"), + i18n.Shared(language, "desktop.runConfig.addNewConfiguration"), + i18n.Shared(language, "desktop.runConfig.orSelectToEdit"), } { if !h.shows(text) { t.Fatalf("%q is not shown", text) } } + // The built-in kinds are offered by the menu the link opens. + h.click(center(h.hitLabeled(i18n.Shared(language, "desktop.runConfig.addNewConfiguration")))) + if shell := i18n.Shared(language, "desktop.runConfig.typeShell"); d.newMenu != runConfigNewMenuPane || !h.shows(shell) { + t.Fatalf("menu %v, %q shown %v", d.newMenu, shell, h.shows(shell)) + } } // Saved configurations that no build plugin starts, such as the java.main entries an earlier diff --git a/docs/assets/builtin-process-runs/README.md b/docs/assets/builtin-process-runs/README.md index d2db72da35..5864d7164a 100644 --- a/docs/assets/builtin-process-runs/README.md +++ b/docs/assets/builtin-process-runs/README.md @@ -8,12 +8,13 @@ Shell 脚本在系统 shell 里真实运行,控制台内容是真实输出, 无头截图不代表 macOS/Windows 原生窗口验收。 运行配置在“运行/调试配置”对话框里新建和编辑。标题栏运行下拉的“新建运行配置…”和“编辑运行配置…”都打开这个对话框。 -对话框左侧是工具栏(+ 新建、− 删除、复制)和按类型分组的配置树,右侧是选中配置的编辑器。 +对话框左侧是工具栏(+ 新建、− 删除、复制、新建文件夹、按字母顺序排序)和按类型分组的配置树,右侧是选中配置的编辑器。 +配置树的图标是各类型的彩色文件图标:Shell 脚本、PowerShell 脚本、批处理脚本和程序各不相同。 底部左边是“运行”,右边是“取消 / 应用 / 确定”。 | 场景 | 深色中文 | 浅色英文 | | --- | --- | --- | -| 还没有配置时打开对话框:左侧提示点 + 新建,右侧列出 macOS 提供的四类内置运行。批处理脚本(cmd)标“仅 Windows”,但也能新建 | [截图](builtin-run-dialog-empty-dark.png) | [截图](builtin-run-dialog-empty-light.png) | +| 还没有配置时打开对话框,和 IDEA 一样:左侧是“未添加运行配置。”和链接“添加新… ⌃N”,右侧是链接“添加新的运行配置…”和“或选择要编辑的运行配置”。两个链接和 ⌃N 都打开类型菜单 | [截图](builtin-run-dialog-empty-dark.png) | [截图](builtin-run-dialog-empty-light.png) | | 新建 Shell 脚本,执行方式为脚本文件:勾选了“存为项目文件”,填了脚本路径、脚本选项、项目内的工作目录和一个环境变量。解释器路径没填,自动值取自脚本首行的 `#!/bin/bash`。脚本选项、解释器路径和解释器选项旁的 ⓘ 说明各自传给谁 | [截图](builtin-run-shell-file-dark.png) | [截图](builtin-run-shell-file-light.png) | | 同一配置换成脚本文本,出现多行文本框。文本没有首行 `#!`,解释器自动值变为 `/bin/sh` | [截图](builtin-run-shell-text-dark.png) | [截图](builtin-run-shell-text-light.png) | | 点击对话框的“运行”后:配置写入 `.lithe/run/configurations.yaml`,对话框关闭,Run 窗口打开并选中这次运行。控制台打印脚本输出,执行树以“进程已结束,退出码 0。”结束;标题栏改选 Greet | [截图](builtin-run-run-output-dark.png) | [截图](builtin-run-run-output-light.png) | @@ -22,6 +23,9 @@ Shell 脚本在系统 shell 里真实运行,控制台内容是真实输出, | 新建可执行程序:程序路径、程序参数(含带引号的空格参数)和工作目录 | [截图](builtin-run-executable-dark.png) | [截图](builtin-run-executable-light.png) | | 在 macOS 上新建批处理脚本:能编辑、能保存,编辑器顶部提示“批处理脚本只能在 Windows 上运行;在这台电脑上可以编辑和保存,但不能运行。”。配置树里这一行带警告图标,对话框的“运行”置灰 | [截图](builtin-run-batch-dark.png) | [截图](builtin-run-batch-light.png) | | 点“确定”保存全部四个配置后,标题栏选中 Package:运行按钮置灰;按下时只提示原因,不会启动 | [截图](builtin-run-title-unavailable-dark.png) | [截图](builtin-run-title-unavailable-light.png) | +| 选中 Greet 点“新建文件夹”,改名为 Scripts,再关掉“按字母顺序排序”:Shell 脚本下先列文件夹 Scripts,Greet 在里面;排序按钮不再高亮 | [截图](builtin-run-folders-dark.png) | [截图](builtin-run-folders-light.png) | +| 选中文件夹 Scripts:右侧是文件夹名称框和说明“文件夹只用来整理列表,随其中的配置一起保存;空文件夹不会保存。” | [截图](builtin-run-folder-pane-dark.png) | [截图](builtin-run-folder-pane-light.png) | +| 选中 Tool 点复制:副本“Tool(副本)”排在 Tool 后面,编辑器里的字段和原配置一致,按“应用”或“确定”才保存 | [截图](builtin-run-copy-dark.png) | [截图](builtin-run-copy-light.png) | | 标题栏运行下拉:Package 带警告图标,下方注明“仅 Windows”,仍可选中。插件运行配置文件 `.lithe/run/plugin/dev.example.engine.toml` 写坏后,下拉多出一项“未读取 dev.example.engine.toml 中的运行配置”,点击后在编辑器中打开该文件 | [截图](builtin-run-run-menu-dark.png) | [截图](builtin-run-run-menu-light.png) | `docs/assets/run-config-empty/` 是另一组截图,展示项目没有可用运行配置时的标题栏下拉和对话框。 diff --git a/docs/assets/builtin-process-runs/builtin-run-batch-dark.png b/docs/assets/builtin-process-runs/builtin-run-batch-dark.png index f4f4d44b34..335068bd74 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-batch-dark.png and b/docs/assets/builtin-process-runs/builtin-run-batch-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-batch-light.png b/docs/assets/builtin-process-runs/builtin-run-batch-light.png index 983cb7c620..883de20c27 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-batch-light.png and b/docs/assets/builtin-process-runs/builtin-run-batch-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-copy-dark.png b/docs/assets/builtin-process-runs/builtin-run-copy-dark.png new file mode 100644 index 0000000000..577c4ff505 Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-copy-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-copy-light.png b/docs/assets/builtin-process-runs/builtin-run-copy-light.png new file mode 100644 index 0000000000..22d020296e Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-copy-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-dialog-empty-dark.png b/docs/assets/builtin-process-runs/builtin-run-dialog-empty-dark.png index 3b723f01d8..2774e2ca4c 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-dialog-empty-dark.png and b/docs/assets/builtin-process-runs/builtin-run-dialog-empty-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-dialog-empty-light.png b/docs/assets/builtin-process-runs/builtin-run-dialog-empty-light.png index 817235c727..bb6f4e04fd 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-dialog-empty-light.png and b/docs/assets/builtin-process-runs/builtin-run-dialog-empty-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-executable-dark.png b/docs/assets/builtin-process-runs/builtin-run-executable-dark.png index ca0e4b036d..86df2749dd 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-executable-dark.png and b/docs/assets/builtin-process-runs/builtin-run-executable-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-executable-light.png b/docs/assets/builtin-process-runs/builtin-run-executable-light.png index be66b733e2..74faf32f88 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-executable-light.png and b/docs/assets/builtin-process-runs/builtin-run-executable-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-folder-pane-dark.png b/docs/assets/builtin-process-runs/builtin-run-folder-pane-dark.png new file mode 100644 index 0000000000..e8bbe73001 Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-folder-pane-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-folder-pane-light.png b/docs/assets/builtin-process-runs/builtin-run-folder-pane-light.png new file mode 100644 index 0000000000..4252b0c0a4 Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-folder-pane-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-folders-dark.png b/docs/assets/builtin-process-runs/builtin-run-folders-dark.png new file mode 100644 index 0000000000..0510912a17 Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-folders-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-folders-light.png b/docs/assets/builtin-process-runs/builtin-run-folders-light.png new file mode 100644 index 0000000000..7dc1b6cee5 Binary files /dev/null and b/docs/assets/builtin-process-runs/builtin-run-folders-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-new-menu-dark.png b/docs/assets/builtin-process-runs/builtin-run-new-menu-dark.png index 8cb3528914..121db54523 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-new-menu-dark.png and b/docs/assets/builtin-process-runs/builtin-run-new-menu-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-new-menu-light.png b/docs/assets/builtin-process-runs/builtin-run-new-menu-light.png index f7efce4885..67340b247a 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-new-menu-light.png and b/docs/assets/builtin-process-runs/builtin-run-new-menu-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-powershell-dark.png b/docs/assets/builtin-process-runs/builtin-run-powershell-dark.png index 4ae34aeb70..c211c18e11 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-powershell-dark.png and b/docs/assets/builtin-process-runs/builtin-run-powershell-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-powershell-light.png b/docs/assets/builtin-process-runs/builtin-run-powershell-light.png index 48f09c55e0..30124f3c1f 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-powershell-light.png and b/docs/assets/builtin-process-runs/builtin-run-powershell-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-run-menu-dark.png b/docs/assets/builtin-process-runs/builtin-run-run-menu-dark.png index 33552a59a0..78224581e9 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-run-menu-dark.png and b/docs/assets/builtin-process-runs/builtin-run-run-menu-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-run-output-dark.png b/docs/assets/builtin-process-runs/builtin-run-run-output-dark.png index f01aff37f4..7ba3124d5b 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-run-output-dark.png and b/docs/assets/builtin-process-runs/builtin-run-run-output-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-shell-file-dark.png b/docs/assets/builtin-process-runs/builtin-run-shell-file-dark.png index 7f78cf30ea..47af8c6fc0 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-shell-file-dark.png and b/docs/assets/builtin-process-runs/builtin-run-shell-file-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-shell-file-light.png b/docs/assets/builtin-process-runs/builtin-run-shell-file-light.png index e17e3cdce5..ed26e7beaf 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-shell-file-light.png and b/docs/assets/builtin-process-runs/builtin-run-shell-file-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-shell-text-dark.png b/docs/assets/builtin-process-runs/builtin-run-shell-text-dark.png index 0562566266..1459e019ff 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-shell-text-dark.png and b/docs/assets/builtin-process-runs/builtin-run-shell-text-dark.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-shell-text-light.png b/docs/assets/builtin-process-runs/builtin-run-shell-text-light.png index e3ef47afb6..f30d65579a 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-shell-text-light.png and b/docs/assets/builtin-process-runs/builtin-run-shell-text-light.png differ diff --git a/docs/assets/builtin-process-runs/builtin-run-title-unavailable-dark.png b/docs/assets/builtin-process-runs/builtin-run-title-unavailable-dark.png index 5f087ab7a4..2d5d489e0d 100644 Binary files a/docs/assets/builtin-process-runs/builtin-run-title-unavailable-dark.png and b/docs/assets/builtin-process-runs/builtin-run-title-unavailable-dark.png differ diff --git a/docs/assets/run-config-empty/title-run-empty-edit-dark-en-US.png b/docs/assets/run-config-empty/title-run-empty-edit-dark-en-US.png index f044ed9bd6..24af8ec9e6 100644 Binary files a/docs/assets/run-config-empty/title-run-empty-edit-dark-en-US.png and b/docs/assets/run-config-empty/title-run-empty-edit-dark-en-US.png differ diff --git a/docs/assets/run-config-empty/title-run-empty-edit-light-zh-CN.png b/docs/assets/run-config-empty/title-run-empty-edit-light-zh-CN.png index 10193cbf32..f737020f6a 100644 Binary files a/docs/assets/run-config-empty/title-run-empty-edit-light-zh-CN.png and b/docs/assets/run-config-empty/title-run-empty-edit-light-zh-CN.png differ diff --git a/docs/assets/run-config-empty/title-run-empty-menu-dark-en-US.png b/docs/assets/run-config-empty/title-run-empty-menu-dark-en-US.png index 46b5c7ae62..069cfe6204 100644 Binary files a/docs/assets/run-config-empty/title-run-empty-menu-dark-en-US.png and b/docs/assets/run-config-empty/title-run-empty-menu-dark-en-US.png differ diff --git a/docs/assets/run-config-empty/title-run-empty-menu-light-zh-CN.png b/docs/assets/run-config-empty/title-run-empty-menu-light-zh-CN.png index 9594063837..fca3bf4c89 100644 Binary files a/docs/assets/run-config-empty/title-run-empty-menu-light-zh-CN.png and b/docs/assets/run-config-empty/title-run-empty-menu-light-zh-CN.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index bc228223bc..46763a7231 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -27,6 +27,12 @@ native_path() { fi } +# Lithe-core-rust main at 5204e81 (#91 squash-merged on top of 16176c1): a run configuration +# names the folder it is listed in, runConfig.resolve returns the list in the order the local layer +# saves (by name by default) with sortAlphabetically, runConfig.arrange moves configurations between +# folders and saves that order, and runConfig.copyConfiguration copies any configuration, a build +# provider run included (#2100). Main 16176c1 adds #86 (build tree layout and the default active +# items of multi-select options) and the squash-merged #75. # Lithe-core-rust branch feat/workspace-common-references at 5c48a67 (#75, merged with main at # 6f5fbcc, #87 on top of #90 and #89): git.workspaceCommonReferences takes each repository's # git.references entries unchanged and returns the branches every repository has in that entry @@ -229,7 +235,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="5c48a6727fb0d22713a3f067a6f452edf41fad3a" +PINNED_CORE_REVISION="5204e81635378425505c592575f251eeff640ee7" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/scripts/desktop/generate-desktop-icons.sh b/scripts/desktop/generate-desktop-icons.sh index 6e3c867545..07366d520e 100755 --- a/scripts/desktop/generate-desktop-icons.sh +++ b/scripts/desktop/generate-desktop-icons.sh @@ -31,7 +31,7 @@ ICONS=( eraser undo-2 pencil arrow-up arrow-down git-compare fold-vertical unfold-vertical archive columns-2 pause redo-dot arrow-down-to-dot arrow-up-from-dot circle-dot circle-slash braces variable rotate-ccw github monitor external-link message-circle messages-square - zoom-in zoom-out image-off + zoom-in zoom-out image-off folder-plus arrow-down-a-z ) RAW_URL="https://raw.githubusercontent.com/lucide-icons/lucide/$LUCIDE_VERSION" diff --git a/shared/i18n/locales/en-US.json b/shared/i18n/locales/en-US.json index a42ae11725..576a140f8f 100644 --- a/shared/i18n/locales/en-US.json +++ b/shared/i18n/locales/en-US.json @@ -11542,11 +11542,24 @@ "desktop.runConfig.unavailableInvalid": "The run configuration is invalid: {reason}", "desktop.runConfig.unavailableOther": "This run configuration cannot run now: {reason}", "desktop.runConfig.dialogTitle": "Run/Debug Configurations", - "desktop.runConfig.dialogHint": "Select a run configuration on the left to edit it, or create one:", "desktop.runConfig.newConfigurationEllipsis": "New Run Configuration…", "desktop.runConfig.removeConfiguration": "Remove Configuration", "desktop.runConfig.copyConfiguration": "Copy Configuration", "desktop.runConfig.copyName": "{name} (Copy)", + "desktop.runConfig.emptyTree": "No run configurations added.", + "desktop.runConfig.addNew": "Add New…", + "desktop.runConfig.addNewConfiguration": "Add New Run Configuration…", + "desktop.runConfig.orSelectToEdit": "or select a run configuration to edit", + "desktop.runConfig.newFolder": "New Folder", + "desktop.runConfig.newFolderName": "New Folder", + "desktop.runConfig.sortAlphabetically": "Sort Alphabetically", + "desktop.runConfig.folderNameEmpty": "Enter a folder name.", + "desktop.runConfig.folderNameInvalid": "A folder name can be at most 256 bytes and cannot contain control characters.", + "desktop.runConfig.folderNameTaken": "This kind already has a folder with this name.", + "desktop.runConfig.folderHint": "Folders only organize the list and are saved with the configurations in them; an empty folder is not saved.", + "desktop.runConfig.copyPendingHint": "The copy is made when you press Apply or OK; its options can be edited after that.", + "desktop.runConfig.copyFailed": "Could not copy the run configuration: {reason}", + "desktop.runConfig.arrangeFailed": "Could not save the folders and order: {reason}", "desktop.runConfig.unnamed": "Unnamed", "desktop.runConfig.windowsOnlyType": "Windows only", "desktop.runConfig.typeNotRunnableHere": "Cannot run on this computer", diff --git a/shared/i18n/locales/zh-CN.json b/shared/i18n/locales/zh-CN.json index 9647e6d8d1..8ec94cd706 100644 --- a/shared/i18n/locales/zh-CN.json +++ b/shared/i18n/locales/zh-CN.json @@ -11542,11 +11542,24 @@ "desktop.runConfig.unavailableInvalid": "运行配置无效:{reason}", "desktop.runConfig.unavailableOther": "此运行配置现在无法运行:{reason}", "desktop.runConfig.dialogTitle": "运行/调试配置", - "desktop.runConfig.dialogHint": "在左侧选择一个运行配置进行编辑,或新建一个:", "desktop.runConfig.newConfigurationEllipsis": "新建运行配置…", "desktop.runConfig.removeConfiguration": "删除配置", "desktop.runConfig.copyConfiguration": "复制配置", "desktop.runConfig.copyName": "{name}(副本)", + "desktop.runConfig.emptyTree": "未添加运行配置。", + "desktop.runConfig.addNew": "添加新…", + "desktop.runConfig.addNewConfiguration": "添加新的运行配置…", + "desktop.runConfig.orSelectToEdit": "或选择要编辑的运行配置", + "desktop.runConfig.newFolder": "新建文件夹", + "desktop.runConfig.newFolderName": "新建文件夹", + "desktop.runConfig.sortAlphabetically": "按字母顺序排序", + "desktop.runConfig.folderNameEmpty": "请输入文件夹名称。", + "desktop.runConfig.folderNameInvalid": "文件夹名称不能超过 256 字节,也不能包含控制字符。", + "desktop.runConfig.folderNameTaken": "这一类配置中已经有同名文件夹。", + "desktop.runConfig.folderHint": "文件夹只用来整理列表,随其中的配置一起保存;空文件夹不会保存。", + "desktop.runConfig.copyPendingHint": "按“应用”或“确定”后生成这个副本,之后就可以编辑它的选项。", + "desktop.runConfig.copyFailed": "无法复制运行配置:{reason}", + "desktop.runConfig.arrangeFailed": "无法保存文件夹和排序:{reason}", "desktop.runConfig.unnamed": "未命名", "desktop.runConfig.windowsOnlyType": "仅 Windows", "desktop.runConfig.typeNotRunnableHere": "本机不能运行", diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index c55f948f5b..0cdd1c31ff 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -16311,13 +16311,6 @@ "desktop" ] }, - { - "id": "desktop.runConfig.dialogHint", - "description": "Run/Debug Configurations dialog: hint shown while no configuration is selected, above a button per built-in kind.", - "platforms": [ - "desktop" - ] - }, { "id": "desktop.runConfig.newConfigurationEllipsis", "description": "Menu item and button that open the Run/Debug Configurations dialog to create a run configuration.", @@ -16334,7 +16327,7 @@ }, { "id": "desktop.runConfig.copyConfiguration", - "description": "Run/Debug Configurations dialog: toolbar button that creates a copy of the selected built-in configuration.", + "description": "Run/Debug Configurations dialog: toolbar button that creates a copy of the selected configuration, a plugin run included.", "platforms": [ "desktop" ] @@ -16349,6 +16342,110 @@ "name": "string" } }, + { + "id": "desktop.runConfig.emptyTree", + "description": "Run/Debug Configurations dialog: shown in place of the tree while the project has no run configuration.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.addNew", + "description": "Run/Debug Configurations dialog: link under the empty tree that opens the menu of kinds a new configuration can take; its keys follow it.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.addNewConfiguration", + "description": "Run/Debug Configurations dialog: link in the editor pane while nothing is selected; opens the menu of kinds a new configuration can take.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.orSelectToEdit", + "description": "Run/Debug Configurations dialog: line under the Add New Run Configuration link while nothing is selected.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.newFolder", + "description": "Run/Debug Configurations dialog: toolbar button that makes a folder in the kind of the selection and selects it to be renamed.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.newFolderName", + "description": "Run/Debug Configurations dialog: name of a folder the toolbar button makes; a number follows it when the kind already has one so named.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.sortAlphabetically", + "description": "Run/Debug Configurations dialog: toolbar toggle that lists the configurations by name; off, they keep the order they are dragged to.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.folderNameEmpty", + "description": "Run/Debug Configurations dialog: under the name field of a folder when it is empty.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.folderNameInvalid", + "description": "Run/Debug Configurations dialog: under the name field of a folder when the name is longer than 256 bytes or has control characters.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.folderNameTaken", + "description": "Run/Debug Configurations dialog: under the name field of a folder when another folder of the same kind has the name.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.folderHint", + "description": "Run/Debug Configurations dialog: under the name field of a selected folder, saying what a folder is and how it is saved.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.copyPendingHint", + "description": "Run/Debug Configurations dialog: under the name of a copy of a plugin run configuration, which is made on Apply or OK.", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.runConfig.copyFailed", + "description": "Run/Debug Configurations dialog: shown when Core could not copy a configuration; {reason} is Core's detail.", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, + { + "id": "desktop.runConfig.arrangeFailed", + "description": "Run/Debug Configurations dialog: shown when the folders or the order of the list could not be saved; {reason} is Core's detail.", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } + }, { "id": "desktop.runConfig.unnamed", "description": "Run/Debug Configurations dialog: tree label of a configuration without a name.", diff --git a/shared/platform-feature-matrix/features/builtin-process-runs.json b/shared/platform-feature-matrix/features/builtin-process-runs.json index 26ed180baf..c0c8518f6f 100644 --- a/shared/platform-feature-matrix/features/builtin-process-runs.json +++ b/shared/platform-feature-matrix/features/builtin-process-runs.json @@ -2,7 +2,7 @@ "id": "builtin-process-runs", "area": "运行与调试", "group": "运行配置", - "capability": "内置脚本与程序运行:不装任何插件也能新建、编辑、删除并运行 Shell 脚本、PowerShell 脚本、cmd 批处理和可执行程序四类运行配置。新建和编辑都在参照 IDEA 的“运行/调试配置”对话框里:标题栏运行下拉的“新建运行配置…”“编辑运行配置…”和构建窗口配置列表的“+”打开它,左侧是“+”“−”、复制和按类型分组、可折叠的配置树,右侧是选中配置的编辑器,底部有运行、取消、应用、确定;几条配置的新建、修改和删除在“应用”或“确定”时一起保存,“取消”全部丢弃。批处理只能在 Windows 上运行:macOS/Linux 上仍可新建、编辑和保存(和 Windows 同事共享的配置不会消失),类型旁注明“仅 Windows”,编辑器顶部说明原因,配置树和标题栏下拉的这一行带警告图标,对话框的“运行”和标题栏运行按钮置灰,按下时只提示原因。内置运行的编辑器参照 IDEA 的 Shell Script 配置,有名称、“存为项目文件”、脚本文件或脚本文本、脚本选项、工作目录、环境变量、解释器路径、解释器选项(留空时显示自动值:Shell 按脚本首行 #! 选解释器,没有时 macOS/Linux 用 /bin/sh、Windows 用 bash;PowerShell 用 Windows 的 powershell 或 pwsh;cmd 用 cmd /d),脚本选项、解释器路径和解释器选项旁的 ⓘ 说明各自传给谁;PowerShell 的“绕过执行策略”默认勾选、只在 Windows 生效;可执行程序有程序路径、参数、工作目录和环境变量。字段、默认值、显示条件和校验错误全部来自 Core(runConfig.configurationTypes、runConfig.editorForm),新增字段不改宿主绘制代码。存为项目文件时写 .lithe/run/configurations.yaml,否则写 .lithe/run/local.yaml;插件运行另存 .lithe/run/plugin/<插件>.toml 与 <插件>.local.toml,并记下插件的作者/仓库、版本、版本要求、插件 API 版本和所需能力;旧版 configurations.json、local.json 在没有对应 YAML 时仍读取,第一次编辑该层时改写为 YAML 并删除 JSON。编辑对话框的“运行”、构建窗口的运行配置列表、标题栏的运行按钮和 Run 窗口的再次运行都能启动,启动时 Run 窗口自动打开并选中这次运行,输出进入它的控制台,以“进程已结束,退出码 N。”结束;脚本文本写到系统临时目录(不写安装目录),运行结束后删除。插件出错、未装或项目尚未加载构建模型时,内置运行照常列出和运行;某个运行配置文件没有读取(插件 TOML 写坏、同一配置存了两次、旧版 JSON 已被 YAML 取代)时,标题栏运行下拉按文件名列出它,点击在编辑器中打开", + "capability": "内置脚本与程序运行:不装任何插件也能新建、编辑、删除并运行 Shell 脚本、PowerShell 脚本、cmd 批处理和可执行程序四类运行配置。新建和编辑都在参照 IDEA 的“运行/调试配置”对话框里:标题栏运行下拉的“新建运行配置…”“编辑运行配置…”和构建窗口配置列表的“+”打开它,左侧工具栏是“+”“−”、复制、新建文件夹和“按字母顺序排序”开关,下面是按类型分组、可折叠的配置树(类型下先列文件夹,再列其余配置),右侧是选中配置的编辑器,底部有运行、取消、应用、确定;几条配置的新建、修改、复制、删除、文件夹和顺序在“应用”或“确定”时一起保存,“取消”全部丢弃。焦点在配置树上时 macOS 按 ⌫/⌦、Windows 按 Delete 删除选中的配置,macOS 按 ⌃N、Windows 按 Alt+Insert 打开新建菜单。没有配置时和 IDEA 一样,左侧显示“未添加运行配置。”和“添加新… ⌃N”链接,右侧显示“添加新的运行配置…”链接和“或选择要编辑的运行配置”。复制对所有配置可用:内置运行按表单值复制成“<原名>(副本)”,构建插件生成的运行在应用时由 Core 复制并保留全部选择,副本存进 .lithe/run/plugin/<插件>.local.toml,原配置照常列出。文件夹存在配置自己的 folder 字段(项目配置进 configurations.yaml、本机和生成的配置进 local.yaml),可以新建、重命名(名称不能为空、不能重名、不能含控制字符)和解散,拖动配置可以换文件夹;关掉排序后可以拖动调整顺序,顺序和排序开关只存在 .lithe/run/local.yaml,标题栏下拉和构建窗口的列表顺序与对话框一致。批处理只能在 Windows 上运行:macOS/Linux 上仍可新建、编辑和保存(和 Windows 同事共享的配置不会消失),类型旁注明“仅 Windows”,编辑器顶部说明原因,配置树和标题栏下拉的这一行带警告图标,对话框的“运行”和标题栏运行按钮置灰,按下时只提示原因。内置运行的编辑器参照 IDEA 的 Shell Script 配置,有名称、“存为项目文件”、脚本文件或脚本文本、脚本选项、工作目录、环境变量、解释器路径、解释器选项(留空时显示自动值:Shell 按脚本首行 #! 选解释器,没有时 macOS/Linux 用 /bin/sh、Windows 用 bash;PowerShell 用 Windows 的 powershell 或 pwsh;cmd 用 cmd /d),脚本选项、解释器路径和解释器选项旁的 ⓘ 说明各自传给谁;PowerShell 的“绕过执行策略”默认勾选、只在 Windows 生效;可执行程序有程序路径、参数、工作目录和环境变量。字段、默认值、显示条件和校验错误全部来自 Core(runConfig.configurationTypes、runConfig.editorForm),新增字段不改宿主绘制代码。存为项目文件时写 .lithe/run/configurations.yaml,否则写 .lithe/run/local.yaml;插件运行另存 .lithe/run/plugin/<插件>.toml 与 <插件>.local.toml,并记下插件的作者/仓库、版本、版本要求、插件 API 版本和所需能力;旧版 configurations.json、local.json 在没有对应 YAML 时仍读取,第一次编辑该层时改写为 YAML 并删除 JSON。编辑对话框的“运行”、构建窗口的运行配置列表、标题栏的运行按钮和 Run 窗口的再次运行都能启动,启动时 Run 窗口自动打开并选中这次运行,输出进入它的控制台,以“进程已结束,退出码 N。”结束;脚本文本写到系统临时目录(不写安装目录),运行结束后删除。插件出错、未装或项目尚未加载构建模型时,内置运行照常列出和运行;某个运行配置文件没有读取(插件 TOML 写坏、同一配置存了两次、旧版 JSON 已被 YAML 取代)时,标题栏运行下拉按文件名列出它,点击在编辑器中打开", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", @@ -29,7 +29,8 @@ "desktop/internal/workbench/title_run.go", "desktop/internal/workbench/title_run_view.go", "desktop/internal/workbench/title_run_test.go", - "docs/assets/builtin-process-runs/README.md" + "docs/assets/builtin-process-runs/README.md", + "desktop/internal/fileicons/fileicons.go" ] }, "windows": { @@ -56,10 +57,11 @@ "desktop/internal/workbench/runconfig_dialog_test.go", "desktop/internal/workbench/title_run.go", "desktop/internal/workbench/title_run_view.go", - "desktop/internal/workbench/title_run_test.go" + "desktop/internal/workbench/title_run_test.go", + "desktop/internal/fileicons/fileicons.go" ] }, "owner": "Run", - "verification": "不装任何插件打开一个空文件夹:标题栏“编辑运行配置…”打开“运行/调试配置”对话框,空白页列出四类内置运行;点“+”新建 Shell 脚本,选“脚本文本”写 echo hello,勾选“存为项目文件”后点对话框的“运行”,确认 .lithe/run/configurations.yaml 出现该配置、Run 窗口控制台输出 hello 并以“进程已结束,退出码 0。”结束、系统临时目录没有残留的 lithe-run-script-*;标题栏运行按钮再次运行同一配置。改为脚本文件(项目内的 .sh,带与不带 #! 首行各一次)、填脚本选项、工作目录和环境变量,确认解释器自动值随首行变化,保存后重开回显一致;取消勾选“存为项目文件”后配置移到 .lithe/run/local.yaml。新建可执行程序运行项目内程序与 PATH 上的程序;程序不存在、工作目录出项目或不存在时运行前提示原因。在对话框里连续新建两条配置后点“应用”,确认两条一起保存、对话框不关;选中一条点“−”再点“取消”,确认没有删除,点“确定”后才删除;复制一条配置,确认副本名为“<原名>(副本)”且字段一致。macOS/Linux 上新建批处理:类型旁标“仅 Windows”,可编辑保存,编辑器顶部有原因,对话框“运行”和标题栏运行按钮置灰,下拉里该行带警告图标并注明“仅 Windows”,按标题栏运行只提示原因;Windows 上分别运行 .ps1(默认带 -ExecutionPolicy Bypass,取消勾选后不带)、.cmd/.bat(含空格与引号参数)和 .exe。放一份旧版 .lithe/run/configurations.json,确认仍列出,编辑一次后改写为 YAML 并删除 JSON。让一个插件的 TOML 文件写坏,确认内置运行仍列出可运行,运行下拉出现“未读取 <文件名> 中的运行配置”,点击后在编辑器打开该文件。自动化覆盖:runconfig_process_test.go 的端到端测试用真实 Core 和系统 shell(Windows 为 cmd)新建、保存、运行(确认 Run 窗口打开并选中这次运行)并从标题栏再运行;runconfig_dialog_test.go 覆盖对话框的应用、取消、删除、复制、分组折叠,以及批处理在非 Windows 上能编辑保存、不能运行;runconfig_process_visual_test.go 生成 docs/assets/builtin-process-runs 的无头截图;单元测试覆盖 PATH 查找跳过相对目录、临时脚本只写在本次目录、工作目录不出项目、浏览路径转为项目相对、字段显示条件和保留未绘制字段的值;TestUnreadablePluginRunDocumentKeepsBuiltInRunsListed 覆盖写坏的插件文件不影响内置运行、下拉列出并打开该文件;buildprocess 测试覆盖批处理参数转义。", - "notes": "Issue #2100。只内置平台自带的脚本和二进制程序,Python、Node 等其他运行交给插件注入。Windows 上未指定解释器的 Shell 脚本按 PATH 找 bash,可能找到 WSL 的 bash;cmd 参数转义不处理 %(cmd 会展开环境变量);Core 拆分脚本选项、程序参数和解释器选项时把反斜杠当转义符(只在单引号内按原样保留),Windows 路径要用单引号括起来或把 \\ 写成 \\\\。对话框在应用窗口内以模态层显示,暂不支持 IDEA 的文件夹分组和拖动排序。macOS 原生窗口验收、Windows 与 Linux 实机验证待做。" + "verification": "不装任何插件打开一个空文件夹:标题栏“编辑运行配置…”打开“运行/调试配置”对话框,空白页列出四类内置运行;点“+”新建 Shell 脚本,选“脚本文本”写 echo hello,勾选“存为项目文件”后点对话框的“运行”,确认 .lithe/run/configurations.yaml 出现该配置、Run 窗口控制台输出 hello 并以“进程已结束,退出码 0。”结束、系统临时目录没有残留的 lithe-run-script-*;标题栏运行按钮再次运行同一配置。改为脚本文件(项目内的 .sh,带与不带 #! 首行各一次)、填脚本选项、工作目录和环境变量,确认解释器自动值随首行变化,保存后重开回显一致;取消勾选“存为项目文件”后配置移到 .lithe/run/local.yaml。新建可执行程序运行项目内程序与 PATH 上的程序;程序不存在、工作目录出项目或不存在时运行前提示原因。在对话框里连续新建两条配置后点“应用”,确认两条一起保存、对话框不关;选中一条点“−”再点“取消”,确认没有删除,点“确定”后才删除;复制一条配置,确认副本名为“<原名>(副本)”且字段一致;有构建插件生成的运行时复制它,点“应用”后确认 .lithe/run/plugin/<插件>.local.toml 出现副本、原配置仍在。删掉全部配置后重开对话框,确认左右两侧的 IDEA 式空白页,点两个链接和按 ⌃N(Windows 为 Alt+Insert)都弹出类型菜单。选中配置按 ⌫(Windows 为 Delete)删除,“取消”后恢复。选中配置点“新建文件夹”,在右侧把它改名(空名、重名、含 Tab 时提示原因),“应用”后确认配置文件里写入 folder;把另一条配置拖进这个文件夹;选中文件夹点“−”解散。关掉“按字母顺序排序”后拖动调整顺序,“应用”后确认只有 .lithe/run/local.yaml 的 arrangement 变化、标题栏下拉顺序一致,重新打开排序后恢复按名称。macOS/Linux 上新建批处理:类型旁标“仅 Windows”,可编辑保存,编辑器顶部有原因,对话框“运行”和标题栏运行按钮置灰,下拉里该行带警告图标并注明“仅 Windows”,按标题栏运行只提示原因;Windows 上分别运行 .ps1(默认带 -ExecutionPolicy Bypass,取消勾选后不带)、.cmd/.bat(含空格与引号参数)和 .exe。放一份旧版 .lithe/run/configurations.json,确认仍列出,编辑一次后改写为 YAML 并删除 JSON。让一个插件的 TOML 文件写坏,确认内置运行仍列出可运行,运行下拉出现“未读取 <文件名> 中的运行配置”,点击后在编辑器打开该文件。自动化覆盖:runconfig_process_test.go 的端到端测试用真实 Core 和系统 shell(Windows 为 cmd)新建、保存、运行(确认 Run 窗口打开并选中这次运行)并从标题栏再运行;runconfig_dialog_test.go 覆盖对话框的应用、取消、删除(含 ⌫/Delete 键)、复制(含插件运行复制进 <插件>.local.toml)、文件夹新建/重命名/解散、手动顺序与排序开关、IDEA 式空白页与 ⌃N/Alt+Insert、分组折叠,以及批处理在非 Windows 上能编辑保存、不能运行;runconfig_process_visual_test.go 生成 docs/assets/builtin-process-runs 的无头截图;单元测试覆盖 PATH 查找跳过相对目录、临时脚本只写在本次目录、工作目录不出项目、浏览路径转为项目相对、字段显示条件和保留未绘制字段的值;TestUnreadablePluginRunDocumentKeepsBuiltInRunsListed 覆盖写坏的插件文件不影响内置运行、下拉列出并打开该文件;buildprocess 测试覆盖批处理参数转义。", + "notes": "Issue #2100。只内置平台自带的脚本和二进制程序,Python、Node 等其他运行交给插件注入。Windows 上未指定解释器的 Shell 脚本按 PATH 找 bash,可能找到 WSL 的 bash;cmd 参数转义不处理 %(cmd 会展开环境变量);Core 拆分脚本选项、程序参数和解释器选项时把反斜杠当转义符(只在单引号内按原样保留),Windows 路径要用单引号括起来或把 \\ 写成 \\\\。对话框在应用窗口内以模态层显示。空文件夹只在对话框打开期间存在,不会保存(和 IDEA 一样,文件夹记在配置上)。配置树的行不显示悬停提示(Viva 的树行没有标识),不可运行的原因写在编辑器顶部和无障碍标签里。macOS 原生窗口验收、Windows 与 Linux 实机验证待做。" }