diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index fcd975a2ae..c382be06b2 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -61,6 +61,8 @@ pub(crate) use bar::{home_key, home_showing}; #[cfg(test)] use bar::{menu_body, pointer_reaches_title}; pub use context::{context_items, context_menu_body, ruler_menu_body, ruler_unit_items}; +#[cfg(test)] +use entries::flatten; pub use entries::{ InsertableItem, MenuEntry, Row, context_entries, entry, insertable, insertable_items, menu_entries, plays_in_app, pretty_shortcut, shown_label, shown_shortcut, diff --git a/crates/ui-egui/src/menus/entries.rs b/crates/ui-egui/src/menus/entries.rs index f79a9a6518..8c92fbc071 100644 --- a/crates/ui-egui/src/menus/entries.rs +++ b/crates/ui-egui/src/menus/entries.rs @@ -115,13 +115,17 @@ pub struct MenuEntry { pub params: Value, pub enabled: bool, pub shortcut: String, + /// `path` as the menus draw it in the UI language: a plug-in's submenu and a Scripts folder + /// keep their names. + #[serde(skip)] + pub shown_path: Vec, } /// 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) { - flatten(app, vec![title.to_string()], &items, &mut out); + flatten(app, vec![title.to_string()], vec![crate::i18n::t(title).to_string()], &items, &mut out); } out } @@ -129,7 +133,7 @@ pub fn menu_entries(app: &VectorcraftApp) -> Vec { /// Flattened canvas context menu for `ui.contextMenu.list` (paths are its submenus). pub fn context_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; - flatten(app, vec![], &context_items(app), &mut out); + flatten(app, vec![], vec![], &context_items(app), &mut out); out } @@ -251,7 +255,7 @@ pub fn insertable_items(english_names: bool) -> Vec { out } -fn flatten(app: &VectorcraftApp, path: Vec, items: &[Item], out: &mut Vec) { +pub(super) fn flatten(app: &VectorcraftApp, path: Vec, shown: Vec, items: &[Item], out: &mut Vec) { for it in items { match it { Item::Cmd(l, id, p) => { @@ -272,6 +276,7 @@ fn flatten(app: &VectorcraftApp, path: Vec, items: &[Item], out: &mut Ve params: p.clone(), enabled, shortcut: item_shortcut(id, p).or_else(|| shortcut_of(id)).unwrap_or("").to_string(), + shown_path: shown.clone(), }) } Item::Todo(l, sc) => out.push(MenuEntry { @@ -281,11 +286,16 @@ fn flatten(app: &VectorcraftApp, path: Vec, items: &[Item], out: &mut Ve params: Value::Null, enabled: false, shortcut: sc.to_string(), + shown_path: shown.clone(), }), Item::Sub(l, ch) => { let mut p = path.clone(); p.push(l.to_string()); - flatten(app, p, ch, out); + // The menus draw a plug-in's submenu and a Scripts folder by their own names ([`entry`]). + let mut s = shown.clone(); + let own = super::labels::holds_plugin_commands(ch) || crate::scripts_menu::is_folder(ch); + s.push(if own { l.to_string() } else { crate::i18n::t(l).to_string() }); + flatten(app, p, s, ch, out); } _ => {} } diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 4a25841b5b..d5991d8b20 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -193,6 +193,40 @@ fn discover_command_results_follow_their_menu_label() { assert_eq!(back["results"][index]["label"], "Hide Grid"); } +/// A menu entry's shown path translates the menus' own names and keeps a Scripts folder's name, as +/// the menus draw it; Help shows that path. +#[test] +fn menu_entry_shown_paths_keep_script_folder_names() { + let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let de = crate::i18n::Lang::from_code("de").unwrap(); + assert_ne!(crate::i18n::tr(de, "File"), "File"); + let script = json!({"path": "File/a.jsx"}); + let folder = vec![Item::Cmd("a", crate::scripts_menu::COMMAND, script)]; + let items = vec![Item::Sub("Scripts", vec![Item::Sub("File", folder), Item::Cmd("Other Script…", "ui.runScript", Value::Null)])]; + let mut out = vec![]; + crate::i18n::set_current(de); + flatten(&app, vec!["File".into()], vec![crate::i18n::t("File").into()], &items, &mut out); + crate::i18n::set_current(crate::i18n::Lang::EN); + let script = out.iter().find(|e| e.command.as_deref() == Some(crate::scripts_menu::COMMAND)).unwrap(); + assert_eq!(script.path, ["File", "Scripts", "File"]); + assert_eq!(script.shown_path, [crate::i18n::tr(de, "File"), crate::i18n::tr(de, "Scripts"), "File"]); +} + +/// Outside macOS the window's menu bar has no VectorCraft menu, so Help lists no command under it. +#[test] +fn discover_leaves_out_menus_the_window_does_not_show() { + crate::i18n::set_current(crate::i18n::Lang::EN); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default()); + let app_menu: Vec = + menu_entries(&app).into_iter().filter(|e| e.path.first().is_some_and(|t| t == "VectorCraft")).filter_map(|e| e.command).collect(); + assert!(!app_menu.is_empty()); + for id in app_menu { + let found = app.run("help.discover.search", json!({"query": id})).unwrap(); + let listed = found["results"].as_array().unwrap().iter().any(|hit| hit["path"][0] == "VectorCraft"); + assert_eq!(listed, cfg!(target_os = "macos"), "{id}: {found}"); + } +} + /// Help finds a command by the label its menu shows in the UI language, also where the menu names /// an effect by its own id (Effect › Pathfinder › Add reads Réunion in French). #[test] diff --git a/crates/ui-egui/src/panels/discover.rs b/crates/ui-egui/src/panels/discover.rs index 0f3816ca1b..1c3fd12262 100644 --- a/crates/ui-egui/src/panels/discover.rs +++ b/crates/ui-egui/src/panels/discover.rs @@ -80,7 +80,7 @@ fn refresh(app: &mut VectorcraftApp) { hit.english_label = entry.label.clone(); hit.english_path = entry.path.clone(); hit.label = menus::shown_label(app, &hit.id, &hit.params, &hit.english_label); - hit.path = hit.english_path.iter().map(|part| crate::i18n::tr(lang, part).into()).collect(); + hit.path = entry.shown_path.clone(); hit.shortcut = menus::item_shortcut(&hit.id, &hit.params).or_else(|| menus::shortcut_of(&hit.id)).unwrap_or_default().into(); } _ => {} @@ -118,8 +118,12 @@ fn search(app: &VectorcraftApp, query: &str) -> Vec { } for entry in menus::menu_entries(app) { let Some(id) = entry.command else { continue }; + // The menu bar in the window has no VectorCraft menu; only the native macOS bar shows it. + if !cfg!(target_os = "macos") && entry.path.first().is_some_and(|title| title == "VectorCraft") { + continue; + } let label = menus::shown_label(app, &id, &entry.params, &entry.label); - let path: Vec = entry.path.iter().map(|part| crate::i18n::tr(lang, part).into()).collect(); + let path = entry.shown_path; if matches(&query, &format!("{} {label} {} {} {id}", entry.label, entry.path.join(" "), path.join(" "))) { hits.push(Hit { kind: "command", diff --git a/docs/mcp.md b/docs/mcp.md index 257657eaa8..768ba4c530 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3267,7 +3267,9 @@ the results. VectorCraft limits a query to 1024 characters and rejects a longer `{query, results: [{kind, id, label, path, shortcut}], selected}`. `kind` is `tool`, `command`, or `tutorial`; `selected` is a zero-based result index or `null`. Search matches all the query's words without regard to case, using translated tool labels, command labels as their menus show -them, and the English labels, ids, and menu paths. Tutorial text remains in English. After a shortcut or the interface +them, and the English labels, ids, and menu paths. A result's `path` names the menus as they are +drawn, with plug-in submenus and Scripts folders under their own names. Outside macOS, items of +the VectorCraft application menu, which only the macOS menu bar shows, are left out. Tutorial text remains in English. After a shortcut or the interface language changes, the kept results show the current shortcuts, labels, and menu paths, with the query and the selected result unchanged. A command result also shows its menu item's current label (Show Grid becomes Hide Grid), and a command that no menu lists any more, such as a removed