diff --git a/crates/ui-egui/src/dialogs/color_group_options.rs b/crates/ui-egui/src/dialogs/color_group_options.rs index 859d7752f6..36fab4b2a1 100644 --- a/crates/ui-egui/src/dialogs/color_group_options.rs +++ b/crates/ui-egui/src/dialogs/color_group_options.rs @@ -32,7 +32,9 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { let key = "group"; let group = match p.get(key) { Some(Value::String(g)) => g.clone(), - None | Some(Value::Null) => crate::panels::swatches::sole_selected_group(app).ok_or("missing `group`")?, + None | Some(Value::Null) => { + crate::panels::swatches::sole_selected_group(app).ok_or("select a color group in the Swatches panel, or pass group")? + } Some(_) => return Err(format!("`{key}` must be a string")), }; let st = app.session.active().ok_or("no document open")?; diff --git a/crates/ui-egui/src/shortcut_editor.rs b/crates/ui-egui/src/shortcut_editor.rs index 3417515bf1..6dfcfd0a7d 100644 --- a/crates/ui-egui/src/shortcut_editor.rs +++ b/crates/ui-egui/src/shortcut_editor.rs @@ -712,6 +712,29 @@ const NEEDS_A_PARAM: [&str; 77] = [ "type.ruby", ]; +/// UI commands with no default key, no menu bar item and a params doc whose fields are all optional +/// that a key press can run with no params: each opens its dialog for the selection, the current +/// item or the panel's selection, or reports in the status bar why it cannot. Rename names the +/// selection, Color Picker… opens for the proxy in front, Brush Options… for the selected path's +/// brush, and Layer Options for the highlighted rows. +pub(crate) const KEY_ONLY_UI: [&str; 15] = [ + "ui.rename", + "ui.colorPicker", + "ui.newSwatch", + "ui.newColorGroup", + "ui.colorGroupOptions", + "ui.newBrush", + "ui.brushOptions", + "ui.layerOptions", + "ui.corners", + "ui.placementOptionsDialog", + "ui.relinkDialog", + "ui.perspectivePlane", + "ui.bulletsAndNumbering", + "ui.missingFontsDialog", + "ui.findFontsInFolder", +]; + /// The (label, params) of each menu bar item, by command id. fn menu_bar_items() -> &'static HashMap> { static ITEMS: OnceLock>> = OnceLock::new(); @@ -802,11 +825,9 @@ fn listed_on_its_own(c: &vectorcraft_engine::CommandSpec) -> bool { /// Is UI command `id` (default key `sc`, params doc `params`) listed in Edit › Keyboard Shortcuts /// whether or not an item of the menu bar runs it? It is when it has a default key or a params doc -/// of `{}` or `{path…}`. Rename has no default key, and a key press names the selection: it needs -/// no `id`. Color Picker… has no default key either, and a key press opens it for the proxy in -/// front. +/// of `{}` or `{path…}`, or is one of [`KEY_ONLY_UI`]. fn ui_listed_on_its_own(id: &str, sc: &str, params: &str) -> bool { - !sc.is_empty() || params.starts_with("{}") || params.starts_with("{path") || id == "ui.rename" || id == "ui.colorPicker" + !sc.is_empty() || params.starts_with("{}") || params.starts_with("{path") || KEY_ONLY_UI.contains(&id) } /// Does a menu bar item run the command with no params, so that it does what its label says and opens diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index cabde4b445..491b075729 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -1839,3 +1839,26 @@ fn a_filter_plugin_row_translates_its_path_and_not_its_name() { assert_eq!(filter, format!("{path} › Group")); assert_eq!(command, format!("{path} › {}", crate::i18n::tr(zh, "Group"))); } + +/// A UI command whose params are all optional and that no item of the menu bar runs can be given a +/// key: Keyboard Shortcuts lists it, and the key opens its dialog or says in the status bar why it +/// cannot. +#[test] +fn a_key_runs_a_ui_command_whose_params_are_all_optional() { + for id in crate::shortcut_editor::KEY_ONLY_UI { + let mut app = app_with_a_selected_rectangle(); + let listed = app.run("shortcuts.list", json!({"query": id})).unwrap(); + assert!(listed.as_array().is_some_and(|rows| rows.iter().any(|r| r["id"] == id)), "{id} is listed: {listed}"); + // Rename edits the name in place and Color Picker… opens the framework's picker; other tests + // check what they open. + if ["ui.rename", "ui.colorPicker"].contains(&id) { + continue; + } + let ctx = ready(&mut app); + bind(&mut app, id, "Cmd+Alt+Shift+F12"); + app.ui.status.clear(); + key_frame(&mut app, &ctx, tap(Key::F12, cmd() | Modifiers::ALT | Modifiers::SHIFT)); + key_frame(&mut app, &ctx, vec![]); + assert!(dialog_kind(&app).is_some() || !app.ui.status.is_empty(), "{id}: the key opens a dialog or reports why not"); + } +} diff --git a/docs/mcp.md b/docs/mcp.md index d0798ea7b6..081c670c87 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -8382,6 +8382,13 @@ Commands listed this way include `type.fractionalWidths`, `type.systemLayout`, ` `links.embed`, `links.update`, `object.slice.delete`, `artboard.switchOrientation`, `artboard.distributeSpacing`, `appearance.targetContents` and `paint.invert`. +They also list these UI commands, which have no menu bar item and no default shortcut and whose params are all +optional: `ui.newSwatch`, `ui.newColorGroup`, `ui.colorGroupOptions`, `ui.newBrush`, `ui.brushOptions`, +`ui.layerOptions`, `ui.corners`, `ui.placementOptionsDialog`, `ui.relinkDialog`, `ui.perspectivePlane`, +`ui.bulletsAndNumbering`, `ui.missingFontsDialog` and `ui.findFontsInFolder`. A key assigned to one runs it with no +params, as `{}` does: it opens the dialog for the selection or the current item, or the status bar shows why it cannot, +for example "no brush selected". + Edit › Keyboard Shortcuts and `shortcuts.list` leave out a command with no default shortcut when a key press cannot run it: no item of the menu bar runs it, it opens no dialog when run without params, and it is one of these: diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 29cc1b5a18..e4e7cbbbea 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -416,7 +416,9 @@ the type shortcuts (tracking/kerning/leading/baseline steps with Alt/Shift), and Layers panel. The shortcut editor also lists the commands that are in no menu but run without parameters (Edit › Duplicate, panel-menu commands such as Break Link to Symbol), so they can be given shortcuts (#1539). It lists each button of the Align panel's Align Objects, Distribute Objects and Distribute Spacing rows under Align, with no default shortcut, and a -shortcut set there runs what a click on the button runs, with the panel's Align To choice and Distribute Spacing value. The [ and ] keys reach the Blob Brush, the Eraser and the Symbolism tools in the app (#1734, part of #1661). +shortcut set there runs what a click on the button runs, with the panel's Align To choice and Distribute Spacing value. +It also lists the panel and dialog commands whose parameters are all optional, such as New Swatch…, Brush Options… +and Corners…, and a shortcut set there opens the dialog for the selection or says in the status bar why it cannot. The [ and ] keys reach the Blob Brush, the Eraser and the Symbolism tools in the app (#1734, part of #1661). Cmd/Ctrl+Alt+. (`stroke.weightUp`, Stroke Weight Up) and Cmd/Ctrl+Alt+, (`stroke.weightDown`, Stroke Weight Down), the keys a [public feature request reply](https://illustrator.uservoice.com/forums/333657-illustrator-desktop-feature-requests/suggestions/32307397-increment-decrement-stroke-weight-key-commands) gives them, step the weight of each selected stroke from its own weight: by a quarter unit of Units › Stroke up to one unit, then by whole units, down to a quarter unit; with nothing selected they step the weight of the next object drawn (#5797).