diff --git a/crates/ui-egui/src/dialogs/marks_ui.rs b/crates/ui-egui/src/dialogs/marks_ui.rs index bc28337289..38d3673e15 100644 --- a/crates/ui-egui/src/dialogs/marks_ui.rs +++ b/crates/ui-egui/src/dialogs/marks_ui.rs @@ -918,7 +918,7 @@ impl PdfCraftApp { let heading = title(kind, replace); // Passed inline: a closure made apart from the call gets one lifetime for its argument and result. // PLAN: assumed `self.dialogs: DialogHost`, `self.host`/`self.wake` (pdf-hub-w1 note 11) - let dialog = HostedParamDialog::new(ctx, dialog_key(kind), fields, move |fields: &mut DialogFields| { + let mut dialog = HostedParamDialog::new(ctx, dialog_key(kind), fields, move |fields: &mut DialogFields| { let mut draft = base.clone(); read_fields(&mut draft, fields, kind, &units); let has_file = fields.text("file.path").is_some_and(|p| !p.is_empty()); @@ -953,6 +953,8 @@ impl PdfCraftApp { } dialog }); + // The pager row is there from the first pass, so the dialog is sized with its row. + dialog.set_preview_pager(Some(PanePager { shown: current + 1, count, shown_label: None, back: false, next: false, unit: PagerUnit::Page })); self.dialogs.open(dialog); self.marks_preview = Some(MarksPreview::new(kind, self.host.jobs_shared().clone(), self.wake.clone())); } diff --git a/crates/ui-egui/src/editing/close.rs b/crates/ui-egui/src/editing/close.rs index f4c2810404..9b7f0fd8b5 100644 --- a/crates/ui-egui/src/editing/close.rs +++ b/crates/ui-egui/src/editing/close.rs @@ -277,6 +277,7 @@ impl PdfCraftApp { .title(crate::i18n::fmt(template, &[("name", &shown)])) .message(tl!("Your changes will be lost if you don't save them.")) .icon(craft::behavior::IconId::new("save")) + .dont_save_label(tl!("Don't save")) }; self.close_guard_dialog = Some(self.dialogs.open(dialog)); } diff --git a/crates/ui-egui/src/menus/tab_context.rs b/crates/ui-egui/src/menus/tab_context.rs index 42f7132280..96c7903b80 100644 --- a/crates/ui-egui/src/menus/tab_context.rs +++ b/crates/ui-egui/src/menus/tab_context.rs @@ -126,9 +126,9 @@ mod tests { use craft::i18n::WordSet as _; let dialog = craft::ui::dialog::DialogWords::english(); let common = craft::ui::runtime::words::CommonWords::english(); - // The app words the question as a document app does on every platform (document_wording). - let dont_save = dialog.unsaved_dont_save; - (dont_save.as_str().to_string(), common.cancel.as_str().to_string()) + // The app words the question as production does on every platform: "Don't save", in lower case. + let _ = dialog; + ("Don't save".to_string(), common.cancel.as_str().to_string()) } #[test] diff --git a/crates/ui-egui/tests/it/editing.rs b/crates/ui-egui/tests/it/editing.rs index 8169faea8c..80ddb72b7c 100644 --- a/crates/ui-egui/tests/it/editing.rs +++ b/crates/ui-egui/tests/it/editing.rs @@ -50,14 +50,14 @@ fn scripted_app() -> PdfCraftApp { crate::control::app_with_files(FILES.with(std::sync::Arc::clone)) } -/// The unsaved-changes question's Save answer in the platform's words (the framework dialog asks Yes and No off macOS). +/// The unsaved-changes question's Save answer in the platform's words (production's wording, on every platform). fn save_answer() -> &'static str { - if cfg!(target_os = "macos") { "Save" } else { "Yes" } + "Save" } /// The unsaved-changes question's Don't Save answer in the platform's words. fn dont_save() -> &'static str { - if cfg!(target_os = "macos") { "Don't Save" } else { "No" } + "Don't save" } /// The next Save's picker answers `path`. @@ -544,7 +544,7 @@ fn closing_a_dirty_tab_asks_and_cancel_keeps_it() { h.run_steps(3); h.key_press_modifiers(Modifiers::COMMAND, Key::W); h.run_steps(3); - h.get_by_label_contains("save the changes you made to “doc.pdf”"); + assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some()); h.get_by_label("Cancel").click(); h.run_steps(3); assert_eq!(h.state().views.len(), 1, "cancel keeps the document open"); @@ -568,7 +568,7 @@ fn closing_a_dirty_tab_can_save_first() { let ctx_h = h.ctx.clone(); h.state_mut().request_close_tab(&ctx_h, 0); h.run_steps(2); - h.get_by_label(save_answer()).click(); + h.query_all_by_label(save_answer()).last().expect("the prompt's Save button").click(); h.run_steps(3); assert!(h.state().views.is_empty()); let saved = pdfcraft_render::inspect(std::sync::Arc::new(saved_file(&out)), None).unwrap(); @@ -578,15 +578,15 @@ fn closing_a_dirty_tab_can_save_first() { #[test] fn the_save_prompt_answers_to_the_keyboard() { - // Issue #8: Enter saves; ⌘D / Ctrl+D and, off macOS, Alt+N (the button's letter) don't save; + // Issue #8: Enter saves; ⌘D / Ctrl+D and Alt+D (the Don't save button's letter) don't save; // Escape cancels. While the prompt is open, ⌘D is not Document properties. - for (m, key) in [(Modifiers::COMMAND, Key::D), (Modifiers::ALT, Key::N)] { + for (m, key) in [(Modifiers::COMMAND, Key::D), (Modifiers::ALT, Key::D)] { let mut h = organize(2); h.get_by_label("Rotate clockwise").click(); h.run_steps(3); h.key_press_modifiers(Modifiers::COMMAND, Key::W); h.run_steps(3); - h.get_by_label_contains("save the changes you made to “doc.pdf”"); + assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some()); h.key_press_modifiers(m, key); h.run_steps(3); assert!(h.state().views.is_empty(), "{m:?}+{key:?} doesn't save and closes"); @@ -621,7 +621,7 @@ fn dirty_prompt() -> Harness<'static, PdfCraftApp> { h.run_steps(3); h.key_press_modifiers(Modifiers::COMMAND, Key::W); h.run_steps(3); - h.get_by_label_contains("save the changes you made to “doc.pdf”"); + assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some()); h } @@ -703,7 +703,7 @@ fn keys_leave_the_document_under_a_dialog_alone() { assert_eq!(h.state().views[0].target_pages(), [1], "Escape went to the dialog, not the page selection"); h.key_press_modifiers(Modifiers::COMMAND, Key::W); h.run_steps(3); - h.get_by_label_contains("save the changes you made to “doc.pdf”"); // with the dialog closed, ⌘W asks to close the file again + assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some()); // with the dialog closed, ⌘W asks to close the file again } #[test] @@ -729,10 +729,10 @@ fn quitting_with_unsaved_changes_asks_for_each_document() { } h.key_press_modifiers(Modifiers::COMMAND, Key::Q); h.run_steps(3); - h.get_by_label_contains("save the changes you made to “doc.pdf”"); + assert!(h.query_all_by_label_contains("Save changes to “doc.pdf”").next().is_some()); h.get_by_label(dont_save()).click(); h.run_steps(3); - h.get_by_label_contains("save the changes you made to “second.pdf”"); + assert!(h.query_all_by_label_contains("Save changes to “second.pdf”").next().is_some()); h.get_by_label(dont_save()).click(); h.run_steps(3); assert!(h.state().views.is_empty()); @@ -997,11 +997,11 @@ fn save_prompt_stays_inside_the_screen_for_a_long_filename() { h.run_steps(4); let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1365.0, 719.0)); let inside = |r: egui::Rect| screen.contains(r.min) && screen.contains(r.max); - let title = h.get_by_label_contains("save the changes you made to"); + let title = h.query_all_by_label_contains("Save changes to").last().expect("the prompt's title"); let title_rect = title.rect(); assert!(inside(title_rect), "the title rect {title_rect:?} leaves the screen"); for button in [save_answer(), "Cancel", dont_save()] { - let rect = h.get_by_label(button).rect(); + let rect = h.query_all_by_label(button).last().unwrap_or_else(|| panic!("no {button} button")).rect(); assert!(inside(rect), "the {button} button rect {rect:?} leaves the screen"); } } @@ -1039,16 +1039,16 @@ fn save_prompt_fits_the_smallest_window_whatever_the_name() { h.run_steps(4); let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, size); let inside = |r: egui::Rect| screen.contains(r.min) && screen.contains(r.max); - let title = h.get_by_label_contains("save the changes you made to"); + let title = h.query_all_by_label_contains("Save changes to").last().expect("the prompt's title"); let title_rect = title.rect(); assert!(inside(title_rect), "{start}…: the title rect {title_rect:?} leaves the screen"); - let opening = format!("Do you want to save the changes you made to “{start}"); + let opening = format!("Save changes to “{start}"); assert!( - h.query_by(|n| n.value().is_some_and(|l| l.starts_with(&opening) && l.contains('…') && l.contains(".pdf” before closing?"))).is_some(), + h.query_all_by(|n| n.label().or(n.value()).is_some_and(|l| l.starts_with(&opening) && l.contains('…') && l.contains(".pdf” before closing?"))).next().is_some(), "{start}…: the title keeps the start and the extension" ); for button in [save_answer(), "Cancel", dont_save()] { - let rect = h.get_by_label(button).rect(); + let rect = h.query_all_by_label(button).last().unwrap_or_else(|| panic!("no {button} button")).rect(); assert!(inside(rect), "{start}…: the {button} button rect {rect:?} leaves the screen"); } } diff --git a/crates/ui-egui/tests/it/forms.rs b/crates/ui-egui/tests/it/forms.rs index 1bb0d1ee09..fa70697b94 100644 --- a/crates/ui-egui/tests/it/forms.rs +++ b/crates/ui-egui/tests/it/forms.rs @@ -67,12 +67,12 @@ fn card_count(h: &Harness<'static, PdfCraftApp>) -> usize { /// Whether the "Save changes?" prompt is on screen. fn asks_to_save(h: &Harness<'static, PdfCraftApp>) -> bool { - h.query_by_role_and_label(egui::accesskit::Role::Dialog, "Unsaved changes").is_some() + h.query_by(|n| n.role() == egui::accesskit::Role::Dialog && n.label().is_some_and(|l| l.starts_with("Save changes to “"))).is_some() } -/// The unsaved-changes question's Save answer in the platform's words (the framework dialog asks Yes and No off macOS). +/// The unsaved-changes question's Save answer in the platform's words (production's wording, on every platform). fn save_answer() -> &'static str { - if cfg!(target_os = "macos") { "Save" } else { "Yes" } + "Save" } fn harness() -> Harness<'static, PdfCraftApp> { diff --git a/crates/ui-egui/tests/it/pickers.rs b/crates/ui-egui/tests/it/pickers.rs index 9c88acbd5e..954194e5c5 100644 --- a/crates/ui-egui/tests/it/pickers.rs +++ b/crates/ui-egui/tests/it/pickers.rs @@ -145,22 +145,14 @@ fn settle(r: &mut Rig, what: &str, ready: impl Fn(&PdfCraftApp) -> bool) { panic!("timed out waiting for {what}"); } -/// The unsaved-changes question's "save it" answer as the framework words it on this OS: Save on macOS, Yes on -/// Windows and Linux. +/// The unsaved-changes question's "save it" answer, in production's words on every platform. fn save_answer() -> String { - use craft::i18n::WordSet as _; - let words = craft::ui::dialog::DialogWords::english(); - let save = if cfg!(target_os = "macos") { words.unsaved_save } else { words.unsaved_yes }; - save.as_str().to_string() + "Save".to_string() } -/// The unsaved-changes question's "don't save" answer as the framework words it on this OS: Don't Save on macOS, -/// No on Windows and Linux. +/// The unsaved-changes question's "don't save" answer, in production's words on every platform. fn dont_save_answer() -> String { - use craft::i18n::WordSet as _; - let words = craft::ui::dialog::DialogWords::english(); - let discard = if cfg!(target_os = "macos") { words.unsaved_dont_save } else { words.unsaved_no }; - discard.as_str().to_string() + "Don't save".to_string() } /// Presses the button called `label` of the dialog on top (the last such node drawn). diff --git a/crates/ui-egui/tests/it/recovery.rs b/crates/ui-egui/tests/it/recovery.rs index a9e5791eac..2133d88f51 100644 --- a/crates/ui-egui/tests/it/recovery.rs +++ b/crates/ui-egui/tests/it/recovery.rs @@ -129,7 +129,7 @@ fn leftovers(dir: &Path) -> Vec { /// The label of the question's "don't save" button on this platform. fn dont_save() -> &'static str { // PLAN: the words come from `DialogWords` (`unsaved_dont_save` on macOS, `unsaved_no` elsewhere); literal here as the catalog's English. - if cfg!(target_os = "macos") { "Don't Save" } else { "No" } + "Don't save" } #[test] diff --git a/crates/ui-egui/tests/it/signing.rs b/crates/ui-egui/tests/it/signing.rs index cf662206e4..77e51974cf 100644 --- a/crates/ui-egui/tests/it/signing.rs +++ b/crates/ui-egui/tests/it/signing.rs @@ -288,8 +288,8 @@ fn verify_dirty_snapshot_close(h: &mut Harness<'static, PdfCraftApp>) { h.state_mut().views[1].close_requested = true; h.run_steps(2); assert_eq!(h.state().views.len(), 2); - h.get_by_label("Do you want to save the changes you made to “contract_signed (signed version).pdf” before closing?"); - let discard = if cfg!(target_os = "macos") { "Don't Save" } else { "No" }; + assert!(h.query_all_by_label("Save changes to “contract_signed (signed version).pdf” before closing?").next().is_some()); + let discard = "Don't save"; h.query_all_by_label(discard).last().expect("the question has a Don't Save / No button").click(); h.run_steps(2); assert_eq!(h.state().views.len(), 1); diff --git a/crates/ui-egui/tests/it/split_view.rs b/crates/ui-egui/tests/it/split_view.rs index 5910eb6614..9f40291b78 100644 --- a/crates/ui-egui/tests/it/split_view.rs +++ b/crates/ui-egui/tests/it/split_view.rs @@ -24,9 +24,7 @@ fn page_size(s: &PdfCraftApp, i: usize) -> Option { /// The label of the unsaved-changes dialog's "don't keep the changes" answer on this OS, as the /// framework words it. fn dont_save() -> String { - use craft::i18n::WordSet as _; - let words = craft::ui::dialog::DialogWords::english(); - if cfg!(target_os = "macos") { words.unsaved_dont_save } else { words.unsaved_no }.as_str().to_owned() + "Don't save".to_owned() } /// `pages` portrait pages (300 × 400) with a line of text each. diff --git a/crates/ui-egui/tests/it/ui.rs b/crates/ui-egui/tests/it/ui.rs index 96443df76a..021985dcb8 100644 --- a/crates/ui-egui/tests/it/ui.rs +++ b/crates/ui-egui/tests/it/ui.rs @@ -1598,7 +1598,7 @@ fn cancelling_then_discarding_an_earlier_dirty_tab_preserves_the_selected_docume h.run_steps(3); h.get_by_label("middle.pdf").click(); h.run_steps(3); - let discard = if cfg!(target_os = "macos") { "Don't Save" } else { "No" }; + let discard = "Don't save"; close_named_tab(&mut h, "first.pdf, modified"); h.get_by_label(discard); h.get_by_label("Cancel").click(); @@ -1612,7 +1612,7 @@ fn cancelling_then_discarding_an_earlier_dirty_tab_preserves_the_selected_docume assert_eq!(h.state().active_ids().map(|(_, id)| id), Some(ids[1])); assert_eq!(h.state().views.iter().map(|view| view.id).collect::>(), [ids[1], ids[2]]); assert!(h.state().session.get(ids[0]).is_none()); - assert!(h.query_by_role_and_label(egui::accesskit::Role::Dialog, "Unsaved changes").is_none(), "no prompt is left"); + assert!(h.query_by_label_contains("before closing?").is_none(), "no prompt is left"); for doc in h.state().session.docs() { assert_eq!(doc.bytes.as_slice(), FIXTURE); assert!(!doc.dirty); diff --git a/crates/ui-egui/tests/it/updates.rs b/crates/ui-egui/tests/it/updates.rs index 0ce1bf8bb4..e597f3658d 100644 --- a/crates/ui-egui/tests/it/updates.rs +++ b/crates/ui-egui/tests/it/updates.rs @@ -251,7 +251,7 @@ fn saving_at_the_restart_question_writes_the_file_and_quits() { let (mut h, path) = app_with_unsaved_file("save"); restart_to_update(&mut h); assert!(!h.state().dialogs.open_dialogs().is_empty(), "the unsaved-changes question is on the host"); - let accept = if cfg!(target_os = "macos") { "Save" } else { "Yes" }; + let accept = "Save"; h.query_all_by_label(accept).last().expect("the question has a Save/Yes button").click(); let quit = crate::support::step_until(&mut h, |h| close_requested(h)); assert!(quit, "the app quits once the document is saved"); diff --git a/crates/ui-egui/tests/it/viewer.rs b/crates/ui-egui/tests/it/viewer.rs index b7e6fce7d7..634071fbbd 100644 --- a/crates/ui-egui/tests/it/viewer.rs +++ b/crates/ui-egui/tests/it/viewer.rs @@ -135,7 +135,7 @@ fn close_all_asks_only_for_changed_documents() { h.run_steps(2); assert_eq!(h.state().views.len(), 1, "the clean document closed at once"); // b.pdf asks to be saved: the close dialog is on screen. - h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Unsaved changes"); + assert!(h.query_all_by_label_contains("Save changes to “").next().is_some()); } #[test]