diff --git a/crates/ui-egui/src/canvas/context_menu.rs b/crates/ui-egui/src/canvas/context_menu.rs index 853ec2e038..bfef665bb8 100644 --- a/crates/ui-egui/src/canvas/context_menu.rs +++ b/crates/ui-egui/src/canvas/context_menu.rs @@ -40,7 +40,8 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp app.ui.context_menu_at = Some(at); } let Some(at) = app.ui.context_menu_at else { return }; - let nodes = crate::menus::context_items(app); + let mut nodes = crate::menus::context_items(app); + crate::menus::shown_labels(app, &mut nodes); let mut open = true; let shown = Menu::new(tl!("Canvas").to_string()) .opened_by(opener, Trigger::Manual) diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 6355eca440..abfedacbb5 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -76,6 +76,7 @@ mod tree; mod ui_commands; pub use context::context_items; +pub(crate) use context::shown_labels; #[cfg(test)] use entries::flatten; pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, menu_entries, plays_in_app, shown_label}; diff --git a/crates/ui-egui/src/menus/context.rs b/crates/ui-egui/src/menus/context.rs index 4910dff672..06d9a22523 100644 --- a/crates/ui-egui/src/menus/context.rs +++ b/crates/ui-egui/src/menus/context.rs @@ -300,6 +300,25 @@ fn prune(app: &VectorcraftApp, mut items: Vec) -> Vec { items } +/// Gives each item of `items` (and of its submenus, at every depth) the label the menus draw for it +/// ([`super::shown_label`]): Undo and Redo name the step, as the Edit menu does. The English label stays for the +/// item's letter. +pub(crate) fn shown_labels(app: &VectorcraftApp, items: &mut [Node]) { + for n in items { + match n { + Node::Item(i) => { + let shown = super::shown_label(app, &i.command.id, &i.command.params, &i.label); + if shown != i.label { + i.english.get_or_insert_with(|| i.label.clone()); + i.label = shown; + } + } + Node::Submenu { children, .. } => shown_labels(app, children), + _ => {} + } + } +} + /// Drops the items of `items` (and of its submenus, at every depth) whose command can't run now. fn retain_runnable(app: &VectorcraftApp, items: &mut Vec) { items.retain_mut(|n| match n { diff --git a/crates/ui-egui/src/menus/model.rs b/crates/ui-egui/src/menus/model.rs index 9699991cc6..2c8cc0221d 100644 --- a/crates/ui-egui/src/menus/model.rs +++ b/crates/ui-egui/src/menus/model.rs @@ -521,7 +521,8 @@ impl Build<'_> { } let (id, params) = (command.id.as_str(), &command.params); let (enabled, checked) = shown_state(self.app, id, params)?; - let mut state = CommandState::new().enabled(enabled).title(self.item_title(id, params, &item.label)); + let title = self.item_title(id, params, &item.label); + let mut state = CommandState::new().enabled(enabled).title(title.clone()); if let Some(on) = checked { state = state.checked(on); } @@ -531,7 +532,7 @@ impl Build<'_> { } else if enabled { None } else { - Some(off_reason(self.app, &command, &self.item_title(id, params, &item.label))) + Some(off_reason(self.app, &command, &title)) }; if let Some(tip) = tip { state = state.hint(tip.clone()); @@ -541,6 +542,12 @@ impl Build<'_> { } self.states.set(command.clone(), state); self.refs.push((command.clone(), item.label.clone(), checked.is_some())); + // The bar draws a row's own label, not its state's title, so a row named after the app's state (Undo + // Rectangle, Last Effect: Drop Shadow) takes that name as its label, keeping the English one for its letter. + if title != item.label { + item.english.get_or_insert_with(|| item.label.clone()); + item.label = title; + } Some(self.decorate(item, id, params)) } diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index c48e9d732f..cab67592f1 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -1017,6 +1017,42 @@ fn app_with_a_rectangle() -> VectorcraftApp { app } +/// The in-window Edit menu draws Undo and Redo with the step's name, as the History panel lists it. +#[test] +fn the_edit_menu_draws_undo_and_redo_with_the_step_name() { + use crate::tests::panel_harness::Panel; + fn draw(app: &mut VectorcraftApp, ui: &mut egui::Ui) { + model::refresh(app, ui.ctx()); + craft::menu::MenuBarUi::new(&app.menus.laid).show(ui); + } + crate::i18n::set_current(crate::i18n::Lang::EN); + let mut menu = Panel::new(app_with_a_rectangle(), draw); + menu.click("Edit"); + assert!(menu.shows("Undo Rectangle"), "the Undo row names the step"); + assert!(!menu.shows("Undo"), "no bare Undo row"); + menu.click("Edit"); + menu.app().run("edit.undo", json!({})).unwrap(); + menu.click("Edit"); + assert!(menu.shows("Redo Rectangle"), "the Redo row names the step"); +} + +/// The canvas context menu's Undo and Redo rows name the step, as the Edit menu's do. +#[test] +fn the_context_menu_names_the_undo_and_redo_step() { + crate::i18n::set_current(crate::i18n::Lang::EN); + let mut app = app_with_a_rectangle(); + let labels = |app: &VectorcraftApp| { + let mut nodes = context_items(app); + crate::menus::shown_labels(app, &mut nodes); + command_rows(&nodes).into_iter().map(|(label, id, _)| (id.to_string(), label.to_string())).collect::>() + }; + let shown = labels(&app); + assert!(shown.contains(&("edit.undo".to_string(), "Undo Rectangle".to_string())), "{shown:?}"); + app.run("edit.undo", json!({})).unwrap(); + let shown = labels(&app); + assert!(shown.contains(&("edit.redo".to_string(), "Redo Rectangle".to_string())), "{shown:?}"); +} + /// Edit › Undo and Edit › Redo name a step named after a style as the History panel lists it: /// the template's translation with the style's name in it. #[test]