From b919e33217cb26f95757a9e03ddd6ea7337c58fb Mon Sep 17 00:00:00 2001 From: debarghaya <175645893+GhostMitra@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:24:39 +0530 Subject: [PATCH] UI: close About dialog on Cancel and test Options Cancel from File tab (#782) In release 0.7.0, Cancel in the Preferences dialog (opened via Options in the File tab) did nothing. This was previously addressed on main by #757 (#752). This change adds an egui_kittest regression test verifying that clicking Options from the File tab opens the Preferences dialog and clicking Cancel closes it while keeping Backstage open. In addition, the About dialog's Cancel button now properly closes the dialog instead of being ignored. Closes #782. --- crates/ui-egui/src/backstage_tests.rs | 17 +++++++++++++ crates/ui-egui/src/dialogs.rs | 4 +-- crates/ui-egui/src/lib.rs | 35 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/backstage_tests.rs b/crates/ui-egui/src/backstage_tests.rs index 9b3906a2..18be4599 100644 --- a/crates/ui-egui/src/backstage_tests.rs +++ b/crates/ui-egui/src/backstage_tests.rs @@ -535,3 +535,20 @@ fn print_slides_follow_the_settings() { bs.print_layout = "slides"; assert_eq!(print_page_size(&bs, &doc), (doc.slide_size.width as f32, doc.slide_size.height as f32), "slides print slide-shaped"); } + +/// Options in the File tab opens the Preferences dialog, and Cancel closes it (#782, #752). +#[test] +fn options_in_backstage_opens_preferences_and_cancel_closes_it() { + let mut h = harness(new_app()); + h.get_by_label("File").click(); + h.run_steps(3); + assert!(h.state().backstage_open()); + h.get_by_label("Options").click(); + h.run_steps(3); + assert!(h.state().dialog.is_some(), "Options opens Preferences dialog"); + assert_eq!(h.state().dialog.as_ref().map(|d| d.id.as_str()), Some("preferences")); + h.query_all_by_role_and_label(Role::Button, "Cancel").next().expect("Cancel button").click_accesskit(); + h.run_steps(3); + assert!(h.state().dialog.is_none(), "Cancel closes Preferences dialog"); + assert!(h.state().backstage_open(), "Backstage remains open"); +} diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 576a2297..9d2dbe08 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -2085,8 +2085,8 @@ fn body(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool { } _ => about(app, ui), } - let (ok, _) = buttons(ui, "Close"); - ok + let (ok, cancel) = buttons(ui, "Close"); + ok || cancel } "autocorrect" => { let pr = &mut app.session.prefs; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 88674070..d449874e 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -2642,6 +2642,41 @@ mod tests { assert_ne!(s.session.prefs.snap_to_grid, before.snap_to_grid, "Done keeps snap to grid"); } + /// About dialog: Close and Cancel each close the dialog. + #[test] + fn about_dialog_close_and_cancel_close_it() { + use egui_kittest::kittest::Queryable; + let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state( + |ui, app: &mut SlideApp| { + app.logic(ui.ctx()); + app.ui(ui); + }, + SlideApp::new(Session::with_new(), Services::default()), + ); + harness.run_steps(2); + harness.state_mut().run("app.about", json!({})).unwrap(); + harness.run_steps(2); + assert!(harness.state().dialog.is_some()); + harness + .query_all_by_role_and_label(egui::accesskit::Role::Button, "Cancel") + .next() + .unwrap_or_else(|| panic!("no Cancel button in About dialog")) + .click_accesskit(); + harness.run_steps(2); + assert!(harness.state().dialog.is_none(), "Cancel closes About dialog"); + + harness.state_mut().run("app.about", json!({})).unwrap(); + harness.run_steps(2); + assert!(harness.state().dialog.is_some()); + harness + .query_all_by_role_and_label(egui::accesskit::Role::Button, "Close") + .next() + .unwrap_or_else(|| panic!("no Close button in About dialog")) + .click_accesskit(); + harness.run_steps(2); + assert!(harness.state().dialog.is_none(), "Close closes About dialog"); + } + fn canvas_harness() -> egui_kittest::Harness<'static, SlideApp> { let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state( |ui, app: &mut SlideApp| {