From d29da044d58546386fe3d838d589e80001548f36 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 28 Nov 2026 16:29:51 +0000 Subject: [PATCH] ribbon: Insert's picture button is Pictures; ui.dialog.open close asks about the active presentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Insert tab's picture button took its command's label (Picture from File…); the ribbon names it Pictures, as production did. ui.dialog.open had quit but not close, the key production opens the close prompt by: close runs the close guard for the active presentation and asks only when it has unsaved changes. A test checks that each name the ribbon's controls answer to (split arrows, two-line labels, Pictures) is one button on its tab; the queued-click test finds the ribbon's own chevron by its new name. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs.rs | 5 +-- crates/ui-egui/src/dialogs/closing.rs | 39 +++++++++++++++++++++--- crates/ui-egui/src/lib.rs | 2 ++ crates/ui-egui/src/ribbon/insert.rs | 2 +- crates/ui-egui/src/ribbon_names_tests.rs | 34 +++++++++++++++++++++ crates/ui-egui/src/tests.rs | 5 +-- 6 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 crates/ui-egui/src/ribbon_names_tests.rs diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 82fa7eaba..9da1caa2f 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -188,7 +188,7 @@ fn matching_dialog(host: &DialogHost, key: &str) -> Option { "customShow" => typed_id::(host), "spelling" => typed_id::(host), "find" => typed_id::(host), - "quit" => typed_id::(host), + "quit" | "close" => typed_id::(host), "about" => typed_id::(host), _ => host.open_dialogs().into_iter().find(|dialog| dialog.key.as_deref() == Some(key)).map(|dialog| dialog.id), } @@ -229,7 +229,8 @@ pub(crate) fn open_now(app: &mut SlideApp, ctx: &Context, host: &mut DialogHost, "spelling" => spelling::open(app, ctx, host, params), "accessibility" => accessibility::open(app, ctx, host, params), "find" => find::open(app, ctx, host, params), - "quit" => closing::open(app, ctx, host, params), + "quit" => closing::open(app, ctx, host, craft::quit::CloseScope::Quit), + "close" => closing::open(app, ctx, host, craft::quit::CloseScope::Close), "about" => about::open(app, ctx, host, params), "preferences" => preferences::open(app, ctx, host, params), "autocorrect" => preferences::open_autocorrect(app, ctx, host, params), diff --git a/crates/ui-egui/src/dialogs/closing.rs b/crates/ui-egui/src/dialogs/closing.rs index e9cbfd3b6..0a195a0d8 100644 --- a/crates/ui-egui/src/dialogs/closing.rs +++ b/crates/ui-egui/src/dialogs/closing.rs @@ -9,10 +9,14 @@ use serde_json::{Value, json}; use crate::SlideApp; use crate::app::files::SaveOutcome; -/// Opens the quit guard's current document question, if one is needed. -pub(crate) fn open(app: &mut SlideApp, ctx: &Context, host: &mut DialogHost, _params: &Value) -> Result, String> { - let uids = app.session.documents().iter().filter(|doc| doc.is_dirty()).map(|doc| doc.uid).collect(); - app.start_closing(CloseScope::Quit, uids); +/// Opens the guard's current document question, if one is needed: Quit asks about every unsaved presentation, Close +/// about the active one. +pub(crate) fn open(app: &mut SlideApp, ctx: &Context, host: &mut DialogHost, scope: CloseScope) -> Result, String> { + let uids = match scope { + CloseScope::Close => app.session.active().filter(|doc| doc.is_dirty()).map(|doc| doc.uid).into_iter().collect(), + _ => app.session.documents().iter().filter(|doc| doc.is_dirty()).map(|doc| doc.uid).collect(), + }; + app.start_closing(scope, uids); pump(app, ctx, host); Ok(host.get::().map(StackDialog::id)) } @@ -258,4 +262,31 @@ mod tests { assert!(crate::dialogs::top_dialog(&h.ctx).is_none()); assert_eq!(h.state_mut().close_decision(), CloseDecision::Close); } + + /// The `close` dialog key asks about the active presentation alone, and only when it has unsaved changes. + #[test] + fn the_close_key_asks_about_the_active_unsaved_presentation() { + let mut session = Session::new(); + for title in ["First", "Second"] { + session.execute("file.new", &json!({})).unwrap(); + session.execute("file.properties", &json!({"title": title})).unwrap(); + } + let mut h = harness(session, Services::default()); + h.run_steps(2); + let ctx = h.ctx.clone(); + crate::dialogs::control(h.state_mut(), &ctx, "ui.dialog.open", &json!({"id": "close"})).expect("a dialog method").unwrap(); + h.run_steps(4); + assert!(crate::dialogs::top_dialog(&h.ctx).is_some(), "an unsaved presentation is asked about"); + answer(&h, Some(CloseAnswer::DontSave)); + h.run_steps(4); + assert_eq!(h.state().session.documents().len(), 1, "Don't Save closes the active presentation and keeps the other"); + assert!(!h.state().quit_allowed(), "the other presentation still has its changes"); + + let mut h = harness(Session::with_new(), Services::default()); + h.run_steps(2); + let ctx = h.ctx.clone(); + crate::dialogs::control(h.state_mut(), &ctx, "ui.dialog.open", &json!({"id": "close"})).expect("a dialog method").unwrap(); + h.run_steps(4); + assert!(crate::dialogs::top_dialog(&h.ctx).is_none(), "a presentation without changes needs no question"); + } } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 7483adeab..43ee1b145 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -274,6 +274,8 @@ mod replacefonts_tests; #[cfg(test)] mod reuse_picker_tests; #[cfg(test)] +mod ribbon_names_tests; +#[cfg(test)] mod slide_size_tests; #[cfg(test)] mod split_button_tests; diff --git a/crates/ui-egui/src/ribbon/insert.rs b/crates/ui-egui/src/ribbon/insert.rs index 3afce9236..e8dd631fc 100644 --- a/crates/ui-egui/src/ribbon/insert.rs +++ b/crates/ui-egui/src/ribbon/insert.rs @@ -66,7 +66,7 @@ pub(crate) fn insert(app: &mut SlideApp, row: &mut RibbonRow<'_>) { }); }); row.group(RibbonGroup::new("pictures", "Images", Icon::Picture.id().into()), |ui| { - Button::command("app.insertPictureDialog").icon(Icon::Picture.id()).arrangement(Arrangement::Stacked).show(ui); + Button::command("app.insertPictureDialog").label("Pictures").icon(Icon::Picture.id()).arrangement(Arrangement::Stacked).show(ui); photo_album_button(app, ui); Button::new("Screenshot") .icon(Icon::Screenshot.id()) diff --git a/crates/ui-egui/src/ribbon_names_tests.rs b/crates/ui-egui/src/ribbon_names_tests.rs new file mode 100644 index 000000000..8ce0a6e71 --- /dev/null +++ b/crates/ui-egui/src/ribbon_names_tests.rs @@ -0,0 +1,34 @@ +use crate::{Services, Session}; +use egui::accesskit::Role; +use egui_kittest::kittest::Queryable as _; +use serde_json::json; + +/// The ribbon's controls answer to the names a screen reader user or an agent reaches them by: a split button's arrow +/// part is "