Merge PR #1120: Open notice: do not promise to keep macros that were dropped (#1024)

This commit is contained in:
aiongg
2026-10-22 02:34:35 +00:00
2 changed files with 24 additions and 1 deletions
+8 -1
View File
@@ -826,8 +826,15 @@ impl SheetApp {
}
let vba: Vec<&str> = msgs.iter().copied().filter(|m| m.to_lowercase().contains("macro") || m.contains("VBA")).collect();
if !vba.is_empty() {
// The reader says "dropped" when the VBA project was missing or unreadable; never promise to keep it then.
let dropped = vba.iter().any(|m| m.contains("dropped"));
let text = if dropped {
"This workbook's VBA macros could not be loaded and were dropped, so they will not be in the saved file. Keep the original file."
} else {
"This workbook contains VBA macros. GridCraft keeps them when you save as .xlsm, but does not run them."
};
self.notice = Some(Notice {
text: "This workbook contains VBA macros. GridCraft keeps them intact when you save, but does not run them.".into(),
text: text.into(),
kind: NoticeKind::Warning,
action: Some(("What this means".into(), "macros".into())),
});
+16
View File
@@ -781,6 +781,22 @@ fn opening_a_macro_workbook_shows_a_notice() {
assert!(h.state().notice.is_none());
}
#[test]
fn dropped_macro_warning_never_promises_to_keep_macros() {
let mut h = harness(blank());
for w in [
"macros (VBA project) reference a missing part and were dropped",
"macros (VBA project) could not be read and were dropped: bad zip",
] {
h.state_mut().show_open_warnings(&json!({"warnings": [w]}));
let n = h.state().notice.clone().unwrap();
assert_eq!(n.kind, gridcraft_ui_egui::NoticeKind::Warning);
assert!(n.text.contains("dropped") && !n.text.contains("keeps them"), "{}", n.text);
}
h.state_mut().show_open_warnings(&json!({"warnings": ["macros (VBA project) were kept but not executed"]}));
assert!(h.state().notice.clone().unwrap().text.contains("keeps them when you save as .xlsm"));
}
#[test]
fn plain_open_warning_becomes_an_info_notice() {
let mut h = harness(blank());