From fbb3f4b59f2bcc2bdb3d51e6ea8c89fdfaf68706 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 12:10:07 -0800 Subject: [PATCH 1/3] Window menu: panel rows show their panels' shortcuts Each Window menu row ran `window.panel {panel, toggle: true}`, while the panel's shortcut entry (`panel:`) binds `window.panel {panel}`. The menu row was a separate command with no binding, so no Window row showed a chord, as production's did. The rows now name the command the shortcut runs, and the catalog holds one command per panel. `ui.menu.list` still lists each Window row with `toggle: true`, and a click on the row runs those listed params, so a click puts a showing panel away as before. A plug-in row that shows a panel the Window menu does not list (Fold Lines) keeps its params. --- crates/ui-egui/src/menus.rs | 2 +- crates/ui-egui/src/menus/entries.rs | 36 +++++++++++++++- crates/ui-egui/src/menus/tree.rs | 4 +- crates/ui-egui/src/shortcuts.rs | 7 ++-- crates/ui-egui/src/shortcuts/tests.rs | 59 +++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 7d003be560..b7f833c9ac 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -63,7 +63,7 @@ mod ui_commands; pub use context::context_items; #[cfg(test)] use entries::flatten; -pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, menu_entries, plays_in_app, shown_label}; +pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, is_row_of, menu_entries, plays_in_app, shown_label}; pub(crate) use invoke::graph_dialog; pub use invoke::{click_target, invoke}; pub(crate) use labels::lists_plugin; diff --git a/crates/ui-egui/src/menus/entries.rs b/crates/ui-egui/src/menus/entries.rs index 6524edfd21..d90b4b9872 100644 --- a/crates/ui-egui/src/menus/entries.rs +++ b/crates/ui-egui/src/menus/entries.rs @@ -29,15 +29,49 @@ pub struct MenuEntry { pub shown_path: Vec, } -/// Flattened menu for `ui.menu.list`. +/// Flattened menu for `ui.menu.list`. A row that shows a panel of the Window menu, there or in another menu (Type › +/// Glyphs), lists the params a click on it runs: `window.panel` with `toggle: true`, which puts a showing panel away +/// ([`is_row_of`]). pub fn menu_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; for (title, items) in menu_tree_named(app.session.prefs.font_names_in_english, &Listed::of(app)) { flatten(app, vec![title.to_string()], vec![crate::i18n::t(title).to_string()], &items, &mut out); } + let window_panels: Vec = out + .iter() + .filter(|e| e.path.first().is_some_and(|t| t == "Window") && e.command.as_deref() == Some(PANEL)) + .map(|e| e.params.clone()) + .collect(); + for e in &mut out { + if e.command.as_deref() == Some(PANEL) + && window_panels.contains(&e.params) + && let Some(params) = e.params.as_object_mut() + { + params.entry("toggle").or_insert(Value::Bool(true)); + } + } out } +/// The command of the rows that show a panel. +const PANEL: &str = "window.panel"; + +/// Whether `e` is the row of the menu item that runs command `id` with `params`: the same command and params, or a +/// panel row that [`menu_entries`] lists with `toggle: true` added. +pub fn is_row_of(e: &MenuEntry, id: &str, params: &Value) -> bool { + if e.command.as_deref() != Some(id) { + return false; + } + if e.params == *params { + return true; + } + let mut listed = e.params.clone(); + id == PANEL + && params.get("toggle").is_none() + && listed.as_object_mut().and_then(|o| o.remove("toggle")) == Some(Value::Bool(true)) + && listed == *params +} + /// Flattened canvas context menu for `ui.contextMenu.list` (paths are its submenus). pub fn context_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; diff --git a/crates/ui-egui/src/menus/tree.rs b/crates/ui-egui/src/menus/tree.rs index 13b33dde44..fa5e15d238 100644 --- a/crates/ui-egui/src/menus/tree.rs +++ b/crates/ui-egui/src/menus/tree.rs @@ -45,7 +45,9 @@ impl Listed { } pub fn menu_tree_named(english_names: bool, listed: &Listed) -> Vec<(&'static str, Vec)> { - let panel = |label: &'static str, id: &'static str| cp(label, "window.panel", json!({ "panel": id, "toggle": true })); + // A Window row names the command the panel's shortcut runs, so it shows that shortcut; a click toggles the panel + // (`menu_entries` lists the row with `toggle: true`). + let panel = |label: &'static str, id: &'static str| cp(label, "window.panel", json!({ "panel": id })); vec![ ( // The application menu, shown on macOS only: the layout merges it with the items the diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index eaa0065ba4..7ee393527f 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -276,7 +276,8 @@ fn menu_target(c: &CommandRef) -> Option<(String, serde_json::Value)> { } /// What a click on the menu bar's or the canvas menu's row `c` runs ([`crate::menus::click_target`]): a "…" row with -/// params opens its dialog on them (Clean Up…). `None` for a command that no menu fired. +/// params opens its dialog on them (Clean Up…), and a row of a Window menu panel runs the params it is listed with +/// (`toggle: true`, [`crate::menus::is_row_of`]). `None` for a command that no menu fired. fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Option<(String, serde_json::Value)> { if source != FireSource::Menu || c.params.as_object().is_none_or(serde_json::Map::is_empty) { return None; @@ -284,8 +285,8 @@ fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Opti let row = crate::menus::menu_entries(app) .into_iter() .chain(crate::menus::context_entries(app)) - .find(|e| e.command.as_deref() == Some(c.id.as_str()) && e.params == c.params)?; - Some(crate::menus::click_target(&row.label, &c.id, &c.params)) + .find(|e| crate::menus::is_row_of(e, &c.id, &c.params))?; + Some(crate::menus::click_target(&row.label, &c.id, &row.params)) } /// Params used when a shortcut invokes its command. The named panel function keys retain their diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index 0f302c1551..49d09ddf13 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -246,6 +246,65 @@ fn named_panel_default_chords_toggle_their_panels() { } } +/// Each Window menu row that shows a panel shows the chord of that panel's shortcut, as production's did, and the +/// rows of the panels with a default key show one. +#[test] +fn window_menu_panel_rows_show_their_panels_shortcuts() { + let mut app = new_app(); + let ctx = ready(&mut app); + let rows: Vec = + app.menus.bar.items().into_iter().filter(|it| it.command.id == "window.panel").map(|it| it.command.clone()).collect(); + assert!(!rows.is_empty(), "the Window menu lists panels"); + let mut shown = 0; + for row in &rows { + let panel = row.params["panel"].as_str().expect("a panel row names its panel"); + let entry = crate::keymap::command_of(&format!("panel:{panel}")); + let chord = craft::ui::runtime::commands::chord(&ctx, row); + assert_eq!(chord, craft::ui::runtime::commands::chord(&ctx, &entry), "{panel}: the row shows its shortcut's chord"); + shown += usize::from(chord.is_some()); + } + let with_keys = crate::shortcut_editor::PANEL_SHORTCUTS.iter().filter(|(panel, _)| rows.iter().any(|r| r.params["panel"] == *panel)).count(); + assert!(with_keys > 0 && shown >= with_keys, "{shown} rows show a chord, {with_keys} panels have a default key"); +} + +/// A click on a Window menu row toggles its panel: it puts a showing panel away and shows it again. +#[test] +fn a_window_menu_click_toggles_its_panel() { + use craft::ui::runtime::commands::{FirePhase, FireSource, Fired}; + let mut app = new_app(); + let ctx = ready(&mut app); + let row = app + .menus + .bar + .items() + .into_iter() + .find(|it| it.command.id == "window.panel" && it.command.params["panel"] == "layers") + .map(|it| it.command.clone()); + let row = row.expect("a Window › Layers row"); + let before = crate::panel_docking::showing(&app.ui, "layers"); + let click = |app: &mut VectorcraftApp| { + crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0)); + key_frame(app, &ctx, vec![]); + crate::panel_docking::showing(&app.ui, "layers") + }; + let once = click(&mut app); + assert_ne!(once, before, "the first click toggles Layers"); + assert_eq!(click(&mut app), before, "the second click toggles it back"); +} + +/// `ui.menu.list` lists a Window menu panel row with the toggle a click on it runs, and a plug-in's row that shows a +/// panel the Window menu does not list (Object › Plug-ins › Packaging Tools › Fold Lines) without one. +#[test] +fn listed_window_rows_toggle_and_plugin_panel_rows_do_not() { + let app = new_app(); + let entries = crate::menus::menu_entries(&app); + let row = + |panel: &str| entries.iter().find(|e| e.command.as_deref() == Some("window.panel") && e.params["panel"] == panel).map(|e| e.params.clone()); + assert_eq!(row("layers").map(|p| p["toggle"].clone()), Some(json!(true)), "Window › Layers toggles"); + let fold = row(crate::addons::packaging::ID).expect("a Fold Lines row"); + assert!(fold.get("toggle").is_none(), "Fold Lines shows its panel: {fold}"); +} + /// A shortcut on a panel without a function key of its own runs `window.panel` with the params it has: no toggle is /// added, as production checked. #[test] From 0a85db2eef1bc312e183566254ba86f8fdcb3287 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 19:06:21 -0800 Subject: [PATCH 2/3] Window menu: the task bar's Show Properties Panel keeps Properties showing More Options > Show Properties Panel fired window.panel {panel: "properties"}, which now matched the Window > Properties row and took its toggle, so a click hid a showing Properties panel. The row names toggle: false, which never matches a Window row, and window.panel with toggle: false leaves a panel that can be seen as it is, also in a flyout or a floating window. The params text and docs/mcp.md describe it. The Window menu click test uses Libraries, a docked panel with no function key, so it fails when a click does not take the row's toggle. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/canvas/task_bar.rs | 8 ++++- crates/ui-egui/src/menus/entries.rs | 15 ++++---- crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panel_docking.rs | 6 +++- crates/ui-egui/src/shortcuts/tests.rs | 46 +++++++++++++++++++------ docs/mcp.md | 3 +- 7 files changed, 60 insertions(+), 22 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index ebbf43c814..c5c251b37c 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -739,7 +739,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel", "Show Panel", "", - "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", + "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; toggle false leaves a panel that can be seen as it is, also in a flyout or a floating window; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", ), ( "window.panel.layout", diff --git a/crates/ui-egui/src/canvas/task_bar.rs b/crates/ui-egui/src/canvas/task_bar.rs index 5ec9e92382..22f0836d39 100644 --- a/crates/ui-egui/src/canvas/task_bar.rs +++ b/crates/ui-egui/src/canvas/task_bar.rs @@ -425,6 +425,12 @@ pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) { states.set(CommandRef::new("window.taskBar.resetActions"), CommandState::new().enabled(!app.ui.task_bar_hidden_actions.is_empty())); } +/// More Options › Show Properties Panel. It names `toggle: false`, so a click shows the panel and leaves a showing one +/// showing, docked, floating or in a flyout; it does not run the Window menu row's toggle ([`crate::menus::is_row_of`]). +pub(crate) fn show_properties() -> CommandRef { + CommandRef::with_params("window.panel", json!({"panel": "properties", "toggle": false})) +} + /// The rows More Options shows after the framework's own: Bar Actions, Reset Bar Actions and Show Properties Panel. fn more_rows(offer: &Offer) -> Vec { let actions = offer @@ -437,7 +443,7 @@ fn more_rows(offer: &Offer) -> Vec { PanelRow::Submenu(Label::from(tl!("Bar Actions")), actions), PanelRow::Command(CommandRef::new("window.taskBar.resetActions")), PanelRow::Separator, - PanelRow::Command(CommandRef::with_params("window.panel", json!({"panel": "properties"}))), + PanelRow::Command(show_properties()), ] } diff --git a/crates/ui-egui/src/menus/entries.rs b/crates/ui-egui/src/menus/entries.rs index d90b4b9872..820f304cb4 100644 --- a/crates/ui-egui/src/menus/entries.rs +++ b/crates/ui-egui/src/menus/entries.rs @@ -29,6 +29,9 @@ pub struct MenuEntry { pub shown_path: Vec, } +/// The command id of the menu rows that show a panel. +const PANEL_COMMAND: &str = "window.panel"; + /// Flattened menu for `ui.menu.list`. A row that shows a panel of the Window menu, there or in another menu (Type › /// Glyphs), lists the params a click on it runs: `window.panel` with `toggle: true`, which puts a showing panel away /// ([`is_row_of`]). @@ -39,11 +42,11 @@ pub fn menu_entries(app: &VectorcraftApp) -> Vec { } let window_panels: Vec = out .iter() - .filter(|e| e.path.first().is_some_and(|t| t == "Window") && e.command.as_deref() == Some(PANEL)) + .filter(|e| e.path.first().is_some_and(|t| t == "Window") && e.command.as_deref() == Some(PANEL_COMMAND)) .map(|e| e.params.clone()) .collect(); for e in &mut out { - if e.command.as_deref() == Some(PANEL) + if e.command.as_deref() == Some(PANEL_COMMAND) && window_panels.contains(&e.params) && let Some(params) = e.params.as_object_mut() { @@ -53,11 +56,9 @@ pub fn menu_entries(app: &VectorcraftApp) -> Vec { out } -/// The command of the rows that show a panel. -const PANEL: &str = "window.panel"; - /// Whether `e` is the row of the menu item that runs command `id` with `params`: the same command and params, or a -/// panel row that [`menu_entries`] lists with `toggle: true` added. +/// panel row that [`menu_entries`] lists with `toggle: true` added. Another menu's row that shows a panel without +/// toggling it names `toggle: false` (the task bar's Show Properties Panel), so it does not match a Window row. pub fn is_row_of(e: &MenuEntry, id: &str, params: &Value) -> bool { if e.command.as_deref() != Some(id) { return false; @@ -66,7 +67,7 @@ pub fn is_row_of(e: &MenuEntry, id: &str, params: &Value) -> bool { return true; } let mut listed = e.params.clone(); - id == PANEL + id == PANEL_COMMAND && params.get("toggle").is_none() && listed.as_object_mut().and_then(|o| o.remove("toggle")) == Some(Value::Bool(true)) && listed == *params diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 77b585a69b..92d77a9090 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -740,7 +740,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel", "Show Panel", "", - "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", + "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; toggle false leaves a panel that can be seen as it is, also in a flyout or a floating window; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", ), ( "window.panel.layout", diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index d06f38c22b..da47985003 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -413,13 +413,17 @@ fn ui_dock(app: &mut VectorcraftApp, params: &Value) -> Result { /// library panel or a panel the dock has no place for floats. A flyout or floating panel is put /// away only while it can be seen ([`visible`]): with the dock hidden by Tab or Shift+Tab, the /// dock shows again with the panel where it was, and the toolbar and Control bar stay as they are. -/// Presentation Mode hides every panel, so there the command fails and changes nothing. +/// Presentation Mode hides every panel, so there the command fails and changes nothing. With +/// `toggle: false` a panel that can be seen stays as it is ([`reveal_panel`]). fn show_panel(app: &mut VectorcraftApp, params: &Value) -> Result { let raw = params.get("panel").and_then(Value::as_str).unwrap_or_default(); let panel = normalize(raw).ok_or_else(|| format!("unknown panel `{raw}`"))?; if app.ui.screen_mode >= 3 { return Err("panels can't be shown in Presentation Mode".into()); } + if params.get("toggle") == Some(&Value::Bool(false)) { + return reveal_panel(app, panel); + } place_panel(app, panel) } diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index 49d09ddf13..c65d8056eb 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -255,19 +255,22 @@ fn window_menu_panel_rows_show_their_panels_shortcuts() { let rows: Vec = app.menus.bar.items().into_iter().filter(|it| it.command.id == "window.panel").map(|it| it.command.clone()).collect(); assert!(!rows.is_empty(), "the Window menu lists panels"); - let mut shown = 0; + let mut with_keys = 0; for row in &rows { let panel = row.params["panel"].as_str().expect("a panel row names its panel"); let entry = crate::keymap::command_of(&format!("panel:{panel}")); let chord = craft::ui::runtime::commands::chord(&ctx, row); assert_eq!(chord, craft::ui::runtime::commands::chord(&ctx, &entry), "{panel}: the row shows its shortcut's chord"); - shown += usize::from(chord.is_some()); + if crate::shortcut_editor::PANEL_SHORTCUTS.iter().any(|(p, _)| *p == panel) { + assert!(chord.is_some(), "{panel} has a default key, and its row shows it"); + with_keys += 1; + } } - let with_keys = crate::shortcut_editor::PANEL_SHORTCUTS.iter().filter(|(panel, _)| rows.iter().any(|r| r.params["panel"] == *panel)).count(); - assert!(with_keys > 0 && shown >= with_keys, "{shown} rows show a chord, {with_keys} panels have a default key"); + assert!(with_keys > 0, "some listed panels have a default key"); } -/// A click on a Window menu row toggles its panel: it puts a showing panel away and shows it again. +/// A click on a Window menu row toggles its panel: it puts a showing panel away and shows it again. Libraries is +/// docked in front with no function key, so neither its flyout nor its shortcut toggles it. #[test] fn a_window_menu_click_toggles_its_panel() { use craft::ui::runtime::commands::{FirePhase, FireSource, Fired}; @@ -278,20 +281,43 @@ fn a_window_menu_click_toggles_its_panel() { .bar .items() .into_iter() - .find(|it| it.command.id == "window.panel" && it.command.params["panel"] == "layers") + .find(|it| it.command.id == "window.panel" && it.command.params["panel"] == "libraries") .map(|it| it.command.clone()); - let row = row.expect("a Window › Layers row"); - let before = crate::panel_docking::showing(&app.ui, "layers"); + let row = row.expect("a Window › Libraries row"); + let before = crate::panel_docking::showing(&app.ui, "libraries"); let click = |app: &mut VectorcraftApp| { crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0)); key_frame(app, &ctx, vec![]); - crate::panel_docking::showing(&app.ui, "layers") + crate::panel_docking::showing(&app.ui, "libraries") }; let once = click(&mut app); - assert_ne!(once, before, "the first click toggles Layers"); + assert_ne!(once, before, "the first click toggles Libraries"); assert_eq!(click(&mut app), before, "the second click toggles it back"); } +/// A click on the task bar's More Options › Show Properties Panel leaves a showing Properties panel showing, docked +/// and in an icon column's flyout: it does not take the toggle of Window › Properties. +#[test] +fn the_task_bar_show_properties_row_keeps_properties_showing() { + use craft::ui::runtime::commands::{FirePhase, FireSource, Fired}; + let mut app = new_app(); + let ctx = ready(&mut app); + let row = crate::canvas::task_bar::show_properties(); + let click = |app: &mut VectorcraftApp| { + crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0)); + key_frame(app, &ctx, vec![]); + crate::panel_docking::showing(&app.ui, "properties") + }; + assert!(click(&mut app), "the first click shows Properties"); + assert!(click(&mut app), "a second click leaves Properties showing"); + app.run("window.collapseDock", json!({ "collapsed": true })).expect("the dock collapses to icons"); + key_frame(&mut app, &ctx, vec![]); + assert!(click(&mut app), "a click opens the Properties flyout"); + assert!(click(&mut app), "a second click leaves the flyout open"); + app.run("window.panel", row.params.clone()).expect("the command runs from automation"); + assert!(crate::panel_docking::showing(&app.ui, "properties"), "the command leaves the flyout open from automation too"); +} + /// `ui.menu.list` lists a Window menu panel row with the toggle a click on it runs, and a plug-in's row that shows a /// panel the Window menu does not list (Object › Plug-ins › Packaging Tools › Fold Lines) without one. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 87301d0bf5..40aff43fdb 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2142,7 +2142,8 @@ and the action still plays. `Session::replay` plays a journal the same way. The `color` or `channel` it can't read. `window.panel` refuses every request in Presentation Mode, which hides every panel, and changes nothing. With -`toggle` it hides only a panel that can be seen, which is the panel the Window menu checks. While Tab or Shift+Tab +`toggle` it hides only a panel that can be seen, which is the panel the Window menu checks. With `toggle: false` a panel +that can be seen stays as it is, also in a flyout or a floating window. While Tab or Shift+Tab hides the dock, no panel is checked, and the panel shows again with the dock in its earlier place; the toolbar and the Control bar stay as they are. From 510119e7c1c21c9fb930931b0600a870bca73ba3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 19:49:40 -0800 Subject: [PATCH 3/3] Window menu: panel rows carry their toggle and show the shortcut's chord The Window menu rows run window.panel {panel, toggle: true} again, as on main, so a menu row elsewhere that runs window.panel {panel} (the Contextual Task Bar's More Options > Show Properties Panel) no longer takes a Window row's toggle. Each panel row now sets its shortcut to the chord of the panel's shortcut entry (panel:, the lookup ui.menu.list uses), as the Settings rows set Preferences' chord. The menus are built again when the window's keymap changes, so the first frame's menus, built before the keymap, do not stay without chords. canvas/task_bar.rs, menus/entries.rs and the click lookup in shortcuts.rs are back to main, and window.panel has no toggle: false case. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/canvas/task_bar.rs | 8 +---- crates/ui-egui/src/menus.rs | 2 +- crates/ui-egui/src/menus/entries.rs | 37 +--------------------- crates/ui-egui/src/menus/model.rs | 12 ++++++- crates/ui-egui/src/menus/tree.rs | 4 +-- crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panel_docking.rs | 6 +--- crates/ui-egui/src/shortcuts.rs | 7 ++--- crates/ui-egui/src/shortcuts/tests.rs | 42 +++++++++---------------- docs/mcp.md | 3 +- 11 files changed, 37 insertions(+), 88 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index c5c251b37c..ebbf43c814 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -739,7 +739,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel", "Show Panel", "", - "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; toggle false leaves a panel that can be seen as it is, also in a flyout or a floating window; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", + "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", ), ( "window.panel.layout", diff --git a/crates/ui-egui/src/canvas/task_bar.rs b/crates/ui-egui/src/canvas/task_bar.rs index 22f0836d39..5ec9e92382 100644 --- a/crates/ui-egui/src/canvas/task_bar.rs +++ b/crates/ui-egui/src/canvas/task_bar.rs @@ -425,12 +425,6 @@ pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) { states.set(CommandRef::new("window.taskBar.resetActions"), CommandState::new().enabled(!app.ui.task_bar_hidden_actions.is_empty())); } -/// More Options › Show Properties Panel. It names `toggle: false`, so a click shows the panel and leaves a showing one -/// showing, docked, floating or in a flyout; it does not run the Window menu row's toggle ([`crate::menus::is_row_of`]). -pub(crate) fn show_properties() -> CommandRef { - CommandRef::with_params("window.panel", json!({"panel": "properties", "toggle": false})) -} - /// The rows More Options shows after the framework's own: Bar Actions, Reset Bar Actions and Show Properties Panel. fn more_rows(offer: &Offer) -> Vec { let actions = offer @@ -443,7 +437,7 @@ fn more_rows(offer: &Offer) -> Vec { PanelRow::Submenu(Label::from(tl!("Bar Actions")), actions), PanelRow::Command(CommandRef::new("window.taskBar.resetActions")), PanelRow::Separator, - PanelRow::Command(show_properties()), + PanelRow::Command(CommandRef::with_params("window.panel", json!({"panel": "properties"}))), ] } diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index b7f833c9ac..7d003be560 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -63,7 +63,7 @@ mod ui_commands; pub use context::context_items; #[cfg(test)] use entries::flatten; -pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, is_row_of, menu_entries, plays_in_app, shown_label}; +pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, menu_entries, plays_in_app, shown_label}; pub(crate) use invoke::graph_dialog; pub use invoke::{click_target, invoke}; pub(crate) use labels::lists_plugin; diff --git a/crates/ui-egui/src/menus/entries.rs b/crates/ui-egui/src/menus/entries.rs index 820f304cb4..6524edfd21 100644 --- a/crates/ui-egui/src/menus/entries.rs +++ b/crates/ui-egui/src/menus/entries.rs @@ -29,50 +29,15 @@ pub struct MenuEntry { pub shown_path: Vec, } -/// The command id of the menu rows that show a panel. -const PANEL_COMMAND: &str = "window.panel"; - -/// Flattened menu for `ui.menu.list`. A row that shows a panel of the Window menu, there or in another menu (Type › -/// Glyphs), lists the params a click on it runs: `window.panel` with `toggle: true`, which puts a showing panel away -/// ([`is_row_of`]). +/// Flattened menu for `ui.menu.list`. pub fn menu_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; for (title, items) in menu_tree_named(app.session.prefs.font_names_in_english, &Listed::of(app)) { flatten(app, vec![title.to_string()], vec![crate::i18n::t(title).to_string()], &items, &mut out); } - let window_panels: Vec = out - .iter() - .filter(|e| e.path.first().is_some_and(|t| t == "Window") && e.command.as_deref() == Some(PANEL_COMMAND)) - .map(|e| e.params.clone()) - .collect(); - for e in &mut out { - if e.command.as_deref() == Some(PANEL_COMMAND) - && window_panels.contains(&e.params) - && let Some(params) = e.params.as_object_mut() - { - params.entry("toggle").or_insert(Value::Bool(true)); - } - } out } -/// Whether `e` is the row of the menu item that runs command `id` with `params`: the same command and params, or a -/// panel row that [`menu_entries`] lists with `toggle: true` added. Another menu's row that shows a panel without -/// toggling it names `toggle: false` (the task bar's Show Properties Panel), so it does not match a Window row. -pub fn is_row_of(e: &MenuEntry, id: &str, params: &Value) -> bool { - if e.command.as_deref() != Some(id) { - return false; - } - if e.params == *params { - return true; - } - let mut listed = e.params.clone(); - id == PANEL_COMMAND - && params.get("toggle").is_none() - && listed.as_object_mut().and_then(|o| o.remove("toggle")) == Some(Value::Bool(true)) - && listed == *params -} - /// Flattened canvas context menu for `ui.contextMenu.list` (paths are its submenus). pub fn context_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; diff --git a/crates/ui-egui/src/menus/model.rs b/crates/ui-egui/src/menus/model.rs index 9fdbeb7d84..6052b9e89c 100644 --- a/crates/ui-egui/src/menus/model.rs +++ b/crates/ui-egui/src/menus/model.rs @@ -86,6 +86,9 @@ pub(crate) fn state_key(app: &VectorcraftApp, input: Option) -> u64 { let mut h = DefaultHasher::new(); input.hash(&mut h); app.run_count.hash(&mut h); + // The window's keymap, which the panel rows read their shortcuts from (`Build::decorate`): the framework builds it + // after the first frame's menus, and builds a new one when the bindings or the catalog change. + app.ui_ctx.as_ref().and_then(craft::ui::runtime::commands::keymap).map(|k| std::sync::Arc::as_ptr(&k).addr()).hash(&mut h); let s = &app.session; (s.journal.len(), s.active_index(), s.clipboard.is_empty(), s.tool_composing()).hash(&mut h); if let Some(d) = s.active() { @@ -463,11 +466,18 @@ impl Build<'_> { item_title(self.app, self.lang, id, params, label) } - /// The alternates (a modifier held as the row is chosen) and the font sample of a row. + /// The alternates (a modifier held as the row is chosen), the font sample and the shortcut of a row. fn decorate(&self, item: Item, id: &str, params: &Value) -> Item { let run_with = |mods: Mods, p: Value| Alternate::new(mods, CommandRef::with_params(id, p)); let held = |shift: bool, alt: bool| Mods { cmd: false, ctrl: false, alt, shift }; match id { + // A panel row shows the chord of the panel's shortcut (`panel:`), which binds `window.panel {panel}`; + // a Window row runs it with `toggle: true`, so the framework finds no chord for the row's own command. + "window.panel" => { + let mut item = item; + item.shortcut = super::labels::item_shortcut(self.app, id, params); + item + } "ui.expandDialog" => item.alternate(run_with(held(false, true), json!({ "immediate": true }))), crate::addons::select::link_status::COMMAND => { item.alternate(run_with(held(true, false), crate::addons::select::link_status::with_shift(params.clone()))) diff --git a/crates/ui-egui/src/menus/tree.rs b/crates/ui-egui/src/menus/tree.rs index fa5e15d238..13b33dde44 100644 --- a/crates/ui-egui/src/menus/tree.rs +++ b/crates/ui-egui/src/menus/tree.rs @@ -45,9 +45,7 @@ impl Listed { } pub fn menu_tree_named(english_names: bool, listed: &Listed) -> Vec<(&'static str, Vec)> { - // A Window row names the command the panel's shortcut runs, so it shows that shortcut; a click toggles the panel - // (`menu_entries` lists the row with `toggle: true`). - let panel = |label: &'static str, id: &'static str| cp(label, "window.panel", json!({ "panel": id })); + let panel = |label: &'static str, id: &'static str| cp(label, "window.panel", json!({ "panel": id, "toggle": true })); vec![ ( // The application menu, shown on macOS only: the layout merges it with the items the diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 92d77a9090..77b585a69b 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -740,7 +740,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel", "Show Panel", "", - "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; toggle false leaves a panel that can be seen as it is, also in a flyout or a floating window; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", + "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", ), ( "window.panel.layout", diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index da47985003..d06f38c22b 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -413,17 +413,13 @@ fn ui_dock(app: &mut VectorcraftApp, params: &Value) -> Result { /// library panel or a panel the dock has no place for floats. A flyout or floating panel is put /// away only while it can be seen ([`visible`]): with the dock hidden by Tab or Shift+Tab, the /// dock shows again with the panel where it was, and the toolbar and Control bar stay as they are. -/// Presentation Mode hides every panel, so there the command fails and changes nothing. With -/// `toggle: false` a panel that can be seen stays as it is ([`reveal_panel`]). +/// Presentation Mode hides every panel, so there the command fails and changes nothing. fn show_panel(app: &mut VectorcraftApp, params: &Value) -> Result { let raw = params.get("panel").and_then(Value::as_str).unwrap_or_default(); let panel = normalize(raw).ok_or_else(|| format!("unknown panel `{raw}`"))?; if app.ui.screen_mode >= 3 { return Err("panels can't be shown in Presentation Mode".into()); } - if params.get("toggle") == Some(&Value::Bool(false)) { - return reveal_panel(app, panel); - } place_panel(app, panel) } diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 7ee393527f..eaa0065ba4 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -276,8 +276,7 @@ fn menu_target(c: &CommandRef) -> Option<(String, serde_json::Value)> { } /// What a click on the menu bar's or the canvas menu's row `c` runs ([`crate::menus::click_target`]): a "…" row with -/// params opens its dialog on them (Clean Up…), and a row of a Window menu panel runs the params it is listed with -/// (`toggle: true`, [`crate::menus::is_row_of`]). `None` for a command that no menu fired. +/// params opens its dialog on them (Clean Up…). `None` for a command that no menu fired. fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Option<(String, serde_json::Value)> { if source != FireSource::Menu || c.params.as_object().is_none_or(serde_json::Map::is_empty) { return None; @@ -285,8 +284,8 @@ fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Opti let row = crate::menus::menu_entries(app) .into_iter() .chain(crate::menus::context_entries(app)) - .find(|e| crate::menus::is_row_of(e, &c.id, &c.params))?; - Some(crate::menus::click_target(&row.label, &c.id, &row.params)) + .find(|e| e.command.as_deref() == Some(c.id.as_str()) && e.params == c.params)?; + Some(crate::menus::click_target(&row.label, &c.id, &c.params)) } /// Params used when a shortcut invokes its command. The named panel function keys retain their diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index c65d8056eb..e4b424defd 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -247,19 +247,26 @@ fn named_panel_default_chords_toggle_their_panels() { } /// Each Window menu row that shows a panel shows the chord of that panel's shortcut, as production's did, and the -/// rows of the panels with a default key show one. +/// rows of the panels with a default key show one. The first frame builds the keymap after its menus, so the menus of +/// the next frame show the chords. #[test] fn window_menu_panel_rows_show_their_panels_shortcuts() { let mut app = new_app(); let ctx = ready(&mut app); - let rows: Vec = - app.menus.bar.items().into_iter().filter(|it| it.command.id == "window.panel").map(|it| it.command.clone()).collect(); + key_frame(&mut app, &ctx, vec![]); + let rows: Vec<(craft::keymap::CommandRef, Option)> = app + .menus + .bar + .items() + .into_iter() + .filter(|it| it.command.id == "window.panel" && it.command.params["toggle"] == true) + .map(|it| (it.command.clone(), it.shortcut)) + .collect(); assert!(!rows.is_empty(), "the Window menu lists panels"); let mut with_keys = 0; - for row in &rows { + for (row, chord) in rows { let panel = row.params["panel"].as_str().expect("a panel row names its panel"); let entry = crate::keymap::command_of(&format!("panel:{panel}")); - let chord = craft::ui::runtime::commands::chord(&ctx, row); assert_eq!(chord, craft::ui::runtime::commands::chord(&ctx, &entry), "{panel}: the row shows its shortcut's chord"); if crate::shortcut_editor::PANEL_SHORTCUTS.iter().any(|(p, _)| *p == panel) { assert!(chord.is_some(), "{panel} has a default key, and its row shows it"); @@ -295,14 +302,14 @@ fn a_window_menu_click_toggles_its_panel() { assert_eq!(click(&mut app), before, "the second click toggles it back"); } -/// A click on the task bar's More Options › Show Properties Panel leaves a showing Properties panel showing, docked -/// and in an icon column's flyout: it does not take the toggle of Window › Properties. +/// A click on the task bar's More Options › Show Properties Panel, a menu row that runs `window.panel {panel: +/// "properties"}`, leaves a showing docked Properties panel showing: it does not take the toggle of Window › Properties. #[test] fn the_task_bar_show_properties_row_keeps_properties_showing() { use craft::ui::runtime::commands::{FirePhase, FireSource, Fired}; let mut app = new_app(); let ctx = ready(&mut app); - let row = crate::canvas::task_bar::show_properties(); + let row = craft::keymap::CommandRef::with_params("window.panel", json!({ "panel": "properties" })); let click = |app: &mut VectorcraftApp| { crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0)); key_frame(app, &ctx, vec![]); @@ -310,25 +317,6 @@ fn the_task_bar_show_properties_row_keeps_properties_showing() { }; assert!(click(&mut app), "the first click shows Properties"); assert!(click(&mut app), "a second click leaves Properties showing"); - app.run("window.collapseDock", json!({ "collapsed": true })).expect("the dock collapses to icons"); - key_frame(&mut app, &ctx, vec![]); - assert!(click(&mut app), "a click opens the Properties flyout"); - assert!(click(&mut app), "a second click leaves the flyout open"); - app.run("window.panel", row.params.clone()).expect("the command runs from automation"); - assert!(crate::panel_docking::showing(&app.ui, "properties"), "the command leaves the flyout open from automation too"); -} - -/// `ui.menu.list` lists a Window menu panel row with the toggle a click on it runs, and a plug-in's row that shows a -/// panel the Window menu does not list (Object › Plug-ins › Packaging Tools › Fold Lines) without one. -#[test] -fn listed_window_rows_toggle_and_plugin_panel_rows_do_not() { - let app = new_app(); - let entries = crate::menus::menu_entries(&app); - let row = - |panel: &str| entries.iter().find(|e| e.command.as_deref() == Some("window.panel") && e.params["panel"] == panel).map(|e| e.params.clone()); - assert_eq!(row("layers").map(|p| p["toggle"].clone()), Some(json!(true)), "Window › Layers toggles"); - let fold = row(crate::addons::packaging::ID).expect("a Fold Lines row"); - assert!(fold.get("toggle").is_none(), "Fold Lines shows its panel: {fold}"); } /// A shortcut on a panel without a function key of its own runs `window.panel` with the params it has: no toggle is diff --git a/docs/mcp.md b/docs/mcp.md index 40aff43fdb..87301d0bf5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2142,8 +2142,7 @@ and the action still plays. `Session::replay` plays a journal the same way. The `color` or `channel` it can't read. `window.panel` refuses every request in Presentation Mode, which hides every panel, and changes nothing. With -`toggle` it hides only a panel that can be seen, which is the panel the Window menu checks. With `toggle: false` a panel -that can be seen stays as it is, also in a flyout or a floating window. While Tab or Shift+Tab +`toggle` it hides only a panel that can be seen, which is the panel the Window menu checks. While Tab or Shift+Tab hides the dock, no panel is checked, and the panel shows again with the dock in its earlier place; the toolbar and the Control bar stay as they are.