mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 03:49:11 +00:00
compile fix 6 (all): comments callees (L-218), redact and fill results on the session, presenter keys, forms focus, page-body constructors, dropped files (swarm/cfix6); committed by the lead
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use craft::ui::runtime::drag::OsFile; // PLAN: assumed path of `OsFile` in the facade (ui-contract `runtime/drag.rs`)
|
||||
|
||||
use super::PdfCraftApp;
|
||||
use craft::platform::open::{DroppedFile, Intake};
|
||||
use craft::platform::open::Intake;
|
||||
|
||||
/// The name a dropped file is opened under when the OS gave none.
|
||||
const DROPPED_NAME: &str = "dropped.pdf";
|
||||
@@ -16,10 +16,6 @@ fn bring_to_front(ctx: &egui::Context) {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Focus);
|
||||
}
|
||||
|
||||
fn os_file(file: DroppedFile) -> OsFile {
|
||||
OsFile { name: file.name, path: file.path, mime: String::new(), bytes: file.bytes }
|
||||
}
|
||||
|
||||
impl PdfCraftApp {
|
||||
/// Opens what the file intake holds, batch by batch in arrival order: another launch's paths
|
||||
/// like File ▸ Open, its `combine` files in the Combine files tab, bytes as a new tab, drops
|
||||
@@ -58,7 +54,11 @@ impl PdfCraftApp {
|
||||
self.notify_fmt("Couldn't open {name}: {e}", &[("name", &name), ("e", &error)]);
|
||||
}
|
||||
}
|
||||
Intake::Dropped { files, .. } => self.open_dropped(files.into_iter().map(os_file).collect()),
|
||||
Intake::Dropped { files, .. } => {
|
||||
for file in files {
|
||||
self.open_dropped_file(file.name, file.path, file.bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,19 +67,27 @@ impl PdfCraftApp {
|
||||
/// arrived as bytes (the web) as a new tab.
|
||||
pub(crate) fn open_dropped(&mut self, files: Vec<OsFile>) {
|
||||
for file in files {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if let Some(path) = &file.path {
|
||||
self.open_path(&path.to_string_lossy());
|
||||
continue;
|
||||
}
|
||||
let name = if file.name.is_empty() { DROPPED_NAME.to_string() } else { file.name.clone() };
|
||||
let Some(bytes) = file.bytes else {
|
||||
self.notify_fmt("Couldn't read {name}: {e}", &[("name", &name), ("e", "the file has no contents")]);
|
||||
continue;
|
||||
};
|
||||
if let Err(error) = self.open_bytes(&name, None, bytes.to_vec()) {
|
||||
self.notify_fmt("Couldn't open {name}: {e}", &[("name", &name), ("e", &error)]);
|
||||
}
|
||||
self.open_dropped_file(file.name, file.path, file.bytes);
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens one dropped file, from the window or from the OS's file intake: by its path when it has one, else from
|
||||
/// its bytes under `name`.
|
||||
fn open_dropped_file(&mut self, name: String, path: Option<std::path::PathBuf>, bytes: Option<std::sync::Arc<[u8]>>) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if let Some(path) = &path {
|
||||
self.open_path(&path.to_string_lossy());
|
||||
return;
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
drop(path);
|
||||
let name = if name.is_empty() { DROPPED_NAME.to_string() } else { name };
|
||||
let Some(bytes) = bytes else {
|
||||
self.notify_fmt("Couldn't read {name}: {e}", &[("name", &name), ("e", "the file has no contents")]);
|
||||
return;
|
||||
};
|
||||
if let Err(error) = self.open_bytes(&name, None, bytes.to_vec()) {
|
||||
self.notify_fmt("Couldn't open {name}: {e}", &[("name", &name), ("e", &error)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,13 @@ use std::sync::Arc;
|
||||
use craft::behavior::{CanvasView, PointerButton, PressPhase, Selection};
|
||||
use craft::host::queue::{JobQueue, QueueOptions};
|
||||
use craft::pages::ui::{PageBody, PageView, PageViewOutput, PageViewState, PlacedPage, TextMark, TextMarks, TextSelectState, TextSelection};
|
||||
use craft::review::ui::annotate::AnnotateWords;
|
||||
use craft::ui::canvas::{ContextRequest, Momentary, NavigationOptions, PageBorder, ToolHost};
|
||||
use craft::ui::contract::Show as _;
|
||||
use craft::ui::display::Text;
|
||||
use craft::ui::list::OpenSet;
|
||||
use craft::ui::primitives::TextureStatistics;
|
||||
use craft::ui::runtime::env::Env;
|
||||
use craft::ui::style::DataColor;
|
||||
use egui::{Color32, Pos2, Rect, Vec2, pos2, vec2};
|
||||
use pdfcraft_engine::text_links::TextLink;
|
||||
@@ -259,8 +261,6 @@ pub struct DocView {
|
||||
/// `redactions_applied` is below it, a delivered step is undone and Save asks where. A desktop
|
||||
/// save leaves it at 0.
|
||||
pub redactions_downloaded: usize,
|
||||
/// A queued Fill & Sign signature: select it after its edit succeeds, then leave placement.
|
||||
pub(crate) fill_signature_page: Option<usize>,
|
||||
/// The "Signature added … Lock now" notice was dismissed; placing another signature shows it
|
||||
/// again (#2149).
|
||||
pub(crate) lock_offer_dismissed: bool,
|
||||
@@ -302,6 +302,8 @@ pub struct PageSession {
|
||||
pub(crate) presenter: presenter::Presenter,
|
||||
/// An edit requested by the view (organize toolbar, keys), applied by the app this frame.
|
||||
pub pending_edit: Option<Edit>,
|
||||
/// The pending edit is a Fill & Sign signature or initials: the app notes the document as signed once it applies.
|
||||
pub(crate) fill_signature: bool,
|
||||
/// The page a press or key made the current one (Edit text's objects selected on it, a radio button stepped to),
|
||||
/// with the user-space rectangle on it to scroll into view (a field Tab moved to), gone to by the app after the
|
||||
/// pass: the page view holds the view state while the body runs.
|
||||
@@ -396,6 +398,7 @@ impl PageSession {
|
||||
compare_marks: Vec::new(),
|
||||
presenter: Default::default(),
|
||||
pending_edit: None,
|
||||
fill_signature: false,
|
||||
pending_page: None,
|
||||
pending_redaction: None,
|
||||
redaction_refused: false,
|
||||
@@ -574,7 +577,6 @@ impl DocView {
|
||||
redactions_undone_after_save: 0,
|
||||
saved_redactions_cut_off: false,
|
||||
redactions_downloaded: 0,
|
||||
fill_signature_page: None,
|
||||
lock_offer_dismissed: false,
|
||||
}
|
||||
}
|
||||
@@ -879,6 +881,8 @@ struct BodyOut {
|
||||
copy_selected: bool,
|
||||
/// What the Camera image controls asked the app for.
|
||||
action: Option<ViewAction>,
|
||||
/// The comment under the pointer (page, index): its pop-up's connector shows while it is.
|
||||
hovered_comment: Option<(usize, usize)>,
|
||||
}
|
||||
|
||||
/// The part list of a pass, in paint order: pictures, paragraphs and added items, links and text links (only under
|
||||
@@ -908,7 +912,13 @@ fn page_parts_of(
|
||||
links_of(session, cx, body).parts(&mut parts);
|
||||
}
|
||||
if cx.tool == QuickTool::Select && !cx.comments_hidden {
|
||||
crate::comments::parts(&mut parts, session, cx.info, body.pages, cx.rotation, cx.unobstructed);
|
||||
// The comment a press under the pointer would take, hit within the theme's reach and with its markers at the
|
||||
// icon size, both as the tools on the canvas read them.
|
||||
let env = Env::of(ui);
|
||||
let map = comments::PageMap::new(cx.info, body.pages, cx.rotation);
|
||||
let pointer = ui.input(|i| i.pointer.hover_pos()).map(|p| craft::behavior::kurbo::Point::new(p.x.into(), p.y.into()));
|
||||
let (tolerance, icon_side) = (map.doc_len(env.hit_reach()), map.doc_len(env.tokens.size.icon.md));
|
||||
parts.extend(comments::parts(cx.info, &map, cx.prefs, cx.tool, pointer, &session.comments.tool, tolerance, icon_side));
|
||||
}
|
||||
if !cx.preparing {
|
||||
let can_fill = cx.doc.allows_form_filling();
|
||||
@@ -949,7 +959,7 @@ fn pressed_by(phase: &PressPhase, button: PointerButton) -> bool {
|
||||
}
|
||||
|
||||
/// What a press on a part does, routed by its owner.
|
||||
fn route_press(ctx: &egui::Context, session: &mut PageSession, press: &PagePress, cx: &PageBodyCx<'_>, body: &PageBody<'_>, out: &mut BodyOut) {
|
||||
fn route_press(ui: &egui::Ui, session: &mut PageSession, press: &PagePress, cx: &PageBodyCx<'_>, body: &PageBody<'_>, out: &mut BodyOut) {
|
||||
let geo = cx.geometry(body);
|
||||
if pressed_by(&press.phase, PointerButton::Secondary) {
|
||||
// The page's menu reads what the secondary press went to.
|
||||
@@ -970,9 +980,15 @@ fn route_press(ctx: &egui::Context, session: &mut PageSession, press: &PagePress
|
||||
}
|
||||
}
|
||||
}
|
||||
// PLAN: assumed `comments::tool::part_pressed(session, info, press)` (pdf-comments-w8).
|
||||
Owner::Comment { .. } => crate::comments::part_pressed(session, cx.info, press),
|
||||
Owner::Field { .. } => crate::forms_ui::field_press(ctx, session, cx.doc, cx.info, cx.doc.allows_form_filling(), press, geo),
|
||||
Owner::Comment { .. } => {
|
||||
if let Some(xf) = session.page_xform(press.page, geo) {
|
||||
let page_cx =
|
||||
comments::PageCx { page: press.page, xf: &xf, info: cx.info, prefs: cx.prefs, allowed: cx.allowed, hidden: cx.comments_hidden };
|
||||
let words = Env::of(ui).words::<AnnotateWords>();
|
||||
comments::part_pressed(&mut session.comments, press, &page_cx, &words);
|
||||
}
|
||||
}
|
||||
Owner::Field { .. } => crate::forms_ui::field_press(ui.ctx(), session, cx.doc, cx.info, cx.doc.allows_form_filling(), press, geo),
|
||||
Owner::SignTab { field } => {
|
||||
if clicked && let Some(field) = cx.form.get(*field) {
|
||||
session.sign.field = Some(field.name.clone());
|
||||
@@ -1000,20 +1016,22 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession,
|
||||
|
||||
// 2-3. Every part on the pages, in one control: hit priority ranks parts inside one control only.
|
||||
let (parts, tabs) = page_parts_of(ui, body, &mut *session, cx);
|
||||
// PLAN: assumed `forms_ui::focus_owner(&FormView) -> Option<Owner>` for the focused field (pdf-forms-w7 AP-6).
|
||||
let focus = crate::forms_ui::focus_owner(&session.forms);
|
||||
let focus = crate::forms_ui::focus_owner(&session.forms, cx.form);
|
||||
let parts_out = PageParts::new(&parts).focus(focus).show_at(ui, body.rect);
|
||||
out.hovered_comment = match parts_out.hovered {
|
||||
Some((Owner::Comment { index }, page)) => Some((page, index)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(press) = &parts_out.press {
|
||||
// Any press on a page ends Select All of the document, on a link too.
|
||||
if matches!(press.phase, PressPhase::Down { .. }) {
|
||||
session.all_text = false;
|
||||
}
|
||||
route_press(ui.ctx(), session, press, cx, body, out);
|
||||
route_press(ui, session, press, cx, body, out);
|
||||
}
|
||||
if let Some((owner, page)) = &parts_out.focused {
|
||||
if let Some((owner, _)) = &parts_out.focused {
|
||||
// Focus arrived on a field (Tab, a request or a click): the field opens, a text field with its text selected.
|
||||
// PLAN: assumed `forms_ui::field_focused(session, doc, form, owner, page)` (pdf-forms-w5 AP-6).
|
||||
crate::forms_ui::field_focused(session, cx.doc, cx.form, owner, *page);
|
||||
crate::forms_ui::field_focused(session, cx.form, owner);
|
||||
}
|
||||
if let Some((Owner::Field { .. }, key)) = &parts_out.key
|
||||
&& let Some(edit) = crate::forms_ui::field_key(session, cx.info, cx.form, key, cx.geometry(body))
|
||||
@@ -1041,7 +1059,12 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession,
|
||||
out.context = reply.context;
|
||||
out.back_to_select = finish.back_to_select;
|
||||
out.snapshot = finish.snapshot;
|
||||
out.open_boxes = finish.open_boxes;
|
||||
// Set Page Boxes opens on the current page: the page double-clicked becomes it first.
|
||||
if let Some(page) = finish.open_boxes {
|
||||
session.pending_page = Some((page, None));
|
||||
out.open_boxes = true;
|
||||
}
|
||||
out.turn = finish.turn;
|
||||
out.open_signature = finish.open_signature;
|
||||
let outcome = session.prepare.take_outcome();
|
||||
out.back_to_select |= outcome.placed;
|
||||
@@ -1094,22 +1117,20 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession,
|
||||
_ => None,
|
||||
};
|
||||
let selected = session.prepare.selected.as_ref().map(|(name, _)| name.as_str());
|
||||
// PLAN: assumed `CalcOrderOverlay::new(&CalcOrderView, pages, rotation, generation, selected, hovered,
|
||||
// viewport)` (pdf-forms-w12 gives `new(.., viewport: body.rect)`).
|
||||
crate::calc_order_ui::CalcOrderOverlay::new(
|
||||
&session.calc_order,
|
||||
body.pages,
|
||||
cx.rotation,
|
||||
cx.doc.edit_generation(),
|
||||
selected,
|
||||
hovered,
|
||||
body.rect,
|
||||
)
|
||||
.show_at(ui, body.rect);
|
||||
crate::calc_order_ui::CalcOrderOverlay::new(&session.calc_order, cx.form, cx.info)
|
||||
.placed(body.pages)
|
||||
.rotation(cx.rotation)
|
||||
.generation(cx.doc.edit_generation())
|
||||
.selected(selected)
|
||||
.hovered(hovered.as_ref())
|
||||
.viewport(body.rect)
|
||||
.show_at(ui, body.rect);
|
||||
}
|
||||
if let Some(preview) = cx.table_preview {
|
||||
// PLAN: assumed `field_table_ui::TablePreview::new(&Preview, pages, rotation)` (pdf-forms-w11).
|
||||
crate::field_table_ui::TablePreview::new(preview, body.pages, cx.rotation).show_at(ui, body.rect);
|
||||
// The table being set up, on its page when that page is placed.
|
||||
if let Some(preview) = cx.table_preview
|
||||
&& let Some(xf) = session.page_xform(preview.page(), cx.geometry(body))
|
||||
{
|
||||
crate::field_table_ui::TablePreview::new(tl!("Table cells"), preview, xf).show_at(ui, body.rect);
|
||||
}
|
||||
// The find marks under any tool, and the text selection where the Select tool is not the one painting it.
|
||||
let texts = selection::DocTexts::new(&session.texts, &session.text_failed, cx.rotation, cx.sizes);
|
||||
@@ -1126,7 +1147,8 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession,
|
||||
// it through, so the pointer is not hidden yet (pdf-canvas-w18).
|
||||
let (now, pointer) = ui.input(|i| (i.time, i.pointer.hover_pos()));
|
||||
let frame = presenter::frame(&mut session.presenter, body, at, cx.info, ui.painter(), now, cx.animates, pointer);
|
||||
out.turn = frame.step;
|
||||
// A full-screen key's turn first, then the display time's.
|
||||
out.turn = out.turn.or(frame.step);
|
||||
}
|
||||
if cx.tool == QuickTool::EnhanceCamera {
|
||||
let quad = crate::camera_ui::show_quad(ui, body, session, cx.can_modify, cx.current);
|
||||
@@ -1315,6 +1337,7 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu
|
||||
host: &app.host,
|
||||
wake: &app.wake,
|
||||
author: &app.comment_prefs.author,
|
||||
comment_prefs: &app.comment_prefs,
|
||||
date_text: &date_text,
|
||||
fill: page_tools::FillPrefs {
|
||||
text_size: app.fill_text_size,
|
||||
@@ -1424,8 +1447,9 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu
|
||||
if let Some(e) = crate::comments::composer(ui, view, info, &app.comment_prefs) {
|
||||
view.session.pending_edit = Some(e);
|
||||
}
|
||||
let session = &mut view.session;
|
||||
if let Some(e) = crate::comments::note_popups(ui, session, info, &app.comment_prefs, doc.comments_hidden(), allowed) {
|
||||
let popups = crate::comments::note_popups(ui, view, info, &app.comment_prefs, doc.comments_hidden(), allowed, body_out.hovered_comment);
|
||||
if let Some(e) = popups {
|
||||
let session = &mut view.session;
|
||||
// A click on the composer's Post also takes the focus from a pop-up's box, saving what
|
||||
// was typed there: both edits land in this pass, so both are kept, in one batch.
|
||||
session.pending_edit = Some(match session.pending_edit.take() {
|
||||
|
||||
@@ -98,6 +98,8 @@ pub(crate) struct PageToolCx<'a> {
|
||||
pub(crate) wake: &'a Wake,
|
||||
/// The comment author, written on stamps and Fill & Sign marks.
|
||||
pub(crate) author: &'a str,
|
||||
/// The comment preferences: the style and author of the markup a selection becomes.
|
||||
pub(crate) comment_prefs: &'a comments::CommentPrefs,
|
||||
/// The date as Fill & Sign's date field writes it, or why it cannot.
|
||||
pub(crate) date_text: &'a Result<String, String>,
|
||||
/// The Fill & Sign choices.
|
||||
@@ -161,7 +163,7 @@ pub(crate) struct PageTool<'a> {
|
||||
released: bool,
|
||||
/// Full screen: the presenter's keys the tool took for it in this pass, applied after the run.
|
||||
presenting: bool,
|
||||
presenter_keys: Vec<ToolKey>,
|
||||
presenter_keys: Vec<(ToolKey, bool)>,
|
||||
}
|
||||
|
||||
/// What the page tool finished in a pass. The fields the page body reads are public; the rest are applied to the
|
||||
@@ -180,11 +182,14 @@ pub(crate) struct ToolFinish {
|
||||
pub(crate) open_signature: Option<bool>,
|
||||
/// Fill & Sign refused a click, and why.
|
||||
pub(crate) refused: Option<String>,
|
||||
/// Full screen: a page key turned the page, forward when `true`.
|
||||
pub(crate) turn: Option<bool>,
|
||||
edit: Option<Edit>,
|
||||
camera_page: Option<usize>,
|
||||
sign_drawn: Option<(usize, [f64; 4])>,
|
||||
redaction: Option<RedactResult>,
|
||||
presenter_keys: Vec<ToolKey>,
|
||||
/// The presenter's keys of the pass, each with whether Shift was held.
|
||||
presenter_keys: Vec<(ToolKey, bool)>,
|
||||
/// The quick tool, when it selects text.
|
||||
text_tool: Option<QuickTool>,
|
||||
text_finished: bool,
|
||||
@@ -392,7 +397,7 @@ impl<'a> PageTool<'a> {
|
||||
finish.edit = tool.placed();
|
||||
finish.back_to_select = finish.edit.is_some();
|
||||
}
|
||||
Arm::Redact(mut tool) => finish.redaction = tool.finished(),
|
||||
Arm::Redact(tool) => finish.redaction = tool.finished(),
|
||||
Arm::SignArea(mut tool) => finish.sign_drawn = tool.finished(),
|
||||
Arm::Snapshot(mut tool) => finish.snapshot = tool.take_result(),
|
||||
Arm::Crop(mut tool) => {
|
||||
@@ -426,34 +431,29 @@ impl ToolFinish {
|
||||
if let Some(drawn) = self.sign_drawn.take() {
|
||||
session.sign.drawn = Some(drawn);
|
||||
}
|
||||
match self.redaction.take() {
|
||||
Some(RedactResult::Marks(marks, page)) => session.pending_redaction = Some((QuickTool::Redact, marks, page)),
|
||||
Some(RedactResult::Refused) => session.redaction_refused = true,
|
||||
None => {}
|
||||
if let Some(redaction) = self.redaction.take() {
|
||||
redaction.land(session, cx.info, cx.geometry());
|
||||
}
|
||||
match fill {
|
||||
Some(FillOutcome::Edit(edit)) => session.pending_edit = Some(*edit),
|
||||
// PLAN: forms-w5's `FillOutcome::Signature(Box<Edit>)` carries no page, which `fill_signature_page` needs
|
||||
// (production set the clicked page); assumed `Signature(Box<Edit>, usize)`.
|
||||
Some(FillOutcome::Signature(edit, page)) => {
|
||||
Some(FillOutcome::Signature(edit)) => {
|
||||
session.pending_edit = Some(*edit);
|
||||
session.fill_signature_page = Some(page);
|
||||
session.fill_signature = true;
|
||||
}
|
||||
Some(FillOutcome::CreateSignature) => self.open_signature = Some(false),
|
||||
Some(FillOutcome::CreateInitials) => self.open_signature = Some(true),
|
||||
Some(FillOutcome::Refused(why)) => self.refused = Some(why),
|
||||
None => {}
|
||||
}
|
||||
for key in self.presenter_keys.drain(..) {
|
||||
// PLAN: assumed `Presenter::key(&mut self, &ToolKey)` (pdf-canvas-w18 names the keys it takes).
|
||||
session.presenter.key(&key);
|
||||
}
|
||||
// The first page key of the pass turns the page; the rest wait for the next pass's keys.
|
||||
self.turn = self.presenter_keys.drain(..).find_map(|(key, shift)| session.presenter.key(&key, shift));
|
||||
if let Some(tool @ QuickTool::Comment(_)) = self.text_tool {
|
||||
let geo = cx.geometry();
|
||||
let hidden = cx.doc.comments_hidden();
|
||||
for placed in cx.pages {
|
||||
// PLAN: assumed `comments::PageCx::of(page, info)` for the per-page cx of `page_after_text` (pdf-comments-w8
|
||||
// decided `page_after_text(cx: &PageCx, tool, finished, view)` and pdf-comments-w7 rewrites `PageCx`).
|
||||
let page_cx = comments::PageCx::of(placed.page, cx.info);
|
||||
comments::page_after_text(&page_cx, tool, self.text_finished, session);
|
||||
let xf = geo.xform_of(placed);
|
||||
let page_cx = comments::PageCx { page: placed.page, xf: &xf, info: cx.info, prefs: cx.comment_prefs, allowed: cx.allowed, hidden };
|
||||
comments::page_after_text(&page_cx, tool, self.text_finished, session, geo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -536,7 +536,7 @@ impl CanvasTool for PageTool<'_> {
|
||||
_ => false,
|
||||
}
|
||||
{
|
||||
self.presenter_keys.push(key.clone());
|
||||
self.presenter_keys.push((key.clone(), cx.mods.shift));
|
||||
return true;
|
||||
}
|
||||
self.tool_mut().key(key, cx)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{Arc, DocInfo, DocView, Edit, PageSession, PageText, Pos2, Range, Rect, comments};
|
||||
use super::{Arc, DocInfo, DocView, Edit, PageGeometry, PageSession, PageText, Pos2, Range, Rect, comments};
|
||||
use crate::QuickTool;
|
||||
use craft::behavior::Selection;
|
||||
use craft::behavior::kurbo::{self, Point};
|
||||
@@ -241,6 +241,60 @@ impl PageSession {
|
||||
self.marks_waiting = None;
|
||||
}
|
||||
|
||||
/// Whether a page the selection covers is still to be read, so a selection is never copied or marked short.
|
||||
fn selection_unread(&self, geo: PageGeometry<'_>) -> bool {
|
||||
self.text.selection.is_some_and(|s| !s.unread_pages(&self.doc_texts(geo.rotation, geo.sizes)).is_empty())
|
||||
}
|
||||
|
||||
/// Whether the selection covers a page whose text could not be read ([`DocView::selection_has_unreadable_page`]).
|
||||
fn selection_has_unreadable_page(&self) -> bool {
|
||||
self.text.selection.is_some_and(|s| s.pages().any(|p| self.text_failed.contains(&p)))
|
||||
}
|
||||
|
||||
/// What a marking tool marks for the text selection, with the pages placed by `geo`
|
||||
/// ([`DocView::tool_marks`]).
|
||||
pub(crate) fn tool_marks(
|
||||
&mut self,
|
||||
tool: QuickTool,
|
||||
finished: bool,
|
||||
page: Option<usize>,
|
||||
whole: bool,
|
||||
info: &DocInfo,
|
||||
geo: PageGeometry<'_>,
|
||||
) -> ToolMarks {
|
||||
let Some(sel) = self.text.selection else {
|
||||
self.marks_waiting = None;
|
||||
return ToolMarks::None;
|
||||
};
|
||||
if finished {
|
||||
self.marks_waiting = Some((tool, sel));
|
||||
}
|
||||
if !self.marks_waiting.as_ref().is_some_and(|(t, s)| *t == tool && *s == sel) {
|
||||
// The selection or the tool changed: the wait is over, so a drag passing back through
|
||||
// the selection it was for doesn't mark it before it is released.
|
||||
self.marks_waiting = None;
|
||||
return ToolMarks::None;
|
||||
}
|
||||
if whole && self.selection_has_unreadable_page() {
|
||||
self.marks_waiting = None;
|
||||
return ToolMarks::Unreadable;
|
||||
}
|
||||
if self.selection_unread(geo) {
|
||||
return ToolMarks::None;
|
||||
}
|
||||
let marks = self.selection_quads(info, geo.rotation);
|
||||
if marks.is_empty() {
|
||||
// Every page is read and nothing is selected: nothing to wait for.
|
||||
self.marks_waiting = None;
|
||||
return ToolMarks::None;
|
||||
}
|
||||
if page.is_some_and(|page| !marks.iter().any(|(p, _)| *p == page)) {
|
||||
return ToolMarks::None;
|
||||
}
|
||||
self.marks_waiting = None;
|
||||
ToolMarks::Marks(marks, head_page_of(&sel))
|
||||
}
|
||||
|
||||
/// The edit adding what a tool marks on a text selection ([`DocView::selection_marks_edit`]).
|
||||
pub(crate) fn selection_marks_edit(&mut self, edits: Vec<Edit>, head: usize) -> Option<Edit> {
|
||||
let edit = one_undo_step(edits);
|
||||
@@ -257,7 +311,7 @@ impl DocView {
|
||||
|
||||
/// Whether a page the selection covers is still to be read, so a selection is never copied or marked short.
|
||||
fn selection_unread(&self) -> bool {
|
||||
self.session.text.selection.is_some_and(|s| !s.unread_pages(&self.doc_texts()).is_empty())
|
||||
self.session.selection_unread(self.geometry())
|
||||
}
|
||||
|
||||
/// The text selection as markup quadrilaterals in user space, one entry per page with
|
||||
@@ -277,7 +331,7 @@ impl DocView {
|
||||
/// selected, so a redaction of the rest would leave that page's content in place: Redact
|
||||
/// refuses such a selection rather than mark it short.
|
||||
pub(crate) fn selection_has_unreadable_page(&self) -> bool {
|
||||
self.session.text.selection.is_some_and(|s| s.pages().any(|p| self.session.text_failed.contains(&p)))
|
||||
self.session.selection_has_unreadable_page()
|
||||
}
|
||||
|
||||
/// What a marking tool (a markup tool, Redact) marks for the text selection a drag, a
|
||||
@@ -289,37 +343,8 @@ impl DocView {
|
||||
/// changed meanwhile. With `whole`, a selection over a page whose text could not be read is
|
||||
/// refused instead ([`Self::selection_has_unreadable_page`]).
|
||||
pub(crate) fn tool_marks(&mut self, tool: QuickTool, finished: bool, page: Option<usize>, whole: bool, info: &DocInfo) -> ToolMarks {
|
||||
let Some(sel) = self.session.text.selection else {
|
||||
self.session.marks_waiting = None;
|
||||
return ToolMarks::None;
|
||||
};
|
||||
if finished {
|
||||
self.session.marks_waiting = Some((tool, sel));
|
||||
}
|
||||
if !self.session.marks_waiting.as_ref().is_some_and(|(t, s)| *t == tool && *s == sel) {
|
||||
// The selection or the tool changed: the wait is over, so a drag passing back through
|
||||
// the selection it was for doesn't mark it before it is released.
|
||||
self.session.marks_waiting = None;
|
||||
return ToolMarks::None;
|
||||
}
|
||||
if whole && self.selection_has_unreadable_page() {
|
||||
self.session.marks_waiting = None;
|
||||
return ToolMarks::Unreadable;
|
||||
}
|
||||
if self.selection_unread() {
|
||||
return ToolMarks::None;
|
||||
}
|
||||
let marks = self.selection_quads(info);
|
||||
if marks.is_empty() {
|
||||
// Every page is read and nothing is selected: nothing to wait for.
|
||||
self.session.marks_waiting = None;
|
||||
return ToolMarks::None;
|
||||
}
|
||||
if page.is_some_and(|page| !marks.iter().any(|(p, _)| *p == page)) {
|
||||
return ToolMarks::None;
|
||||
}
|
||||
self.session.marks_waiting = None;
|
||||
ToolMarks::Marks(marks, head_page_of(&sel))
|
||||
let geo = PageGeometry { sizes: &self.page_sizes, rotation: self.view.rotation, viewport: self.viewport };
|
||||
self.session.tool_marks(tool, finished, page, whole, info, geo)
|
||||
}
|
||||
|
||||
/// The edit adding what a tool marks on a text selection, one edit per page, as one undo
|
||||
|
||||
@@ -275,9 +275,11 @@ impl SignatureDrag {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn paint(&self, draw: &Draw<'_>, cx: &PageCx<'_>, cv: &CommentView, pending: Option<&Edit>) {
|
||||
/// The comment being dragged, drawn from its layers under `tool`, the quick tool the page sees: only Select and the
|
||||
/// Fill & Sign tools move comments.
|
||||
pub fn paint(&self, draw: &Draw<'_>, cx: &PageCx<'_>, tool: QuickTool, cv: &CommentView, pending: Option<&Edit>) {
|
||||
let (Some((_, page, index)), Some(layers)) = (self.key, &self.layers) else { return };
|
||||
if page != cx.page || !matches!(cx.tool, QuickTool::Select | QuickTool::Fill(_)) || cx.hidden {
|
||||
if page != cx.page || !matches!(tool, QuickTool::Select | QuickTool::Fill(_)) || cx.hidden {
|
||||
return;
|
||||
}
|
||||
let in_flight = cv.tool.in_flight();
|
||||
|
||||
@@ -883,7 +883,7 @@ impl PdfCraftApp {
|
||||
/// user has been told why, so the typing isn't lost and the caller can stop.
|
||||
fn apply_queued_edit(&mut self, i: usize) -> bool {
|
||||
let Some(edit) = self.views.get_mut(i).and_then(|v| v.session.pending_edit.take()) else { return true };
|
||||
let signature_page = self.views.get_mut(i).and_then(|v| v.fill_signature_page.take());
|
||||
let signature = self.views.get_mut(i).is_some_and(|v| std::mem::take(&mut v.session.fill_signature));
|
||||
let doc_id = self.views.get(i).map(|v| v.id);
|
||||
let committed = self.views.get_mut(i).and_then(|v| v.session.forms.committed.take());
|
||||
let typed = match (&edit, &committed) {
|
||||
@@ -891,9 +891,7 @@ impl PdfCraftApp {
|
||||
_ => false,
|
||||
};
|
||||
if self.apply_edit(edit) {
|
||||
if signature_page.is_some()
|
||||
&& let Some(id) = doc_id
|
||||
{
|
||||
if signature && let Some(id) = doc_id {
|
||||
self.placed_signatures.insert(id);
|
||||
// A new signature shows the Lock now notice again, even if the last was dismissed.
|
||||
if let Some(view) = self.views.get_mut(i) {
|
||||
|
||||
@@ -12,9 +12,10 @@ use egui::Pos2;
|
||||
|
||||
use super::bridge::{self, PageMap};
|
||||
use super::state::{Composer, ComposerKind, PageCx};
|
||||
use super::{CommentPrefs, CommentTool, CommentView, DocInfo, DocView, Edit, MAX_LINE_WIDTH, QuickTool};
|
||||
use super::{CommentPrefs, CommentTool, CommentView, DocInfo, Edit, MAX_LINE_WIDTH, QuickTool};
|
||||
use crate::canvas::page_parts::{Owner, PagePress};
|
||||
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 {
|
||||
@@ -388,19 +389,20 @@ fn settled_points(a: &Marked, map: &PageMap<'_>) -> Vec<[f64; 2]> {
|
||||
/// After text selection ran: a markup tool turns a finished selection into a comment; Replace Text asks for the
|
||||
/// replacement. `finished` is true in the pass the selection's release came (a drag release or a double click); the
|
||||
/// call runs on every pass a markup tool is active, since a selection on pages still being read is marked later.
|
||||
pub(crate) fn page_after_text(cx: &PageCx<'_>, tool: QuickTool, finished: bool, view: &mut DocView) {
|
||||
/// `geo` places the pages of the pass.
|
||||
pub(crate) fn page_after_text(cx: &PageCx<'_>, tool: QuickTool, finished: bool, session: &mut PageSession, geo: PageGeometry<'_>) {
|
||||
let QuickTool::Comment(tool) = tool else { return };
|
||||
if tool == CommentTool::ReplaceText && cx.allowed && finished {
|
||||
// A replacement sits on one page: a selection across pages stays selected for the bar's
|
||||
// markup or Copy.
|
||||
if let Ok([(page, quads)]) = <[_; 1]>::try_from(view.selection_quads(cx.info))
|
||||
if let Ok([(page, quads)]) = <[_; 1]>::try_from(session.selection_quads(cx.info, geo.rotation))
|
||||
&& page == cx.page
|
||||
{
|
||||
view.clear_selection();
|
||||
session.clear_selection();
|
||||
let last = quads.last().copied().unwrap_or_default();
|
||||
let at = [last[2].max(last[6]), last[1].max(last[3])];
|
||||
view.session.comments.replace = Some(quads);
|
||||
view.session.comments.composer = Some(Composer { page, at, kind: ComposerKind::Replace, text: String::new(), focus: true });
|
||||
session.comments.replace = Some(quads);
|
||||
session.comments.composer = Some(Composer { page, at, kind: ComposerKind::Replace, text: String::new(), focus: true });
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -408,8 +410,8 @@ pub(crate) fn page_after_text(cx: &PageCx<'_>, tool: QuickTool, finished: bool,
|
||||
// Once, from whichever of the selection's pages is drawn: after an edge scroll its first page
|
||||
// may be out of view. Every page it covers gets its own markup, in one undo step, once all
|
||||
// of them are read.
|
||||
if let crate::canvas::ToolMarks::Marks(marks, head) = view.tool_marks(QuickTool::Comment(tool), finished, Some(cx.page), false, cx.info) {
|
||||
view.clear_selection();
|
||||
if let crate::canvas::ToolMarks::Marks(marks, head) = session.tool_marks(QuickTool::Comment(tool), finished, Some(cx.page), false, cx.info, geo) {
|
||||
session.clear_selection();
|
||||
let edits = marks.into_iter().map(|(page, quads)| {
|
||||
Edit::AddAnnotation(pdfcraft_engine::NewAnnotation {
|
||||
page,
|
||||
@@ -419,6 +421,6 @@ pub(crate) fn page_after_text(cx: &PageCx<'_>, tool: QuickTool, finished: bool,
|
||||
author: cx.prefs.author.clone(),
|
||||
})
|
||||
});
|
||||
view.session.pending_edit = view.selection_marks_edit(edits.collect(), head);
|
||||
session.pending_edit = session.selection_marks_edit(edits.collect(), head);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,27 @@ pub(crate) fn focused_field<'a>(focus: &Focus, form: &'a [FormField]) -> Option<
|
||||
focus.obj.and_then(|o| form.iter().find(|f| f.obj == o && f.name == focus.name)).or_else(|| form.iter().find(|f| f.name == focus.name))
|
||||
}
|
||||
|
||||
/// The page part of the field the focus is on, for the page parts' focus.
|
||||
pub(crate) fn focus_owner(forms: &FormView, form: &[FormField]) -> Option<Owner> {
|
||||
let focus = forms.focus.as_ref()?;
|
||||
let field = form.iter().position(|f| f.name == focus.name && focus.obj.is_none_or(|o| o == f.obj))?;
|
||||
Some(Owner::Field { field, widget: focus.widget })
|
||||
}
|
||||
|
||||
/// Focus arrived on a field's part (Tab, a focus request or a click): the field opens, unless it is open already,
|
||||
/// with its whole value selected so typing replaces it, as Tab between fields opens it.
|
||||
pub(crate) fn field_focused(session: &mut PageSession, form: &[FormField], owner: &Owner) {
|
||||
let Owner::Field { field, widget } = *owner else { return };
|
||||
let Some(f) = form.get(field) else { return };
|
||||
if session.forms.focus.as_ref().is_some_and(|x| x.is_on(f, widget)) {
|
||||
return;
|
||||
}
|
||||
commit(session, form);
|
||||
let mut opened = open_focus(f, widget);
|
||||
opened.selection = TextSelection::new(0, opened.text.chars().count());
|
||||
session.forms.focus = Some(opened);
|
||||
}
|
||||
|
||||
/// The edit picking the options at `picked` (positions in `f`'s options) in the list box `f`.
|
||||
/// The edit names the field, and positions are read in the first field of that name: a same-name
|
||||
/// twin listing its options in another order gives its picks as positions there. One option
|
||||
|
||||
@@ -12,7 +12,7 @@ use pdfcraft_render::DocInfo;
|
||||
use crate::QuickTool;
|
||||
use crate::canvas::PageXform;
|
||||
use crate::canvas::page_select::PageSelectTool;
|
||||
use crate::canvas::{DocView, PageBoxDrag, ToolMarks};
|
||||
use crate::canvas::{PageBoxDrag, PageGeometry, PageSession, ToolMarks};
|
||||
|
||||
/// The smallest box, in screen points on each side, that counts as a mark.
|
||||
const LEAST_BOX: f32 = 3.0;
|
||||
@@ -34,6 +34,28 @@ pub(crate) enum RedactResult {
|
||||
Text { page: usize },
|
||||
}
|
||||
|
||||
impl RedactResult {
|
||||
/// Hands the finished gesture to the session as a pending redaction, or as a refusal when a
|
||||
/// selected page's text could not be read; `geo` places the pages of the pass.
|
||||
pub(crate) fn land(self, session: &mut PageSession, info: &DocInfo, geo: PageGeometry<'_>) {
|
||||
match self {
|
||||
Self::Area { page, quad } => {
|
||||
session.pending_redaction = Some((QuickTool::Redact, vec![(page, vec![quad])], page));
|
||||
}
|
||||
// Across pages: a mark on each page it covers, once all are read; refused when one of
|
||||
// them could not be read, rather than leave it unmarked.
|
||||
Self::Text { page } => match session.tool_marks(QuickTool::Redact, true, Some(page), true, info, geo) {
|
||||
ToolMarks::Marks(marks, head) => {
|
||||
session.clear_selection();
|
||||
session.pending_redaction = Some((QuickTool::Redact, marks, head));
|
||||
}
|
||||
ToolMarks::Unreadable => session.redaction_refused = true,
|
||||
ToolMarks::None => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Redact tool for one pass.
|
||||
pub(crate) struct RedactTool<'a> {
|
||||
select: PageSelectTool<'a>,
|
||||
@@ -71,25 +93,10 @@ impl<'a> RedactTool<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// After the host ran: hands a finished gesture to the view as a pending redaction, or as a
|
||||
/// refusal when a selected page's text could not be read.
|
||||
pub(crate) fn finished(self, view: &mut DocView) {
|
||||
match self.finished {
|
||||
Some(RedactResult::Area { page, quad }) => {
|
||||
view.session.pending_redaction = Some((QuickTool::Redact, vec![(page, vec![quad])], page));
|
||||
}
|
||||
// Across pages: a mark on each page it covers, once all are read; refused when one of
|
||||
// them could not be read, rather than leave it unmarked.
|
||||
Some(RedactResult::Text { page }) => match view.tool_marks(QuickTool::Redact, true, Some(page), true, self.info) {
|
||||
ToolMarks::Marks(marks, head) => {
|
||||
view.clear_selection();
|
||||
view.session.pending_redaction = Some((QuickTool::Redact, marks, head));
|
||||
}
|
||||
ToolMarks::Unreadable => view.session.redaction_refused = true,
|
||||
ToolMarks::None => {}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
/// After the host ran: the gesture the pass finished, which [`RedactResult::land`] applies once the tool's
|
||||
/// borrows of the session end.
|
||||
pub(crate) fn finished(self) -> Option<RedactResult> {
|
||||
self.finished
|
||||
}
|
||||
|
||||
fn placed_at(&self, p: Pos2) -> Option<&'a PlacedPage> {
|
||||
|
||||
Reference in New Issue
Block a user