Prompt to save before running Shutdown Scripts

This commit is contained in:
dotCooCoo
2026-10-27 12:05:51 -07:00
parent 5e32a2a39c
commit 5e583c1549
+27 -1
View File
@@ -16,7 +16,16 @@ use crate::theme::Tokens;
use crate::{Dialog, EffectcraftApp};
/// Commands that replace or close the open project (Quit is asked when the window closes).
const CLOSING: &[&str] = &["file.newProject", "file.open", "file.openRecent", "file.closeProject", "file.revert", "file.openDemoProject", "templates.create"];
const CLOSING: &[&str] = &[
"file.newProject",
"file.open",
"file.openRecent",
"file.closeProject",
"file.revert",
"file.openDemoProject",
"templates.create",
"file.runShutdownScripts",
];
/// The command waiting on the prompt, and whether the user already answered it.
#[derive(Clone, Debug, Default)]
@@ -212,6 +221,23 @@ mod tests {
assert!(app.session.is_dirty());
}
#[test]
fn shutdown_scripts_prompt_before_discarding_unsaved_work() {
let (mut app, ctx) = app();
modified(&mut app);
let result = crate::menus::invoke(&mut app, &ctx, "file.runShutdownScripts", json!({})).unwrap();
assert_eq!(result, json!({"dialog": "unsavedChanges"}));
assert_eq!(app.session.project.comps().count(), 1);
assert!(app.session.is_dirty());
answer_with(&mut app, &ctx, Answer::Cancel);
assert_eq!(app.session.project.comps().count(), 1);
assert!(app.session.is_dirty());
crate::menus::invoke(&mut app, &ctx, "file.runShutdownScripts", json!({})).unwrap();
answer_with(&mut app, &ctx, Answer::Discard);
assert_eq!(app.session.project.comps().count(), 0);
assert!(!app.session.is_dirty() && app.dialog.is_none());
}
#[test]
fn closing_a_modified_project_asks_and_cancel_keeps_it() {
let (mut app, ctx) = app();