From b7bbc7f80cac60046d3f3aa1ddc39994f2e7bd3d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 21 Nov 2026 23:35:57 -0500 Subject: [PATCH] Dialogs look: extract and header/footer explain refusals, OCR note above footer, compare shows 1-3, replace and number show totals, word count refusal alone --- crates/ui-egui/src/dialogs/marks_ui.rs | 4 +++ crates/ui-egui/src/dialogs/page_dialogs.rs | 37 +++++++++++++++++---- crates/ui-egui/src/dialogs/word_count_ui.rs | 6 +++- crates/ui-egui/src/workflows/compare_ui.rs | 6 +++- crates/ui-egui/src/workflows/ocr_ui.rs | 4 +-- crates/ui-egui/tests/it/min_window.rs | 11 ++++++ crates/ui-egui/tests/it/pickers.rs | 1 + 7 files changed, 57 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/dialogs/marks_ui.rs b/crates/ui-egui/src/dialogs/marks_ui.rs index 40b1b2796a..bc28337289 100644 --- a/crates/ui-egui/src/dialogs/marks_ui.rs +++ b/crates/ui-egui/src/dialogs/marks_ui.rs @@ -924,6 +924,7 @@ impl PdfCraftApp { let has_file = fields.text("file.path").is_some_and(|p| !p.is_empty()); let notes = notes_of(kind, &draft, has_file, &geometry, &selection); let applies = notes.applies; + let refusal = notes.reason.clone(); let mut dialog = ParamDialog::new(dialog_key(kind), heading.clone(), rows(kind, &geometry)) .values(craft::ui::contract::Bind::bound(fields)) .previews(true) @@ -939,6 +940,9 @@ impl PdfCraftApp { } else { crate::i18n::fmt(tl!("Applies to {n} pages"), &[("n", &applies.to_string())]) }; + if let Some(reason) = &refusal { + Text::new(reason.clone()).tone(craft::theme::variant::Tone::Bad).show(ui); + } Text::new(applies).show(ui); if replace { Text::new(tl!("Replaces the existing one on those pages.")).show(ui); diff --git a/crates/ui-egui/src/dialogs/page_dialogs.rs b/crates/ui-egui/src/dialogs/page_dialogs.rs index f4198eed4c..912bf97f22 100644 --- a/crates/ui-egui/src/dialogs/page_dialogs.rs +++ b/crates/ui-egui/src/dialogs/page_dialogs.rs @@ -5,8 +5,10 @@ use std::sync::Arc; use craft::pages::ui::{PageRangeChoices, PageRangeOptions}; use craft::pages::{PageRange, PageScope, Subset}; -use craft::ui::contract::Bind; +use craft::theme::variant::Tone; +use craft::ui::contract::{Bind, Show as _}; use craft::ui::dialog::{DialogResult, dialog_id}; +use craft::ui::display::Text; use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamResult}; use craft::ui::runtime::env::Label; use craft::ui::runtime::memory::SaveKey; @@ -123,18 +125,25 @@ impl ExtractFacts { some => some, }; let chosen = pages_to_extract(&typed, self.selected.clone(), self.count); + let message = match &chosen { + Ok(pages) if pages.len() == 1 => tl!("1 page selected.").to_string(), + Ok(pages) => fmt(tl!("{n} pages selected."), &[("n", &pages.len().to_string())]), + Err(e) => e.clone(), + }; + let bad = chosen.is_err(); let params = vec![ Param::new("pages", tl!("Pages"), ParamKind::text("")).hint(hint), + Param::custom("pages-message", "", move |ui, _, _| { + let text = Text::new(message.clone()); + if bad { text.tone(Tone::Bad).show(ui) } else { text.show(ui) } + }) + .full_width(), Param::new("name", tl!("File name"), ParamKind::text("")), Param::new("delete", tl!("Delete pages after extracting"), ParamKind::bool(false)), Param::new("separate", tl!("Extract pages as separate files"), ParamKind::bool(false)), ]; let dialog = ParamDialog::new(EXTRACT, tl!("Extract pages"), params).ok_label(tl!("Extract").into()).values(Bind::bound(fields)); - match chosen { - Ok(pages) if pages.len() == 1 => dialog.footer_note(tl!("1 page selected.")), - Ok(pages) => dialog.footer_note(fmt(tl!("{n} pages selected."), &[("n", &pages.len().to_string())])), - Err(e) => dialog.ok_enabled(false).ok_reason(e.into()), - } + dialog.ok_enabled(chosen.is_ok()) } } @@ -223,7 +232,7 @@ fn number_dialog<'b>(fields: &'b mut DialogFields, count: usize) -> ParamDialog< let last = count.max(1) as i64; let params = vec![ Param::new("from", tl!("Pages"), ParamKind::int(Some(1), Some(last), 1)), - Param::new("to", tl!("to"), ParamKind::int(Some(1), Some(last), last)), + Param::new("to", fmt(tl!("to (of {n})"), &[("n", &count.to_string())]), ParamKind::int(Some(1), Some(last), last)), Param::new( "style", tl!("Style"), @@ -277,6 +286,20 @@ impl ReplaceSource { fmt(tl!("Replacement: pages of {name}"), &[("name", &self.name)]), ParamKind::int(Some(1), Some(max_start as i64), 1), ), + Param::read_only_text( + "totals", + "", + fmt( + tl!("Original: {n} pages. Replacement: pages {a} to {b} of {m}."), + &[ + ("n", &count.to_string()), + ("a", &src_from.to_string()), + ("b", &(src_from + n.saturating_sub(1)).to_string()), + ("m", &self.src_pages.to_string()), + ], + ), + ) + .full_width(), ]; let note = if fits { tl!("Only the page content changes: links, comments, form fields and bookmarks on the original pages stay.") diff --git a/crates/ui-egui/src/dialogs/word_count_ui.rs b/crates/ui-egui/src/dialogs/word_count_ui.rs index 2c0d20aa38..c4348aa79a 100644 --- a/crates/ui-egui/src/dialogs/word_count_ui.rs +++ b/crates/ui-egui/src/dialogs/word_count_ui.rs @@ -114,9 +114,13 @@ impl StackDialog for WordCountDialog { } fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { - let WordCountDialog { options, shown, done, .. } = self; + let WordCountDialog { options, shown, done, key, .. } = self; let close = FooterButton::new(tl!("Close").to_string(), DialogRole::Cancel); let out = FormDialog::new(tl!("Word count").to_string(), Bind::bound(options)).shaped(|d| d.buttons([close])).show(ui, |ui, _, o| { + if key.is_none() && let Some(Err(error)) = shown { + Text::new(error.clone()).show(ui); + return true; + } Checkbox::new(Bind::bound(&mut o.current_page)).label(tl!("Current page only").to_string()).show(ui); Checkbox::new(Bind::bound(&mut o.options.exclude_tables)).label(tl!("Exclude tagged tables").to_string()).show(ui); Checkbox::new(Bind::bound(&mut o.options.exclude_code)).label(tl!("Exclude tagged code blocks").to_string()).show(ui); diff --git a/crates/ui-egui/src/workflows/compare_ui.rs b/crates/ui-egui/src/workflows/compare_ui.rs index 444387a91d..64cf04f30f 100644 --- a/crates/ui-egui/src/workflows/compare_ui.rs +++ b/crates/ui-egui/src/workflows/compare_ui.rs @@ -86,7 +86,11 @@ pub(crate) fn open_compare_dialog(app: &mut PdfCraftApp, ctx: &egui::Context) { let pages_ok = parse_pages(fields.text("pages").unwrap_or_default(), count).is_ok(); let options = others.iter().map(|(key, name)| (key.clone(), name.clone().into())).collect(); let pages = Param::custom("pages", tl!("Pages").to_string(), move |ui, fields, _| { - let shown = parse_pages(fields.text("pages").unwrap_or_default(), count).unwrap_or_default(); + let mut shown = parse_pages(fields.text("pages").unwrap_or_default(), count).unwrap_or_default(); + if shown.is_empty() { + // An empty entry compares every page, so the field shows them all (1-3). + shown = (0..count).collect(); + } let out = PageRangeField::new(tl!("Pages").to_string(), &shown, count, 0).show(ui); if let Some(picked) = out.picked { fields.set("pages", format_pages(&picked)); diff --git a/crates/ui-egui/src/workflows/ocr_ui.rs b/crates/ui-egui/src/workflows/ocr_ui.rs index 89b631e6e9..7d3806e34f 100644 --- a/crates/ui-egui/src/workflows/ocr_ui.rs +++ b/crates/ui-egui/src/workflows/ocr_ui.rs @@ -469,9 +469,7 @@ fn recognize_dialog(fields: &mut DialogFields, count: usize, current: usize) -> .ok_enabled(reason.is_none()) .values(Bind::bound(fields)); if let Some(note) = download_notice.or_else(|| reason.clone()) { - dialog = dialog.below(move |ui, _| { - let _ = Text::new(Label::from(note.clone())).show(ui); - }); + dialog = dialog.footer_note(Label::from(note)); } if let Some(why) = reason { dialog = dialog.ok_reason(Label::from(why)); diff --git a/crates/ui-egui/tests/it/min_window.rs b/crates/ui-egui/tests/it/min_window.rs index 17484dda22..5020a39205 100644 --- a/crates/ui-egui/tests/it/min_window.rs +++ b/crates/ui-egui/tests/it/min_window.rs @@ -82,6 +82,17 @@ fn protected_with(algorithm: pdfcraft_cos::Algorithm, user: &str, owner: &str, p pdfcraft_cos::write_full(&doc, &Default::default()).unwrap() } +#[test] +fn word_count_refusal_hides_options_when_copying_is_forbidden() { + let mut h = harness(egui::vec2(1200.0, 900.0)); + let ctx = h.ctx.clone(); + h.state_mut().open_bytes(&ctx, "locked.pdf", None, protected("", "owner", 0b0100)).unwrap(); + h.state_mut().run_command(&ctx, "file.word_count"); + h.run_steps(4); + assert!(h.query_by_label("Current page only").is_none(), "options are unavailable when copying is forbidden"); + assert!(h.query_by_label_contains("security settings don't allow copying").is_some(), "the refusal explains why"); +} + /// A narrow window: the stacked notice bar keeps both buttons inside the window and apart. #[test] fn the_stacked_notice_keeps_its_buttons_in_view() { diff --git a/crates/ui-egui/tests/it/pickers.rs b/crates/ui-egui/tests/it/pickers.rs index 02f439bac0..9c88acbd5e 100644 --- a/crates/ui-egui/tests/it/pickers.rs +++ b/crates/ui-egui/tests/it/pickers.rs @@ -470,6 +470,7 @@ fn extract_pages_takes_the_page_ranges_typed_in_the_dialog() { h.state_mut().active = Some(0); open_extract(&mut h, Extract { pages: Some("2, 9"), ..Default::default() }); assert!(h.get_all_by_label("Extract").last().unwrap().accesskit_node().is_disabled(), "Extract is off"); + assert!(h.query_all_by_label("page 9 is out of range (1–6)").next().is_some(), "the invalid range is explained"); press(&mut h, "Cancel"); assert_eq!(h.state().views.len(), 2, "nothing extracted"); // Extract and delete takes the typed pages out of the document.