diff --git a/crates/ui-egui/src/app/prefs.rs b/crates/ui-egui/src/app/prefs.rs index bb9f19a2ff..e97ec3d432 100644 --- a/crates/ui-egui/src/app/prefs.rs +++ b/crates/ui-egui/src/app/prefs.rs @@ -48,6 +48,10 @@ impl PdfCraftApp { options.wheel_line = self.scroll_speed.wheel_line(); options.key_line = self.scroll_speed.key_line(); options.invert_middle = self.invert_middle_drag; + // Linux latches a middle-click auto-scroll; the other platforms drag the view. + if cfg!(target_os = "linux") { + options.middle_button = craft::behavior::MiddleButton::AutoScroll; + } options.animated_zoom = !self.animation_effects.reduced(None); options } diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 3ec17f3668..51f33bb4f5 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -235,6 +235,9 @@ pub struct DocView { pub pages_panel: Option, /// The Pages-panel gap under the pointer (where dropped files go), when it can take pages. pub panel_gap: Option, + /// Files dropped on a gap of the page grid or the Pages panel, with the gap, until the app + /// inserts them. + pub(crate) dropped_files: Option<(usize, Vec)>, /// Transient keyboard owner for this document's Pages sidebar. pub(crate) pages_focus_id: Option, /// Scale of the thumbnails in the Pages inspector, independent of document and grid zoom. @@ -570,6 +573,7 @@ impl DocView { grid_gap: None, pages_panel: None, panel_gap: None, + dropped_files: None, pages_focus_id: None, thumbnail_zoom: 1.0, grid_reveal: None, diff --git a/crates/ui-egui/src/canvas/organize.rs b/crates/ui-egui/src/canvas/organize.rs index 022371c688..2d706a61ee 100644 --- a/crates/ui-egui/src/canvas/organize.rs +++ b/crates/ui-egui/src/canvas/organize.rs @@ -226,7 +226,10 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document, } ThumbnailEvent::ContextMenu(request) => opened = Some(request.at), ThumbnailEvent::Insert(at) => view.pending_action = Some(ViewAction::InsertFromFileAt(at)), - ThumbnailEvent::FilesDropped { insert, .. } => view.grid_gap = Some(insert), + ThumbnailEvent::FilesDropped { insert, files, .. } => { + view.grid_gap = Some(insert); + view.dropped_files = Some((insert, files)); + } ThumbnailEvent::Action { page, action, .. } => { view.session.pending_edit = match action { ROTATE_CCW => Some(Edit::RotatePages { pages: vec![page], degrees: -90 }), diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index a85fd0ade2..b9b402785c 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -7,6 +7,7 @@ use craft::theme::ModeChoice; use craft::ui::buttons::{Button, IconButton}; use craft::ui::contract::{Bind, Outcome as _, Props as _, Show as _, ShowContainer as _}; use craft::ui::menu::{Menu, MenuItem}; +use craft::ui::popover::DropVeil; use craft::ui::runtime::env::WindowKey; use craft::ui::shell::{AppShell, Slot, Title, TitleBar}; @@ -33,12 +34,30 @@ pub(crate) fn shell(app: &mut PdfCraftApp, ui: &mut egui::Ui) { .title_bar(|ui, _, app: &mut PdfCraftApp| title_bar(app, ui)) .top(Slot::new("modes").visible(modes_visible), |ui, _, app: &mut PdfCraftApp| mode_bar::show(app, ui)) .end(Slot::new("view-rail").visible(window_ui), |ui, _, app: &mut PdfCraftApp| view_rail::show(app, ui)) - .body(|ui, _, app: &mut PdfCraftApp| side_panels::dock(app, ui)) + .body(|ui, _, app: &mut PdfCraftApp| window_body(app, ui)) .show(ui, app); // PLAN: assumed `set_screen_mode(&mut self, ScreenMode)` (pdf-shell-w8) app.set_screen_mode(out.screen_mode); } +/// The dock, under the veil that shows files held over the window. Files dropped on the window open as +/// documents; the Combine files tab takes its own through its veil. +fn window_body(app: &mut PdfCraftApp, ui: &mut egui::Ui) { + let mut dropped = None; + let _ = DropVeil::new(tl!("Drop to open the files")).show(ui, |ui, files| { + if let Some(files) = files { + dropped = Some(files.files.clone()); + } + side_panels::dock(app, ui); + }); + if let Some(files) = dropped + && !app.combine_showing() + { + let ctx = ui.ctx().clone(); + app.open_dropped(&ctx, files); + } +} + /// The title bar: Home, the document tabs and Open, then the community, shortcuts, theme and /// Preferences buttons. The window's caption buttons are the bar's own. fn title_bar(app: &mut PdfCraftApp, ui: &mut egui::Ui) { diff --git a/crates/ui-egui/src/editing.rs b/crates/ui-egui/src/editing.rs index 16352f9700..b137a32eec 100644 --- a/crates/ui-egui/src/editing.rs +++ b/crates/ui-egui/src/editing.rs @@ -528,6 +528,9 @@ impl PdfCraftApp { // its change has run the field's exit) before the focus scripts run. self.run_focus_scripts(ctx, i); self.run_field_triggers(ctx, i); + if let Some((at, files)) = self.views.get_mut(i).and_then(|v| v.dropped_files.take()) { + self.insert_dropped(ctx, files, at); + } match self.views.get_mut(i).and_then(|v| v.pending_action.take()) { Some(crate::canvas::ViewAction::InsertFromFile) => self.insert_from_file_dialog(), Some(crate::canvas::ViewAction::InsertFromFileAt(at)) => self.insert_from_file_at(Some(at)), diff --git a/crates/ui-egui/src/panels/all_tools_ui.rs b/crates/ui-egui/src/panels/all_tools_ui.rs index da59cb3510..75432ce38a 100644 --- a/crates/ui-egui/src/panels/all_tools_ui.rs +++ b/crates/ui-egui/src/panels/all_tools_ui.rs @@ -107,7 +107,9 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) { // The header rows are keyed after the tiles, whose keys are their positions. let groups: Vec> = spans.into_iter().enumerate().map(|(at, (start, count, title))| TileGroup::new(shown.len() + at, start, count, title)).collect(); + // The panel's body scrolls as a whole, so the grid takes the height of its rows and owns no scroll. let grid = TileGrid::::new(tl!("All tools").to_owned()) + .natural_height(true) .select(SelectMode::Single) .activate(ActivateOn::Click) .card() diff --git a/crates/ui-egui/src/panels/pages.rs b/crates/ui-egui/src/panels/pages.rs index a60c817c20..f74e1f3c5c 100644 --- a/crates/ui-egui/src/panels/pages.rs +++ b/crates/ui-egui/src/panels/pages.rs @@ -74,7 +74,10 @@ pub(super) fn body(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult { } } ThumbnailEvent::ContextMenu(request) => target = Some(request.key), - ThumbnailEvent::FilesDropped { insert, .. } => view.panel_gap = Some(insert), + ThumbnailEvent::FilesDropped { insert, files, .. } => { + view.panel_gap = Some(insert); + view.dropped_files = Some((insert, files)); + } _ => {} } } diff --git a/crates/ui-egui/tests/it/control.rs b/crates/ui-egui/tests/it/control.rs index 2a460709ca..6e231b584d 100644 --- a/crates/ui-egui/tests/it/control.rs +++ b/crates/ui-egui/tests/it/control.rs @@ -140,6 +140,9 @@ fn harness_on(app: PdfCraftApp, pages: usize, width: f32, scale: f32) -> (Harnes let (tx, rx) = std::sync::mpsc::channel(); let mut h = Harness::builder().with_size(egui::vec2(width, 900.0)).with_pixels_per_point(scale).build_eframe(move |cc| { crate::support::install_runtime(&cc.egui_ctx); + // What `automation::server::serve` does for the running app: keep the presented frame's access tree for + // `ui.inspect`, `ui.click {label}` and `ui.focus`. + craft::ui::runtime::windows::WindowHost::of(&cc.egui_ctx).keep_access_tree(); { let mut app = app; app.set_option(&egui::Context::default(), "language", "en").unwrap(); @@ -179,13 +182,15 @@ pub(crate) fn ok(h: &mut Harness<'static, PdfCraftApp>, c: &ControlClient, metho /// click that holds, moves, then releases. `modifiers` are held for the whole gesture and `button` /// is `"primary"`, `"secondary"` or `"middle"`. fn drag(h: &mut Harness<'static, PdfCraftApp>, c: &ControlClient, from: Value, to: Value, steps: usize, modifiers: &[&str], button: &str) { - ok(h, c, "ui.click", json!({"x": from[0], "y": from[1], "hold": true, "button": button, "modifiers": modifiers})); + let modifiers_held = |names: &[&str]| -> Value { Value::Object(names.iter().map(|name| ((*name).to_owned(), Value::Bool(true))).collect()) }; + let held = modifiers_held(modifiers); + ok(h, c, "ui.click", json!({"x": from[0], "y": from[1], "hold": true, "button": button, "modifiers": held})); let point = |p: &Value| [p[0].as_f64().unwrap_or_default(), p[1].as_f64().unwrap_or_default()]; let (from, to) = (point(&from), point(&to)); let steps = steps.max(1); for step in 1..=steps { let t = step as f64 / steps as f64; - ok(h, c, "ui.move", json!({"x": from[0] + (to[0] - from[0]) * t, "y": from[1] + (to[1] - from[1]) * t, "modifiers": modifiers})); + ok(h, c, "ui.move", json!({"x": from[0] + (to[0] - from[0]) * t, "y": from[1] + (to[1] - from[1]) * t, "modifiers": held})); } // `ui.release` takes no modifiers: releasing the button ends the gesture they were held for. ok(h, c, "ui.release", json!({"button": button})); @@ -313,9 +318,9 @@ fn control_button_focus_preserves_document_undo_redo_shortcuts() { assert!(!h.ctx.text_edit_focused()); ok(&mut h, &c, "ui.command", json!({"id": "page.insert_blank"})); assert_eq!(ok(&mut h, &c, "ui.state", json!({}))["documents"][0]["pages"], 3); - ok(&mut h, &c, "ui.key", json!({"key": "Z", "modifiers": ["command"]})); + ok(&mut h, &c, "ui.key", json!({"key": "Z", "modifiers": {"command": true}})); assert_eq!(ok(&mut h, &c, "ui.state", json!({}))["documents"][0]["pages"], 2); - ok(&mut h, &c, "ui.key", json!({"key": "Z", "modifiers": ["command", "shift"]})); + ok(&mut h, &c, "ui.key", json!({"key": "Z", "modifiers": {"command": true, "shift": true}})); assert_eq!(ok(&mut h, &c, "ui.state", json!({}))["documents"][0]["pages"], 3); } @@ -332,7 +337,7 @@ fn control_text_focus_retains_text_undo_ownership() { assert!(h.ctx.text_edit_focused()); ok(&mut h, &c, "ui.type", json!({"text": "target"})); assert_eq!(search_text(&h), "target"); - ok(&mut h, &c, "ui.key", json!({"key": "Z", "modifiers": ["command"]})); + ok(&mut h, &c, "ui.key", json!({"key": "Z", "modifiers": {"command": true}})); assert_eq!(search_text(&h), ""); assert_eq!(ok(&mut h, &c, "ui.state", json!({}))["documents"][0]["pages"], 3); } @@ -599,7 +604,7 @@ fn moving_before_middle_button_release_keeps_scrolling_without_starting_page_too h.state_mut().quick_tool = pdfcraft_ui_egui::QuickTool::Crop; let p = h.state().views[0].viewport_rect().center(); let top = h.state().views[0].page_screen_rect(0).unwrap().top(); - ok(&mut h, &c, "ui.drag", json!({ "from": [p.x, p.y], "to": [p.x, p.y + 60.0], "steps": 12, "button": "middle" })); + drag(&mut h, &c, json!([p.x, p.y]), json!([p.x, p.y + 60.0]), 12, &[], "middle"); h.run_steps(2); assert!(h.state().views[0].page_screen_rect(0).unwrap().top() < top - 20.0); assert!(!h.state().views[0].auto_scrolling(), "releasing after holding and scrolling turns auto-scroll off"); @@ -611,7 +616,7 @@ fn moving_before_middle_button_release_keeps_scrolling_without_starting_page_too assert!(!h.state().session.get(h.state().views[0].id).unwrap().dirty, "the Crop tool must not receive a wheel drag"); // Small movement within the dead zone before release still latches auto-scroll on. - ok(&mut h, &c, "ui.drag", json!({ "from": [p.x, p.y], "to": [p.x, p.y + 10.0], "steps": 4, "button": "middle" })); + drag(&mut h, &c, json!([p.x, p.y]), json!([p.x, p.y + 10.0]), 4, &[], "middle"); assert!(h.state().views[0].auto_scrolling(), "release within the dead zone keeps scrolling toggled on"); ok(&mut h, &c, "ui.move", json!({ "x": p.x, "y": p.y + 60.0 })); h.run_steps(8); @@ -764,7 +769,7 @@ fn autoscroll_is_scoped_to_the_active_view_and_cannot_start_under_a_dialog() { ok(&mut h, &c, "ui.click", json!({ "x": p.x, "y": p.y, "button": "middle" })); assert!(!h.state().views[0].auto_scrolling(), "a modal owns its input"); assert!(call(&mut h, &c, "ui.move", json!({ "x": "bad", "y": 2 })).is_err()); - assert!(call(&mut h, &c, "ui.drag", json!({ "from": [1, 2], "to": [3, 4], "button": "bad" })).is_err()); + assert!(call(&mut h, &c, "ui.click", json!({ "x": 1, "y": 2, "button": "bad" })).is_err()); } #[cfg(target_os = "linux")] @@ -808,7 +813,7 @@ fn middle_button_pans_while_held_outside_linux() { h.state_mut().quick_tool = pdfcraft_ui_egui::QuickTool::Crop; let p = h.state().views[0].viewport_rect().center(); let top = h.state().views[0].page_screen_rect(1).unwrap().top(); - ok(&mut h, &c, "ui.drag", json!({ "from": [p.x, p.y], "to": [p.x, p.y - 60.0], "steps": 12, "button": "middle" })); + drag(&mut h, &c, json!([p.x, p.y]), json!([p.x, p.y - 60.0]), 12, &[], "middle"); h.run_steps(2); let moved = h.state().views[0].page_screen_rect(1).unwrap().top(); assert!((moved - (top - 60.0)).abs() < 1.0, "the page follows the pointer 1:1: {top} -> {moved}"); @@ -830,7 +835,7 @@ fn inverted_middle_drag_moves_the_view_the_way_the_pointer_goes() { h.run_steps(2); let p = h.state().views[0].viewport_rect().center(); let top = h.state().views[0].page_screen_rect(1).unwrap().top(); - ok(&mut h, &c, "ui.drag", json!({ "from": [p.x, p.y], "to": [p.x, p.y - 60.0], "steps": 12, "button": "middle" })); + drag(&mut h, &c, json!([p.x, p.y]), json!([p.x, p.y - 60.0]), 12, &[], "middle"); h.run_steps(2); let moved = h.state().views[0].page_screen_rect(1).unwrap().top(); assert!((moved - (top + 60.0)).abs() < 1.0, "dragging up scrolls up, so the page moves down: {top} -> {moved}"); @@ -998,7 +1003,7 @@ fn preferences_menu_and_shortcut_allow_switching_interface_languages() { assert_eq!(ok(&mut h, &c, "ui.state", json!({}))["language"], code); } ok(&mut h, &c, "ui.click", json!({ "label": "OK" })); - ok(&mut h, &c, "ui.key", json!({ "key": ",", "modifiers": ["command"] })); + ok(&mut h, &c, "ui.key", json!({ "key": ",", "modifiers": {"command": true} })); let prefs = ok(&mut h, &c, "ui.inspect", json!({ "query": "表示言語" })); assert!(prefs["count"].as_u64().unwrap() > 0, "{prefs}"); ok(&mut h, &c, "ui.click", json!({ "label": "OK" })); @@ -1129,7 +1134,7 @@ fn commands_keys_and_typing() { assert_eq!(list["commands"].as_array().unwrap().iter().find(|x| x["id"] == "edit.undo").unwrap()["enabled"], true); // ⌘K opens the palette; typing filters it; Escape closes it. - ok(&mut h, &c, "ui.key", json!({ "key": "K", "modifiers": ["command"] })); + ok(&mut h, &c, "ui.key", json!({ "key": "K", "modifiers": {"command": true} })); assert!(palette_on_screen(&h), "the palette is on screen"); ok(&mut h, &c, "ui.type", json!({ "text": "split" })); let hits = ok(&mut h, &c, "ui.inspect", json!({ "query": "split document" })); @@ -1164,16 +1169,7 @@ fn ctrl_dragging_a_thumbnail_through_the_control_channel_copies_the_page() { let (a, b) = (cell(&mut h, &c, 1), cell(&mut h, &c, 3)); // The gesture reads the OS the context reports: Option on macOS, Ctrl elsewhere. let copy = if h.ctx.os() == egui::os::OperatingSystem::Mac { "alt" } else { "ctrl" }; - ok( - &mut h, - &c, - "ui.drag", - json!({ - "from": [(a[0] + a[2]) / 2.0, (a[1] + a[3]) / 2.0], - "to": [b[2] - 4.0, (b[1] + b[3]) / 2.0], - "modifiers": [copy], - }), - ); + drag(&mut h, &c, json!([(a[0] + a[2]) / 2.0, (a[1] + a[3]) / 2.0]), json!([b[2] - 4.0, (b[1] + b[3]) / 2.0]), 8, &[copy], "primary"); h.run_steps(3); let st = ok(&mut h, &c, "ui.state", json!({})); assert_eq!(st["documents"][0]["pages"], 4, "the drag copied the page instead of moving it: {st}"); @@ -1209,7 +1205,7 @@ fn saved_signature_can_be_changed_through_the_control_channel() { let r = field["rect"].as_array().unwrap(); let [x0, y0, x1, y1] = [0, 1, 2, 3].map(|i| r[i].as_f64().unwrap()); ok(&mut h, &c, "ui.click", json!({ "x": (x0 + x1) / 2.0, "y": (y0 + y1) / 2.0 })); - ok(&mut h, &c, "ui.key", json!({ "key": "A", "modifiers": ["command"] })); + ok(&mut h, &c, "ui.key", json!({ "key": "A", "modifiers": {"command": true} })); ok(&mut h, &c, "ui.type", json!({ "text": "Grace Hopper" })); ok(&mut h, &c, "ui.click", json!({ "label": "Apply" })); assert_eq!(h.state().signature, Some(craft::review::SavedSignature::Typed("Grace Hopper".into()))); @@ -1230,7 +1226,7 @@ fn drawing_a_comment_by_drag_and_its_context_menu() { let r = &st["active"]["pages_on_screen"][0]["rect"]; let (x0, y0, x1, y1) = (r[0].as_f64().unwrap(), r[1].as_f64().unwrap(), r[2].as_f64().unwrap(), r[3].as_f64().unwrap()); let (a, b) = ([x0 + (x1 - x0) * 0.2, y0 + (y1 - y0) * 0.2], [x0 + (x1 - x0) * 0.5, y0 + (y1 - y0) * 0.4]); - ok(&mut h, &c, "ui.drag", json!({ "from": a, "to": b })); + drag(&mut h, &c, json!(a), json!(b), 8, &[], "primary"); h.run_steps(2); let st = ok(&mut h, &c, "ui.state", json!({})); assert_eq!(st["active"]["selected_comment"], json!({ "page": 1, "index": 1 }), "{st}"); @@ -1239,7 +1235,7 @@ fn drawing_a_comment_by_drag_and_its_context_menu() { ok(&mut h, &c, "ui.click", json!({ "x": (a[0] + b[0]) / 2.0, "y": (a[1] + b[1]) / 2.0, "button": "secondary" })); let menu = ok(&mut h, &c, "ui.inspect", json!({ "query": "Set status" })); assert!(menu["count"].as_u64().unwrap() >= 1, "{menu}"); - assert!(call(&mut h, &c, "ui.drag", json!({ "from": [1, 2] })).unwrap_err().contains("to must be")); + assert!(call(&mut h, &c, "ui.move", json!({ "x": 1 })).is_err()); } #[test] @@ -1825,7 +1821,7 @@ fn navigation_history_for_os(os: egui::os::OperatingSystem) { assert!(call(&mut h, &c, "ui.command", json!({"id": "view.previous_view"})).is_err()); // Empty-history shortcuts were silent before registry integration and must stay silent. for key in ["[", "]"] { - ok(&mut h, &c, "ui.key", json!({"key": key, "modifiers": ["command"]})); + ok(&mut h, &c, "ui.key", json!({"key": key, "modifiers": {"command": true}})); assert!(crate::support::shown_notice(&h).is_none(), "an unavailable history action must not ask to open the already-open document"); } let before = h.state().session.get(h.state().views[0].id).unwrap().bytes.clone(); @@ -1839,9 +1835,9 @@ fn navigation_history_for_os(os: egui::os::OperatingSystem) { ok(&mut h, &c, "ui.command", json!({"id": "view.next_view"})); assert_eq!(h.state().views[0].current(), 3); ok(&mut h, &c, "ui.set", json!({"key": "page", "value": "5"})); - ok(&mut h, &c, "ui.key", json!({"key": "[", "modifiers": ["command"]})); + ok(&mut h, &c, "ui.key", json!({"key": "[", "modifiers": {"command": true}})); assert_eq!(h.state().views[0].current(), 3, "shortcut traverses exactly one history entry"); - ok(&mut h, &c, "ui.key", json!({"key": "]", "modifiers": ["command"]})); + ok(&mut h, &c, "ui.key", json!({"key": "]", "modifiers": {"command": true}})); assert_eq!(h.state().views[0].current(), 4); ok(&mut h, &c, "ui.command", json!({"id": "view.previous_view"})); let ctx_h = h.ctx.clone(); diff --git a/crates/ui-egui/tests/it/text_select.rs b/crates/ui-egui/tests/it/text_select.rs index cb147e0198..f95cc800e5 100644 --- a/crates/ui-egui/tests/it/text_select.rs +++ b/crates/ui-egui/tests/it/text_select.rs @@ -514,6 +514,13 @@ fn three_pages() -> Harness<'static, PdfCraftApp> { app.set_option(&egui::Context::default(), "zoom", "75").unwrap(); }); crate::support::wait_until(&mut h, "every page's text layer", |app| { + eprintln!( + "DIAG a_flick_off_the_page_still_selects_from_the_press: glyph {:?} rect {:?} text {:?} pending {}", + (0..3).map(|p| app.views[0].glyph_screen_pos(p, 10).is_some()).collect::>(), + (0..3).map(|p| app.views[0].page_screen_rect(p).is_some()).collect::>(), + (0..3).map(|p| app.views[0].has_page_text(p)).collect::>(), + app.render_pending() + ); (0..3).all(|p| app.views[0].glyph_screen_pos(p, 10).is_some()) && !app.render_pending() }); let viewport = h.state().views[0].viewport_rect(); diff --git a/crates/ui-egui/tests/it/ui.rs b/crates/ui-egui/tests/it/ui.rs index 189ed12e69..2565445bd7 100644 --- a/crates/ui-egui/tests/it/ui.rs +++ b/crates/ui-egui/tests/it/ui.rs @@ -458,7 +458,8 @@ fn a_document_asking_for_full_screen_is_asked_about_first() { let mut h = harness(move |app| app.open_bytes(&egui::Context::default(), "deck.pdf", None, deck()).expect("opens")); h.run_steps(3); assert!(!h.state().full_screen(), "nothing happens before the answer"); - h.get_by_label("Open in Full Screen mode?"); + // The dialog and its title share the label: the dialog is the one node of its role. + h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Open in Full Screen mode?"); h.get_by_label("Not now").click(); h.run_steps(3); assert!(!h.state().full_screen());