From 6f511ac810eb28df1ace4b1527153ff77beb1e4d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 18:50:31 -0800 Subject: [PATCH] Retire old Composite Fonts approval after File Revert --- crates/ui-egui/src/dialogs/composite_fonts.rs | 16 +++++----- .../src/dialogs/composite_fonts/tests.rs | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/dialogs/composite_fonts.rs b/crates/ui-egui/src/dialogs/composite_fonts.rs index d1f01049d3..287f6702a2 100644 --- a/crates/ui-egui/src/dialogs/composite_fonts.rs +++ b/crates/ui-egui/src/dialogs/composite_fonts.rs @@ -137,7 +137,7 @@ enum PartEdit { /// [`COMMAND`] and answers whether the dialog may close. pub struct CompositeFontsDialog { /// The document whose fonts the draft edits. - document: u64, + document: (u64, u64), fonts: Vec, /// The index of the font picked. selected: usize, @@ -172,7 +172,7 @@ pub struct CompositeFontsDialog { pub fn open(app: &mut VectorcraftApp) -> Result { let document = app.session.active().ok_or("no document open")?; let dialogs = app.dialogs().ok_or("no window to show the dialog in")?; - let dialog = CompositeFontsDialog::new(document.uid, document.doc.composite_fonts.to_vec(), crate::font_menu::hold(app)); + let dialog = CompositeFontsDialog::new((document.uid, document.reverts), document.doc.composite_fonts.to_vec(), crate::font_menu::hold(app)); dialogs.with(|host| host.open(dialog)); Ok(Value::Null) } @@ -244,7 +244,7 @@ fn part_mut(f: &mut CompositeFont, at: usize) -> Option<&mut CompositePart> { impl CompositeFontsDialog { /// The dialog over `fonts`, the first picked. - fn new(document: u64, fonts: Vec, hold: PickerHold) -> Self { + fn new(document: (u64, u64), fonts: Vec, hold: PickerHold) -> Self { let mut sample = Map::new(); sample::defaults(&mut sample); CompositeFontsDialog { @@ -862,11 +862,11 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &Context) { }) else { return; }; - if let Some((document, fonts)) = held { - let answer = if app.session.active().is_some_and(|active| active.uid == document) { - app.run(COMMAND, json!({ "fonts": fonts })).map(|_| ()).map_err(Label::from) - } else { - Err(Label::from(tl!("Composite Fonts can only change the document where it was opened.").to_owned())) + if let Some(((document, reverts), fonts)) = held { + let answer = match app.session.active().filter(|active| active.uid == document) { + Some(active) if active.reverts == reverts => app.run(COMMAND, json!({ "fonts": fonts })).map(|_| ()).map_err(Label::from), + Some(_) => Err(Label::from(tl!("The document was reverted. Reopen this dialog to continue."))), + None => Err(Label::from(tl!("Composite Fonts can only change the document where it was opened."))), }; with_dialog(app, |d| d.held.answer(answer)); } diff --git a/crates/ui-egui/src/dialogs/composite_fonts/tests.rs b/crates/ui-egui/src/dialogs/composite_fonts/tests.rs index 2db07b9344..5fa9d45204 100644 --- a/crates/ui-egui/src/dialogs/composite_fonts/tests.rs +++ b/crates/ui-egui/src/dialogs/composite_fonts/tests.rs @@ -575,3 +575,33 @@ fn custom_character_sets_draw_their_characters_and_the_buttons() { assert!(p.shows(name), "{name} is drawn"); } } + +#[test] +fn composite_fonts_approval_does_not_replace_definitions_restored_by_revert() { + let mut app = app(); + open(&mut app).unwrap(); + dialog(&mut app, |d| d.new_font("Saved Font".into())); + ok(&mut app).unwrap(); + let dir = vectorcraft_testkit::TempDir::new("composite-fonts-revert"); + app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string()))); + app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string()))); + app.run("file.saveAs", json!({"path": dir.join("Art.vectorcraft")})).unwrap(); + open(&mut app).unwrap(); + dialog(&mut app, |d| d.new_font("Unsaved Font".into())); + ok(&mut app).unwrap(); + open(&mut app).unwrap(); + dialog(&mut app, |d| d.new_font("Stale Draft Font".into())); + + app.run("file.revert", json!({"confirmed": true})).unwrap(); + let restored_step = steps(&app); + assert_eq!(names(&app), ["Saved Font"]); + assert_eq!(ok(&mut app), Err("The document was reverted. Reopen this dialog to continue.".into())); + assert_eq!(names(&app), ["Saved Font"]); + assert_eq!(steps(&app), restored_step); + + cancel(&mut app); + open(&mut app).unwrap(); + dialog(&mut app, |d| d.new_font("Fresh Font".into())); + ok(&mut app).unwrap(); + assert_eq!(names(&app), ["Saved Font", "Fresh Font"]); +}