mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 17:27:54 +00:00
red8 g1: app red round 8 fixes
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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")),
|
||||
],
|
||||
}],
|
||||
},
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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.",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user