diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index 592305267d..efd6a3d5fd 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -47,7 +47,8 @@ impl PdfCraftApp { } ("animation_effects", _) => { // PLAN: assumed `crate::settings::motion_from_name(&str) -> Option` and `set_motion(&mut self, MotionChoice)`, which writes the field and the store (pdf-shell-w9). - let motion = crate::settings::motion_from_name(value).ok_or("animation_effects must be system, on, or off")?; + // The control channel and the command line take the names in any case, as before the port. + let motion = crate::settings::motion_from_name(&value.to_ascii_lowercase()).ok_or("animation_effects must be system, on, or off")?; self.set_motion(motion); } ("panel", _) => { diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index db306ecde7..46788a074a 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1500,7 +1500,8 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu organize_grid(&mut app.views[index], doc, &mut organize::GridCx { ui, session: &app.session, zoom: &mut app.organize_zoom, invert_middle }); return None; } - // The room under the notice bars, inside the rect the caller gave. let rect = rect.intersect(ui.available_rect_before_wrap()); + // 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(); // Prepare a form ▸ Calculation order: the order's steps and links on the page. diff --git a/crates/ui-egui/src/canvas/page_parts.rs b/crates/ui-egui/src/canvas/page_parts.rs index 910c3e75c9..e3198f46a5 100644 --- a/crates/ui-egui/src/canvas/page_parts.rs +++ b/crates/ui-egui/src/canvas/page_parts.rs @@ -6,7 +6,7 @@ use craft::behavior::{CursorIcon, HitLevel, HitPriority, HitShape, Input, Intent, Metrics, PartKey, PartRef, PressPhase, Sense}; use craft::keymap::Mods; use craft::ui::contract::{ - Common, Component, Cx, Focus as _, MeasureCx, NoValue, Outcome, PartsCx, Pointer as _, Props as _, Role, TooltipAt, TooltipSpec, + Common, Component, Cx, Focus as _, MeasureCx, NoValue, Outcome, PartsCx, Pointer as _, Props as _, Role, TooltipAt, TooltipSpec, TooltipWhen, }; use craft::ui::runtime::commands::FireSource; use craft::ui::runtime::env::Label; @@ -371,7 +371,8 @@ impl Component for PageParts<'_> { builder = builder.cursor(cursor); } if let Some(tip) = &part.tip { - builder = builder.tooltip(TooltipSpec::new(Label::from(tip.clone())).at(TooltipAt::Pointer)); + // A page part's tip shows as the pointer comes onto the part, beside the pointer, as production's did. + builder = builder.tooltip(TooltipSpec::new(Label::from(tip.clone())).at(TooltipAt::Pointer).when(TooltipWhen::Now)); } if part.focusable { builder.focusable(); diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 5884b7957b..72bafede89 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -53,8 +53,16 @@ fn window_body(app: &mut PdfCraftApp, ui: &mut egui::Ui) { if let Some(files) = dropped && !app.combine_showing() { - let ctx = ui.ctx().clone(); - app.open_dropped(&ctx, files); + // While the page grid shows, it takes files dropped anywhere in the window: one let go off the grid goes + // in after the last page, as there is no gap under the pointer to say where. + let grid = app.active_ids().filter(|(_, id)| app.session.get(*id).is_some_and(|doc| doc.allows_assembly())).map(|(index, _)| index); + match grid.and_then(|index| app.views.get_mut(index)).filter(|view| view.organize) { + Some(view) => view.dropped_files = Some((usize::MAX, files)), + None => { + let ctx = ui.ctx().clone(); + app.open_dropped(&ctx, files); + } + } } } diff --git a/crates/ui-egui/src/chrome/view_rail.rs b/crates/ui-egui/src/chrome/view_rail.rs index 7a2463bfc5..5a9dd24f57 100644 --- a/crates/ui-egui/src/chrome/view_rail.rs +++ b/crates/ui-egui/src/chrome/view_rail.rs @@ -28,7 +28,11 @@ pub(crate) fn show(app: &mut PdfCraftApp, ui: &mut Ui) { let Some(page) = doc.info.pages.get(current) else { return }; let page_size = Size::new(f64::from(page.width.max(1.0)), f64::from(page.height.max(1.0))); - IconButton::command(IconId::new(if rail_on_right { "panel_left" } else { "panel_right" }), "view.dock_side").show(ui); + if rail_on_right { + IconButton::command(IconId::new("panel_left"), "view.rail.left").show(ui); + } else { + IconButton::command(IconId::new("panel_right"), "view.rail.right").show(ui); + } // The rows' marks come from the commands' checked state (the catalog), not from here. let display_icon = if view.view.display == PageDisplay::Single { "file-text" } else { "columns-2" }; diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index da76ea4f34..d5efc13e7c 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -122,9 +122,10 @@ impl PdfCraftApp { v.view.fit = fit; } } - "view.dock_side" => { - let edge = if crate::side_panels::state(self)["tools_side"] == "right" { "left" } else { "right" }; - if let Err(e) = crate::side_panels::command(self, false, &serde_json::json!({ "panel": "tools", "edge": edge })) { + "view.rail.left" | "view.rail.right" => { + use craft::behavior::DockSide; + let side = if id == "view.rail.left" { DockSide::Start } else { DockSide::End }; + if let Err(e) = crate::side_panels::set_rail_side(self, side) { self.notify(e); } } diff --git a/crates/ui-egui/src/commands/catalog.rs b/crates/ui-egui/src/commands/catalog.rs index b45bf438a6..7f0e63ea02 100644 --- a/crates/ui-egui/src/commands/catalog.rs +++ b/crates/ui-egui/src/commands/catalog.rs @@ -25,7 +25,9 @@ const CATALOG_ONLY: &[(&str, &str, &str)] = &[ ("tools.expand", "Expand all tools", "maximize-2"), ("tools.collapse", "Collapse all tools", "minimize-2"), ("tools.all", "All tools", "layout-grid"), - ("view.dock_side", "Move the side panel to the other side", "arrow-left-right"), + // The rail's button names the side it moves the rail to. + ("view.rail.left", "Dock navigation rail on Left", "panel-left"), + ("view.rail.right", "Dock navigation rail on Right", "panel-right"), ("view.fit_toggle", "Toggle fit", "scan"), ("bookmark.paste", "Paste bookmarks", "clipboard-paste"), ("bookmark.expand_all", "Expand all bookmarks", "chevrons-down"), diff --git a/crates/ui-egui/src/dialogs/preferences.rs b/crates/ui-egui/src/dialogs/preferences.rs index 9bfbfc2b40..6248363b1c 100644 --- a/crates/ui-egui/src/dialogs/preferences.rs +++ b/crates/ui-egui/src/dialogs/preferences.rs @@ -304,7 +304,7 @@ fn side_table<'a>() -> Table<'a, bool> { fn animation_table<'a>() -> Table<'a, MotionChoice> { vec![ - (MotionChoice::System, "system", tl_ctx!("animation effects", "System")), + (MotionChoice::System, "system", tl_ctx!("animation effects", "Use system setting")), (MotionChoice::Full, "on", tl_ctx!("animation effects", "On")), (MotionChoice::Off, "off", tl_ctx!("animation effects", "Off")), ] diff --git a/crates/ui-egui/src/hotbar.rs b/crates/ui-egui/src/hotbar.rs index 0206c6bc2c..aac06726bb 100644 --- a/crates/ui-egui/src/hotbar.rs +++ b/crates/ui-egui/src/hotbar.rs @@ -25,8 +25,9 @@ const TOOL_HAND: &str = "view.hand_tool"; const TOOL_CROP: &str = "page.crop"; const TOOL_EDIT_TEXT: &str = "edit.edit_text"; -const SLOT_POINTER: SlotId = 0; -const SLOT_CROP: SlotId = 1; +const SLOT_SELECT: SlotId = 0; +const SLOT_HAND: SlotId = 1; +const SLOT_CROP: SlotId = 2; /// The first comment group's slot; group `g` is `SLOT_COMMENT + g`. const SLOT_COMMENT: SlotId = 10; const SLOT_EDIT_TEXT: SlotId = 20; @@ -122,7 +123,8 @@ fn last_used(app: &PdfCraftApp) -> LastUsed { /// The built-in slots, then one slot for each of `user` commands. fn slots_with(app: &PdfCraftApp, user: &[String]) -> Vec> { let mut slots = vec![ - ToolSlot::new(SLOT_POINTER, vec![rail_tool(TOOL_SELECT), rail_tool(TOOL_HAND)]), + ToolSlot::new(SLOT_SELECT, vec![rail_tool(TOOL_SELECT)]), + ToolSlot::new(SLOT_HAND, vec![rail_tool(TOOL_HAND)]), ToolSlot::ending_group(SLOT_CROP, vec![rail_tool(TOOL_CROP)]), ]; let groups = comments::GROUPS.len(); diff --git a/crates/ui-egui/src/panels/bookmarks.rs b/crates/ui-egui/src/panels/bookmarks.rs index 856093200e..0c4714b8b9 100644 --- a/crates/ui-egui/src/panels/bookmarks.rs +++ b/crates/ui-egui/src/panels/bookmarks.rs @@ -202,6 +202,10 @@ impl DisplayOrder> for Rows<'_> { fn open(&self, at: usize) -> bool { self.0.get(at).is_some_and(|r| r.open) } + /// The title: what the rename field starts from and type-ahead matches. + fn text(&self, at: usize) -> Option> { + self.0.get(at).map(|r| std::borrow::Cow::Borrowed(r.item.title.as_str())) + } } impl ItemSource> for Rows<'_> {} diff --git a/crates/ui-egui/src/tools/comments/menu.rs b/crates/ui-egui/src/tools/comments/menu.rs index efe361c4e4..59e9f48eee 100644 --- a/crates/ui-egui/src/tools/comments/menu.rs +++ b/crates/ui-egui/src/tools/comments/menu.rs @@ -230,7 +230,7 @@ pub(crate) fn popover_from( ui: &mut egui::Ui, label: &str, opener: impl FnOnce(&mut egui::Ui) -> egui::Response, - body: impl FnOnce(&mut egui::Ui) -> bool, + mut body: impl FnMut(&mut egui::Ui) -> bool, ) { let resp = opener(ui); let key = resp.id.with("popover-open"); @@ -239,12 +239,10 @@ pub(crate) fn popover_from( if craft::ui::contract::clicked(&resp) { open = !open; } - let mut body = Some(body); let mut done = false; + // The popover runs its body in a sizing pass and again in the pass that shows it. Popover::new(label.to_string(), Bind::bound(&mut open)).opened_by(&resp).show(ui, |ui, _| { - if let Some(body) = body.take() { - done = body(ui); - } + done |= body(ui); }); open &= !done; ui.memory_mut(|m| m.data.insert_temp(key, open)); diff --git a/crates/ui-egui/tests/it/redact.rs b/crates/ui-egui/tests/it/redact.rs index 66c14f8a8b..d3cfd3997a 100644 --- a/crates/ui-egui/tests/it/redact.rs +++ b/crates/ui-egui/tests/it/redact.rs @@ -47,10 +47,9 @@ fn pick(files: &ScriptedFiles, path: &std::path::Path) { files.queue(Picked::Paths(vec![path.to_owned()])); } -/// The message of the newest notice card the main window shows. +/// The text of the newest notice card the main window shows. fn latest_notice(h: &Harness<'static, PdfCraftApp>) -> String { - use craft::ui::runtime::{env::WindowKey, toast}; - toast::cards(&h.ctx, &WindowKey::main()).last().map(|card| card.toast.message.as_str().to_owned()).unwrap_or_default() + crate::support::shown_notice(h).unwrap_or_default() } fn at(h: &Harness<'static, PdfCraftApp>, x: f32, y: f32) -> Pos2 { @@ -611,6 +610,9 @@ fn redaction_properties_for_this_run_only_and_cancel() { for row in ["Outline colour:", "Fill colour:", "Opacity:"] { assert!(h.get_all_by_label(row).count() > 0, "{row} is offered"); } + // The dialog's body scrolls; the check box is its last row, below the room the body shows. + h.get_by_label("Make properties default").scroll_to_me(); + h.run_steps(3); h.get_by_label("Make properties default").click(); h.run_steps(3); assert!(!h.state().redact_props.as_ref().unwrap().remember); diff --git a/crates/ui-egui/tests/it/stamps.rs b/crates/ui-egui/tests/it/stamps.rs index 7a810354fe..4bdf12d203 100644 --- a/crates/ui-egui/tests/it/stamps.rs +++ b/crates/ui-egui/tests/it/stamps.rs @@ -172,6 +172,9 @@ fn a_dynamic_custom_stamp_keeps_its_line_and_fills_it_in_when_placed() { let ctx = h.ctx.clone(); h.state_mut().start_custom_stamp(&ctx, "logo.png".into(), png); h.run_steps(2); + // The dialog's body scrolls; the check box may sit below the room it shows. + h.get_by_label("Add a line filled in when the stamp is placed").scroll_to_me(); + h.run_steps(3); h.get_by_label("Add a line filled in when the stamp is placed").click(); h.run_steps(2); diff --git a/crates/ui-egui/tests/it/ui.rs b/crates/ui-egui/tests/it/ui.rs index 3d0f72b76e..ef394fcdbb 100644 --- a/crates/ui-egui/tests/it/ui.rs +++ b/crates/ui-egui/tests/it/ui.rs @@ -79,7 +79,32 @@ fn run_command(h: &mut Harness<'static, PdfCraftApp>, id: &str) { /// The text of every notice card the main window shows, oldest first. fn posted_notices(h: &Harness<'static, PdfCraftApp>) -> Vec { use craft::ui::runtime::{env::WindowKey, toast}; - toast::cards(&h.ctx, &WindowKey::main()).into_iter().map(|card| card.toast.message.as_str().to_owned()).collect() + // A posted notice's text is the card's title; a message and lines may follow it. + toast::cards(&h.ctx, &WindowKey::main()) + .into_iter() + .map(|card| { + let toast = &card.toast; + let parts = toast.title.iter().chain(std::iter::once(&toast.message)).chain(&toast.lines); + parts.map(|part| part.as_str()).filter(|text| !text.is_empty()).collect::>().join("\n") + }) + .collect() +} + +/// Picks `option` in the open Preferences' drop-down named `row`, after opening `page` when given. A choice row is the +/// preferences pattern's drop-down, so its options show only while it is open: the last node of that name is the open +/// list's. +fn pick_preference(h: &mut Harness<'static, PdfCraftApp>, page: Option<&str>, row: &str, option: &str) { + use egui::accesskit::Role; + if let Some(page) = page { + h.get_by_label(page).click(); + h.run_steps(3); + } + h.get_by_role_and_label(Role::ComboBox, row).scroll_to_me(); + h.run_steps(4); + h.get_by_role_and_label(Role::ComboBox, row).click(); + h.run_steps(3); + h.get_all_by_label(option).last().unwrap_or_else(|| panic!("the {option:?} option of {row:?} is on screen")).click(); + h.run_steps(2); } #[test] @@ -87,8 +112,7 @@ fn tools_panel_side_preference_moves_and_persists() { let mut h = harness(|_| {}); h.set_option("dialog", "preferences").unwrap(); h.run_steps(3); - h.get_by_label("Tools panel side"); - h.get_by_label("Right").click(); + pick_preference(&mut h, None, "Tools panel side", "Right"); h.get_by_label("OK").click(); h.run_steps(3); assert_eq!(side(&mut h, "tools_side"), "right"); @@ -97,7 +121,7 @@ fn tools_panel_side_preference_moves_and_persists() { assert_eq!(side(&mut restored, "tools_side"), "right"); h.set_option("dialog", "preferences").unwrap(); h.run_steps(3); - h.get_by_label("Left").click(); + pick_preference(&mut h, None, "Tools panel side", "Left"); h.get_by_label("OK").click(); h.run_steps(3); assert_eq!(side(&mut h, "tools_side"), "left"); @@ -408,13 +432,13 @@ fn navigation_rail_toggles_between_right_and_left_and_persists() { assert_eq!(side(&mut h2, "rail_side"), "left"); h2.set_option("dialog", "preferences").unwrap(); h2.run_steps(3); - h2.get_by_label("Navigation rail side: Right").click(); + pick_preference(&mut h2, None, "Navigation rail side", "Right"); h2.get_by_label("OK").click(); h2.run_steps(3); assert_eq!(side(&mut h2, "rail_side"), "right"); h2.set_option("dialog", "preferences").unwrap(); h2.run_steps(3); - h2.get_by_label("Navigation rail side: Left").click(); + pick_preference(&mut h2, None, "Navigation rail side", "Left"); h2.get_by_label("OK").click(); h2.run_steps(3); assert_eq!(side(&mut h2, "rail_side"), "left"); @@ -1362,13 +1386,8 @@ fn default_workspace_mode_persists_and_tolerates_invalid_settings() { assert_eq!(app.mode, Mode::AllTools); } // Chosen in Preferences, the default applies to the next open. - use egui::accesskit::Role; let mut h = harness(|app| app.set_option(&egui::Context::default(), "dialog", "preferences").unwrap()); - h.get_by_label("Default workspace mode"); - h.get_by_role_and_label(Role::RadioButton, "Read").scroll_to_me(); - h.run_steps(4); - h.get_by_role_and_label(Role::RadioButton, "Read").click(); - h.run_steps(2); + pick_preference(&mut h, Some("Documents and view"), "Default workspace mode", "Read"); h.get_by_label("OK").click(); h.run_steps(2); assert_eq!(h.state().default_mode, Mode::Read); @@ -1430,18 +1449,13 @@ fn explicit_mode_overrides_default_before_and_after_open() { #[test] fn preferences_choose_animation_effects_and_the_choice_is_saved() { use craft::theme::MotionChoice; - use egui::accesskit::Role; let mut h = harness(|app| app.set_option(&egui::Context::default(), "dialog", "preferences").unwrap()); // PLAN: assumed the app keeps the choice in `animation_effects: MotionChoice` and the settings JSON key `animation_effects` (pdf-shell-w9) assert_eq!(h.state().animation_effects, MotionChoice::System); - h.get_by_label("Animation effects"); for (label, choice) in [("Off", MotionChoice::Off), ("On", MotionChoice::Full), ("Use system setting", MotionChoice::System), ("Off", MotionChoice::Off)] { - h.get_by_role_and_label(Role::RadioButton, label).scroll_to_me(); - h.run_steps(4); - h.get_by_role_and_label(Role::RadioButton, label).click(); - h.run_steps(2); + pick_preference(&mut h, None, "Animation effects", label); h.get_by_label("OK").click(); h.run_steps(2); assert_eq!(h.state().animation_effects, choice, "{label}"); @@ -1451,11 +1465,14 @@ fn preferences_choose_animation_effects_and_the_choice_is_saved() { let saved = serde_json::to_string(&h.state().settings_snapshot()).unwrap(); assert!(saved.contains(r#""animation_effects":"off""#), "{saved}"); let mut restored = crate::control::new_app(); - restored.apply_settings(&pdfcraft_ui_egui::settings::import_json(&saved).0); + restored.apply_settings(&serde_json::from_str::(&saved).unwrap()); assert_eq!(restored.animation_effects, MotionChoice::Off); + // Settings from an earlier release (the flat JSON object) are untrusted: an unknown name leaves the system choice. + let mut legacy = crate::control::new_app(); + legacy.apply_settings(&pdfcraft_ui_egui::settings::import_json(r#"{"animation_effects":"off"}"#).0); + assert_eq!(legacy.animation_effects, MotionChoice::Off); let mut fresh = crate::control::new_app(); - let hostile = saved.replace(r#""animation_effects":"off""#, r#""animation_effects":"sideways""#); - fresh.apply_settings(&pdfcraft_ui_egui::settings::import_json(&hostile).0); + fresh.apply_settings(&pdfcraft_ui_egui::settings::import_json(r#"{"animation_effects":"sideways"}"#).0); assert_eq!(fresh.animation_effects, MotionChoice::System); // The control channel and the command line take the same three names. fresh.set_option(&egui::Context::default(), "animation_effects", "ON").unwrap();