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.