mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 13:15:12 +00:00
Pathfinder: the Repeat row names the operation that ran last
The Pathfinder panel menu's Repeat row read "Repeat Pathfinder" after
every operation. The label for pathfinder.repeat now reads "Repeat
Unite", "Repeat Minus Front" and so on from the last Shape Mode or
Pathfinder operation, through the existing "Repeat {name}" template,
and keeps "Repeat Pathfinder" before any has run. Every row of the
command uses the same label.
This commit is contained in:
@@ -99,6 +99,11 @@ fn command_label(app: &VectorcraftApp, id: &str, label: &str) -> Option<String>
|
||||
Some((e, _)) => format!("Last Effect: {}", vectorcraft_effects::effect_info(e).map(|i| i.label).unwrap_or(e.as_str())),
|
||||
None => label.into(),
|
||||
},
|
||||
// Repeat Pathfinder is named after the Shape Mode or Pathfinder operation that ran last.
|
||||
"pathfinder.repeat" => match last_pathfinder_label(app) {
|
||||
Some(name) => format!("Repeat {name}"),
|
||||
None => label.into(),
|
||||
},
|
||||
// Apply Last Filter and Last Filter… are named after the filter that ran last.
|
||||
crate::dialogs::plugin::APPLY_LAST | crate::dialogs::plugin::LAST => match crate::dialogs::plugin::last_filter_name(app) {
|
||||
Some(name) if id == crate::dialogs::plugin::APPLY_LAST => format!("Apply {name}"),
|
||||
@@ -129,6 +134,11 @@ fn command_label(app: &VectorcraftApp, id: &str, label: &str) -> Option<String>
|
||||
Some(text)
|
||||
}
|
||||
|
||||
/// The Pathfinder panel's name for the Shape Mode or Pathfinder operation that ran last.
|
||||
fn last_pathfinder_label(app: &VectorcraftApp) -> Option<&'static str> {
|
||||
app.last_pathfinder.as_deref().and_then(crate::panels::pathfinder::operation_label)
|
||||
}
|
||||
|
||||
/// Does the menu item `id` show a name that is user, file or system data rather than an interface
|
||||
/// label: a recent file, a saved view, a font, a user library or preset, a custom workspace, a
|
||||
/// plug-in, an SVG filter, a script of the Scripts folder? Such names are shown as they are, never
|
||||
@@ -201,6 +211,10 @@ pub fn display_label(app: &VectorcraftApp, id: &str, label: &str) -> String {
|
||||
}
|
||||
None => crate::i18n::tr_id(lang, id, label).to_string(),
|
||||
},
|
||||
"pathfinder.repeat" => match last_pathfinder_label(app) {
|
||||
Some(name) => fmt(tl!("Repeat {name}"), &[("name", tl!(name))]),
|
||||
None => crate::i18n::tr_id(lang, id, label).to_string(),
|
||||
},
|
||||
// The filter's name is the plug-in's own text, never translated.
|
||||
crate::dialogs::plugin::APPLY_LAST | crate::dialogs::plugin::LAST => match crate::dialogs::plugin::last_filter_name(app) {
|
||||
Some(name) if id == crate::dialogs::plugin::APPLY_LAST => fmt(tl!("Apply {filter}"), &[("filter", &name)]),
|
||||
|
||||
@@ -520,6 +520,28 @@ mod tests {
|
||||
assert!(p.app().run("pathfinder.repeat", json!({})).is_err());
|
||||
}
|
||||
|
||||
/// The state the window's menus give the Repeat row, which the panel menu's row reads.
|
||||
fn repeat_row(p: &Panel) -> Option<CommandState> {
|
||||
crate::menus::model::refresh(&mut p.app(), p.ctx());
|
||||
p.app().menus.states.get(&CommandRef::new("pathfinder.repeat")).cloned()
|
||||
}
|
||||
|
||||
/// Before an operation has run, the Repeat row reads Repeat Pathfinder and is dimmed; after Unite
|
||||
/// or Minus Front from the panel it names that operation.
|
||||
#[test]
|
||||
fn the_repeat_row_names_the_last_operation() {
|
||||
let mut p = Panel::new(two_squares(), show);
|
||||
let command = CommandRef::new("pathfinder.repeat");
|
||||
let off = crate::menus::model::off_reason(&p.app(), &command, "Repeat Pathfinder");
|
||||
assert_eq!(repeat_row(&p), Some(CommandState::new().enabled(false).hint(off)), "the plain label, dimmed");
|
||||
p.click("Unite");
|
||||
select_two_squares(&mut p.app(), 110.0);
|
||||
assert_eq!(repeat_row(&p), Some(CommandState::new().enabled(true).title("Repeat Unite")));
|
||||
p.click("Minus Front");
|
||||
select_two_squares(&mut p.app(), 210.0);
|
||||
assert_eq!(repeat_row(&p), Some(CommandState::new().enabled(true).title("Repeat Minus Front")));
|
||||
}
|
||||
|
||||
/// One selected path cannot supply the operands for Unite; the command reports the failure.
|
||||
#[test]
|
||||
fn repeat_with_one_path_keeps_art_and_history() {
|
||||
|
||||
Reference in New Issue
Block a user