From c53f0a91b3458275a344400a6c8c6553d7bb9932 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 17:06:07 -0800 Subject: [PATCH 1/3] Reproduce stale Swatches Delete approvals --- crates/ui-egui/src/panels/swatches/tests.rs | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index 596914f8a3..e86c8a03d9 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -377,6 +377,52 @@ fn delete_asks_then_removes_the_selection_and_unlinks_art() { assert_eq!(deletable(&app, &["[None]".into(), REGISTRATION.into(), "Grays".into()]), ["Grays"]); } +#[test] +fn delete_confirmation_keeps_matching_swatches_in_another_drawing() { + let mut app = app(); + let key = crate::dialogs::confirm::KIND; + let source = app.session.active().unwrap().uid; + delete(&mut app, vec!["Red".into()], false); + assert!(dialog_open(&app, key)); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + assert_ne!(app.session.active().unwrap().uid, source); + let undo = app.session.active().unwrap().history.undo.len(); + assert!(doc(&app).swatch("Red").is_some()); + + confirm(&mut app, key); + assert!(doc(&app).swatch("Red").is_some(), "the other tab keeps its identically named swatch"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert!(app.session.set_active(0)); + assert!(doc(&app).swatch("Red").is_some(), "the source swatch still needs a fresh confirmation"); +} + +#[test] +fn delete_confirmation_keeps_the_swatch_restored_by_revert() { + let mut app = app(); + let key = crate::dialogs::confirm::KIND; + let file = std::env::temp_dir().join(format!("vectorcraft-swatch-delete-revert-{}.vectorcraft", std::process::id())); + app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|err| err.to_string()))); + app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|err| err.to_string()))); + app.run("file.saveAs", json!({"path": file.to_string_lossy()})).unwrap(); + let saved_color = doc(&app).swatch("Red").unwrap().paint.color(); + let st = app.session.active().unwrap(); + let (uid, reverts) = (st.uid, st.reverts); + + app.run("swatch.edit", json!({"name": "Red", "color": "#00ff00"})).unwrap(); + assert_ne!(doc(&app).swatch("Red").unwrap().paint.color(), saved_color); + delete(&mut app, vec!["Red".into()], false); + app.run("file.revert", json!({"confirmed": true})).unwrap(); + let _ = std::fs::remove_file(file); + let st = app.session.active().unwrap(); + assert_eq!((st.uid, st.reverts), (uid, reverts + 1)); + assert_eq!(doc(&app).swatch("Red").unwrap().paint.color(), saved_color); + let undo = st.history.undo.len(); + + confirm(&mut app, key); + assert_eq!(doc(&app).swatch("Red").expect("the restored swatch stays").paint.color(), saved_color); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo); +} + /// Only None and Registration are reserved: a user swatch or color group whose name starts with /// `[` can be deleted, the swatch can be edited, and names the document does not hold are left out. #[test] From 5492a5e50082b3dc1aad4ff58508c78f57eace98 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 17:06:08 -0800 Subject: [PATCH 2/3] Reproduce stale Graphic Styles Delete approvals --- crates/ui-egui/src/panels/graphic_styles.rs | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/crates/ui-egui/src/panels/graphic_styles.rs b/crates/ui-egui/src/panels/graphic_styles.rs index 1d089378d3..241d545789 100644 --- a/crates/ui-egui/src/panels/graphic_styles.rs +++ b/crates/ui-egui/src/panels/graphic_styles.rs @@ -1150,6 +1150,56 @@ mod tests { assert!(names(&app).is_empty() && confirm::open_question(&app).is_none()); } + #[test] + fn delete_confirmation_keeps_matching_styles_in_another_drawing() { + let mut app = app(); + app.run("graphicStyle.new", json!({"name": "Mine"})).unwrap(); + let source = app.session.active().unwrap().uid; + on_event(&mut app, PresetEvent::Delete("Mine".into()), false); + assert!(asks_delete(&app)); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + assert_ne!(app.session.active().unwrap().uid, source); + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 25})).unwrap(); + app.run("graphicStyle.new", json!({"name": "Mine"})).unwrap(); + let before = names(&app); + let undo = app.session.active().unwrap().history.undo.len(); + + answer_dialog(&mut app, dialog_id(confirm::KIND), &[], true); + assert_eq!(names(&app), before, "the other tab keeps its identically named style"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert!(app.session.set_active(0)); + assert!(doc(&app).graphic_style_index("Mine").is_some(), "the source style still needs a fresh confirmation"); + } + + #[test] + fn delete_confirmation_keeps_the_style_restored_by_revert() { + let mut app = app(); + app.run("graphicStyle.new", json!({"name": "Mine"})).unwrap(); + let file = std::env::temp_dir().join(format!("vectorcraft-style-delete-revert-{}.vectorcraft", std::process::id())); + app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|err| err.to_string()))); + app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|err| err.to_string()))); + app.run("file.saveAs", json!({"path": file.to_string_lossy()})).unwrap(); + let saved = doc(&app); + let index = saved.graphic_style_index("Mine").unwrap(); + let st = app.session.active().unwrap(); + let (uid, reverts) = (st.uid, st.reverts); + + app.run("paint.setFill", json!({"color": "#b32f5f"})).unwrap(); + app.run("graphicStyle.redefine", json!({"name": "Mine"})).unwrap(); + on_event(&mut app, PresetEvent::Delete("Mine".into()), false); + assert!(asks_delete(&app)); + app.run("file.revert", json!({"confirmed": true})).unwrap(); + let _ = std::fs::remove_file(file); + let st = app.session.active().unwrap(); + assert_eq!((st.uid, st.reverts), (uid, reverts + 1)); + assert_eq!(doc(&app).graphic_style_index("Mine"), Some(index)); + let undo = st.history.undo.len(); + + answer_dialog(&mut app, dialog_id(confirm::KIND), &[], true); + assert_eq!(doc(&app).graphic_style_index("Mine"), Some(index), "the restored style stays"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + } + #[test] fn thumbnails_are_versioned_by_look_and_change_when_a_style_changes() { let mut app = app(); From 32cd38351dda0b7853ef8d676e9d45d9db65b441 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 17:19:20 -0800 Subject: [PATCH 3/3] Keep Swatches and Graphic Styles Delete approvals on the opening drawing --- crates/ui-egui/src/dialogs/confirm.rs | 29 +++++++++++++++---- crates/ui-egui/src/panels/graphic_styles.rs | 10 ++++++- crates/ui-egui/src/panels/swatches/actions.rs | 8 ++++- crates/ui-egui/src/panels/swatches/tests.rs | 2 ++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/dialogs/confirm.rs b/crates/ui-egui/src/dialogs/confirm.rs index c6e5a6780f..bdafe12b9d 100644 --- a/crates/ui-egui/src/dialogs/confirm.rs +++ b/crates/ui-egui/src/dialogs/confirm.rs @@ -90,12 +90,18 @@ struct Asked { command: String, params: Value, /// The document that must still be active for a document-specific confirmation. - document: Option, + document: Option, /// The automation roots in force when asked: the command runs under them. scope: ScopeHandle, /// Automation asked ([`VectorcraftApp::automation_asked`]): the command runs as automation. automated: bool, } + +struct DocumentOwner { + uid: u64, + reverts: Option, +} + wrapped_dialog!(Question, StandardPrompt, KIND); /// A message with a Close button. @@ -136,12 +142,19 @@ pub fn ask(app: &mut VectorcraftApp, message: &str, detail: &str, command: &str, /// Ask about the active document. OK is valid only while that document is active. pub(crate) fn ask_in_document(app: &mut VectorcraftApp, message: &str, detail: &str, command: &str, params: Value) { - if let Some(document) = app.session.active().map(|st| st.uid) { + if let Some(document) = app.session.active().map(|st| DocumentOwner { uid: st.uid, reverts: None }) { ask_for(app, Some(document), message, detail, command, params); } } -fn ask_for(app: &mut VectorcraftApp, document: Option, message: &str, detail: &str, command: &str, params: Value) { +/// Ask about items in the active document. Reverting its contents invalidates the approval. +pub(crate) fn ask_in_document_contents(app: &mut VectorcraftApp, message: &str, detail: &str, command: &str, params: Value) { + if let Some(document) = app.session.active().map(|st| DocumentOwner { uid: st.uid, reverts: Some(st.reverts) }) { + ask_for(app, Some(document), message, detail, command, params); + } +} + +fn ask_for(app: &mut VectorcraftApp, document: Option, message: &str, detail: &str, command: &str, params: Value) { let Some(dialogs) = app.dialogs() else { app.status(format!("{message} (no window to ask in)")); return; @@ -278,8 +291,14 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &Context) { && answer.choice == PromptChoice::Proceed && let Some(Asked { command, params, document, scope, automated }) = answer.take_tag::() { - if document.is_some_and(|document| app.session.active().is_none_or(|st| st.uid != document)) { - app.status(tl!("This dialog was opened in a different document.")); + let refusal = document.and_then(|owner| match app.session.active() { + Some(st) if st.uid == owner.uid => { + owner.reverts.filter(|reverts| *reverts != st.reverts).map(|_| tl!("The document was reverted. Reopen this dialog to continue.")) + } + _ => Some(tl!("This dialog was opened in a different document.")), + }); + if let Some(reason) = refusal { + app.status(reason); } else if let Err(e) = scope.run(|| crate::file_asks::as_automated(app, automated, |app| app.run(&command, params))) { app.status(e); } diff --git a/crates/ui-egui/src/panels/graphic_styles.rs b/crates/ui-egui/src/panels/graphic_styles.rs index 241d545789..62a5bc68d4 100644 --- a/crates/ui-egui/src/panels/graphic_styles.rs +++ b/crates/ui-egui/src/panels/graphic_styles.rs @@ -780,7 +780,13 @@ fn delete(app: &mut VectorcraftApp, names: &[String], now: bool) { [n] => crate::i18n::fmt(tl!("Delete the graphic style “{name}”?"), &[("name", n)]), _ => crate::i18n::tn(names.len() as u64, "Delete this {n} graphic style?", "Delete these {n} graphic styles?"), }; - crate::dialogs::confirm::ask(app, &message, tl!("Objects using them keep their look but are no longer linked."), "graphicStyle.delete", params); + crate::dialogs::confirm::ask_in_document_contents( + app, + &message, + tl!("Objects using them keep their look but are no longer linked."), + "graphicStyle.delete", + params, + ); } // ---------- the panel menu ---------- @@ -1167,6 +1173,7 @@ mod tests { answer_dialog(&mut app, dialog_id(confirm::KIND), &[], true); assert_eq!(names(&app), before, "the other tab keeps its identically named style"); assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert_eq!(app.ui.status, "This dialog was opened in a different document."); assert!(app.session.set_active(0)); assert!(doc(&app).graphic_style_index("Mine").is_some(), "the source style still needs a fresh confirmation"); } @@ -1198,6 +1205,7 @@ mod tests { answer_dialog(&mut app, dialog_id(confirm::KIND), &[], true); assert_eq!(doc(&app).graphic_style_index("Mine"), Some(index), "the restored style stays"); assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert_eq!(app.ui.status, "The document was reverted. Reopen this dialog to continue."); } #[test] diff --git a/crates/ui-egui/src/panels/swatches/actions.rs b/crates/ui-egui/src/panels/swatches/actions.rs index b865cf2130..13d912b40c 100644 --- a/crates/ui-egui/src/panels/swatches/actions.rs +++ b/crates/ui-egui/src/panels/swatches/actions.rs @@ -62,7 +62,13 @@ pub(super) fn delete(app: &mut VectorcraftApp, names: Vec, now: bool) { [n] => crate::i18n::fmt(tl!("Delete “{name}”?"), &[("name", n)]), _ => crate::i18n::tn(names.len() as u64, "Delete this {n} swatch or group?", "Delete these {n} swatches and groups?"), }; - crate::dialogs::confirm::ask(app, &message, tl!("Art using a deleted global swatch keeps its colour."), "swatch.delete", params); + crate::dialogs::confirm::ask_in_document_contents( + app, + &message, + tl!("Art using a deleted global swatch keeps its colour."), + "swatch.delete", + params, + ); } /// Duplicates the swatches `names` (`swatch.duplicate`, each copy just after its swatch and in its diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index e86c8a03d9..28ae03a07b 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -392,6 +392,7 @@ fn delete_confirmation_keeps_matching_swatches_in_another_drawing() { confirm(&mut app, key); assert!(doc(&app).swatch("Red").is_some(), "the other tab keeps its identically named swatch"); assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert_eq!(app.ui.status, "This dialog was opened in a different document."); assert!(app.session.set_active(0)); assert!(doc(&app).swatch("Red").is_some(), "the source swatch still needs a fresh confirmation"); } @@ -421,6 +422,7 @@ fn delete_confirmation_keeps_the_swatch_restored_by_revert() { confirm(&mut app, key); assert_eq!(doc(&app).swatch("Red").expect("the restored swatch stays").paint.color(), saved_color); assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert_eq!(app.ui.status, "The document was reverted. Reopen this dialog to continue."); } /// Only None and Registration are reserved: a user swatch or color group whose name starts with