From 59d85ca138f32393da9e014603c15b82539f16c0 Mon Sep 17 00:00:00 2001 From: prxnvt <53838599+prxnvt@users.noreply.github.com> Date: Sun, 25 Oct 2026 03:30:45 -0400 Subject: [PATCH] UI: the macro editor refuses a taken name in the person's words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`. --- crates/ui-egui/src/macro_editor.rs | 9 ++++++++- crates/ui-egui/tests/it/macro_editor.rs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/macro_editor.rs b/crates/ui-egui/src/macro_editor.rs index 621caae22..f140a8beb 100644 --- a/crates/ui-egui/src/macro_editor.rs +++ b/crates/ui-egui/src/macro_editor.rs @@ -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()); diff --git a/crates/ui-egui/tests/it/macro_editor.rs b/crates/ui-egui/tests/it/macro_editor.rs index 91abbd397..33d3861e4 100644 --- a/crates/ui-egui/tests/it/macro_editor.rs +++ b/crates/ui-egui/tests/it/macro_editor.rs @@ -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); }