Merge branch 'red9/g1' into area/app-1

This commit is contained in:
Dylan M. Taylor
2026-11-19 17:27:14 -05:00
9 changed files with 102 additions and 47 deletions
+11
View File
@@ -905,6 +905,17 @@ impl PdfCraftApp {
OpenOutcome::Pending
}
/// Reopen `path` from the last session: shown at `place` once open, and brought to the front only when `front`.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn reopen_path(&mut self, path: &str, place: pdfcraft_render::RemoteDestination, front: bool) {
if !matches!(self.open_file_request(path, Some(place), None, None), OpenOutcome::Pending) {
return;
}
if let Some(pending) = self.pending_opens.iter_mut().find(|p| p.path.as_deref().is_some_and(|p| same_file(p, path))) {
pending.activate = front;
}
}
/// Apply an explicit launch layout after the command-line display overrides settle.
#[cfg(not(target_arch = "wasm32"))]
pub fn set_launch_layout(&mut self, value: &str) -> Result<(), String> {
+6 -3
View File
@@ -35,7 +35,7 @@ pub(super) mod crop;
mod find;
pub(super) mod image_pick;
mod navigation;
mod organize;
pub(crate) mod organize;
// PLAN: no sheet assigns the `mod` lines of the four new page-body files (pdf-canvas-w9 `page_parts.rs`,
// `page_tools.rs`; pdf-canvas-w10 `pictures.rs`; pdf-canvas-w15 `page_overlays.rs`); the host writes them here.
pub(crate) mod page_overlays;
@@ -398,6 +398,8 @@ pub struct PageSession {
/// What the last secondary press on a page went to, and on which page (`None` off the pages): the page's menu
/// shows its entries when it has a menu and is the one selected, or else the page's own.
pub(crate) menu_for: Option<(usize, Owner)>,
/// A right-click of this pass that a page control kept for itself (a picture's crop): the page's menu stays shut.
pub(crate) context_held: bool,
}
impl PageSession {
@@ -455,6 +457,7 @@ impl PageSession {
redact_gesture: Default::default(),
stamp_press: None,
menu_for: None,
context_held: false,
}
}
}
@@ -554,7 +557,7 @@ impl DocView {
/// that were already completed before cancellation.
pub(crate) fn cancel_pointer_gestures(&mut self, ctx: &egui::Context) {
self.session.comments.tool.cancel_drawing();
self.cancel_organize_press(ctx);
self.cancel_page_drags(ctx);
}
/// A view of a newly opened document, shown as `defaults` say, with fields highlighted when `highlight_fields`
@@ -641,7 +644,7 @@ impl DocView {
self.view.go_to = None;
self.session.flash = None;
// Thumbnail drags hold page indexes from before the change.
self.cancel_organize_press(ctx);
self.cancel_page_drags(ctx);
self.session.comments.document_changed(info);
}
+21 -4
View File
@@ -26,12 +26,17 @@ const ROTATE_CCW: usize = 0;
const ROTATE_CW: usize = 1;
const DELETE: usize = 2;
/// The grid's id: the press owner `PageThumbnails::id` takes and `cancel_organize_press` ends. One place builds it, so the
/// The grid's id: the press owner `PageThumbnails::id` takes and `cancel_page_drags` ends. One place builds it, so the
/// two cannot drift; the pane key outlives `document_replaced`.
fn organize_grid_id(view: &DocView) -> egui::Id {
egui::Id::new(("organize-grid", view.view_key()))
}
/// The Pages panel grid's id, built the same way as [`organize_grid_id`].
pub(crate) fn pages_panel_grid_id(view: &DocView) -> egui::Id {
egui::Id::new(("pages-panel-grid", view.view_key()))
}
impl DocView {
/// Open Organize Pages on the page being read (issue #1910). An empty selection means the
/// current page, so a selection left from earlier that does not include it is dropped, and
@@ -73,10 +78,11 @@ impl DocView {
self.selected = Selection::new(Vec::new(), None, anchor.filter(|a| *a < self.page_count));
}
/// Ends a page drag the Organize grid holds open: its indices came from a document the edit, undo, redo or
/// replacement has since changed.
pub(crate) fn cancel_organize_press(&self, ctx: &egui::Context) {
/// Ends a page drag the Organize grid or the Pages panel holds open: its indices came from a document the edit,
/// undo, redo or replacement has since changed.
pub(crate) fn cancel_page_drags(&self, ctx: &egui::Context) {
PageThumbnails::cancel_press(ctx, organize_grid_id(self));
PageThumbnails::cancel_press(ctx, pages_panel_grid_id(self));
}
}
@@ -187,6 +193,16 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document,
(IconId::new("rotate_cw"), CommandRef::new("page.rotate")),
(IconId::new("trash-2"), CommandRef::new("page.delete")),
];
// Each action names the page it acts on, so a screen reader can tell one tile's buttons from the next.
let action_label = |action: usize, page: usize| {
let template = match action {
ROTATE_CCW => tl!("Rotate page {label} counterclockwise"),
ROTATE_CW => tl!("Rotate page {label} clockwise"),
_ => tl!("Delete page {label}"),
};
let label = info.pages.get(page).map_or_else(|| (page + 1).to_string(), |p| p.label.clone());
crate::i18n::fmt(template, &[("label", &label)]).into()
};
let insert_label = |at: usize| {
match info.pages.get(at) {
Some(p) => crate::i18n::fmt(tl!("Insert a file before page {label}"), &[("label", &p.label)]),
@@ -205,6 +221,7 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document,
.editable(editable)
.size(&mut *cx.zoom)
.actions(&actions)
.action_label(&action_label)
.insert_label(&insert_label)
.middle_button(middle)
.invert_middle(cx.invert_middle)
+5
View File
@@ -384,6 +384,11 @@ pub(crate) fn show(
cx: &PageMenuCx<'_>,
) -> PageMenuPick {
let mut pick = PageMenuPick::default();
// A right-click a page control kept for itself (the picture being cropped) opens no menu: the menu does not run in
// the pass of its trigger.
if std::mem::take(&mut view.session.context_held) {
return pick;
}
let mut menu = Menu::context(tl!("Page").to_string(), opener);
if let Some(request) = request {
menu = menu.anchor(Anchor::Point(request.at));
+4 -1
View File
@@ -188,7 +188,10 @@ fn enabled(app: &PdfCraftApp, ctx: &egui::Context, command: &CommandRef) -> bool
}
PASTE if edit_objects && app.object_clipboard.is_some() => doc.is_some_and(pdfcraft_engine::Document::allows_modification),
CUT => organize && enabled_id("page.cut"),
PASTE => organize && app.page_clipboard.is_some() && enabled_id("page.paste"),
PASTE if organize => app.page_clipboard.is_some() && enabled_id("page.paste"),
// On the pages Paste takes what the clipboard holds (a picture, comments), which only the paste itself reads:
// ⌘V and the platform's delivered paste are this command.
PASTE => has_doc,
SELECT_ALL | DELETE => has_doc || app.combine_showing() && !app.combine_draft.is_empty(),
id if id.starts_with("view.zoom.") || id.starts_with("view.rotate.") => has_doc,
PANEL => menus::panel(command).is_some(),
+2
View File
@@ -33,7 +33,9 @@ pub(super) fn body(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult {
let before = view.thumbnail_zoom();
let mut zoom = f64::from(before);
let current = view.current();
let grid_id = crate::canvas::organize::pages_panel_grid_id(view);
let output = PageThumbnails::new(tl!("Pages"), &source, &mut view.selected, current, DataColor::new(egui::Color32::WHITE))
.id(grid_id)
.editable(editable)
.size(&mut zoom)
.show(ui);
+7 -22
View File
@@ -51,28 +51,13 @@ impl PdfCraftApp {
let is_open = |path: &str| {
self.views.iter().any(|v| self.session.get(v.id).and_then(|d| d.path.as_deref()).map(session::absolute).as_deref() == Some(path))
};
let documents = last.to_reopen(&skip, is_open);
let mut active = None;
let mut prompt = self.password_prompt.take();
for document in documents {
let before = self.views.len();
self.open_path(&document.path);
if let Some(p) = self.password_prompt.take() {
prompt.get_or_insert(p);
}
if self.views.len() > before
&& let Some(view) = self.views.last_mut()
{
// `go_to_page` clamps a page past the end.
view.go_to_page(document.view["page"].as_u64().and_then(|p| usize::try_from(p).ok()).unwrap_or(0));
if last.active.as_deref() == Some(document.path.as_str()) {
active = Some(self.views.len() - 1);
}
}
}
self.password_prompt = prompt;
if active.is_some() {
self.active = active;
// The opens are queued: each takes the page it showed with it, and only the session's active file comes
// to the front.
for document in last.to_reopen(&skip, is_open) {
let page = document.view["page"].as_u64().and_then(|p| usize::try_from(p).ok()).unwrap_or(0);
let place = pdfcraft_render::RemoteDestination::Page { page, view: pdfcraft_render::DestView::Top };
let front = last.active.as_deref().is_none_or(|active| active == document.path);
self.reopen_path(&document.path, place, front);
}
}
#[cfg(target_arch = "wasm32")]
+23 -3
View File
@@ -1,6 +1,6 @@
use super::{DocInfo, Edit, MAX_OUTLINES, PageGeometry, PageSession, PageXform, Pos2, Rect, user_box};
use crate::canvas::page_parts::{Owner, PageLayer, PagePart, PagePress};
use craft::behavior::geometry::{BoxAllow, BoxRules, BoxState, CropBox, CropGuide, ScaleRule, TransformMode};
use craft::behavior::geometry::{BoxAllow, BoxPart, BoxRules, BoxState, CropBox, CropGuide, ScaleRule, TransformMode};
use craft::behavior::kurbo::{BezPath, Point, Rect as DocRect, Vec2};
use craft::behavior::{CanvasView, CursorIcon, EditEvent, HitShape, IconId, PointerButton};
use craft::draw::ui::transform::{RotateZone, TransformBox};
@@ -249,7 +249,7 @@ pub(crate) fn picture_controls(
let Some(image) = images.get(index) else { continue };
let cropping = session.image_selection.as_ref().is_some_and(|s| s.crop.is_some());
let pic = PagePicture { placed, xf: &xf, info, index, image };
let made = if cropping { crop_controls(ui, body, session, &pic) } else { box_controls(ui, body, session, doc, &pic) };
let made = if cropping { crop_controls(ui, body, session, &pic, &images) } else { box_controls(ui, body, session, doc, &pic) };
edit = edit.or(made);
}
edit
@@ -329,7 +329,13 @@ fn box_controls(
edit
}
fn crop_controls(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession, pic: &PagePicture<'_>) -> Option<Edit> {
fn crop_controls(
ui: &mut egui::Ui,
body: &PageBody<'_>,
session: &mut PageSession,
pic: &PagePicture<'_>,
images: &[pdfcraft_engine::PageImage],
) -> Option<Edit> {
let PagePicture { placed, xf, info, image, .. } = *pic;
let page = placed.page;
let keep = session.image_selection.as_ref().and_then(|s| s.crop.as_ref()).map(|c| c.keep)?;
@@ -346,6 +352,20 @@ fn crop_controls(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSessi
.min_side(least_side(ui, placed))
.guide((CropGuide::Thirds, 0))
.show_at(ui, body.rect);
// The overlay takes every right-click. One on the picture being cropped, its box or its grips is the crop's: crop
// mode stays and the page's menu stays shut. Anywhere else it goes to what lies there, as without crop mode
// (#5835).
if let Some((at, _)) = shown.context {
let hits = |image: &pdfcraft_engine::PageImage| HitShape::Polygon(picture_quad(xf, info, page, image).to_vec()).hit(at);
if hits(image) || !matches!(shown.hovered, None | Some(BoxPart::Outside)) {
session.context_held = true;
} else {
let under = placed.rect.contains(at).then(|| images.iter().rposition(|other| hits(other))).flatten();
picture_context(page, under, session);
session.menu_for = under.map(|index| (page, Owner::Picture { index }));
return None;
}
}
if crop.is_finite() && crop.rect != before.rect {
let to_screen = |p: Point| view.to_screen(p);
let moved = Rect::from_two_pos(to_screen(Point::new(crop.rect.x0, crop.rect.y0)), to_screen(Point::new(crop.rect.x1, crop.rect.y1)));
+23 -14
View File
@@ -226,10 +226,11 @@ fn organize_page_range_tracks_thumbnails_and_applies_typed_selection() {
use egui::accesskit::Role;
let _gpu = gpu();
let mut h = organize(100);
// A tile's check toggles its page as ⌘-click does; the check is the pointer's only, so the test ⌘-clicks.
h.get_by_label("Page 2").click();
h.run_steps(2);
assert_eq!(h.get_by_role_and_label(Role::TextInput, "Selected pages").value().as_deref(), Some("2"));
h.get_by_label("Page 3").click();
h.get_by_label("Page 3").click_modifiers(Modifiers::COMMAND);
h.run_steps(2);
assert_eq!(h.get_by_role_and_label(Role::TextInput, "Selected pages").value().as_deref(), Some("2-3"));
let old = h.state().views[0].selected.clone();
@@ -342,7 +343,7 @@ fn organize_page_actions_rotate_only_the_named_page_and_undo() {
let mut h = organize(3);
h.get_by_label("Page 1").click();
h.run_steps(2);
h.get_by_label("Page 3").click();
h.get_by_label("Page 3").click_modifiers(Modifiers::COMMAND);
h.run_steps(2);
h.get_by_label("Rotate page 1 clockwise").click();
h.run_steps(3);
@@ -1584,10 +1585,12 @@ fn column_headings_sort_the_list_and_flip_on_the_second_click() {
h.get_by_label("File name").click();
h.run_steps(2);
assert_eq!(combine_names(&h), ["a.pdf", "Scan2.pdf", "scan10.pdf"], "case-insensitive, numbers by value");
h.get_by_label("File name, sorted ascending").click();
h.get_by_label("File name").click();
h.run_steps(2);
assert_eq!(combine_names(&h), ["scan10.pdf", "Scan2.pdf", "a.pdf"]);
h.get_by_label("Pages").click();
// The Pages heading: the Pages panel shares its name.
let heading = h.get_by_label("File name").accesskit_node().role();
h.get_by_role_and_label(heading, "Pages").click();
h.run_steps(2);
assert_eq!(combine_names(&h), ["scan10.pdf", "a.pdf", "Scan2.pdf"]);
// Moving a file by hand ends the sorted order.
@@ -1595,7 +1598,7 @@ fn column_headings_sort_the_list_and_flip_on_the_second_click() {
h.get_by_label("Move up").click();
h.run_steps(2);
assert_eq!(h.state().combine_tab.sort, None);
h.get_by_label("Pages");
h.get_by_role_and_label(heading, "Pages");
}
#[test]
@@ -1641,7 +1644,7 @@ fn undo_and_redo_restore_the_combine_list() {
h.run_steps(2);
h.get_by_label("File name").click();
h.run_steps(2);
h.get_by_label("File name, sorted ascending").click();
h.get_by_label("File name").click();
h.run_steps(2);
assert_eq!(combine_names(&h), ["c.pdf", "b.pdf", "a.pdf"]);
h.get_by_label("Undo").click();
@@ -1698,12 +1701,12 @@ fn the_whole_heading_sorts_and_dragging_it_moves_the_column() {
assert_eq!(combine_names(&h), ["a.pdf", "b.pdf"]);
// Drag Size before File name.
let size = h.get_by_label("Size").rect().center();
let name = h.get_by_label("File name, sorted ascending").rect();
let name = h.get_by_label("File name").rect();
drag(&mut h, size, egui::pos2(name.left() + 10.0, name.center().y));
let order = ["size", "name", "pages", "modified", "warnings"].map(craft::behavior::ColumnKey::new);
assert_eq!(h.state().combine_columns.order, order);
assert_eq!(combine_names(&h), ["a.pdf", "b.pdf"], "moving a column doesn't sort");
let (size, name) = (h.get_by_label("Size").rect(), h.get_by_label("File name, sorted ascending").rect());
let (size, name) = (h.get_by_label("Size").rect(), h.get_by_label("File name").rect());
assert!(size.left() < name.left(), "Size now shows first");
}
@@ -2102,7 +2105,11 @@ impl egui::DroppedFile for Dropped {
}
}
/// Drops `files` as a platform does: held over the window for a frame, then dropped.
fn drop_files(h: &mut Harness<'static, PdfCraftApp>, files: Vec<Dropped>) {
h.input_mut().hovered_files = files.iter().map(|f| egui::HoveredFile { path: Some(f.0.into()), mime: String::new() }).collect();
h.step();
h.input_mut().hovered_files.clear();
for f in files {
h.input_mut().dropped_files.push(std::sync::Arc::new(f));
}
@@ -3267,18 +3274,19 @@ fn option_copies_and_ctrl_moves_when_the_context_reports_macos() {
let grab = |h: &Harness<'static, PdfCraftApp>, label: &str| h.get_by_label(label).rect();
let points = |h: &Harness<'static, PdfCraftApp>| (grab(h, "Page 1").center(), grab(h, "Page 3").right_center() - egui::vec2(10.0, 0.0));
// Ctrl is not the copy modifier on macOS, so that drag moves the page.
// ⌘, where Ctrl copies elsewhere, is not the copy modifier on macOS, so that drag moves the page. (Control-press is
// the context click there.)
let mut h = organize(3);
h.ctx.set_os(egui::os::OperatingSystem::Mac);
craft::ui::testing::windows::set_os(&h.ctx, craft::host::target::Os::Mac);
let before = page_texts(h.state());
let (from, to) = points(&h);
page_drag(&mut h, from, to, Modifiers::CTRL);
assert_eq!(page_texts(h.state()), vec![before[1].clone(), before[2].clone(), before[0].clone()], "Ctrl moves on macOS");
page_drag(&mut h, from, to, Modifiers { mac_cmd: true, command: true, ..Modifiers::NONE });
assert_eq!(page_texts(h.state()), vec![before[1].clone(), before[2].clone(), before[0].clone()], "⌘ moves on macOS");
assert_eq!(h.state().session.get(h.state().views[0].id).unwrap().can_undo(), Some("Move page"));
// Option is, so the same drag drops a copy at the gap.
let mut h = organize(3);
h.ctx.set_os(egui::os::OperatingSystem::Mac);
craft::ui::testing::windows::set_os(&h.ctx, craft::host::target::Os::Mac);
let before = page_texts(h.state());
let (from, to) = points(&h);
page_drag(&mut h, from, to, Modifiers::ALT);
@@ -6253,7 +6261,8 @@ fn a_thumbnail_drag_that_ends_off_the_panel_or_outlives_the_pages_is_dropped() {
let to = start_drag(&mut h, "Page 4");
let id = h.state().views[0].id;
let info = h.state().session.get(id).unwrap().info.clone();
h.state_mut().views[0].document_changed(&egui::Context::default(), &info);
let ctx = h.ctx.clone();
h.state_mut().views[0].document_changed(&ctx, &info);
h.hover_at(to);
h.run_steps(1);
h.drop_at(to);