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.