diff --git a/apps/pdfcraft-cli/src/ui.rs b/apps/pdfcraft-cli/src/ui.rs index 032b51642f..832140b16e 100644 --- a/apps/pdfcraft-cli/src/ui.rs +++ b/apps/pdfcraft-cli/src/ui.rs @@ -14,8 +14,7 @@ use super::{CliError, stdout_line}; /// One request to a running app's control channel (`pdfcraft --control PORT`). pub(crate) fn ui(args: &[String]) -> Result<(), CliError> { validate_options("ui", args, UI_OPTIONS)?; - let port = flag(args, "--control") - .ok_or("ui: missing --control PORT (start the app with `pdfcraft --control PORT`)")?; + let port = flag(args, "--control").ok_or("ui: missing --control PORT (start the app with `pdfcraft --control PORT`)")?; let port = control_port(port).map_err(|e| format!("ui: --control {port}: {e}"))?; let env = EnvNames::for_app("PDFCRAFT"); let env_token = std::env::var(&env.token).ok().filter(|v| !v.trim().is_empty()); @@ -28,9 +27,8 @@ pub(crate) fn ui(args: &[String]) -> Result<(), CliError> { let token = client_token(supplied.as_deref(), token_file_given.as_deref(), &FlagNames::default(), &env).map_err(|e| format!("ui: {e}"))?; let pos = positional(args, UI_OPTIONS); - let method = *pos - .first() - .ok_or("ui: missing method (state, inspect, click, move, release, type, key, command, commands, set, open, screenshot, …)")?; + let method = + *pos.first().ok_or("ui: missing method (state, inspect, click, move, release, type, key, command, commands, set, open, screenshot, …)")?; let method = if method.starts_with("ui.") { method.to_string() } else { format!("ui.{method}") }; let mut params = serde_json::Map::new(); for kv in pos.iter().skip(1) { diff --git a/crates/engine/src/catalog.rs b/crates/engine/src/catalog.rs index 8affb889f1..ced85412f3 100644 --- a/crates/engine/src/catalog.rs +++ b/crates/engine/src/catalog.rs @@ -84,7 +84,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ title: "Export to", items: &[ item("Microsoft Word (.docx)", "file-text", "export.docx", Ready), - item("Spreadsheet (.xlsx)", "grid","export.xlsx", Planned("M10")), + item("Spreadsheet (.xlsx)", "grid", "export.xlsx", Planned("M10")), item("Presentation (.pptx)", "presentation", "export.pptx", Ready), item("Image (PNG)", "image", "export.image", Ready), item("Export all images", "image", "export.all_images", Ready), @@ -107,8 +107,8 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ items: &[ item("Add text", "type", "sign.fill.text", Ready), item("Checkmark", "check", "sign.fill.check", Ready), - item("Cross", "close","sign.fill.cross", Ready), - item("Dot", "target","sign.fill.dot", Ready), + item("Cross", "close", "sign.fill.cross", Ready), + item("Dot", "target", "sign.fill.dot", Ready), item("Line", "minus", "sign.fill.line", Ready), item("Date", "clock-3", "sign.fill.date", Ready), item("Signature", "signature", "sign.fill.signature", Ready), @@ -130,11 +130,11 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ title: "Modify page", items: &[ item("Edit text & images", "text-cursor-input", "edit.edit_text", Ready), - item("Rotate pages", "rotate_cw","page.rotate", Ready), + item("Rotate pages", "rotate_cw", "page.rotate", Ready), item("Insert pages", "file-plus-2", "page.insert", Ready), item("Delete pages", "trash-2", "page.delete", Ready), item("Extract pages", "file-output", "page.extract", Ready), - item("Organize pages", "layout_grid","page.organize", Ready), + item("Organize pages", "layout_grid", "page.organize", Ready), ], }, ToolSection { @@ -144,7 +144,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ item("Image", "image-plus", "edit.image", Ready), menu_item("Header and footer", "heading", &["edit.header_footer", "edit.header_footer.update", "edit.header_footer.remove"]), menu_item("Watermark", "stamp", &["edit.watermark", "edit.watermark.update", "edit.watermark.remove"]), - item("Link", "link","edit.link", Ready), + item("Link", "link", "edit.link", Ready), item("Bates numbering", "hash", "edit.bates", Ready), menu_item("Background", "palette", &["edit.background", "edit.background.update", "edit.background.remove"]), item("Attach file", "paperclip", "edit.attach", Ready), @@ -191,8 +191,8 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ ToolSection { title: "Page options", items: &[ - item("Page grid", "layout_grid","page.organize", Ready), - item("Rotate", "rotate_cw","page.rotate", Ready), + item("Page grid", "layout_grid", "page.organize", Ready), + item("Rotate", "rotate_cw", "page.rotate", Ready), item("Delete", "trash-2", "page.delete", Ready), item("Extract", "file-output", "page.extract", Ready), item("Insert", "file-plus-2", "page.insert", Ready), @@ -206,7 +206,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ item("Set page boxes", "square-dashed-mouse-pointer", "page.boxes", Ready), item("Crop pages", "crop", "page.crop", Ready), item("Duplicate pages", "copy-plus", "page.duplicate", Ready), - item("Reverse pages", "swap_vertical","page.reverse", Ready), + item("Reverse pages", "swap_vertical", "page.reverse", Ready), item("Page labels", "tag", "page.number", Ready), item("Page transitions", "presentation", "page.transitions", Planned("M4")), ], @@ -226,8 +226,8 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ items: &[ item("Sticky note", "sticky-note", "comment.note", Ready), item("Highlight text", "highlighter", "comment.highlight", Ready), - item("Underline", "text_underline","comment.underline", Ready), - item("Strikethrough", "text_strikethrough","comment.strikeout", Ready), + item("Underline", "text_underline", "comment.underline", Ready), + item("Strikethrough", "text_strikethrough", "comment.strikeout", Ready), item("Squiggly underline", "spline", "comment.squiggly", Ready), item("Text box", "type", "comment.freetext", Ready), ], @@ -283,7 +283,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ title: "Protect", items: &[ item("Protect with password", "lock", "protect.password", Ready), - item("Remove hidden information", "eye_off","protect.remove_hidden", Ready), + item("Remove hidden information", "eye_off", "protect.remove_hidden", Ready), ], }, ToolSection { @@ -291,7 +291,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ items: &[ item("Encrypt with certificate", "file-lock-2", "protect.certificate", Planned("M8")), item("Security properties", "shield-check", "protect.properties", Ready), - item("Remove security", "lock_open","protect.remove", Ready), + item("Remove security", "lock_open", "protect.remove", Ready), ], }, ], @@ -306,7 +306,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ sections: &[ToolSection { title: "Redact", items: &[ - item("Redact text and images", "rectangle","redact.mark", Ready), + item("Redact text and images", "rectangle", "redact.mark", Ready), item("Redact pages", "file-x", "redact.pages", Ready), item("Find text and redact", "file-search", "redact.search", Ready), item("Set properties", "settings-2", "redact.properties", Ready), @@ -347,7 +347,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ item("Field properties", "settings-2", "form.field.properties", Ready), item("Tab order by rows", "rows-3", "form.tab_order.row", Ready), item("Tab order by columns", "columns-3", "form.tab_order.column", Ready), - item("Calculation order", "list_numbered","form.calculation_order", Ready), + item("Calculation order", "list_numbered", "form.calculation_order", Ready), item("Flatten form fields", "layers", "form.flatten", Ready), item("Import data", "file-input", "form.import_data", Ready), item("Export data", "file-output", "form.export_data", Ready), @@ -357,10 +357,10 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ title: "Add form components", items: &[ item("Text field", "text-cursor-input", "form.add.text", Ready), - item("Text field table", "grid","form.add.text_table", Ready), + item("Text field table", "grid", "form.add.text_table", Ready), item("Checkbox", "check-circle-2", "form.add.checkbox", Ready), item("Radio button", "circle", "form.add.radio", Ready), - item("Drop-down list", "chevron_down","form.add.combo", Ready), + item("Drop-down list", "chevron_down", "form.add.combo", Ready), item("List box", "list", "form.add.list", Ready), item("Button", "square", "form.add.button", Ready), item("Image field", "image", "form.add.image", Ready), @@ -482,7 +482,7 @@ pub static TOOL_GROUPS: &[ToolGroup] = &[ item("Open accessibility report", "file-text", "a11y.report", Ready), item("Add alternate text", "image", "a11y.alt_text", Ready), item("Tags panel", "tag", "a11y.tags", Ready), - item("Fix reading order", "list_numbered","a11y.reading_order", Planned("M12")), + item("Fix reading order", "list_numbered", "a11y.reading_order", Planned("M12")), ], }], }, diff --git a/crates/engine/src/session/save.rs b/crates/engine/src/session/save.rs index 2e26be4056..52085888ab 100644 --- a/crates/engine/src/session/save.rs +++ b/crates/engine/src/session/save.rs @@ -212,10 +212,12 @@ impl Session { // The working bytes hold typed Password-field values (#3926, #3944): a recovery file // is written from a copy without them, and none is written if that copy fails. let bytes = match d.editor.as_ref().filter(|e| pdfcraft_forms::has_password_values(&e.cos) || pdfcraft_xfa::has_password_values(&e.cos)) { - Some(e) => match writable(&e.cos).and_then(|c| write_incremental(&c, &SaveOptions::default()).map_err(|e| EditError::Write(e.to_string()))) { - Ok(b) => Arc::new(b), - Err(_) => return None, - }, + Some(e) => { + match writable(&e.cos).and_then(|c| write_incremental(&c, &SaveOptions::default()).map_err(|e| EditError::Write(e.to_string()))) { + Ok(b) => Arc::new(b), + Err(_) => return None, + } + } None => d.bytes.clone(), }; Some(RecoverySnapshot { diff --git a/crates/engine/src/signature_image.rs b/crates/engine/src/signature_image.rs index dde9c0cd62..f9a22f4084 100644 --- a/crates/engine/src/signature_image.rs +++ b/crates/engine/src/signature_image.rs @@ -220,7 +220,6 @@ impl SignatureImage { pdfcraft_sign::Graphic::Image { width: side(self.size[0]), height: side(self.size[1]), rgba: self.rgba.clone() } } - /// The user-space box for the image with its left edge at `at` (a user-space point on `page`), /// vertically centered, with the same 150 pt width cap as typed names. Left and centered are /// as displayed: on a page with `/Rotate` the box runs along the turned page's axes. diff --git a/crates/ui-egui/examples/properties_scenarios.rs b/crates/ui-egui/examples/properties_scenarios.rs index ec21861d41..348709479c 100644 --- a/crates/ui-egui/examples/properties_scenarios.rs +++ b/crates/ui-egui/examples/properties_scenarios.rs @@ -8,12 +8,12 @@ use std::io::{BufRead, Read, Write}; use std::path::PathBuf; use std::sync::Arc; +use craft::ui::dialog::dialog_id; +use craft::ui::patterns::form_dialogs::HostedParamDialog; use egui::accesskit::Role; use egui_kittest::Harness; use egui_kittest::kittest::{NodeT, Queryable}; use pdfcraft_engine::{DocId, Edit, Session}; -use craft::ui::dialog::dialog_id; -use craft::ui::patterns::form_dialogs::HostedParamDialog; use pdfcraft_ui_egui::{PdfCraftApp, PropsTab}; use serde::Deserialize; use serde_json::{Value, json}; diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index c4f7957c20..805f0ee88d 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -262,7 +262,6 @@ impl PdfCraftApp { blank_paper: crate::paper::Paper::system(), mode_override: None, left: LeftPanel::AllTools, - left_open: true, last_right: RightPanel::Comments, right_before_read: None, comments_panel_closed: false, @@ -471,7 +470,7 @@ impl PdfCraftApp { /// Fields are being edited (Prepare a form or its Calculation order is open, or a field tool /// is picked), unless the form is being previewed. pub fn is_preparing(&self) -> bool { - ((self.left_open && matches!(self.left, LeftPanel::Tool("form") | LeftPanel::CalculationOrder)) + ((self.left_open() && matches!(self.left, LeftPanel::Tool("form") | LeftPanel::CalculationOrder)) || matches!(self.quick_tool, QuickTool::Field(_))) && !self.form_preview } @@ -485,6 +484,16 @@ impl PdfCraftApp { side_panels::right_of(&self.dock) } + /// Whether the dock has the Tools panel open; Read mode and the expanded All tools view hide it without closing it. + pub fn left_open(&self) -> bool { + self.dock.layout.contains(&side_panels::PanelId::Tools) + } + + /// Opens or closes the Tools panel in the dock, the one record of it (L-136). + pub fn set_left_open(&mut self, open: bool) { + side_panels::set_panel_visible(self, side_panels::PanelId::Tools, open); + } + /// The app's root values for this frame: appearance mode, motion, interface scale and the /// interface language's direction. The one place the app's `RootEnv` is built. pub(crate) fn root_env(&self, ctx: &egui::Context) -> RootEnv { diff --git a/crates/ui-egui/src/app/clipboard.rs b/crates/ui-egui/src/app/clipboard.rs index 0b43cd50f1..0dab1742fa 100644 --- a/crates/ui-egui/src/app/clipboard.rs +++ b/crates/ui-egui/src/app/clipboard.rs @@ -84,8 +84,7 @@ impl PdfCraftApp { Ok(_) => true, Err(e) => { if let Some(t) = e.text() { - // PLAN: framework gap F-11: `PlatformText` has no catalog lookup, so its English text is the notice - self.notify_tr(t.english); + self.notify(crate::i18n::platform_text(t)); } false } diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index c81137aab0..c3f447b4d1 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -43,7 +43,7 @@ impl PdfCraftApp { } pub(crate) fn reveal_tools(&mut self) { - self.left_open = true; + self.set_left_open(true); } /// Enter a tool from the catalogue, Home, palette or control channel. Organize is a diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index ac58a18e95..592305267d 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -86,7 +86,7 @@ impl PdfCraftApp { let g = pdfcraft_engine::catalog::group(value).ok_or_else(|| format!("unknown tool {value}"))?; self.select_tool(ctx, g.id); } - ("left", _) => self.left_open = value != "closed", + ("left", _) => self.set_left_open(value != "closed"), ("home", _) => { self.active = None; // With no document open the expanded All tools view covers Home itself, so no diff --git a/crates/ui-egui/src/app/files.rs b/crates/ui-egui/src/app/files.rs index c708283b46..63e7d6e548 100644 --- a/crates/ui-egui/src/app/files.rs +++ b/crates/ui-egui/src/app/files.rs @@ -415,7 +415,7 @@ impl PdfCraftApp { self.portfolio_initial = portfolio_initial.map(|key| (id, key)); } if activate - && self.left_open + && self.left_open() && self.left == LeftPanel::Tool("organize") && let Some(view) = self.views.last_mut() { @@ -431,11 +431,10 @@ impl PdfCraftApp { } else if activate && self.mode != self.default_mode { // Switch workspace like the mode bar, but a left panel the user (or `--left closed`) // closed stays closed, and an unchanged mode keeps the tool panel the user chose. - let (left, left_open) = (self.left, self.left_open); + let left_open = self.left_open(); self.select_mode(ctx, self.default_mode); - if self.left_open != left_open { - self.left_open = left_open; - crate::side_panels::set_panel_visible(self, crate::side_panels::PanelId::from(left), left_open); + if self.left_open() != left_open { + self.set_left_open(left_open); } } if let Some(p) = path { diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index a40c2043c9..e5559019c6 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1457,8 +1457,6 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu // The room under the notice bars, inside the rect the caller gave. let rect = rect.intersect(ui.available_rect_before_wrap()); let preparing = app.is_preparing(); - // PLAN: assumed `side_panels::panel_visible(app, panel) -> bool` for the left panel's visibility (`left_open` is - // not a field after L-136; pdf-shell-w13 names only the setter). // Prepare a form ▸ Calculation order: the order's steps and links on the page. let calc_order = preparing && crate::side_panels::panel_visible(app, crate::LeftPanel::CalculationOrder); // Edit a PDF: added text and images can be selected, moved and edited. diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index 0140fb04b4..f3948d5547 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -405,7 +405,7 @@ impl PdfCraftApp { } } "view.side_panel" => self.toggle_side_panel(), - "view.tools_pane" => self.left_open = !self.left_open, + "view.tools_pane" => self.set_left_open(!self.left_open()), "view.focus_page_input" => { if let Some(view) = active.and_then(|i| self.views.get_mut(i)) { // The page box in the toolbar (chrome.rs); select its label so typing replaces it. diff --git a/crates/ui-egui/src/commands/catalog.rs b/crates/ui-egui/src/commands/catalog.rs index 5a2443e310..09ccb0f1a3 100644 --- a/crates/ui-egui/src/commands/catalog.rs +++ b/crates/ui-egui/src/commands/catalog.rs @@ -106,7 +106,7 @@ fn second_chords(id: &str) -> Vec { } /// The catalog for this platform's chords, built once. -fn shared_catalog(mac: bool) -> Option { +pub(crate) fn shared_catalog(mac: bool) -> Option { let cell = if mac { &CATALOG_MAC } else { &CATALOG_WIN }; cell.get_or_init(|| catalog(mac).ok()).clone() } @@ -206,7 +206,7 @@ fn checked(app: &PdfCraftApp, command: &CommandRef) -> Option { "view.full_screen" => app.full_screen(), "view.read_mode" => app.mode == Mode::Read, "view.side_panel" => app.right().is_some(), - "view.tools_pane" => app.left_open, + "view.tools_pane" => app.left_open(), "view.split" => app.panes.split.is_some(), "view.theme.system" => app.theme_preference == ModeChoice::System, "view.theme.light" => app.theme_preference == ModeChoice::Light, diff --git a/crates/ui-egui/src/control/host.rs b/crates/ui-egui/src/control/host.rs index 9752a8949f..4232b81184 100644 --- a/crates/ui-egui/src/control/host.rs +++ b/crates/ui-egui/src/control/host.rs @@ -144,7 +144,7 @@ impl crate::PdfCraftApp { "comment_tool_pinned": self.comment_prefs.pinned, // Home's pinned folders, in order, and whether each is folded down to its heading. "pinned_folders": self.pinned.folders.iter().map(|f| json!({ "folder": f, "collapsed": self.pinned.collapsed.contains(f) })).collect::>(), - "left_panel": if self.left_open { json!(format!("{:?}", self.left)) } else { Value::Null }, + "left_panel": if self.left_open() { json!(format!("{:?}", self.left)) } else { Value::Null }, "tools_side": dock["tools_side"].clone(), "rail_side": dock["rail_side"].clone(), "right_panel": self.right().map(|r| format!("{r:?}")), diff --git a/crates/ui-egui/src/dialogs/shortcuts.rs b/crates/ui-egui/src/dialogs/shortcuts.rs index a52442b613..5e4cd43987 100644 --- a/crates/ui-egui/src/dialogs/shortcuts.rs +++ b/crates/ui-egui/src/dialogs/shortcuts.rs @@ -66,8 +66,10 @@ impl PdfCraftApp { let mut options = Options::default(); options.editable = false; options.fixed = fixed_rows(ctx); - // PLAN: framework gap: `AppCatalog::defs` is `pub(crate)`, so the catalog's rows and scopes cannot reach `Keymap::new`; the dialog lists the fixed rows only until they are public - let keymap = Keymap::new(Vec::new(), Scopes::new(), Platform::current()); + // The catalog the keys run on; its rows are all app-scoped, so no panel or context scope is named. + let rows = + crate::commands::catalog::shared_catalog(crate::commands::mac_shortcuts(ctx)).map(|catalog| catalog.defs().to_vec()).unwrap_or_default(); + let keymap = Keymap::new(rows, Scopes::new(), Platform::current()); self.shortcuts = Some(ShortcutsSession { state: DialogState::new(), keymap, options }); } diff --git a/crates/ui-egui/src/dialogs/standards_ui.rs b/crates/ui-egui/src/dialogs/standards_ui.rs index 6db1a81fff..2a5854c99e 100644 --- a/crates/ui-egui/src/dialogs/standards_ui.rs +++ b/crates/ui-egui/src/dialogs/standards_ui.rs @@ -186,8 +186,12 @@ impl StackDialog for PdfaDialog { Some(v) => { let findings: Vec = v.iter().enumerate().map(|(n, i)| finding(n as u64, i)).collect(); FindingsSummary::new(&findings).show(ui); - FindingsList::new(tl!("PDF/A problems").to_string()) - .show_items(ui, &Findings::new(&findings), &mut |key, icx| findings[*key as usize].row(&icx.words::())); + // The dialog's body scrolls, so the list scrolls its own rows past a few. + FindingsList::new(tl!("PDF/A problems").to_string()).max_rows(8).show_items( + ui, + &Findings::new(&findings), + &mut |key, icx| findings[*key as usize].row(&icx.words::()), + ); } } true diff --git a/crates/ui-egui/src/editing/tests.rs b/crates/ui-egui/src/editing/tests.rs index 072b6b44d5..8c156ede12 100644 --- a/crates/ui-egui/src/editing/tests.rs +++ b/crates/ui-egui/src/editing/tests.rs @@ -157,8 +157,13 @@ fn moving_pages_cancels_an_in_progress_drawing() { pdf.extend_from_slice(format!("trailer\n<< /Size {} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n", objs.len() + 1).as_bytes()); // A polygon being clicked out on page 0, two points so far, drawn through the tool's pointer - // input; each click waits past the double-click time, so none ends the drawing. - let mut rig = ToolFixture::new("Document", AnnotateTool::new(AnnotationTool::Draw(AnnotationKind::Polygon), 0)); + // input; each click waits past the double-click time, so none ends the drawing. The view puts the page's (0, 0) at + // the canvas's top left corner at zoom 1, so the clicks land on the page. + let view = |room: egui::Rect| { + craft::behavior::CanvasView::new(room, craft::behavior::kurbo::Point::new(f64::from(room.width()) / 2.0, f64::from(room.height()) / 2.0), 1.0) + }; + let tool = AnnotateTool::new(AnnotationTool::Draw(AnnotationKind::Polygon), 0); + let mut rig = ToolFixture::with_view("Document", tool, view, |_, _| {}); for (x, y) in [(50.0, 50.0), (150.0, 50.0)] { let at = rig.canvas().rect.min + egui::vec2(x, y); let fixture = rig.fixture(); diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 7d5f5e8901..078368fb3c 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -574,6 +574,12 @@ pub fn tr_id<'a>(lang: Lang, id: &str, label: &'a str) -> &'a str { if own_id(lang, id, label) { lang.i18n().tid(lang.lang, id, label) } else { tr(lang, label) } } +/// A platform service's message in the current language: its catalog id's row, else the translation of its English. +pub fn platform_text(text: craft::platform::PlatformText) -> String { + let lang = current(); + lang.i18n().tid(lang.lang, text.key(), text.english).to_owned() +} + /// Whether `lang` has PdfCraft's own `@id` row for `id` ([`Lang::has_own`]: command ids are each /// app's own) and it keeps the `{placeholders}` and trailing `…` of the English `label`. craft-i18n /// can't check that, because an `@id` row's source is the id, so a row that doesn't is skipped diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index d69cf21366..2c5c9a9ca9 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -268,7 +268,6 @@ pub struct PdfCraftApp { /// Explicit CLI/control mode lasts for this session and is never persisted. mode_override: Option, pub left: LeftPanel, - pub left_open: bool, /// The side panel F4 reopens: the one open last. pub(crate) last_right: RightPanel, /// The right panel that was open when the user switched to Read mode, which starts with the diff --git a/crates/ui-egui/src/panels/all_tools_ui.rs b/crates/ui-egui/src/panels/all_tools_ui.rs index 75432ce38a..67baf41a2b 100644 --- a/crates/ui-egui/src/panels/all_tools_ui.rs +++ b/crates/ui-egui/src/panels/all_tools_ui.rs @@ -7,8 +7,9 @@ use std::hash::{Hash, Hasher}; use craft::behavior::{IconId, Selection}; use craft::i18n::matcher::Matcher; use craft::keymap::CommandRef; -use craft::ui::contract::{ActivateOn, Bind, CollectionEvent, SelectMode, Show as _, ShowCollection as _, ShowContainer as _}; +use craft::ui::contract::{ActivateOn, Bind, CollectionEvent, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _}; use craft::ui::primitives::IconSpec; +use craft::ui::runtime::focus::FocusRequest; use craft::ui::sections::{HeaderCommand, Panel}; use craft::ui::style::DataColor; use craft::ui::text::TextField; @@ -90,8 +91,10 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) { .titled() .commands([HeaderCommand::new(IconId::new("minimize-2"), CommandRef::new("tools.collapse"))]) .show(ui, |ui, _| { - // PLAN: framework gap F-6 (a one-shot focus request): the search field took focus when the view opened and nothing else had it. - TextField::search(tl!("Search tools and commands…").to_owned(), Bind::bound(&mut app.all_tools_query)).show(ui); + // The search field takes the keys whenever nothing else holds them, as it did when the view opened. + TextField::search(tl!("Search tools and commands…").to_owned(), Bind::bound(&mut app.all_tools_query)) + .request_focus(FocusRequest::WhenNone) + .show(ui); let query = app.all_tools_query.trim().to_owned(); let matcher = Matcher::new(&craft::i18n::Folder::new(crate::i18n::current().code()), &query); @@ -130,7 +133,7 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) { } }); if let Some(id) = chosen { - app.left_open = true; + app.set_left_open(true); app.select_tool(ui.ctx(), id); } } diff --git a/crates/ui-egui/src/panels/edit.rs b/crates/ui-egui/src/panels/edit.rs index 0e12073744..29fa30ac86 100644 --- a/crates/ui-egui/src/panels/edit.rs +++ b/crates/ui-egui/src/panels/edit.rs @@ -108,7 +108,7 @@ pub(super) fn edit_panel(app: &mut PdfCraftApp, ui: &mut egui::Ui, g: &'static T }); }); if shown.output.closed.is_some() || shown.output.action == Some(HeaderAction::Close) { - app.left_open = false; + app.set_left_open(false); } if let Some(id) = tool { app.select_tool(ui.ctx(), id); diff --git a/crates/ui-egui/src/panels/side_panels.rs b/crates/ui-egui/src/panels/side_panels.rs index cd3d12be58..6fcc4e36c6 100644 --- a/crates/ui-egui/src/panels/side_panels.rs +++ b/crates/ui-egui/src/panels/side_panels.rs @@ -12,7 +12,7 @@ use craft::behavior::{Axis, DockSide, IconId}; use craft::keymap::CommandRef; use craft::ui::buttons::IconButton; use craft::ui::contract::{Bind, BodyCx, Show as _}; -use craft::ui::docking::{DockConfig, DockPanels, GroupAt, HidePanels, PanelSpec}; +use craft::ui::docking::{DockConfig, DockPanels, GroupAt, HidePanels, IconicMode, PanelSpec}; use craft::ui::menu::PanelRow; use craft::ui::patterns::dock::DockArea; use craft::ui::primitives::IconSpec; @@ -449,21 +449,15 @@ pub fn dock(app: &mut PdfCraftApp, ui: &mut Ui) { PanelId::Tools => !read && !expanded, _ => active && !expanded && listed(panel), }; - // An icon of the side panels' collapsed column opens its panel docked, as production's rail buttons did, not in a - // flyout: the pick the area writes here becomes the panel shown. - let mut picked = None; - let output = DockArea::new("Dock", Bind::given(workspace), &mut panels, DockConfig::default().native_windows(false)) - .hide(HidePanels::Except(&shown)) - .flyout(Bind::bound(&mut picked)) - .show(ui); + // The side panels' icons are production's rail: they stay beside the expanded column, a click on one opens its + // panel docked, and a click on the open panel's icon closes it. + let config = DockConfig::default().native_windows(false).iconic_mode(IconicMode::Rail); + let output = DockArea::new("Dock", Bind::given(workspace), &mut panels, config).hide(HidePanels::Except(&shown)).show(ui); let before = right_of(&app.dock); for action in output.actions.into_iter().chain(output.requested) { // The area drops what the workspace refuses; one refused here is stale, not the user's mistake. drop(app.dock.apply(action, false, permissions)); } - if let Some(panel) = picked { - set_panel_visible(app, panel, true); - } let after = right_of(&app.dock); if after != before { app.right_panel_chosen(before, after); diff --git a/crates/ui-egui/src/platform/ui_scale.rs b/crates/ui-egui/src/platform/ui_scale.rs index 11bc8e472b..2aa51f0b83 100644 --- a/crates/ui-egui/src/platform/ui_scale.rs +++ b/crates/ui-egui/src/platform/ui_scale.rs @@ -98,16 +98,15 @@ mod tests { #[test] fn the_app_draws_at_the_system_scale_until_a_size_is_chosen() { - // A display that reports 200% (#456: a 1080p screen whose system reports 2×). - // PLAN: framework gap F-12: the harness's `SystemReader` has no text-scale setter, so Auto is checked at the - // display's scale alone until the lead rewires it. + // A display that reports 200% (#456: a 1080p screen whose system reports 2×), and a desktop text scale of 125%. let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 700.0)).with_pixels_per_point(2.0).build_eframe(|cc| { crate::PdfCraftApp::install_runtime(&cc.egui_ctx); + craft::ui::testing::style::report_os_text_scale(&cc.egui_ctx, Some(1.25)); crate::PdfCraftApp::for_unit_tests() }); h.run_steps(3); let ctx = h.ctx.clone(); - assert_eq!(ctx.pixels_per_point(), 2.0, "Auto follows the display's scale"); + assert_eq!(ctx.pixels_per_point(), 2.5, "Auto follows the display's scale and the system's text scale"); h.state_mut().set_option(&ctx, "ui-scale", "100%").expect("a valid size"); h.run_steps(3); assert_eq!(h.ctx.pixels_per_point(), 1.0, "100% is one screen pixel per point"); @@ -122,9 +121,9 @@ mod tests { assert_eq!(h.ctx.pixels_per_point(), 1.5, "the saved size is restored"); h.state_mut().apply_settings(&crate::app::settings::import_json(r#"{"ui_scale":1e30}"#).0); h.run_steps(3); - assert_eq!(h.ctx.pixels_per_point(), 2.0, "a hostile saved size is no choice"); + assert_eq!(h.ctx.pixels_per_point(), 2.5, "a hostile saved size is no choice"); h.state_mut().set_option(&ctx, "ui-scale", "auto").expect("auto"); h.run_steps(3); - assert_eq!(h.ctx.pixels_per_point(), 2.0); + assert_eq!(h.ctx.pixels_per_point(), 2.5); } } diff --git a/crates/ui-egui/src/tools/content_ui.rs b/crates/ui-egui/src/tools/content_ui.rs index 6bea6a8207..c516625729 100644 --- a/crates/ui-egui/src/tools/content_ui.rs +++ b/crates/ui-egui/src/tools/content_ui.rs @@ -1417,7 +1417,7 @@ impl crate::PdfCraftApp { self.views[i].session.image_selection = Some(crate::edit_text_ui::ImageSelection::at(page, before_img)); self.quick_tool = crate::QuickTool::EditText; self.left = crate::LeftPanel::Tool("edit"); - self.left_open = true; + self.set_left_open(true); } } diff --git a/crates/ui-egui/src/tools/measure_ui.rs b/crates/ui-egui/src/tools/measure_ui.rs index 605c0c2f2d..9c7f0d7448 100644 --- a/crates/ui-egui/src/tools/measure_ui.rs +++ b/crates/ui-egui/src/tools/measure_ui.rs @@ -823,7 +823,7 @@ impl ItemSource for MeasurementRows {} pub(crate) fn command(app: &mut PdfCraftApp, id: &str) { app.left = LeftPanel::Tool("measure"); - app.left_open = true; + app.set_left_open(true); if let Some((index, _)) = app.active_ids() && let Some(tool) = id.strip_prefix("measure.").and_then(Tool::from_name) { diff --git a/crates/ui-egui/src/workflows/ocr_ui.rs b/crates/ui-egui/src/workflows/ocr_ui.rs index 4fc52a2bde..35d39c7a4f 100644 --- a/crates/ui-egui/src/workflows/ocr_ui.rs +++ b/crates/ui-egui/src/workflows/ocr_ui.rs @@ -619,7 +619,7 @@ impl PdfCraftApp { fn scan_to_read(&mut self) -> Option { // Edit is on when its panel is open (the Edit tab) or Edit text & images or Add text is picked, // the same test the page view uses for editing content. - let editing = (self.left_open && self.left == crate::LeftPanel::Tool("edit")) + let editing = (self.left_open() && self.left == crate::LeftPanel::Tool("edit")) || matches!(self.quick_tool, crate::QuickTool::EditText | crate::QuickTool::AddText); // Not in Read mode (which leaves the Edit tool picked but is not editing) and not beneath a // dialog or prompt: nothing may change the document under those. It is tried again once @@ -1298,9 +1298,9 @@ mod tests { assert_eq!(found(&mut app), None, "another tool"); // The Edit tab's panel counts, as for the page view, with no tool picked. app.left = LeftPanel::Tool("edit"); - app.left_open = true; + app.set_left_open(true); assert_eq!(found(&mut app), Some(0), "the Edit panel"); - app.left_open = false; + app.set_left_open(false); assert_eq!(found(&mut app), None, "the Edit panel closed"); } diff --git a/crates/ui-egui/tests/it/compare.rs b/crates/ui-egui/tests/it/compare.rs index f34cf7cab3..038862bab3 100644 --- a/crates/ui-egui/tests/it/compare.rs +++ b/crates/ui-egui/tests/it/compare.rs @@ -190,7 +190,8 @@ fn pdfa_dialog_verifies_and_converts() { assert!(h.query_by_label("Remove PDF/A identification").is_none(), "nothing to remove yet"); h.get_by_label("Verify").click(); h.run_steps(3); - h.get_by_label("The document has no XMP metadata"); + // A finding's row is named by its text, then its clause and severity. + assert!(h.query_all_by_label_contains("The document has no XMP metadata").next().is_some(), "the missing XMP is a finding"); h.get_by_label("Save as PDF/A").click(); h.run_steps(3); h.get_by_label("Declared conformance: PDF/A-2b"); diff --git a/crates/ui-egui/tests/it/control.rs b/crates/ui-egui/tests/it/control.rs index 4c79911f55..bd3f294409 100644 --- a/crates/ui-egui/tests/it/control.rs +++ b/crates/ui-egui/tests/it/control.rs @@ -1825,8 +1825,8 @@ fn navigation_history_for_os(os: egui::os::OperatingSystem) { ok(&mut h, &c, "ui.set", json!({"key": "page", "value": "4"})); assert!(enabled(ok(&mut h, &c, "ui.commands", json!({})), "view.previous_view")); // The real rail button is accessible and invokes the same history, not the adjacent page. - let shortcut = if h.ctx.os() == egui::os::OperatingSystem::Mac { "⌘[" } else { "Ctrl+[" }; - ok(&mut h, &c, "ui.click", json!({"label": &format!("Previous view ({shortcut})")})); + // The toolbar names its slots by their commands (L-233). + ok(&mut h, &c, "ui.click", json!({"label": "Previous view"})); assert_eq!(h.state().views[0].current(), 0); assert!(enabled(ok(&mut h, &c, "ui.commands", json!({})), "view.next_view")); ok(&mut h, &c, "ui.command", json!({"id": "view.next_view"})); diff --git a/crates/ui-egui/tests/it/editing.rs b/crates/ui-egui/tests/it/editing.rs index 0d824d939a..1b94474a21 100644 --- a/crates/ui-egui/tests/it/editing.rs +++ b/crates/ui-egui/tests/it/editing.rs @@ -5847,7 +5847,7 @@ fn check_added_text_drag(panel_open: bool) { .unwrap(); let original = h.state().session.save_bytes(id).unwrap(); h = paragraph_drag_harness(original.as_ref().clone(), 0); - h.state_mut().left_open = panel_open; + h.state_mut().set_left_open(panel_open); h.run_steps(4); let added = |h: &Harness<'static, PdfCraftApp>| { let app = h.state(); diff --git a/crates/ui-egui/tests/it/fill_sign.rs b/crates/ui-egui/tests/it/fill_sign.rs index 86a8916970..ceb59e9ded 100644 --- a/crates/ui-egui/tests/it/fill_sign.rs +++ b/crates/ui-egui/tests/it/fill_sign.rs @@ -925,7 +925,7 @@ fn saved_signature_cards_remove_and_add_without_changing_the_document() { click(&mut h, 40.0, 300.0); let original = format!("{:?}", h.state().session.get(h.state().views[0].id).unwrap().info.annotations); h.state_mut().left = pdfcraft_ui_egui::LeftPanel::Tool("fill_sign"); - h.state_mut().left_open = true; + h.state_mut().set_left_open(true); h.run_steps(3); h.get_by_label("Use signature").click(); h.run_steps(2); @@ -2229,7 +2229,7 @@ fn the_first_save_after_placing_a_signature_asks_to_lock_it() { h.run_steps(2); assert!(h.query_by_label("Lock into the page when saving").is_none(), "the panel is closed"); h.state_mut().left = pdfcraft_ui_egui::LeftPanel::Tool("fill_sign"); - h.state_mut().left_open = true; + h.state_mut().set_left_open(true); h.run_steps(3); h.get_by_label("Use signature"); assert_eq!(h.query_all_by_label("Lock into the page when saving").count(), 1, "once, in the panel"); @@ -2697,7 +2697,7 @@ fn fill_and_sign_bar_controls_pick_tools_and_restyle_the_selection() { assert_eq!(h.state().quick_tool, QuickTool::Fill(FillTool::Signature)); assert!(!pad_open(h), "a saved signature opens no pad"); h.state_mut().left = pdfcraft_ui_egui::LeftPanel::Tool("fill_sign"); - h.state_mut().left_open = true; + h.state_mut().set_left_open(true); h.run_steps(3); assert_eq!(h.get_by_label("Use signature").accesskit_node().is_selected(), Some(true), "the active tool's card is marked"); h.execute("sign.fill.check"); diff --git a/crates/ui-egui/tests/it/pickers.rs b/crates/ui-egui/tests/it/pickers.rs index 041d8e5225..845c13e253 100644 --- a/crates/ui-egui/tests/it/pickers.rs +++ b/crates/ui-egui/tests/it/pickers.rs @@ -674,7 +674,7 @@ fn a_late_startup_url_preserves_the_current_edit_workspace_and_save_target() { h.state_mut().mode = Mode::Edit; h.set_option("panel", "pages").unwrap(); h.state_mut().left = LeftPanel::AllTools; - h.state_mut().left_open = false; + h.state_mut().set_left_open(false); h.state_mut().quick_tool = QuickTool::Hand; h.deliver("late.pdf", late); h.steps(2); @@ -683,7 +683,7 @@ fn a_late_startup_url_preserves_the_current_edit_workspace_and_save_target() { assert_eq!(h.state().mode, Mode::Edit); assert_eq!(crate::support::right(h.state()), Some(RightPanel::Pages)); assert_eq!(h.state().left, LeftPanel::AllTools); - assert!(!h.state().left_open); + assert!(!h.state().left_open()); assert_eq!(h.state().quick_tool, QuickTool::Hand); assert!(dirty(h.state(), 0)); assert_eq!(h.state().views.len(), 2, "the startup file remains available in its own tab"); diff --git a/crates/ui-egui/tests/it/pointer.rs b/crates/ui-egui/tests/it/pointer.rs index e0c30f5963..5743d92d1f 100644 --- a/crates/ui-egui/tests/it/pointer.rs +++ b/crates/ui-egui/tests/it/pointer.rs @@ -1502,7 +1502,7 @@ fn with_prepare_on_a_locked_document_a_right_click_on_a_field_selects_nothing() let mut h = open(locked, "150", false); // Prepare doesn't open on such a document; it stays open on a tab switched to one. h.state_mut().left = pdfcraft_ui_egui::LeftPanel::Tool("form"); - h.state_mut().left_open = true; + h.state_mut().set_left_open(true); h.run_steps(4); assert!(h.state().is_preparing(), "Prepare is open"); let id = h.state().views[0].id; diff --git a/crates/ui-egui/tests/it/portfolio.rs b/crates/ui-egui/tests/it/portfolio.rs index e1c60ea81c..dd052a4792 100644 --- a/crates/ui-egui/tests/it/portfolio.rs +++ b/crates/ui-egui/tests/it/portfolio.rs @@ -117,9 +117,9 @@ fn select(h: &mut Harness<'static, PdfCraftApp>, index: usize) { h.run_steps(2); } -/// Whether the right panel called `label` is on screen. -fn panel_shown(h: &Harness<'static, PdfCraftApp>, label: &str) -> bool { - h.query_by_label(label).is_some() +/// Whether the dock has the side panel `panel` open; its rail icon shows whether or not it is. +fn panel_shown(h: &Harness<'static, PdfCraftApp>, panel: RightPanel) -> bool { + crate::support::right(h.state()) == Some(panel) } /// The reader picks the right panel `panel`, or closes it with `None`. @@ -149,25 +149,25 @@ fn a_portfolio_opens_its_initial_document_and_shows_its_files_with_the_panel_clo let mut h = opened(portfolio("/Collection << /D (form.pdf) /View /T >>", &[("intro.pdf", PAGE), ("form.pdf", PAGE)]), true); // The document `/D` names is presented, in a tab of its own, with the reader's own panels. assert_eq!(tabs(&h), (vec!["portfolio.pdf".into(), "form.pdf".into()], Some("form.pdf".into()))); - assert!(!panel_shown(&h, "Attachments")); + assert!(!panel_shown(&h, RightPanel::Attachments)); // The portfolio's tab shows its files, without changing the reader's preference. select(&mut h, 0); - assert!(panel_shown(&h, "Attachments")); + assert!(panel_shown(&h, RightPanel::Attachments)); // Leaving it gives back the closed panel; coming back shows the files again. select(&mut h, 1); - assert!(!panel_shown(&h, "Attachments")); + assert!(!panel_shown(&h, RightPanel::Attachments)); select(&mut h, 0); - assert!(panel_shown(&h, "Attachments")); + assert!(panel_shown(&h, RightPanel::Attachments)); // The reader can still close the list on the portfolio's tab. choose_panel(&mut h, None); - assert!(!panel_shown(&h, "Attachments")); + assert!(!panel_shown(&h, RightPanel::Attachments)); // A panel the reader had open comes back once they leave the portfolio's tab. select(&mut h, 1); choose_panel(&mut h, Some(RightPanel::Bookmarks)); select(&mut h, 0); - assert!(panel_shown(&h, "Attachments")); + assert!(panel_shown(&h, RightPanel::Attachments)); select(&mut h, 1); - assert!(panel_shown(&h, "Bookmarks")); + assert!(panel_shown(&h, RightPanel::Bookmarks)); } /// The initial document opens on its own panels, not on the portfolio's file list. @@ -178,9 +178,9 @@ fn the_initial_document_opens_without_the_portfolios_file_list() { // would, here on its comments, not with the portfolio's file list. let mut h = opened(portfolio("/PageMode /UseAttachments /Collection << /D (form.pdf) >>", &[("intro.pdf", PAGE), ("form.pdf", NOTED)]), false); assert_eq!(tabs(&h).1.as_deref(), Some("form.pdf")); - assert!(panel_shown(&h, "Comments")); + assert!(panel_shown(&h, RightPanel::Comments)); select(&mut h, 0); - assert!(panel_shown(&h, "Attachments")); + assert!(panel_shown(&h, RightPanel::Attachments)); } /// A file opened together with a portfolio, after it, stays in front. @@ -195,9 +195,9 @@ fn a_file_opened_after_the_portfolio_keeps_the_front() { app.open_bytes(&egui::Context::default(), "other.pdf", None, PAGE.to_vec()).unwrap(); }); assert_eq!(tabs(&h), (vec!["portfolio.pdf".into(), "other.pdf".into()], Some("other.pdf".into()))); - assert!(!panel_shown(&h, "Attachments")); + assert!(!panel_shown(&h, RightPanel::Attachments)); select(&mut h, 0); - assert!(panel_shown(&h, "Attachments")); + assert!(panel_shown(&h, RightPanel::Attachments)); } /// A password asked for a file opened together with the portfolio stays asked: the initial @@ -248,14 +248,14 @@ fn read_mode_gives_back_the_panel_the_file_list_replaced() { h.state_mut().open_bytes(&ctx_h, "other.pdf", None, PAGE.to_vec()).unwrap(); h.run_steps(2); select(&mut h, 0); - assert!(panel_shown(&h, "Attachments")); + assert!(panel_shown(&h, RightPanel::Attachments)); assert!(h.execute("view.read_mode")); h.run_steps(2); - assert!(!panel_shown(&h, "Attachments")); + assert!(!panel_shown(&h, RightPanel::Attachments)); select(&mut h, 1); assert!(h.execute("view.read_mode")); h.run_steps(2); - assert!(!panel_shown(&h, "Attachments"), "the panel was closed before the list showed"); + assert!(!panel_shown(&h, RightPanel::Attachments), "the panel was closed before the list showed"); } /// A panel the reader picks in Read mode on the portfolio's tab stays when they switch tabs. @@ -270,7 +270,7 @@ fn a_panel_picked_in_read_mode_stays_when_the_tab_changes() { h.run_steps(2); choose_panel(&mut h, Some(RightPanel::Attachments)); select(&mut h, 1); - assert!(panel_shown(&h, "Attachments")); + assert!(panel_shown(&h, RightPanel::Attachments)); } /// `/View /H` presents the initial document but leaves the file list to the reader. @@ -279,7 +279,7 @@ fn a_portfolio_that_keeps_its_list_hidden_still_presents_its_initial_document() let mut h = opened(portfolio("/Collection << /D (form.pdf) /View /H >>", &[("intro.pdf", PAGE), ("form.pdf", PAGE)]), true); assert_eq!(tabs(&h).1.as_deref(), Some("form.pdf")); select(&mut h, 0); - assert!(!panel_shown(&h, "Attachments"), "/View /H: the list shows when the reader asks for it"); + assert!(!panel_shown(&h, RightPanel::Attachments), "/View /H: the list shows when the reader asks for it"); } /// Without a PDF to present, the portfolio stays in front with its files listed. @@ -290,7 +290,7 @@ fn a_portfolio_without_an_initial_document_shows_its_files_over_the_cover() { for collection in ["/Collection << /View /D >>", "/Collection << /D (notes.txt) >>"] { let h = opened(portfolio(collection, &[("notes.txt", b"hello"), ("form.pdf", PAGE)]), true); assert_eq!(tabs(&h), (vec!["portfolio.pdf".into()], Some("portfolio.pdf".into())), "{collection}"); - assert!(panel_shown(&h, "Attachments"), "{collection}"); + assert!(panel_shown(&h, RightPanel::Attachments), "{collection}"); } } @@ -304,5 +304,5 @@ fn a_portfolio_inside_the_initial_document_waits_for_the_reader() { assert_eq!(tabs(&h), (vec!["portfolio.pdf".into(), "inner.pdf".into()], Some("inner.pdf".into()))); // Its own tab still shows its files. select(&mut h, 0); - assert!(panel_shown(&h, "Attachments")); + assert!(panel_shown(&h, RightPanel::Attachments)); } diff --git a/crates/ui-egui/tests/it/prepare.rs b/crates/ui-egui/tests/it/prepare.rs index c36cd5d0f6..d71580052b 100644 --- a/crates/ui-egui/tests/it/prepare.rs +++ b/crates/ui-egui/tests/it/prepare.rs @@ -1461,7 +1461,7 @@ fn the_table_window_closes_when_its_document_is_left() { assert_eq!(names(&h).len(), before, "nothing added to either document"); // So does leaving Prepare a form. draw_table(&mut h); - h.state_mut().left_open = false; + h.state_mut().set_left_open(false); h.run_steps(2); assert!(!table_open(&h)); } @@ -1475,14 +1475,14 @@ fn a_table_drawn_with_the_panel_closed_opens_it_again() { let before = names(&h).len(); assert!(h.execute("form.add.text_table")); h.run_steps(2); - h.state_mut().left_open = false; + h.state_mut().set_left_open(false); h.run_steps(2); assert!(h.state().is_preparing(), "the picked tool keeps the form prepared"); let (a, b) = (at(&h, 40.0, 240.0), at(&h, 240.0, 360.0)); drag(&mut h, a, b); h.run_steps(3); assert!(table_open(&h), "the window stays open"); - assert!(h.state().left_open && h.state().is_preparing(), "Prepare a form is open again"); + assert!(h.state().left_open() && h.state().is_preparing(), "Prepare a form is open again"); h.get_by_label("Add fields").click(); h.run_steps(3); assert!(names(&h).len() > before, "the table is added"); diff --git a/crates/ui-egui/tests/it/ui.rs b/crates/ui-egui/tests/it/ui.rs index 8287740e61..3d0f72b76e 100644 --- a/crates/ui-egui/tests/it/ui.rs +++ b/crates/ui-egui/tests/it/ui.rs @@ -40,7 +40,8 @@ fn home_shows_welcome_and_tools() { let h = harness(|_| {}); h.get_by_label_contains("Welcome to PdfCraft"); assert!(h.query_all_by_label("Organize pages").count() >= 2, "tool list + home card"); - h.get_by_label("Open file"); + // The start screen's own Open button, beside the menu bar's. + assert!(h.query_all_by_role_and_label(egui::accesskit::Role::Button, "Open…").count() >= 2, "Home offers Open"); } /// A side string of the control state's `side_panels` (`tools_side`, `rail_side`). @@ -340,7 +341,8 @@ fn opening_a_pdf_shows_comments_and_bookmarks() { let mut h = harness(|app| app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens")); // Documents with comments open on the Comments panel, like Acrobat. h.get_by_label_contains("Check the numbers"); - h.get_by_label("Bookmarks").click(); + // The rail's icon: the open column's tabs are named alike. + h.get_by_role_and_label(egui::accesskit::Role::Button, "Bookmarks").click(); h.run_steps(3); h.get_by_label("Alpha section"); h.get_by_label("Beta section"); @@ -353,7 +355,7 @@ fn closed_side_panes_stay_closed_after_a_restart_and_opening_a_pdf() { use pdfcraft_ui_egui::RightPanel; let mut h = harness(|app| app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens")); assert_eq!(right(h.state()), Some(RightPanel::Comments)); - assert!(h.state().left_open); + assert!(h.state().left_open()); h.state_mut().choose_right_panel(None); h.set_option("left", "closed").unwrap(); h.run_steps(3); @@ -363,14 +365,14 @@ fn closed_side_panes_stay_closed_after_a_restart_and_opening_a_pdf() { app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"); }); assert_eq!(right(h.state()), None, "the closed right pane reopened"); - assert!(!h.state().left_open, "the closed left pane reopened"); + assert!(!h.state().left_open(), "the closed left pane reopened"); assert!(h.query_by_label_contains("Check the numbers").is_none()); // Within a session too: another document opens with them closed. let ctx_h = h.ctx.clone(); h.state_mut().open_bytes(&ctx_h, "again.pdf", None, FIXTURE.to_vec()).unwrap(); h.run_steps(3); assert_eq!(right(h.state()), None); - assert!(!h.state().left_open); + assert!(!h.state().left_open()); } /// #2884: a right panel the user closed stays closed when a PDF asks for its outline @@ -513,17 +515,18 @@ fn read_mode_closes_the_panes_and_leaving_it_brings_them_back() { fn read_mode_hides_the_quick_toolbar() { use pdfcraft_ui_egui::{Mode, QuickTool}; let mut h = harness(|app| app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens")); - h.get_by_label("Hand (H)").click(); + // The toolbar's slots are named by their commands (L-233). + h.get_by_role_and_label(egui::accesskit::Role::Button, "Hand").click(); h.run_steps(2); assert_eq!(h.state().quick_tool, QuickTool::Hand); run_command(&mut h, "view.read_mode"); h.run_steps(3); - assert!(h.query_by_label("Select (V)").is_none(), "no quick toolbar in Read mode"); + assert!(h.query_by_role_and_label(egui::accesskit::Role::Button, "Select").is_none(), "no quick toolbar in Read mode"); assert_eq!(h.state().quick_tool, QuickTool::Select); run_command(&mut h, "view.read_mode"); h.run_steps(3); assert_eq!(h.state().mode, Mode::AllTools); - h.get_by_label("Select (V)"); + h.get_by_role_and_label(egui::accesskit::Role::Button, "Select"); } /// All tools ▸ Edit a PDF turns on Edit text & images at once, as the Edit tab does, so the page @@ -644,8 +647,8 @@ fn a_link_prompt_above_a_save_prompt_owns_its_keys() { app.apply_edit(&egui::Context::default(), pdfcraft_engine::Edit::RotatePages { pages: vec![0], degrees: 90 }); }); h.run_steps(3); - // The save prompt is the close dialog the tab's close action opens. - h.get_by_label("first.pdf, modified").click_button(egui::PointerButton::Middle); + // The save prompt is the close dialog closing the tab opens. + assert!(h.execute("file.close")); h.run_steps(3); h.state_mut().pending_link = Some(pdfcraft_ui_egui::PendingLink { url: "https://example.org".to_owned(), origin: pdfcraft_ui_egui::LinkOrigin::Link }); @@ -1470,10 +1473,10 @@ fn explicit_mode_preserves_independent_tool_and_panel_options() { app.set_option(&egui::Context::default(), "left", "closed").unwrap(); app.set_option(&egui::Context::default(), "mode", "edit").unwrap(); assert_eq!(app.left, LeftPanel::Tool("export")); - assert!(!app.left_open); + assert!(!app.left_open()); app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).unwrap(); assert_eq!(app.left, LeftPanel::Tool("export")); - assert!(!app.left_open); + assert!(!app.left_open()); } #[test] @@ -1486,7 +1489,7 @@ fn opening_a_pdf_keeps_a_closed_left_panel_and_the_chosen_tool() { app.set_option(&egui::Context::default(), "left", "closed").unwrap(); app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).unwrap(); assert_eq!(app.mode, Mode::Edit); - assert!(!app.left_open); + assert!(!app.left_open()); // Default All Tools: opening another PDF leaves the tool panel the user picked. let mut app = crate::control::new_app(); app.set_option(&egui::Context::default(), "language", "en").unwrap(); diff --git a/crates/ui-egui/tests/it/viewer_prefs.rs b/crates/ui-egui/tests/it/viewer_prefs.rs index 97823f8500..452e8c3d26 100644 --- a/crates/ui-egui/tests/it/viewer_prefs.rs +++ b/crates/ui-egui/tests/it/viewer_prefs.rs @@ -79,14 +79,14 @@ fn a_document_that_hides_the_interface_opens_without_it_and_f8_brings_it_back() assert_eq!(shown(&h), (false, false, false), "the toolbar, menu and rail are hidden"); assert_eq!(h.state().hidden_interface(), HiddenInterface::ALL); // The quick-action bar is a toolbar too. - assert!(h.query_by_label_contains("Hand (H)").is_none()); + assert!(h.query_by_role_and_label(egui::accesskit::Role::Button, "Hand").is_none()); // The tab strip stays: the tabs and Home are still there. h.get_by_label("Home"); h.key_press(egui::Key::F8); h.run_steps(3); assert_eq!(shown(&h), (true, true, true), "F8 shows them"); - h.get_by_label_contains("Hand (H)"); + h.get_by_role_and_label(egui::accesskit::Role::Button, "Hand"); h.key_press(egui::Key::F8); h.run_steps(3); assert_eq!(shown(&h), (false, false, false), "and hides them again"); @@ -309,8 +309,8 @@ fn fit_window_sizes_the_window_to_the_first_page() { let (size, at) = window_commands(&mut h, 12); let size = size.expect("the window is resized"); assert_eq!(at, None, "not moved"); - // A 2:3 portrait page fitted to the window's height makes a narrower window. - assert!(size.x < 1000.0 && (size.y - 900.0).abs() < 1.0, "{size:?}"); + // A 2:3 portrait page fitted to the window's height makes a narrower window than the 1400-point one. + assert!(size.x < 1400.0 && (size.y - 900.0).abs() < 1.0, "{size:?}"); // Asked once. assert_eq!(window_commands(&mut h, 6), (None, None)); // The page now fills the document area's height and nearly its width.