mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 03:49:11 +00:00
lead: the workspace compiles with its tests. main.rs: claim without the assumed portable flag, title bar from settings.layout, the app opens and attaches its settings store (attach_settings, owed by pdf-shell-w9), control channel, ctx (L-208); q221: redact_props pub (pdf-forms-w13 row 63), comments::thread_id pub, the grid test reads its texture bytes; PastePlacement pub (its field is)
This commit is contained in:
+14
-17
@@ -258,23 +258,21 @@ fn main() -> eframe::Result {
|
||||
// Absolute for this instance too: links relative to a document resolve against its folder,
|
||||
// never the working directory.
|
||||
let files = single_instance::absolute(&files);
|
||||
// PLAN: assumed single_instance::claim(&[String], bool, bool, portable: bool) (pdf-shell-w6): a portable copy claims its own instance.
|
||||
let instance = match single_instance::claim(&files, may_hand_off, combine, portable()) {
|
||||
let instance = match single_instance::claim(&files, may_hand_off, combine) {
|
||||
single_instance::Claim::HandedOff => return Ok(()),
|
||||
single_instance::Claim::Primary(server) => Some(server),
|
||||
single_instance::Claim::Alone => None,
|
||||
};
|
||||
let settings = pdfcraft_ui_egui::settings::open();
|
||||
// Who draws the window frame: the platform and Preferences ▸ Use system title bar decide,
|
||||
// unless `PDFCRAFT_TITLEBAR` overrides them.
|
||||
let frame = craft::window::policy::decide_for(
|
||||
craft::window::Prefix::new("PDFCRAFT"),
|
||||
craft::window::policy::Backend::from_env(),
|
||||
settings.get().title_bar_choice,
|
||||
);
|
||||
// unless `PDFCRAFT_TITLEBAR` overrides them. The store is read here and opened again by the
|
||||
// app (each window attempt opens its own: the OpenGL retry runs the creator again).
|
||||
let title_bar = pdfcraft_ui_egui::settings::open().get().layout.system_title_bar.map_or(Default::default(), |on| {
|
||||
if on { craft::window::policy::TitleBarPref::System } else { craft::window::policy::TitleBarPref::Integrated }
|
||||
});
|
||||
let frame = craft::window::policy::decide_for(craft::window::Prefix::new("PDFCRAFT"), craft::window::policy::Backend::from_env(), title_bar);
|
||||
let integrated = !matches!(frame.frame, craft::window::policy::Frame::Native);
|
||||
let choice = renderer_choice(std::env::var("PDFCRAFT_RENDERER").ok().as_deref());
|
||||
let launch = Launch { files, options, control, create_images, combine, integrated, two_paged, settings };
|
||||
let launch = Launch { files, options, control, create_images, combine, integrated, two_paged };
|
||||
// Finder, Open With and the Dock deliver files as Apple events, not arguments; catch the one
|
||||
// that launched us as well as later ones. Lives until the event loop returns.
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -438,8 +436,6 @@ struct Launch {
|
||||
/// The app's bar is the title bar.
|
||||
integrated: bool,
|
||||
two_paged: bool,
|
||||
/// The settings store the preferences come from.
|
||||
settings: pdfcraft_ui_egui::settings::Store,
|
||||
}
|
||||
|
||||
/// Decode `png` as a [`winit::window::Icon`] for the Windows taskbar and Alt+Tab (`ICON_BIG`).
|
||||
@@ -490,7 +486,7 @@ fn app_creator<'a>(
|
||||
instance: Option<&'a single_instance::Server>,
|
||||
#[cfg(target_os = "macos")] apple_events: &'a apple_events::AppleEvents,
|
||||
) -> eframe::AppCreator<'a> {
|
||||
let Launch { files, options, control, create_images, combine, two_paged, settings, .. } = launch;
|
||||
let Launch { files, options, control, create_images, combine, two_paged, .. } = launch;
|
||||
Box::new(move |cc| {
|
||||
started.set(true);
|
||||
let ctx = cc.egui_ctx.clone();
|
||||
@@ -509,6 +505,7 @@ fn app_creator<'a>(
|
||||
app.units = pdfcraft_ui_egui::units::Unit::system();
|
||||
// The system's reopen-windows choice (macOS) starts the preference; a saved choice replaces it.
|
||||
app.reopen_last_session = reopen::system_default();
|
||||
let settings = pdfcraft_ui_egui::settings::open();
|
||||
app.apply_settings(&settings.get());
|
||||
app.attach_settings(settings);
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -532,7 +529,7 @@ fn app_creator<'a>(
|
||||
let host = craft::ui::runtime::windows::WindowHost::of(&cc.egui_ctx);
|
||||
let (requests, listening) =
|
||||
craft::automation::server::listen(*port, token.clone(), host).map_err(|e| format!("--control {port}: {e}"))?;
|
||||
app.attach_control(requests, Some(listening));
|
||||
app.attach_control(craft::automation::ControlChannel::new(requests), Some(listening));
|
||||
}
|
||||
// The OCR Verify screen stores its per-language dictionary in the data folder.
|
||||
app.ocr_verify.dictionary_dir = pdfcraft_ui_egui::settings::dictionary_dir();
|
||||
@@ -555,12 +552,12 @@ fn app_creator<'a>(
|
||||
}
|
||||
let defer_layout = two_paged && !files.is_empty() && !create_images;
|
||||
if create_images {
|
||||
if let Err(e) = app.begin_image_import_paths(&files) {
|
||||
if let Err(e) = app.begin_image_import_paths(&cc.egui_ctx, &files) {
|
||||
app.notify(e);
|
||||
}
|
||||
} else if combine {
|
||||
app.reopen_last_files(&[]);
|
||||
app.combine_paths(&ctx, &files);
|
||||
app.combine_paths(&cc.egui_ctx, &files);
|
||||
} else {
|
||||
// With the preference on, last session's files come back first; files named on
|
||||
// the command line open after them, in front (#442).
|
||||
@@ -568,7 +565,7 @@ fn app_creator<'a>(
|
||||
startup::open_files(&mut app, &files, two_paged);
|
||||
}
|
||||
for (k, v) in options {
|
||||
let result = if defer_layout && k == "layout" { app.set_launch_layout(&v) } else { app.set_option(&k, &v) };
|
||||
let result = if defer_layout && k == "layout" { app.set_launch_layout(&v) } else { app.set_option(&cc.egui_ctx, &k, &v) };
|
||||
if let Err(e) = result {
|
||||
log::warn!("--{k} {v}: {e}");
|
||||
}
|
||||
|
||||
@@ -241,6 +241,11 @@ impl PdfCraftApp {
|
||||
PdfCraftSettings { layout, print, behavior, view, comment, signature, dock, recent, hotbar, session }
|
||||
}
|
||||
|
||||
/// Hands the app the settings store it saves the preferences to from now on (the launch opens it).
|
||||
pub fn attach_settings(&mut self, store: settings::Store) {
|
||||
self.settings = Some(store);
|
||||
}
|
||||
|
||||
/// Applies settings the store or an import produced. A value that is absent keeps what the app
|
||||
/// has; a value out of range is clamped or refused as the dialogs would.
|
||||
pub fn apply_settings(&mut self, s: &PdfCraftSettings) {
|
||||
|
||||
@@ -671,7 +671,7 @@ pub struct PdfCraftApp {
|
||||
/// properties default" ticked left).
|
||||
pub redact_defaults: RedactPrefs,
|
||||
/// Redaction Tool Properties, while it is open: the values before it opened, for Cancel.
|
||||
pub(crate) redact_props: Option<RedactPrefs>,
|
||||
pub redact_props: Option<RedactPrefs>,
|
||||
pub redact_search: RedactSearchDraft,
|
||||
/// Find text to redact, while it is open.
|
||||
pub(crate) redact_search_open: bool,
|
||||
|
||||
@@ -34,9 +34,11 @@ mod tool;
|
||||
|
||||
#[cfg(test)]
|
||||
use bridge::hover_tip;
|
||||
/// The comment thread of the annotation at `(page, index)`: the key the Comments panel files it under.
|
||||
pub use bridge::thread_id;
|
||||
pub(crate) use bridge::{
|
||||
PageMap, annotations, delete_selected, edit, edit_anchor, id_of, key_of, kind_of, markers, parts, pdf_date_seconds, rgb8, screen_to_user_rect,
|
||||
thread_id, thread_key, tips, tips_shown,
|
||||
thread_key, tips, tips_shown,
|
||||
};
|
||||
pub(crate) use colours::{RecentColours, border_choice, fill_choice, palette, to_rgb};
|
||||
pub(crate) use composer::composer;
|
||||
|
||||
@@ -36,7 +36,7 @@ pub(crate) fn key_of(id: AnnotationId) -> (usize, usize) {
|
||||
|
||||
/// The panel's thread id of the comment at `(page, index)`: the comment's own annotation id. The one mapping the
|
||||
/// panel, the pop-ups and the tests use.
|
||||
pub(crate) fn thread_id(page: usize, index: usize) -> ThreadId {
|
||||
pub fn thread_id(page: usize, index: usize) -> ThreadId {
|
||||
ThreadId(id_of(page, index).0)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::canvas::page_select::PageSelectTool;
|
||||
use crate::canvas::{PageGeometry, PageSession};
|
||||
|
||||
/// Copied comments hanging on the pointer, waiting for a click to place them.
|
||||
pub(crate) struct PastePlacement {
|
||||
pub struct PastePlacement {
|
||||
/// The copied comments as XFDF.
|
||||
pub xfdf: String,
|
||||
/// The bundle's box in user space.
|
||||
|
||||
@@ -2177,7 +2177,12 @@ fn zoomed_pages_in_view_are_rendered_at_the_size_drawn() {
|
||||
// The 200 × 300 fixture fits by height; keep its aspect ratio instead of stretching
|
||||
// it to the full cell width. Request enough pixels for that actual preview width.
|
||||
let drawn = 194.0 * 3.0 * (200.0 / 300.0) * h.ctx.pixels_per_point();
|
||||
let sharp = |h: &Harness<'static, PdfCraftApp>, page| h.state().views[0].grid_page_pixels(page);
|
||||
// The one page's grid texture is width × 1.5 width × 4 bytes (RGBA, the fixture's 2:3), the only
|
||||
// texture in Organize: its width is read back from the view's texture statistics.
|
||||
let sharp = |h: &Harness<'static, PdfCraftApp>, _page: usize| {
|
||||
let bytes = h.state().views[0].textures.bytes;
|
||||
(bytes > 0).then(|| ((bytes as f64) / 6.0).sqrt() as u32)
|
||||
};
|
||||
for _ in 0..200 {
|
||||
if sharp(&h, 0).is_some_and(|w| w as f32 >= drawn * 0.9) {
|
||||
break;
|
||||
|
||||
@@ -734,7 +734,16 @@ fn a_highlight_across_pages_selects_its_last_part_and_opens_its_note() {
|
||||
let doc = app.session.get(app.views[0].id).unwrap();
|
||||
let on_page_2 = doc.info.annotations.iter().find(|a| a.page == 1 && a.subtype == "Highlight").map(|a| a.index).expect("a highlight on page 2");
|
||||
assert_eq!(app.views[0].session.comments.primary(), Some((1, on_page_2)), "the part where the selection ends is selected");
|
||||
assert!(app.views[0].session.comments.panel.editing.as_ref().is_some_and(|(p, i, _)| (*p, *i) == (1, on_page_2)), "its note is open");
|
||||
assert!(
|
||||
app.views[0]
|
||||
.session
|
||||
.comments
|
||||
.panel
|
||||
.editing
|
||||
.as_ref()
|
||||
.is_some_and(|(thread, _, _)| *thread == pdfcraft_ui_egui::comments::thread_id(1, on_page_2)),
|
||||
"its note is open"
|
||||
);
|
||||
}
|
||||
|
||||
/// Review of #5017: dragged back up, from page 2 to page 1, the selection ends on page 1: the
|
||||
@@ -751,7 +760,16 @@ fn a_highlight_dragged_back_across_pages_selects_its_part_where_the_drag_ended()
|
||||
let doc = app.session.get(app.views[0].id).unwrap();
|
||||
let on_page_1 = doc.info.annotations.iter().find(|a| a.page == 0 && a.subtype == "Highlight").map(|a| a.index).expect("a highlight on page 1");
|
||||
assert_eq!(app.views[0].session.comments.primary(), Some((0, on_page_1)), "the part where the drag ended is selected");
|
||||
assert!(app.views[0].session.comments.panel.editing.as_ref().is_some_and(|(p, i, _)| (*p, *i) == (0, on_page_1)), "its note is open");
|
||||
assert!(
|
||||
app.views[0]
|
||||
.session
|
||||
.comments
|
||||
.panel
|
||||
.editing
|
||||
.as_ref()
|
||||
.is_some_and(|(thread, _, _)| *thread == pdfcraft_ui_egui::comments::thread_id(0, on_page_1)),
|
||||
"its note is open"
|
||||
);
|
||||
}
|
||||
|
||||
/// Review of #5017: only markup on a text selection across pages is followed up as one markup.
|
||||
|
||||
Reference in New Issue
Block a user