UI: the macro editor refuses a taken name in the person's words

Saving over a macro now needs `replace: true`, and the engine's refusal says so in terms for
programs. A new draft whose name another macro has (or a kept one from a newer version) is
refused by the editor first, with "A macro called “three” already exists. Choose another name."

- Test: `a_new_macro_never_replaces_one_with_its_name`.
This commit is contained in:
prxnvt committed 2026-10-25 06:48:57 -04:00
1 parent ea5eb2ae3c
commit 59d85ca138
2 files changed
+9 -2

No files matched your search

+8 -1
View File
@@ -586,8 +586,15 @@ pub fn save(app: &mut SheetApp, ed: &mut Editor) -> bool {
// The workbook has it under the new name now, even if the save below fails.
ed.saved_as = Some(ed.draft.name.clone());
}
// A new draft never replaces a macro that has its name.
// A new draft never replaces a macro that has its name; the person chooses another.
let replace = ed.saved_as.is_some();
if !replace
&& let Some(doc) = app.session.active()
&& let Err(e) = gridcraft_engine::macros::check_new_name(&doc.wb, &ed.draft.name)
{
app.message = Some(("Save Macro".into(), e));
return false;
}
match app.run("macro.save", json!({"macro": gridcraft_engine::macros::macro_json(&ed.draft), "replace": replace})) {
Ok(_) => {
ed.saved_as = Some(ed.draft.name.clone());
+1 -1
View File
@@ -291,7 +291,7 @@ fn a_new_macro_never_replaces_one_with_its_name() {
assert_eq!(wb.macros[0].steps.len(), 3, "{button}: the saved macro is intact");
assert!(value(&h, "B1").is_empty(), "{button}: nothing ran");
let msg = h.state_mut().message.take().map(|(_, m)| m).unwrap_or_default();
assert!(msg.contains("A macro called 'three' already exists"), "{button}: {msg}");
assert!(msg.contains("A macro called “three” already exists. Choose another name."), "{button}: {msg}");
assert!(h.state().macros.editor.as_ref().unwrap().saved_as.is_none());
h.run_steps(2);
}