From f38bfd02b92de6b8d1b6c46af5b4c6c4ff17c03b Mon Sep 17 00:00:00 2001 From: choupeanut Date: Sun, 29 Nov 2026 00:25:49 +0800 Subject: [PATCH 1/2] fix(ui): nest a plugin tool's toolbox groups in the Tools pane (#3022) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The plugin branch of the Tools pane drew one flat group per whole toolbox string (labelled by its last part) and grouped only neighbours, so interleaved tools of one toolbox made the same group several times. It now splits the toolbox on " › " and nests its groups with the Browser's toolbox_levels, which skips empty parts and stops at eight levels. A tool whose toolbox names no group sits directly under Plugins. Groups below the first open while searching. docs/plugins.md describes tools[].toolbox. --- crates/ui-egui/src/panes.rs | 71 +++++++++++++++++++++++++---------- crates/ui-egui/tests/smoke.rs | 43 +++++++++++++++++++++ docs/plugins.md | 5 +++ 3 files changed, 99 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index aa1b9ca889..430d2ed68c 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -2749,7 +2749,7 @@ fn catalog(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { // A large toolbox (the GeoLibre suite) opens one level at a time: // `GeoLibre › Raster › General`. if in_box.len() > 40 { - toolbox_levels(app, ui, &in_box, 1, &link); + toolbox_levels(app, ui, &in_box, 1, false, &link); } else { for tool in in_box { link(app, ui, tool); @@ -3020,27 +3020,39 @@ fn folder_browser(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } } +/// The deepest toolbox level drawn as a group: a toolbox may hold up to 2,000 bytes of ` › `, and +/// every level filters its tools again. Tools below it are listed in their last group. +const MAX_TOOLBOX_LEVELS: usize = 8; + +/// The parts of a tool's toolbox (`Plugins › 1. Grid › Variograms`), without empty ones, down to +/// [`MAX_TOOLBOX_LEVELS`]. +fn toolbox_parts(toolbox: &str) -> impl Iterator { + toolbox.split(" › ").filter(|s| !s.trim().is_empty()).take(MAX_TOOLBOX_LEVELS) +} + /// `tools` grouped by the `depth`-th part of their toolbox (`GeoLibre › Raster › General`), one -/// closed header per group and nested again below it; tools whose toolbox stops here are listed. +/// header per group (open when `open`) and nested again below it; tools whose toolbox stops here +/// are listed. fn toolbox_levels( app: &mut RustGisApp, ui: &mut Ui, tools: &[&'static rustgis_engine::analysis::ToolSpec], depth: usize, - link: &dyn Fn(&mut RustGisApp, &mut Ui, &rustgis_engine::analysis::ToolSpec), + open: bool, + link: &dyn Fn(&mut RustGisApp, &mut Ui, &'static rustgis_engine::analysis::ToolSpec), ) { - let part = |x: &rustgis_engine::analysis::ToolSpec| x.toolbox.split(" › ").nth(depth); + let part = |x: &rustgis_engine::analysis::ToolSpec| toolbox_parts(x.toolbox).nth(depth); let mut groups: Vec<&str> = tools.iter().filter_map(|x| part(x)).collect(); groups.sort(); groups.dedup(); for g in groups { let inside: Vec<_> = tools.iter().copied().filter(|x| part(x) == Some(g)).collect(); - let path: Vec<&str> = inside.first().map(|x| x.toolbox.split(" › ").take(depth + 1).collect()).unwrap_or_default(); - egui::CollapsingHeader::new(crate::i18n::location(g)).id_salt(("toolbox", path)).default_open(false).show(ui, |ui| { - toolbox_levels(app, ui, &inside, depth + 1, link); + let path: Vec<&str> = inside.first().map(|x| toolbox_parts(x.toolbox).take(depth + 1).collect()).unwrap_or_default(); + egui::CollapsingHeader::new(crate::i18n::location(g)).id_salt(("toolbox", path)).default_open(open).show(ui, |ui| { + toolbox_levels(app, ui, &inside, depth + 1, open, link); }); } - for tool in tools.iter().filter(|x| part(x).is_none()) { + for tool in tools.iter().copied().filter(|x| part(x).is_none()) { link(app, ui, tool); } } @@ -4046,24 +4058,28 @@ fn geoprocessing(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } } }; - // Plugin tools, by toolbox ("Plugins › Vector Toolkit"): first when browsing (a user - // who just installed a plugin looks for it), with the matches when searching. + // Plugin tools, by toolbox ("Plugins › 1. Grid › Variograms"): first when browsing (a user + // who just installed a plugin looks for it), with the matches when searching. One group + // per toolbox name below "Plugins", nested by the ` › ` in it; the groups below the first + // open when searching, so the matches show. let plugin_tools: Vec<&'static rustgis_engine::analysis::ToolSpec> = rustgis_engine::analysis::external_tools_of(rustgis_engine::plugins::tools::SOURCE).iter().filter(|x| matches(x)).collect(); if !plugin_tools.is_empty() { ui.label(egui::RichText::new(tl!("Plugins")).size(11.0).color(t.text_dim)); - let mut boxes: Vec<&str> = plugin_tools.iter().map(|t| t.toolbox).collect(); - boxes.dedup(); - for b in boxes { - let in_box: Vec<_> = plugin_tools.iter().filter(|x| x.toolbox == b).collect(); - egui::CollapsingHeader::new(format!("{} ({})", b.rsplit(" › ").next().unwrap_or(b), in_box.len())) + let top = |x: &rustgis_engine::analysis::ToolSpec| toolbox_parts(x.toolbox).nth(1); + let mut tops: Vec<&str> = plugin_tools.iter().filter_map(|x| top(x)).collect(); + tops.sort(); + tops.dedup(); + for b in tops { + let in_box: Vec<_> = plugin_tools.iter().copied().filter(|x| top(x) == Some(b)).collect(); + egui::CollapsingHeader::new(format!("{} ({})", crate::i18n::location(b), in_box.len())) .id_salt(("gp-plugin", b)) .default_open(true) - .show(ui, |ui| { - for tool in in_box { - row(app, ui, tool); - } - }); + .show(ui, |ui| toolbox_levels(app, ui, &in_box, 2, !q.is_empty(), &row)); + } + // A toolbox of only separators names no group: its tools sit under "Plugins". + for tool in plugin_tools.iter().copied().filter(|x| top(x).is_none()) { + row(app, ui, tool); } ui.add_space(6.0); } @@ -7995,6 +8011,21 @@ pub(crate) fn layout_menu(app: &mut RustGisApp, ui: &mut Ui, n: &str) { pub(crate) mod tests { use super::*; + /// A toolbox's parts skip the empty ones and stop at the deepest level drawn, so a hostile + /// manifest's `toolbox` neither adds blank groups nor nests a thousand deep (#3022). + #[test] + fn toolbox_parts_skip_empty_ones_and_stop_at_the_deepest_level() { + fn parts(t: &str) -> Vec<&str> { + toolbox_parts(t).collect() + } + assert_eq!(parts("Plugins › 1. Grid › Variograms"), ["Plugins", "1. Grid", "Variograms"]); + assert_eq!(parts("Plugins › › Grid › › Examples › "), ["Plugins", "Grid", "Examples"]); + assert!(parts("").is_empty() && parts(" › › ").is_empty()); + let deep = vec!["a"; 300].join(" › "); + assert!(deep.len() < 2_000); + assert_eq!(toolbox_parts(&deep).count(), MAX_TOOLBOX_LEVELS); + } + /// A layer linked to its file says so after its name, with the file and what linking means /// (#2350); a copy, and the same layer once Load All Features copies it, don't. Another note /// (a change on disk) goes with it. diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs index acfa3044cf..740d7922a0 100644 --- a/crates/ui-egui/tests/smoke.rs +++ b/crates/ui-egui/tests/smoke.rs @@ -2209,6 +2209,49 @@ fn plugins_can_have_a_tab_of_their_own() { rp::unload("ui-tab"); } +/// A plugin's toolbox path (`A. Grid › Variograms`) nests in the Tools pane, whatever the order of +/// its tools: one group per path, not one per run of neighbours (#3022). +#[test] +fn plugin_tools_nest_by_their_toolbox_path() { + let _turn = PLUGINS.lock().unwrap_or_else(|e| e.into_inner()); + use egui::accesskit::Role; + use rustgis_ui_egui::rustgis_engine::plugins as rp; + let mut m: serde_json::Value = serde_json::from_str(&rp::testing::manifest("ui-nest", &[])).unwrap(); + let tool = |id: &str, name: &str, toolbox: &str| json!({"id": id, "name": name, "toolbox": toolbox, "params": []}); + // Tools of one toolbox are not next to each other; one has none, one only separators. + m["tools"] = json!([ + tool("v1", "Nest Variogram One", "A. Grid › Variograms"), + tool("c1", "Nest Contours", "B. Topography"), + tool("e1", "Nest Example", "A. Grid › Examples"), + tool("v2", "Nest Variogram Two", "A. Grid › Variograms"), + tool("n1", "Nest Unplaced", ""), + tool("s1", "Nest Loose", " › › "), + ]); + let pkg = rp::testing::zip_of(&[("plugin.json", m.to_string().as_bytes()), ("plugin.wasm", &rp::testing::wasm())]); + rp::load(rp::Package::from_zip(&pkg).unwrap(), "test").unwrap(); + let mut h = harness_with_size(egui::vec2(1400.0, 2000.0)); + h.state_mut().run("ui.pane.geoprocessing", json!(null)).unwrap(); + for _ in 0..4 { + h.step(); + } + let headers = + |h: &egui_kittest::Harness<'_, RustGisApp>, label: &str| h.query_all_by_role_and_label(Role::DisclosureTriangle, label).count(); + // The parent of both nested groups, once; the groups under it, once each. + assert_eq!(headers(&h, "A. Grid (3)"), 1); + assert_eq!(headers(&h, "B. Topography (1)"), 1); + assert_eq!(headers(&h, "Test ui-nest (1)"), 1, "no toolbox: named after the plugin"); + assert_eq!(headers(&h, "Variograms"), 1); + assert_eq!(headers(&h, "Examples"), 1); + assert_eq!(h.query_all_by_label("Nest Variogram One").count(), 0, "a nested group opens when asked"); + h.get_by_role_and_label(Role::DisclosureTriangle, "Variograms").click(); + h.run(); + assert_eq!(h.query_all_by_label("Nest Variogram One").count(), 1); + assert_eq!(h.query_all_by_label("Nest Variogram Two").count(), 1); + assert_eq!(h.query_all_by_label("Nest Contours").count(), 1); + assert_eq!(h.query_all_by_label("Nest Loose").count(), 1); + rp::unload("ui-nest"); +} + #[test] fn plugin_small_ribbon_columns_and_nested_menus_preserve_actions() { if in_own_process("plugin_small_ribbon_columns_and_nested_menus_preserve_actions") { diff --git a/docs/plugins.md b/docs/plugins.md index 57471a440c..b714a91cb9 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -198,6 +198,11 @@ cargo build --release --target wasm32-unknown-unknown Ask only for what you use. - `commands[].params`: a string describing the command's parameters for scripts and agents, not a JSON object or a form definition; it defaults to `"{}"`. +- `tools[].toolbox`: where the tool sits in the **Tools** pane, under **Plugins**. Separate levels + with ` › `: `1. Grid and isolines › Variograms` makes a **1. Grid and isolines** group with a + **Variograms** group in it, up to eight levels counting **Plugins**. A tool with no toolbox sits + in a group named after the plugin. Groups are listed alphabetically, in whatever order the tools + come in `plugin.json`; empty levels are skipped. - `commands[].icon`: the name of one of RustGIS's own icons (`stats`, `zoom_full`, `bookmark`, `buffer`…), or a puzzle piece when it isn't one. - `commands[].form` (optional) gives the command a dialog of its own: its ribbon button (tab From a21252996f80d6f2f53bb9c37504788161fe6ef4 Mon Sep 17 00:00:00 2001 From: choupeanut Date: Sun, 29 Nov 2026 00:42:00 +0800 Subject: [PATCH 2/2] fix(ui): open nested plugin tool groups when searching, trim toolbox parts (#3022) A header reads default_open only the first time it is drawn, so a group drawn closed while browsing stayed closed under a search. The open state is now in the headers' identity, so browsing and searching keep their own. A toolbox part is trimmed, so "A" and "A " are one group. docs/plugins.md says groups sort alphabetically, so numbers need leading zeros. --- crates/ui-egui/src/panes.rs | 15 +++++++++------ crates/ui-egui/tests/smoke.rs | 35 +++++++++++++++++++++++++++++++++++ docs/plugins.md | 3 ++- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 430d2ed68c..20663f0e3e 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -3024,15 +3024,17 @@ fn folder_browser(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { /// every level filters its tools again. Tools below it are listed in their last group. const MAX_TOOLBOX_LEVELS: usize = 8; -/// The parts of a tool's toolbox (`Plugins › 1. Grid › Variograms`), without empty ones, down to -/// [`MAX_TOOLBOX_LEVELS`]. +/// The parts of a tool's toolbox (`Plugins › 1. Grid › Variograms`), trimmed and without empty +/// ones, down to [`MAX_TOOLBOX_LEVELS`]. fn toolbox_parts(toolbox: &str) -> impl Iterator { - toolbox.split(" › ").filter(|s| !s.trim().is_empty()).take(MAX_TOOLBOX_LEVELS) + toolbox.split(" › ").map(str::trim).filter(|s| !s.is_empty()).take(MAX_TOOLBOX_LEVELS) } /// `tools` grouped by the `depth`-th part of their toolbox (`GeoLibre › Raster › General`), one -/// header per group (open when `open`) and nested again below it; tools whose toolbox stops here -/// are listed. +/// header per group (open at first when `open`) and nested again below it; tools whose toolbox +/// stops here are listed. `open` is in the headers' identity, so the groups drawn while browsing +/// (closed) and while searching (open) keep their own state: a header only reads `default_open` +/// the first time it is drawn. fn toolbox_levels( app: &mut RustGisApp, ui: &mut Ui, @@ -3048,7 +3050,7 @@ fn toolbox_levels( for g in groups { let inside: Vec<_> = tools.iter().copied().filter(|x| part(x) == Some(g)).collect(); let path: Vec<&str> = inside.first().map(|x| toolbox_parts(x.toolbox).take(depth + 1).collect()).unwrap_or_default(); - egui::CollapsingHeader::new(crate::i18n::location(g)).id_salt(("toolbox", path)).default_open(open).show(ui, |ui| { + egui::CollapsingHeader::new(crate::i18n::location(g)).id_salt(("toolbox", path, open)).default_open(open).show(ui, |ui| { toolbox_levels(app, ui, &inside, depth + 1, open, link); }); } @@ -8020,6 +8022,7 @@ pub(crate) mod tests { } assert_eq!(parts("Plugins › 1. Grid › Variograms"), ["Plugins", "1. Grid", "Variograms"]); assert_eq!(parts("Plugins › › Grid › › Examples › "), ["Plugins", "Grid", "Examples"]); + assert_eq!(parts("Plugins › A › B"), parts("Plugins › A › B "), "a part's own spaces are not part of its name"); assert!(parts("").is_empty() && parts(" › › ").is_empty()); let deep = vec!["a"; 300].join(" › "); assert!(deep.len() < 2_000); diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs index 740d7922a0..f713a60862 100644 --- a/crates/ui-egui/tests/smoke.rs +++ b/crates/ui-egui/tests/smoke.rs @@ -2252,6 +2252,41 @@ fn plugin_tools_nest_by_their_toolbox_path() { rp::unload("ui-nest"); } +/// A nested group drawn closed while browsing opens when the user then searches, so the matches +/// show; clearing the search brings back the closed group (#3022). +#[test] +fn plugin_tool_groups_open_when_searching() { + let _turn = PLUGINS.lock().unwrap_or_else(|e| e.into_inner()); + use egui::accesskit::Role; + use rustgis_ui_egui::rustgis_engine::plugins as rp; + let mut m: serde_json::Value = serde_json::from_str(&rp::testing::manifest("ui-find", &[])).unwrap(); + m["tools"] = json!([ + {"id": "v1", "name": "Find Variogram One", "toolbox": "A. Grid › Variograms", "params": []}, + {"id": "e1", "name": "Find Example", "toolbox": "A. Grid › Examples", "params": []}, + ]); + let pkg = rp::testing::zip_of(&[("plugin.json", m.to_string().as_bytes()), ("plugin.wasm", &rp::testing::wasm())]); + rp::load(rp::Package::from_zip(&pkg).unwrap(), "test").unwrap(); + let mut h = harness_with_size(egui::vec2(1400.0, 2000.0)); + h.state_mut().run("ui.pane.geoprocessing", json!(null)).unwrap(); + for _ in 0..4 { + h.step(); + } + assert_eq!(h.query_all_by_role_and_label(Role::DisclosureTriangle, "Variograms").count(), 1); + assert_eq!(h.query_all_by_label("Find Variogram One").count(), 0, "closed while browsing"); + h.state_mut().gp.search = "Variogram One".into(); + for _ in 0..4 { + h.step(); + } + assert_eq!(h.query_all_by_label("Find Variogram One").count(), 1, "open while searching"); + assert_eq!(h.query_all_by_label("Find Example").count(), 0, "not a match"); + h.state_mut().gp.search.clear(); + for _ in 0..4 { + h.step(); + } + assert_eq!(h.query_all_by_label("Find Variogram One").count(), 0, "closed again after the search"); + rp::unload("ui-find"); +} + #[test] fn plugin_small_ribbon_columns_and_nested_menus_preserve_actions() { if in_own_process("plugin_small_ribbon_columns_and_nested_menus_preserve_actions") { diff --git a/docs/plugins.md b/docs/plugins.md index b714a91cb9..57376c1ca8 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -202,7 +202,8 @@ cargo build --release --target wasm32-unknown-unknown with ` › `: `1. Grid and isolines › Variograms` makes a **1. Grid and isolines** group with a **Variograms** group in it, up to eight levels counting **Plugins**. A tool with no toolbox sits in a group named after the plugin. Groups are listed alphabetically, in whatever order the tools - come in `plugin.json`; empty levels are skipped. + come in `plugin.json`; empty levels are skipped. Numbered groups sort as text, so write the + numbers with leading zeros (`01.`, `02.`, … `10.`) to keep their order. - `commands[].icon`: the name of one of RustGIS's own icons (`stats`, `zoom_full`, `bookmark`, `buffer`…), or a puzzle piece when it isn't one. - `commands[].form` (optional) gives the command a dialog of its own: its ribbon button (tab