mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 04:58:07 +00:00
red10 g5: app red round 10 fixes
This commit is contained in:
@@ -530,11 +530,13 @@ impl PdfCraftApp {
|
||||
(Ok(bytes), _) => {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.pick_first(PickRequest::save("attachment").file_name(safe_file_name(&att.name, "attachment")), None, move |app, _, path| {
|
||||
match craft::atomic::atomic_write(&path, &bytes) {
|
||||
Ok(()) => {
|
||||
match app.host.files().write(&path, &bytes, craft::host::WriteIntent::SaveAs) {
|
||||
Ok(taken_by_host) => {
|
||||
// Windows: the file keeps the document's Mark-of-the-Web (#3990). Best
|
||||
// effort: a volume without alternate data streams can't carry it.
|
||||
let _ = pdfcraft_platform::zone::mark_from(&path, source.as_deref().map(std::path::Path::new));
|
||||
if !taken_by_host {
|
||||
let _ = pdfcraft_platform::zone::mark_from(&path, source.as_deref().map(std::path::Path::new));
|
||||
}
|
||||
app.notify_fmt("Saved {name}", &[("name", &path.display().to_string())])
|
||||
}
|
||||
Err(e) => app.notify_fmt("Couldn't save: {e}", &[("e", &e.to_string())]),
|
||||
@@ -921,7 +923,10 @@ impl PdfCraftApp {
|
||||
pub fn set_launch_layout(&mut self, value: &str) -> Result<(), String> {
|
||||
let (layout, continuous) = canvas::parse_display_token(value).ok_or("layout must be single, continuous, two-up or two-page")?;
|
||||
self.launch_layout = Some((layout, continuous));
|
||||
self.settle_launch_layout();
|
||||
// The option may arrive before any flagged open; don't consume it before it has a target.
|
||||
if self.launch_display_target.is_some() {
|
||||
self.settle_launch_layout();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,6 @@ impl PdfCraftApp {
|
||||
|
||||
/// A picker is on screen or waiting: opens and full-screen prompts hold back meanwhile.
|
||||
pub(crate) fn picks_pending(&self) -> bool {
|
||||
self.host.files().pick_pending()
|
||||
!self.picks.waiting.is_empty() || self.host.files().pick_pending()
|
||||
}
|
||||
}
|
||||
|
||||
+34
-22
@@ -8,13 +8,14 @@ use craft::behavior::{DisplayOrder, ItemSource, SizeHint};
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::theme::variant::Tone;
|
||||
use craft::ui::buttons::{Button, IconButton};
|
||||
use craft::ui::contract::{CollectionEvent, Props as _, Show as _, ShowCollection as _};
|
||||
use craft::ui::contract::{ActivateOn, CollectionEvent, Pad, Props as _, Show as _, ShowCollection as _, ShowContainer as _, clicked};
|
||||
use craft::ui::display::{PictureSize, Text};
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::list::ThumbSize;
|
||||
use craft::ui::notices::Notice;
|
||||
use craft::ui::runtime::env::Env;
|
||||
use craft::ui::shell::{RecentFile, StartAction, StartLink, StartPlace, StartScreen};
|
||||
use craft::ui::style::DataColor;
|
||||
use craft::ui::shell::{RecentFile, StartAction, StartPlace, StartScreen};
|
||||
use craft::ui::style::{DataColor, SurfaceKind};
|
||||
use craft::ui::tile_grid::{Tile, TileGrid, TilePartEvent};
|
||||
use pdfcraft_engine::catalog::{self, ToolGroup};
|
||||
|
||||
@@ -30,6 +31,7 @@ enum Asked {
|
||||
Unpin(&'static str),
|
||||
PinTools,
|
||||
CloseCommunityCard,
|
||||
Link(&'static str),
|
||||
}
|
||||
|
||||
/// Tool tiles keyed by their position in the shown list.
|
||||
@@ -66,9 +68,11 @@ fn tool_tile(g: &'static ToolGroup, unpinnable: bool) -> Tile<'static> {
|
||||
///
|
||||
/// The start page scrolls as a whole, so the grid takes the height of its rows and owns no scroll.
|
||||
fn tool_grid(ui: &mut egui::Ui, name: &str, groups: &[&'static ToolGroup], unpinnable: bool, asked: &RefCell<Vec<Asked>>) {
|
||||
let out = TileGrid::<usize>::new(name.to_string())
|
||||
.natural_height(true)
|
||||
.show_items(ui, &Tools(groups.len()), &mut |key, _| tool_tile(groups[*key], unpinnable));
|
||||
let out = TileGrid::<usize>::new(name.to_string()).activate(ActivateOn::Click).natural_height(true).show_items(
|
||||
ui,
|
||||
&Tools(groups.len()),
|
||||
&mut |key, _| tool_tile(groups[*key], unpinnable),
|
||||
);
|
||||
for event in out.response.events {
|
||||
match event {
|
||||
CollectionEvent::Activate(key) => {
|
||||
@@ -99,14 +103,6 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
|
||||
RecentFile::new(r.path.as_str(), r.name.as_str()).note(format!("{pages} · {}", human_size(r.size)))
|
||||
})
|
||||
.collect();
|
||||
let links: Vec<StartLink> = pdfcraft_engine::links::LINKS
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, l)| {
|
||||
let label = if i == 0 { tl!("Join our Discord") } else { tl!(l.label) };
|
||||
StartLink::command(label.to_string(), Some(IconId::new(l.icon)), CommandRef::new(l.command))
|
||||
})
|
||||
.collect();
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let pinned_folders = app.pinned_folders(&Env::of(ui));
|
||||
|
||||
@@ -121,18 +117,31 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
|
||||
.max_recent(app.recent_limit)
|
||||
.offers_new(false)
|
||||
.drop_hint(tl!("Files you open in PdfCraft appear here").to_string())
|
||||
.links(&links)
|
||||
.section(StartPlace::BeforeRecent, |ui, _| {
|
||||
let _ = Text::new(tl!("Welcome to PdfCraft").to_string()).show(ui);
|
||||
let _ = Text::new(tl!("An open-source PDF workbench — local, private, and scriptable.").to_string()).show(ui);
|
||||
if community_card {
|
||||
brand::mark(ui, PictureSize::Thumb(ThumbSize::Medium));
|
||||
let _ = Text::new(tl!("Join the ArtCraft community").to_string()).show(ui);
|
||||
let _ = Text::new(tl!("Get help, share feedback and follow development on Discord.").to_string()).show(ui);
|
||||
// Closed for this run only: the card is back on the next launch.
|
||||
if IconButton::new(IconId::new("x")).id_salt("community-close").label(tl!("Close")).show(ui).clicked() {
|
||||
asked.borrow_mut().push(Asked::CloseCommunityCard);
|
||||
}
|
||||
Stack::new().label(tl!("Join the ArtCraft community")).fill_width().surface(SurfaceKind::Raised).pad(Pad::Regular).show(
|
||||
ui,
|
||||
|ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
brand::mark(ui, PictureSize::Thumb(ThumbSize::Medium));
|
||||
let _ = Text::new(tl!("Join the ArtCraft community").to_string()).show(ui);
|
||||
if clicked(&IconButton::new(IconId::new("x")).id_salt("community-close").label(tl!("Close")).show(ui)) {
|
||||
asked.borrow_mut().push(Asked::CloseCommunityCard);
|
||||
}
|
||||
});
|
||||
let _ = Text::new(tl!("Get help, share feedback and follow development on Discord.").to_string()).show(ui);
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
for (i, link) in pdfcraft_engine::links::LINKS.iter().enumerate() {
|
||||
let label = if i == 0 { tl!("Join our Discord") } else { tl!(link.label) };
|
||||
if clicked(&Button::new(label.to_string()).icon(IconId::new(link.icon)).show(ui)) {
|
||||
asked.borrow_mut().push(Asked::Link(link.command));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
let _ = Text::new(tl!("Recommended tools").to_string()).show(ui);
|
||||
tool_grid(ui, tl!("Recommended tools"), &recommended, false, &asked);
|
||||
@@ -187,6 +196,9 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
|
||||
// PLAN: assumed `PdfCraftApp::open_pin_tools(&mut self)` (pdf-dialogs-w9).
|
||||
Asked::PinTools => app.open_pin_tools(),
|
||||
Asked::CloseCommunityCard => app.community_card_closed = true,
|
||||
Asked::Link(id) => {
|
||||
app.execute(ui.ctx(), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,18 @@ pub(crate) fn panel_spec(app: &PdfCraftApp, ctx: &egui::Context) -> PanelSpec {
|
||||
.command(CommandRef::with_params("view.panel", serde_json::json!({ "panel": "toolbar" })))
|
||||
}
|
||||
|
||||
pub(crate) fn measure_rail(app: &mut PdfCraftApp, ui: &egui::Ui, width: f32) -> f32 {
|
||||
app.hotbar.normalize();
|
||||
let toolbar = slots(app);
|
||||
let current = current_tool(app);
|
||||
let last_used = last_used(app);
|
||||
let mut rail = ToolRail::new(tl!("Toolbar").to_string(), &toolbar, ¤t, &last_used).edit_toolbar(tl!("Edit toolbar").to_string());
|
||||
if app.hotbar.drawer_open {
|
||||
rail = rail.editing();
|
||||
}
|
||||
rail.measure_rail(ui, width, |ui, _footer| footer_controls(ui, app)).y
|
||||
}
|
||||
|
||||
// Every conversion between the engine's `f64` colour and the framework's goes through these two.
|
||||
fn to_srgba(color: Rgb) -> Srgba {
|
||||
Srgba::rgb(color[0] as f32, color[1] as f32, color[2] as f32)
|
||||
|
||||
@@ -330,7 +330,9 @@ impl DockPanels<PanelId> for Panels<'_> {
|
||||
}
|
||||
|
||||
fn group_view(&mut self, panels: &[PanelId], _active: usize, ui: &mut Ui, at: GroupAt, _cx: &mut BodyCx<'_>) -> Option<f32> {
|
||||
// Measuring is the dock's; a shown view takes the rect it is given.
|
||||
if let GroupAt::Measure(width) = at {
|
||||
return panels.contains(&PanelId::Toolbar).then(|| crate::hotbar::measure_rail(self.app, ui, width));
|
||||
}
|
||||
let GroupAt::Show(rect) = at else { return None };
|
||||
if panels.contains(&PanelId::Toolbar) {
|
||||
crate::hotbar::show_rail(self.app, ui);
|
||||
|
||||
@@ -145,10 +145,17 @@ impl Rig {
|
||||
panic!("{method} was not answered while a job was held");
|
||||
}
|
||||
|
||||
/// Runs the oldest held job and shows its result.
|
||||
/// Runs the next open, including any unrelated host jobs queued ahead of it, and shows its result.
|
||||
fn release(&mut self) {
|
||||
assert!(self.jobs.run_next(), "a job is waiting");
|
||||
self.h.run_steps(2);
|
||||
let finished = self.h.state().opens.counts().finished;
|
||||
for _ in 0..100 {
|
||||
assert!(self.jobs.run_next(), "an open job is waiting");
|
||||
if self.h.state().opens.counts().finished > finished {
|
||||
self.h.run_steps(2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
panic!("the open job did not finish");
|
||||
}
|
||||
|
||||
fn tabs(&self) -> usize {
|
||||
@@ -185,7 +192,11 @@ impl Rig {
|
||||
|
||||
/// Types `password` into the dialog and presses Open; the retry waits for `release`.
|
||||
fn enter_password(&mut self, password: &str) {
|
||||
self.h.get_all_by_label("Password").last().expect("the password dialog is on screen").type_text(password);
|
||||
self.h.get_by_role_and_label(egui::accesskit::Role::PasswordInput, "Password").focus();
|
||||
self.h.run_steps(1);
|
||||
self.h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
|
||||
self.h.run_steps(1);
|
||||
self.h.get_by_role_and_label(egui::accesskit::Role::PasswordInput, "Password").type_text(password);
|
||||
self.h.run_steps(1);
|
||||
self.press("Open");
|
||||
}
|
||||
@@ -557,12 +568,12 @@ fn launch_layout_waits_for_cli_opens_and_preserves_restored_tabs() {
|
||||
let restored = rig.layout_of("existing.pdf").expect("the restored tab");
|
||||
let (a, b) = (TempFile::new("layout-a", "pdf", &fixture(1)), TempFile::new("layout-b", "pdf", &fixture(1)));
|
||||
if layout_first {
|
||||
rig.h.state_mut().set_launch_layout("two-up").expect("a layout");
|
||||
rig.h.state_mut().set_launch_layout("two-page").expect("a layout");
|
||||
}
|
||||
rig.h.state_mut().open_path_with_display(&a.path(), PageDisplay::Single, false);
|
||||
rig.h.state_mut().open_path_with_display(&b.path(), PageDisplay::Single, false);
|
||||
if !layout_first {
|
||||
rig.h.state_mut().set_launch_layout("two-up").expect("a layout");
|
||||
rig.h.state_mut().set_launch_layout("two-page").expect("a layout");
|
||||
}
|
||||
rig.release();
|
||||
assert_eq!(rig.layout_of("existing.pdf"), Some(restored), "the restored tab is not targeted");
|
||||
@@ -607,14 +618,14 @@ fn launch_layout_failed_or_cancelled_opens_do_not_target_existing_documents() {
|
||||
#[test]
|
||||
fn flagged_startup_opens_wait_for_password_ownership_before_the_first_frame() {
|
||||
let mut rig = Rig::empty();
|
||||
rig.h.state_mut().set_launch_layout("two-up").expect("a layout");
|
||||
rig.h.state_mut().set_launch_layout("two-page").expect("a layout");
|
||||
let locked = TempFile::new("flag-locked", "pdf", &encrypted_fixture());
|
||||
let plain = TempFile::new("flag-plain", "pdf", &fixture(1));
|
||||
rig.h.state_mut().open_path_with_display(&locked.path(), PageDisplay::Single, false);
|
||||
// Naming the locked file again joins its open instead of queuing a second one.
|
||||
rig.h.state_mut().open_path_with_display(&locked.path(), PageDisplay::Single, false);
|
||||
rig.h.state_mut().open_path_with_display(&plain.path(), PageDisplay::Single, false);
|
||||
assert_eq!(rig.jobs.waiting(), 2);
|
||||
assert_eq!(rig.h.state().pending_opens.len(), 2);
|
||||
rig.release();
|
||||
assert!(rig.password_dialog());
|
||||
rig.release();
|
||||
|
||||
@@ -1278,17 +1278,17 @@ mod tests {
|
||||
/// Two paragraphs, one above the other, close enough that the reach of their edges overlaps.
|
||||
fn two_paragraphs() -> Vec<u8> {
|
||||
let streams = [
|
||||
"BT /F1 12 Tf 20 160 Td (Alpha beta gamma delta epsilon zeta eta theta) Tj ET",
|
||||
"BT /F2 9 Tf 20 143 Td (Iota kappa lambda mu nu xi omicron pi rho) Tj ET",
|
||||
"/P BMC BT /F1 12 Tf 20 160 Td (Alpha beta gamma delta epsilon zeta eta theta) Tj ET EMC",
|
||||
"/P BMC BT /F2 9 Tf 20 143 Td (Iota kappa lambda mu nu xi omicron pi rho) Tj ET EMC",
|
||||
];
|
||||
let body = streams.join("\n");
|
||||
let objs = [
|
||||
"<< /Type /Catalog /Pages 2 0 R >>".to_string(),
|
||||
"<< /Type /Pages /Kids [4 0 R] /Count 1 /MediaBox [0 0 200 300] >>".to_string(),
|
||||
"<< /Type /Pages /Kids [4 0 R] /Count 1 /MediaBox [0 0 400 300] >>".to_string(),
|
||||
"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>".to_string(),
|
||||
"<< /Type /Page /Parent 2 0 R /Contents 5 0 R /Resources << /Font << /F1 3 0 R /F2 6 0 R >> >> >>".to_string(),
|
||||
format!("<< /Length {} >>\nstream\n{body}\nendstream", body.len()),
|
||||
// A face of its own, so the lower paragraph is not read as the upper one's next line.
|
||||
// A second face gives each paragraph its own appearance.
|
||||
"<< /Type /Font /Subtype /Type1 /BaseFont /Times-Roman >>".to_string(),
|
||||
];
|
||||
let mut out = b"%PDF-1.7\n".to_vec();
|
||||
@@ -1333,7 +1333,7 @@ mod tests {
|
||||
assert_eq!(before.len(), 2, "the fixture has two paragraphs: {before:?}");
|
||||
let (upper_rows, lower_rows) = (rows_of(&h, "Alpha").unwrap(), rows_of(&h, "Iota").unwrap());
|
||||
let r = h.state().views[0].page_screen_rect(0).expect("on screen");
|
||||
let k = r.width() / 200.0;
|
||||
let k = r.width() / 400.0;
|
||||
let screen = |x: f64, y: f64| pos2(r.left() + x as f32 * k, r.top() + (300.0 - y as f32) * k);
|
||||
let drag = |h: &mut egui_kittest::Harness<'static, crate::PdfCraftApp>, from: Pos2, to: Pos2| {
|
||||
h.hover_at(from);
|
||||
|
||||
@@ -153,8 +153,8 @@ fn after_enhance_page_crop_and_organize_take_over() {
|
||||
h.get_by_label("Enhance page").click();
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().views[0].session.camera_done.map(|d| d.page), Some(0));
|
||||
// The quick toolbar also has a "Crop pages" button; the camera panel's pill is the first match.
|
||||
h.get_all_by_label(button).next().unwrap().click();
|
||||
// The quick toolbar also has a "Crop pages" button.
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Group, "Camera image").get_by_label(button).click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().quick_tool, then, "{button}");
|
||||
assert_eq!(h.state().views[0].session.camera_done, None, "{button}");
|
||||
|
||||
@@ -22,8 +22,8 @@ fn harness(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, P
|
||||
#[test]
|
||||
fn home_community_card_closes_for_this_run() {
|
||||
let mut h = harness(|_| {});
|
||||
h.get_by_label("Join the ArtCraft community");
|
||||
h.get_by_label("Close").click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Group, "Join the ArtCraft community");
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Group, "Join the ArtCraft community").get_by_label("Close").click();
|
||||
h.run_steps(2);
|
||||
assert!(h.state().community_card_closed);
|
||||
assert!(h.query_by_label("Join the ArtCraft community").is_none());
|
||||
|
||||
@@ -17,7 +17,7 @@ use std::sync::Arc;
|
||||
|
||||
const BOX_LABELS: [&str; 6] =
|
||||
["Left Header Text", "Center Header Text", "Right Header Text", "Left Footer Text", "Center Footer Text", "Right Footer Text"];
|
||||
const WATERMARK_TEXT: &str = "Watermark text";
|
||||
const WATERMARK_TEXT: &str = "Text";
|
||||
const REPLACE: &str = "Page 1 paints its own white backdrop, which would hide the background. Replace it";
|
||||
|
||||
const FIXTURE: &[u8] = b"%PDF-1.7
|
||||
@@ -82,22 +82,22 @@ impl Rig {
|
||||
}
|
||||
|
||||
/// The app on a host built over `ManualJobs`.
|
||||
fn app_on(jobs: Arc<ManualJobs>) -> PdfCraftApp {
|
||||
support::held_app(jobs)
|
||||
}
|
||||
|
||||
fn harness() -> Rig {
|
||||
harness_with(FIXTURE.to_vec())
|
||||
}
|
||||
|
||||
fn harness_with(pdf: Vec<u8>) -> Rig {
|
||||
harness_with_files(pdf, Arc::new(craft::host::ScriptedFiles::new()))
|
||||
}
|
||||
|
||||
fn harness_with_files(pdf: Vec<u8>, files: Arc<craft::host::ScriptedFiles>) -> Rig {
|
||||
let jobs = Arc::new(ManualJobs::new());
|
||||
let uploads = Uploads::default();
|
||||
let on = jobs.clone();
|
||||
let h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).renderer(uploads.clone()).build_eframe(move |cc| {
|
||||
crate::support::install_runtime(&cc.egui_ctx);
|
||||
{
|
||||
let mut app = app_on(on.clone());
|
||||
let mut app = support::test_app(support::host_with(on.clone(), files.clone()));
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "doc.pdf", None, pdf.clone()).unwrap();
|
||||
app
|
||||
@@ -146,7 +146,9 @@ fn set_range(h: &mut Rig, kind: MarkKind, range: PageRange) {
|
||||
}
|
||||
|
||||
fn type_into(h: &mut Rig, label: &str, text: &str) {
|
||||
h.get_by_label(label).type_text(text);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::MultilineTextInput, label).focus();
|
||||
h.steps(1);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::MultilineTextInput, label).type_text(text);
|
||||
h.steps(2);
|
||||
}
|
||||
|
||||
@@ -189,8 +191,9 @@ fn header_and_footer_dialog_draws_in_the_chosen_face() {
|
||||
let mut h = harness();
|
||||
assert!(h.execute("edit.header_footer"));
|
||||
h.steps(3);
|
||||
h.get_by_label("Font:");
|
||||
h.get_by_value("Helvetica").click();
|
||||
let font = h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Font");
|
||||
assert_eq!(font.value().as_deref(), Some("Helvetica"));
|
||||
font.click();
|
||||
h.steps(2);
|
||||
h.get_by_label("Times").click();
|
||||
h.steps(2);
|
||||
@@ -230,43 +233,34 @@ fn watermark_and_background_dialogs() {
|
||||
assert!(ok_disabled(&h), "OK waits for text");
|
||||
h.get_by_label("Horizontal offset from centre");
|
||||
type_into(&mut h, WATERMARK_TEXT, "DRAFT");
|
||||
h.get_by_label("OK").click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Add Watermark").get_by_label("OK").click();
|
||||
h.steps(3);
|
||||
h.execute("edit.background");
|
||||
h.steps(2);
|
||||
h.get_by_label("OK").click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Add Background").get_by_label("OK").click();
|
||||
h.steps(3);
|
||||
assert_eq!(marks(&h).len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn backgrounds_and_watermarks_from_a_file() {
|
||||
let mut h = harness();
|
||||
let files = Arc::new(craft::host::ScriptedFiles::answering([craft::host::Picked::Contents(vec![("letterhead.pdf".into(), FIXTURE.to_vec())])]));
|
||||
let mut h = harness_with_files(FIXTURE.to_vec(), files);
|
||||
h.execute("edit.background");
|
||||
h.steps(2);
|
||||
support::outside_menus(&h, "File").click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::RadioButton, "File").click();
|
||||
h.steps(2);
|
||||
h.get_by_label("No file chosen");
|
||||
assert!(h.get_by_role_and_label(egui::accesskit::Role::TextInput, "File").value().unwrap_or_default().is_empty());
|
||||
assert!(ok_disabled(&h), "OK waits for a file");
|
||||
// (Browse… opens the system picker; the test answers it with a file.)
|
||||
let dir = std::env::temp_dir().join(format!("pdfcraft-marks-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let file = dir.join("letterhead.pdf");
|
||||
std::fs::write(&file, FIXTURE).unwrap();
|
||||
h.state_mut()
|
||||
.dialogs
|
||||
.get_mut_by_id::<HostedParamDialog>(dialog_of(MarkKind::Background))
|
||||
.expect("the dialog is open")
|
||||
.answer_path("file.path", file);
|
||||
h.get_by_label("Browse…").click();
|
||||
h.steps(3);
|
||||
h.get_by_label("Page number");
|
||||
h.get_by_label("Scale relative to target page");
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Dialog, "Add Background").get_by_role_and_label(egui::accesskit::Role::SpinButton, "Page number");
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Slider, "Scale relative to target page");
|
||||
h.get_by_label("OK").click();
|
||||
h.steps(3);
|
||||
assert_eq!(marks(&h), vec![MarkKind::Background]);
|
||||
let s = h.state();
|
||||
assert_eq!(s.session.get(s.views[0].id).unwrap().can_undo(), Some("Add background"));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Three pages: a white backdrop of its own (as browsers write), a page-sized picture (a scan)
|
||||
|
||||
@@ -94,13 +94,13 @@ fn clicking_pinned_tool_card_selects_it() {
|
||||
h.get_by_label("Unpin from Home").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().pinned_tools.is_empty());
|
||||
assert!(h.query_by_label("Redact a PDF").is_none());
|
||||
assert!(h.query_by_role_and_label(egui::accesskit::Role::ListBox, "Pinned Tools").is_none());
|
||||
h.get_by_label_contains("Pinned Tools");
|
||||
|
||||
// Pinned again, a click on the tile selects the tool.
|
||||
h.state_mut().pin_tool("redact");
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Redact a PDF").click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::ListBox, "Pinned Tools").get_by_label("Redact a PDF").click();
|
||||
h.run_steps(3);
|
||||
|
||||
// Redact tool panel is now active
|
||||
|
||||
@@ -140,23 +140,6 @@ fn painted_text(h: &Harness<'static, PdfCraftApp>) -> Vec<(String, bool, egui::R
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_recent_names_and_paths_are_cut_before_the_page_count() {
|
||||
let name = format!("{}.pdf", "Quarterly report final version ".repeat(10));
|
||||
let path = format!("/{}/{name}", "A folder with a long name".repeat(8));
|
||||
let h = harness({
|
||||
let (name, path) = (name.clone(), path.clone());
|
||||
move |app| app.recent.push(pdfcraft_ui_egui::RecentFile { name, path, pages: 7, size: 2048 })
|
||||
});
|
||||
let text = painted_text(&h);
|
||||
let detail = text.iter().find(|(s, ..)| s.starts_with("7 pages")).expect("the row shows its page count").2;
|
||||
for whole in [&name, &path] {
|
||||
let (_, cut, rect) = text.iter().find(|(s, ..)| s == whole).expect("the row shows the name and the path");
|
||||
assert!(*cut, "{whole:?} is cut short");
|
||||
assert!(rect.right() < detail.left(), "{whole:?} ends before the page count");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn home_removes_one_recent_file_or_clears_them_all() {
|
||||
// Tall enough that the Recent list is on screen without scrolling.
|
||||
@@ -173,12 +156,14 @@ fn home_removes_one_recent_file_or_clears_them_all() {
|
||||
});
|
||||
h.run_steps(4);
|
||||
assert!(h.query_by_label("Remove second.pdf from Recent").is_none(), "the remove button shows only over its row");
|
||||
h.get_by_label("second.pdf").hover();
|
||||
h.get_by(|n| n.role() == egui::accesskit::Role::ListItem && n.label().is_some_and(|s| s.starts_with("second.pdf,"))).hover();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Remove second.pdf from Recent").click();
|
||||
h.run_steps(2);
|
||||
let names: Vec<String> = h.state().recent.iter().map(|r| r.name.clone()).collect();
|
||||
assert_eq!(names, ["first.pdf", "third.pdf"], "only that file left the list");
|
||||
h.get_by(|n| n.role() == egui::accesskit::Role::ListItem && n.label().is_some_and(|s| s.starts_with("first.pdf,"))).click_secondary();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Clear Recent Files").click();
|
||||
h.run_steps(2);
|
||||
assert!(h.state().recent.is_empty(), "Clear empties the list");
|
||||
@@ -2038,13 +2023,14 @@ fn home_recent_context_menu_reveals_the_target_without_opening_or_removing_it()
|
||||
h.run_steps(4);
|
||||
queue.run_all();
|
||||
h.run_steps(2);
|
||||
let label = if cfg!(target_os = "macos") { "Reveal in Finder" } else { "Reveal in File Explorer" };
|
||||
h.get_by_label("target.pdf").click_secondary();
|
||||
let label = "Show in Folder";
|
||||
h.get_by(|n| n.role() == egui::accesskit::Role::ListItem && n.label().is_some_and(|s| s.starts_with("target.pdf,"))).click_secondary();
|
||||
h.run_steps(3);
|
||||
assert!(!h.get_by_label(label).accesskit_node().is_disabled());
|
||||
assert!(h.state().views.is_empty(), "right-click must not open the PDF");
|
||||
assert_eq!(h.state().recent.len(), 2);
|
||||
h.get_by_label(label).click();
|
||||
h.run_steps(2);
|
||||
queue.run_all();
|
||||
h.run_steps(3);
|
||||
assert!(h.query_by_label(label).is_none(), "choosing the action closes its menu");
|
||||
|
||||
@@ -585,6 +585,8 @@ fn the_rail_zoom_field_sets_a_typed_zoom() {
|
||||
let type_zoom = |h: &mut Harness<'static, PdfCraftApp>, typed: &str, key: Key| {
|
||||
h.get_by_role_and_label(Role::SpinButton, "Zoom").click();
|
||||
h.run_steps(2);
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
|
||||
h.run_steps(1);
|
||||
h.get_by_role_and_label(Role::SpinButton, "Zoom").type_text(typed);
|
||||
h.run_steps(1);
|
||||
h.key_press(key);
|
||||
|
||||
Reference in New Issue
Block a user