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

This commit is contained in:
Dylan M. Taylor
2026-11-19 14:39:16 -05:00
5 changed files with 53 additions and 70 deletions
+11 -4
View File
@@ -1,5 +1,5 @@
use super::{DocView, Edit, Pos2, ViewAction};
use craft::behavior::{IconId, MiddleButton, Selection};
use craft::behavior::{GesturePhase, IconId, MiddleButton, Selection};
use craft::keymap::CommandRef;
use craft::pages::ui::thumbnails::{ORGANIZE_ZOOM, PageThumbnails, ThumbnailArrangement, ThumbnailEvent};
use craft::ui::bars::{Bar, BarKind};
@@ -218,7 +218,12 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document,
for event in out.events {
match event {
ThumbnailEvent::Go(page) => view.go_to_page(page),
ThumbnailEvent::Reorder(craft::behavior::EditEvent::Commit { after, .. }) => commit_reorder(view, after.keys, after.to, after.copy),
// A drag ends as a commit, a keyboard move as a set; proposals during the drag move nothing.
ThumbnailEvent::Reorder(edit) if matches!(edit.phase(), Some(GesturePhase::Commit) | None) => {
if let Some(mv) = edit.value() {
commit_reorder(view, mv.keys.clone(), mv.to, mv.copy);
}
}
ThumbnailEvent::Delete(pages) => view.session.pending_edit = Some(Edit::DeletePages { pages }),
ThumbnailEvent::Activate(page) => {
view.organize = false;
@@ -246,8 +251,10 @@ pub(super) fn organize_grid(view: &mut DocView, doc: &pdfcraft_engine::Document,
}
if let Some(at) = cx.ui.data(|d| d.get_temp::<Option<Pos2>>(menu_id)).flatten() {
let mut open = true;
// PLAN: assumed `Anchor::Point(Pos2)` places a menu opened from an event at the request's point.
Menu::new(tl!("Page")).anchor(Anchor::Point(at)).open(Bind::bound(&mut open)).show(cx.ui, |ui, _| page_menu(ui, view, editable));
Menu::context(tl!("Page"), &out.response)
.anchor(Anchor::Point(at))
.open(Bind::bound(&mut open))
.show(cx.ui, |ui, _| page_menu(ui, view, editable));
if !open {
cx.ui.data_mut(|d| d.insert_temp::<Option<Pos2>>(menu_id, None));
}
+7
View File
@@ -88,6 +88,13 @@ impl PdfCraftApp {
let id = fired.command.id.as_str();
let active = self.active;
match id {
// The Combine list takes Select all and Delete while it shows, whatever has the focus
// there (a text field keeps them).
"edit.select_all" if self.combine_showing() => {
let rows: Vec<usize> = (0..self.combine_draft.len()).collect();
self.select_combine_rows(&rows);
}
crate::menus::DELETE if self.combine_showing() => self.combine_apply(crate::combine_ui::RowAction::Remove),
"edit.select_all" => {
if let Some(i) = active {
self.select_all(i, ctx);
+1 -1
View File
@@ -187,7 +187,7 @@ 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"),
SELECT_ALL | DELETE => 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(),
id => enabled_id(id),
+8 -5
View File
@@ -44,7 +44,8 @@ impl PdfCraftApp {
}
/// One pass over the dialog: applies the chosen order when it differs from what every page has and the document
/// is as the dialog opened it.
/// is still active and as the dialog opened it. Another document becoming active, or an edit, while the dialog
/// was open means the pages at those indices may not be the ones chosen: nothing changes and the user is told.
pub(crate) fn page_props_pass(&mut self, ctx: &egui::Context, _ctx: &egui::Context) {
let Some(result) = self.dialogs.take_by_id::<HostedParamDialog>(dialog_id(KEY)) else { return };
let Some(draft) = self.page_props_draft.take() else { return };
@@ -54,11 +55,13 @@ impl PdfCraftApp {
if draft.before == Some(order) {
return;
}
let current = self.session.get(draft.doc).is_some_and(|d| d.edit_generation() == draft.generation);
let Some(index) = self.views.iter().position(|v| v.id == draft.doc) else { return };
if current {
self.active = Some(index);
let active = self.active_ids().is_some_and(|(_, id)| id == draft.doc);
if active && self.session.get(draft.doc).is_some_and(|d| d.edit_generation() == draft.generation) {
self.apply_edit(ctx, Edit::SetTabOrder { pages: draft.pages, order });
} else {
self.notify_tr(
"The document changed while the dialog was open, so nothing was changed. Open Page properties again to set the tab order.",
);
}
}
}
+26 -60
View File
@@ -571,9 +571,9 @@ fn closing_a_dirty_tab_can_save_first() {
#[test]
fn the_save_prompt_answers_to_the_keyboard() {
// Issue #8: Enter saves; ⌘D / Ctrl+D, Alt+D and Alt+N don't save; Escape cancels. While the
// prompt is open, ⌘D is not Document properties.
for (m, key) in [(Modifiers::COMMAND, Key::D), (Modifiers::ALT, Key::D), (Modifiers::ALT, Key::N)] {
// Issue #8: Enter saves; ⌘D / Ctrl+D and, off macOS, Alt+N (the button's letter) don't save;
// Escape cancels. While the prompt is open, ⌘D is not Document properties.
for (m, key) in [(Modifiers::COMMAND, Key::D), (Modifiers::ALT, Key::N)] {
let mut h = organize(2);
h.get_by_label("Rotate clockwise").click();
h.run_steps(3);
@@ -1184,6 +1184,9 @@ fn a_custom_property_whose_name_the_tools_refuse_is_listed_and_left_alone() {
// `/Client#20name` and `/Project#20` are valid PDF names with a space in them, which a new custom
// property can't have; `/Project#20` is not `/Project`. `/Dept#E9` is not UTF-8 and is listed as
// "Dept\u{FFFD}". `/Revision` is a number, so it isn't listed.
if crate::support::skip_without_glyphs("a_custom_property_whose_name_the_tools_refuse_is_listed_and_left_alone", "en", "Dept\u{FFFD}") {
return;
}
let pdf = String::from_utf8(fixture(1)).unwrap().replace(
"/Root 1 0 R >>\nstartxref",
"/Root 1 0 R /Info << /Client#20name (Acme) /Project#20 (Padded) /Dept#E9 (Sales) /Project (Apollo) /Revision 4 >> >>\nstartxref",
@@ -1434,7 +1437,7 @@ fn combining_files_opens_a_new_unsaved_tab() {
assert_eq!(doc.name, "Combined.pdf");
assert!(doc.dirty && doc.path.is_none(), "unsaved until the user saves it");
assert_eq!(doc.info.outline.iter().map(|o| o.title.as_str()).collect::<Vec<_>>(), ["one", "two"]);
h.get_by_label("Combined.pdf (edited)");
h.get_by_label("Combined.pdf, modified");
}
#[test]
@@ -2216,7 +2219,7 @@ fn grid_zoom(h: &Harness<'static, PdfCraftApp>) -> f64 {
#[test]
fn page_grid_size_is_remembered_for_every_document_and_restart() {
let mut h = organize(3);
h.get_by_label("Larger pages").click();
h.get_by_label("Larger Thumbnails").click();
h.run_steps(3);
assert_eq!(grid_zoom(&h), 1.25);
let ctx_h = h.ctx.clone();
@@ -2342,7 +2345,7 @@ fn split_from_organize_grid_context_menu() {
h.run_steps(2);
h.get_all_by_label("Split document…").last().unwrap().click();
h.run_steps(3);
h.get_by_label("Split document");
h.get_by_role_and_label(Role::Dialog, "Split document");
// The cut before the selected page is chosen: two parts, not one per page.
h.get_by_label_contains("Creates 2 files from 4 pages");
h.get_all_by_label("Split").last().unwrap().click();
@@ -2923,7 +2926,7 @@ fn restricted_documents_show_a_notice_and_block_page_changes() {
assert_eq!(texts_of(h.state(), 0).len(), 2, "page changes are blocked");
assert_eq!(h.query_all_by_label_contains("Insert a file").count(), 0, "nothing to insert into");
// Looking closer is not a page change.
h.get_by_label("Larger pages").click();
h.get_by_label("Larger Thumbnails").click();
h.run_steps(2);
assert_eq!(grid_zoom(&h), 1.25);
assert!(!dirty(&h));
@@ -7993,7 +7996,8 @@ fn a_selected_pictures_keys_wait_for_its_page_to_be_on_screen() {
});
h.run_steps(6);
assert!(h.state().views[0].continuous(), "a continuous view");
assert!(h.state().views[0].page_screen_rect(0).is_none(), "page 1 is off the screen");
let viewport = h.state().views[0].viewport_rect();
assert!(h.state().views[0].page_screen_rect(0).is_none_or(|r| !r.intersects(viewport)), "page 1 is off the screen");
h.key_press(egui::Key::Delete);
h.run_steps(4);
assert_eq!(h.state().session.get(id).unwrap().page_images(0).len(), pictures, "the picture stays");
@@ -8527,7 +8531,7 @@ fn leaving_organize_goes_back_to_the_workspace_panel() {
h.state_mut().left = LeftPanel::Tool("organize");
h.state_mut().views[0].organize = true;
h.run_steps(3);
h.get_by_label("Pages selected".to_uppercase().as_str());
h.get_by_label("Insert a blank page after the selection");
// What opening a page from the grid does.
h.state_mut().views[0].organize = false;
h.run_steps(3);
@@ -11419,8 +11423,7 @@ fn edit_cut_from_the_menu_bar_cuts_the_page() {
}
/// A native menu's Edit ▸ Paste with a page's context menu open closes the menu, which the click
/// never reached, and the platform's answer pastes the page, also when it comes late (on Wayland
/// egui-winit reads the clipboard asynchronously, within 3 seconds).
/// never reached, and pastes the page; each Edit ▸ Paste pastes it once.
#[test]
fn a_late_paste_for_a_native_edit_paste_with_a_context_menu_open_pastes_the_page() {
let mut h = organize(3);
@@ -11433,44 +11436,18 @@ fn a_late_paste_for_a_native_edit_paste_with_a_context_menu_open_pastes_the_page
let pages = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(h.state().views[0].id).unwrap().info.pages.len();
h.get_by_label("Page 2").click_button(egui::PointerButton::Secondary);
h.run_steps(2);
assert!(egui::Popup::is_any_open(&h.ctx), "the page's context menu is open");
assert!(h.query_by_role(Role::Menu).is_some(), "the page's context menu is open");
support::fire_menu(&mut h, "edit.paste");
assert!(support::asked_for_the_clipboard(&h), "Edit ▸ Paste asked the platform for the clipboard");
h.run_steps(3);
assert!(!egui::Popup::is_any_open(&h.ctx), "Edit ▸ Paste closed the context menu");
h.event(egui::Event::Paste("clipboard text".into()));
assert!(h.query_by_role(Role::Menu).is_none(), "Edit ▸ Paste closed the context menu");
assert_eq!(pages(&h), 4, "Edit ▸ Paste pasted the page");
support::fire_menu(&mut h, "edit.paste");
h.run_steps(3);
assert_eq!(pages(&h), 4, "the late paste pasted the page");
assert_eq!(pages(&h), 5, "a second Edit ▸ Paste pasted it again");
}
/// Two native Edit ▸ Pastes with a page's context menu open each ask for the clipboard, and each
/// answer pastes the page (on Wayland they come one by one).
#[test]
fn two_native_edit_pastes_with_a_context_menu_open_paste_twice() {
let mut h = organize(3);
h.run_steps(2);
h.get_by_label("Page 2").click();
h.run_steps(2);
h.event(egui::Event::Copy);
h.run_steps(3);
assert!(h.state().page_clipboard.is_some(), "the page is copied");
let pages = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(h.state().views[0].id).unwrap().info.pages.len();
h.get_by_label("Page 2").click_button(egui::PointerButton::Secondary);
h.run_steps(2);
assert!(egui::Popup::is_any_open(&h.ctx), "the page's context menu is open");
for _ in 0..2 {
support::fire_menu(&mut h, "edit.paste");
assert!(support::asked_for_the_clipboard(&h), "Edit ▸ Paste asked the platform for the clipboard");
}
for pasted in [4, 5] {
h.event(egui::Event::Paste("clipboard text".into()));
h.run_steps(3);
assert_eq!(pages(&h), pasted, "each answer pastes the page");
}
}
/// A paste behind a page's context menu stays there, also one that answers an Edit ▸ Paste asked
/// for before the user opened the menu (egui-winit answers it as it answers ⌘V): it pastes no page.
/// A paste (⌘V's answer from the platform) behind a page's context menu stays there: it pastes no
/// page.
#[test]
fn a_paste_behind_a_context_menu_opened_after_edit_paste_pastes_nothing() {
let mut h = organize(3);
@@ -11483,18 +11460,17 @@ fn a_paste_behind_a_context_menu_opened_after_edit_paste_pastes_nothing() {
let pages = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(h.state().views[0].id).unwrap().info.pages.len();
support::fire_menu(&mut h, "edit.paste");
h.run_steps(2);
assert_eq!(pages(&h), 4, "Edit ▸ Paste pasted the page");
h.get_by_label("Page 2").click_button(egui::PointerButton::Secondary);
h.run_steps(2);
assert!(egui::Popup::is_any_open(&h.ctx), "the page's context menu is open");
assert!(h.query_by_role(Role::Menu).is_some(), "the page's context menu is open");
h.event(egui::Event::Paste("clipboard text".into()));
h.run_steps(3);
assert_eq!(pages(&h), 3, "the paste behind the context menu pasted the page");
assert_eq!(pages(&h), 4, "the paste behind the context menu pasted no page");
}
/// Edit ▸ Paste from the in-window menu bar pastes the copied page in Organize. The bar reads as
/// open on the pass after its click, so Edit ▸ Paste asks the platform for the clipboard once it
/// has let go of the keys, and the answer (kittest gives none, so the test does) comes to the
/// pages. An answer to a request sent with the click would come while the bar still held the keys.
/// Edit ▸ Paste from the in-window menu bar pastes the copied page in Organize, where the clipboard
/// commands are the picked pages' (`page.paste`), once and whatever the system clipboard holds.
#[test]
fn edit_paste_from_the_menu_bar_pastes_the_copied_page() {
let mut h = organize(3);
@@ -11508,16 +11484,6 @@ fn edit_paste_from_the_menu_bar_pastes_the_copied_page() {
assert_eq!(pages(&h), 3);
support::open_menu(&mut h, "Edit");
support::menu_row(&h, "Paste").click();
h.step();
assert!(craft_menu::bar::is_open(&h.ctx), "the bar reads as open on the pass after the click");
assert!(!support::asked_for_the_clipboard(&h), "Edit ▸ Paste asked while the bar held the keys");
let mut asked = false;
for _ in 0..4 {
h.step();
asked |= support::asked_for_the_clipboard(&h);
}
assert!(asked, "Edit ▸ Paste asked the platform for the clipboard");
h.event(egui::Event::Paste("clipboard text".into()));
h.run_steps(4);
assert_eq!(pages(&h), 4, "Edit ▸ Paste pasted the page");
}