mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-27 04:37:07 +00:00
compile fix 3 (rest) (swarm/cfix3); committed by the lead
This commit is contained in:
@@ -75,12 +75,9 @@ pub(crate) fn show(app: &mut PdfCraftApp, ui: &mut Ui) {
|
||||
let current_label = view.current_page_label(labels.get(current).map(String::as_str));
|
||||
// Taken once, in the pass that shows the field, also while the field is not focused.
|
||||
let reselect = std::mem::take(&mut view.page_input_reselect);
|
||||
let edit = TextField::new("Current page", Bind::bound(&mut view.page_input))
|
||||
.id(view.page_input_id())
|
||||
.select_on_focus()
|
||||
.select_all(reselect)
|
||||
.submits()
|
||||
.show(ui);
|
||||
let input_id = view.page_input_id();
|
||||
let edit =
|
||||
TextField::new("Current page", Bind::bound(&mut view.page_input)).id(input_id).select_on_focus().select_all(reselect).submits().show(ui);
|
||||
if edit.submitted {
|
||||
let typed = view.page_input.clone();
|
||||
view.go_to_typed(&typed, &labels);
|
||||
|
||||
@@ -317,7 +317,7 @@ impl PdfCraftApp {
|
||||
.or_else(|| self.run_view_command(ctx, id, active))
|
||||
.or_else(|| self.run_page_command(ctx, id, active, targets))
|
||||
.or_else(|| self.run_edit_command(ctx, id, active))
|
||||
.or_else(|| self.run_form_command(id, active))
|
||||
.or_else(|| self.run_form_command(ctx, id, active))
|
||||
.or_else(|| self.run_secure_command(ctx, id, active))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
@@ -752,7 +752,7 @@ impl PdfCraftApp {
|
||||
Some(true)
|
||||
}
|
||||
|
||||
fn run_form_command(&mut self, id: &str, active: Option<usize>) -> Option<bool> {
|
||||
fn run_form_command(&mut self, ctx: &egui::Context, id: &str, active: Option<usize>) -> Option<bool> {
|
||||
match id {
|
||||
"form.fields" => self.choose_right_panel(Some(RightPanel::Fields)),
|
||||
"form.calculation_order" => {
|
||||
@@ -792,7 +792,7 @@ impl PdfCraftApp {
|
||||
}
|
||||
"sign.certify_invisible" => {
|
||||
let page = active.and_then(|i| self.views.get(i)).map_or(0, |v| v.current());
|
||||
self.start_signing(page, None, None, Some(2));
|
||||
self.start_signing(ctx, page, None, None, Some(2));
|
||||
}
|
||||
"sign.validate" => {
|
||||
let certs = self.session.trusted_certificates().to_vec();
|
||||
@@ -810,10 +810,10 @@ impl PdfCraftApp {
|
||||
if let Some((_, id)) = self.active_ids()
|
||||
&& self.session.get(id).is_some_and(|d| d.form.is_empty() && d.editable())
|
||||
{
|
||||
self.detect_fields();
|
||||
self.detect_fields(ctx);
|
||||
}
|
||||
}
|
||||
"form.detect" => self.detect_fields(),
|
||||
"form.detect" => self.detect_fields(ctx),
|
||||
"form.field.properties" => {
|
||||
if let Some((name, w)) = active.and_then(|i| self.views[i].session.prepare.selected.clone()) {
|
||||
crate::prepare::dialog::open(self, &name, w, crate::prepare::FieldTab::General);
|
||||
@@ -897,7 +897,7 @@ impl PdfCraftApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
"redact.pages" => crate::redact_ui::dialogs::open_pages(self),
|
||||
"redact.pages" => crate::redact_ui::dialogs::open_pages(self, ctx),
|
||||
"redact.search" => {
|
||||
self.redact_search.found = None;
|
||||
self.redact_search_open = true;
|
||||
|
||||
@@ -53,7 +53,7 @@ mod password_draft_tests {
|
||||
use super::*;
|
||||
|
||||
fn seed_password_drafts(app: &mut PdfCraftApp) {
|
||||
app.start_signing(0, None, None, None);
|
||||
app.start_signing(&egui::Context::default(), 0, None, None, None);
|
||||
let sign = app.sign_draft.as_mut().unwrap();
|
||||
sign.step = crate::sign_ui::SignStep::Choose;
|
||||
sign.password = "sign password".into();
|
||||
|
||||
@@ -306,7 +306,7 @@ fn comment_props_dialog<'b>(
|
||||
let review = if history.is_empty() {
|
||||
vec![PropertyRow::value(tl!("Status"), tl!("No status has been set."))]
|
||||
} else {
|
||||
history.iter().map(|(state, line)| PropertyRow::value(tl!(state), line.clone())).collect()
|
||||
history.iter().map(|(state, line)| PropertyRow::value(tl!(state).to_string(), line.clone())).collect()
|
||||
};
|
||||
let review = PropertiesTab::new(tl!("Review History"), review);
|
||||
|
||||
|
||||
@@ -898,7 +898,9 @@ impl PdfCraftApp {
|
||||
let fields = opening_fields(&self.marks_draft, kind, &units);
|
||||
let base = self.marks_draft.clone();
|
||||
let heading = title(kind, replace);
|
||||
let build = move |fields: &mut DialogFields| {
|
||||
// Passed inline: a closure made apart from the call gets one lifetime for its argument and result.
|
||||
// PLAN: assumed `self.dialogs: DialogHost`, `self.host`/`self.wake` (pdf-hub-w1 note 11)
|
||||
let dialog = HostedParamDialog::new(ctx, dialog_key(kind), fields, move |fields: &mut DialogFields| {
|
||||
let mut draft = base.clone();
|
||||
read_fields(&mut draft, fields, kind, &units);
|
||||
let has_file = fields.text("file.path").is_some_and(|p| !p.is_empty());
|
||||
@@ -928,9 +930,7 @@ impl PdfCraftApp {
|
||||
dialog = dialog.ok_reason(reason.clone().into());
|
||||
}
|
||||
dialog
|
||||
};
|
||||
// PLAN: assumed `self.dialogs: DialogHost`, `self.host`/`self.wake` (pdf-hub-w1 note 11)
|
||||
let dialog = HostedParamDialog::new(ctx, dialog_key(kind), fields, build);
|
||||
});
|
||||
self.dialogs.open(dialog);
|
||||
self.marks_preview = Some(MarksPreview::new(kind, self.host.jobs_shared().clone(), self.wake.clone()));
|
||||
}
|
||||
|
||||
@@ -609,7 +609,7 @@ impl PreferencesModel for Prefs<'_> {
|
||||
self.host.run(ui);
|
||||
let answered = self.answers.lock().map(|mut queue| std::mem::take(&mut *queue)).unwrap_or_default();
|
||||
for (key, colour) in answered {
|
||||
self.set_color(&key, colour.to_rgba());
|
||||
self.set_color(&key, colour);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,16 +105,18 @@ fn radio_row(key: &str, label: &str, options: [(&str, &str); 2]) -> PropertyRow
|
||||
/// A row of buttons that ask the host for `actions` (an id and its label); `lead` is text before them.
|
||||
fn action_row(key: &str, label: &str, lead: Option<String>, actions: Vec<(String, String)>) -> PropertyRow {
|
||||
PropertyRow::field(Param::custom(key, tl!(label).to_string(), move |ui, _, cx| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
if let Some(lead) = &lead {
|
||||
Text::new(lead.clone()).show(ui);
|
||||
}
|
||||
for (id, text) in &actions {
|
||||
if clicked(&Button::new(text.clone()).show(ui)) {
|
||||
cx.request_action(id.clone());
|
||||
Row::new()
|
||||
.show(ui, |ui, _| {
|
||||
if let Some(lead) = &lead {
|
||||
Text::new(lead.clone()).show(ui);
|
||||
}
|
||||
}
|
||||
})
|
||||
for (id, text) in &actions {
|
||||
if clicked(&Button::new(text.clone()).show(ui)) {
|
||||
cx.request_action(id.clone());
|
||||
}
|
||||
}
|
||||
})
|
||||
.response
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -208,7 +210,7 @@ fn custom_row(file_listed: usize, editable: bool, listed: Vec<(String, String)>)
|
||||
if custom_pairs(fields).as_ref() != Some(&props) {
|
||||
fields.set("custom", custom_json(&props));
|
||||
}
|
||||
shown
|
||||
shown.response
|
||||
})
|
||||
.companions(["custom.name", "custom.value", "custom.unlisted"])
|
||||
.opens_with(custom_json(&listed));
|
||||
|
||||
@@ -220,7 +220,10 @@ mod tests {
|
||||
/// The figure in the Words row of the open dialog: the value beside the row's label.
|
||||
fn words_shown(h: &Harness<'_, PdfCraftApp>) -> String {
|
||||
let row = h.get_by_label("Words").parent().expect("the Words label sits in its row");
|
||||
row.children_recursive().filter_map(|n| n.label()).find(|l| l.chars().all(|c| c.is_ascii_digit())).expect("the row shows a figure")
|
||||
row.children_recursive()
|
||||
.filter_map(|n| n.accesskit_node().label().map(|l| l.to_string()))
|
||||
.find(|l| l.chars().all(|c| c.is_ascii_digit()))
|
||||
.expect("the row shows a figure")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -116,7 +116,7 @@ mod tests {
|
||||
let dialog = craft::ui::dialog::DialogWords::english();
|
||||
let common = craft::ui::runtime::words::CommonWords::english();
|
||||
let dont_save = if cfg!(target_os = "macos") { dialog.unsaved_dont_save } else { dialog.unsaved_no };
|
||||
(dont_save.as_str().to_string(), common.cancel.to_string())
|
||||
(dont_save.as_str().to_string(), common.cancel.as_str().to_string())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -116,18 +116,37 @@ pub fn posted(ctx: &egui::Context) -> Vec<toast::Card> {
|
||||
toast::cards(ctx, &WindowKey::main())
|
||||
}
|
||||
|
||||
/// Posts the notices and applies the progress requests queued since the last pass, in the order they were made.
|
||||
pub(crate) fn post_queued(app: &mut PdfCraftApp, ctx: &egui::Context) {
|
||||
// No PdfCraft notice sets a dismiss key, so nothing is ever silenced and the list is empty.
|
||||
for notice in std::mem::take(&mut app.posted_notices) {
|
||||
app.notices.post(ctx, ¬ice, &[]);
|
||||
}
|
||||
for request in std::mem::take(&mut app.progress_requests) {
|
||||
apply(app, ctx, request);
|
||||
}
|
||||
}
|
||||
|
||||
/// The text of every card shown in `ctx` after the app's queue is posted into it, oldest first: a card's title, then its
|
||||
/// message.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn texts(app: &mut PdfCraftApp, ctx: &egui::Context) -> Vec<String> {
|
||||
post_queued(app, ctx);
|
||||
posted(ctx)
|
||||
.iter()
|
||||
.map(|card| {
|
||||
let title = card.toast.title.as_ref().map(|t| t.as_str().to_owned());
|
||||
[title, Some(card.toast.message.as_str().to_owned())].into_iter().flatten().filter(|t| !t.is_empty()).collect::<Vec<_>>().join("\n")
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Posts the queued notices, collects how the notices ended and acts on them: a progress card's Cancel reaches its
|
||||
/// job. Called once per pass. The ends are taken from the center's session state, so a second pass in the same frame
|
||||
/// sees none of the first's.
|
||||
pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
|
||||
let ctx = ui.ctx().clone();
|
||||
// No PdfCraft notice sets a dismiss key, so nothing is ever silenced and the list is empty.
|
||||
for notice in std::mem::take(&mut app.posted_notices) {
|
||||
app.notices.post(&ctx, ¬ice, &[]);
|
||||
}
|
||||
for request in std::mem::take(&mut app.progress_requests) {
|
||||
apply(app, &ctx, request);
|
||||
}
|
||||
post_queued(app, &ctx);
|
||||
let ends = app.notices.clone().show(ui).ends;
|
||||
for end in ends {
|
||||
route(app, &end);
|
||||
|
||||
@@ -291,16 +291,20 @@ pub(super) fn body(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult {
|
||||
Some((_, parent)) if !parent.is_empty() => item_at(outline, parent).map_or(0, |p| p.children.len()),
|
||||
_ => outline.len(),
|
||||
};
|
||||
let mut pick = |ui: &mut egui::Ui, label: &str, enabled: bool, action: BmAction| {
|
||||
// Held apart from `result` so the style and colour submenus can set the choice too.
|
||||
let picked = std::cell::Cell::new(None);
|
||||
let pick = |ui: &mut egui::Ui, label: &'static str, enabled: bool, action: BmAction| {
|
||||
if MenuItem::new(label).enabled(enabled).show(ui).ran {
|
||||
result.bookmark = Some(action);
|
||||
picked.set(Some(action));
|
||||
}
|
||||
};
|
||||
if MenuItem::new(tl!("Rename")).show(ui).ran {
|
||||
request_rename(ui.ctx(), list_id, &path);
|
||||
}
|
||||
let set_page = crate::i18n::fmt(tl!("Set to current page ({n})"), &[("n", &(current + 1).to_string())]);
|
||||
pick(ui, &set_page, true, BmAction::SetToCurrentPage(path.clone()));
|
||||
if MenuItem::new(set_page).show(ui).ran {
|
||||
picked.set(Some(BmAction::SetToCurrentPage(path.clone())));
|
||||
}
|
||||
if let Some(item) = item_at(outline, &path) {
|
||||
// The title's style and colour (ISO 32000-2 §12.3.3, Tables 151 and 152).
|
||||
let style = MenuItem::new(tl!("Style")).show(ui);
|
||||
@@ -322,7 +326,7 @@ pub(super) fn body(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult {
|
||||
}
|
||||
});
|
||||
if styled.is_some() {
|
||||
result.bookmark = styled;
|
||||
picked.set(styled);
|
||||
}
|
||||
}
|
||||
pick(ui, tl!("Move up"), i > 0, BmAction::MoveUp(path.clone()));
|
||||
@@ -334,6 +338,9 @@ pub(super) fn body(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult {
|
||||
let parent = path.get(..depth).unwrap_or_default().to_vec();
|
||||
pick(ui, tl!("Paste"), can_paste, BmAction::Paste { parent, index: i.saturating_add(1) });
|
||||
pick(ui, tl!("Delete"), true, BmAction::Delete(path.clone()));
|
||||
if let Some(action) = picked.take() {
|
||||
result.bookmark = Some(action);
|
||||
}
|
||||
});
|
||||
if menu.output.closed.is_some() {
|
||||
target = None;
|
||||
|
||||
@@ -95,7 +95,7 @@ pub fn panel_body(app: &mut PdfCraftApp, ui: &mut egui::Ui, cx: &mut BodyCx<'_>,
|
||||
Some(crate::sign_ui::PanelAction::ViewSigned { len, revision }) => app.view_signed_version(len, revision),
|
||||
Some(crate::sign_ui::PanelAction::Sign(field)) => {
|
||||
let page = app.views[index].current();
|
||||
app.start_signing(page, None, Some(field), None);
|
||||
app.start_signing(&ctx, page, None, Some(field), None);
|
||||
}
|
||||
Some(crate::sign_ui::PanelAction::ExportCertificate(c)) => {
|
||||
app.export_certificate(&c);
|
||||
|
||||
@@ -467,7 +467,7 @@ fn number<T: Value>(
|
||||
Mixed::Same(v) => Mixed::Same(Some(to(v))),
|
||||
_ => Mixed::Mixed,
|
||||
};
|
||||
let mut field = NumberField::new(tl!(label).to_owned(), Bind::bound_mixed(&mut typed)).range(range);
|
||||
let mut field = NumberField::new(tl!(label).to_owned(), Bind::bound_mixed(&mut typed)).range(range.clone());
|
||||
if let Some(unit) = unit {
|
||||
field = field.unit(unit);
|
||||
}
|
||||
|
||||
@@ -217,12 +217,17 @@ pub(crate) fn note_popups(
|
||||
let color = a.color.map(|c| c.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8));
|
||||
let selected = view.session.comments.is_selected((page, a.index));
|
||||
let drafts: &mut NoteDrafts = view.session.comments.popup_drafts.entry((page, a.index)).or_default();
|
||||
let mut window =
|
||||
NotePopup::new(super::bridge::id_of(page, a.index).0, owned.first().map_or("", |m| m.title.as_str()), rect, &msgs, drafts)
|
||||
.color(color)
|
||||
.selected(selected)
|
||||
.now(now)
|
||||
.allowed(allowed);
|
||||
let mut window = NotePopup::new(
|
||||
super::bridge::id_of(page, a.index).0,
|
||||
owned.first().map_or_else(String::new, |m| m.title.clone()),
|
||||
rect,
|
||||
&msgs,
|
||||
drafts,
|
||||
)
|
||||
.color(color)
|
||||
.selected(selected)
|
||||
.now(now)
|
||||
.allowed(allowed);
|
||||
if let Some(mark) = mark {
|
||||
window = window.anchor(mark, hovered == Some((page, a.index)));
|
||||
}
|
||||
|
||||
@@ -1564,16 +1564,12 @@ mod tests {
|
||||
let (mut app, mut ed) = preview_app();
|
||||
ed.text = "Text preview".into();
|
||||
app.views[0].session.line_editor = Some(ed);
|
||||
let dir = std::env::temp_dir().join(format!("pdfcraft-ui-open-paragraph-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
app.save_override = Some(dir.join("out.pdf").to_string_lossy().into_owned());
|
||||
|
||||
assert!(app.save_active(crate::SaveTarget::InPlace));
|
||||
// A new document asks where to save; the paragraph is applied before it asks.
|
||||
assert!(!app.save_active(crate::SaveTarget::InPlace));
|
||||
assert!(app.views[0].session.line_editor.is_none());
|
||||
let doc = app.session.get(app.views[0].id).unwrap();
|
||||
assert_eq!(doc.text_lines(0).iter().map(|l| l.text.as_str()).collect::<String>(), "Text preview");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -7,11 +7,12 @@ use craft::draw::ui::transform::{RotateZone, TransformBox};
|
||||
use craft::imaging::ui::transform_preview::{PreviewMap, PreviewPixels, PreviewTextures, TransformPreview};
|
||||
use craft::pages::ui::{PageBody, PlacedPage};
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::canvas::{CropOutside, CropOverlay};
|
||||
use craft::ui::canvas::{CropApply, CropOutside, CropOverlay};
|
||||
use craft::ui::canvas_controls::{SelectionOutline, TaskBar};
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::menu::{Menu, MenuIcon, MenuIconRow, MenuItem};
|
||||
use craft::ui::primitives::textures::TextureState;
|
||||
|
||||
pub(crate) use pdfcraft_content::Matrix;
|
||||
|
||||
@@ -360,9 +361,12 @@ fn crop_controls(ui: &mut egui::Ui, body: &PageBody<'_>, view: &mut DocView, pic
|
||||
}
|
||||
return None;
|
||||
}
|
||||
// PLAN: framework gap F-9: `CropOverlayOutput::apply` does not say it was an away click, so the selection stays after one.
|
||||
if done || shown.apply {
|
||||
if done || shown.apply.is_some() {
|
||||
apply_crop_mode(view, image);
|
||||
// A click away lets the selection go; Enter and a double click keep it.
|
||||
if shown.apply == Some(CropApply::Away) {
|
||||
view.session.image_selection = None;
|
||||
}
|
||||
} else if (cancel || shown.discard)
|
||||
&& let Some(s) = view.session.image_selection.as_mut()
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ pub(super) fn choice_list(ui: &mut egui::Ui, field: &FormField, rect: Rect, zoom
|
||||
PopupList::new(tl!("Options"), Bind::bound(&mut *open)).overlay(|overlay| overlay.opener_anchor(Anchor::Rect(rect))).show(ui, |ui, _| {
|
||||
List::<usize>::options(field.name.clone())
|
||||
.document_rows(DocumentRows::new(FontRef::proportional(), size, align))
|
||||
.show_items(ui, &source, &mut |key, _| ListRow::new(names.get(*key).copied().unwrap_or("")).option())
|
||||
.show_items(ui, &source, &mut |key, _| ListRow::new(names.get(*key).copied().unwrap_or_default().to_owned()).option())
|
||||
.events
|
||||
});
|
||||
let mut picked = None;
|
||||
|
||||
@@ -405,8 +405,9 @@ pub(crate) fn delete_selected(session: &mut PageSession) -> Option<Edit> {
|
||||
|
||||
/// Select every widget on the current page.
|
||||
pub(crate) fn select_all(view: &mut DocView, form: &[FormField]) {
|
||||
let current = view.current();
|
||||
let mut selected =
|
||||
form.iter().flat_map(|f| f.widgets.iter().enumerate().filter(|(_, w)| w.page == Some(view.current())).map(|(wi, _)| (f.name.clone(), wi)));
|
||||
form.iter().flat_map(|f| f.widgets.iter().enumerate().filter(move |(_, w)| w.page == Some(current)).map(|(wi, _)| (f.name.clone(), wi)));
|
||||
view.session.prepare.selected = selected.next();
|
||||
view.session.prepare.also = selected.collect();
|
||||
}
|
||||
|
||||
@@ -74,21 +74,21 @@ fn flag_box(ui: &mut egui::Ui, d: &mut FieldDraft, bit: u32, inverted: bool, lab
|
||||
|
||||
/// A labelled one-line text field.
|
||||
pub(super) fn text_row(ui: &mut egui::Ui, salt: &'static str, label: &str, value: &mut String) {
|
||||
Field::new(label).id_salt(salt).show(ui, |ui, _| {
|
||||
Field::new(label.to_owned()).id_salt(salt).show(ui, |ui, _| {
|
||||
TextField::new(label.to_owned(), Bind::bound(&mut *value)).show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
/// A labelled multi-line field for script text: monospaced, and Tab types a tab.
|
||||
pub(super) fn code_row(ui: &mut egui::Ui, salt: &'static str, label: &str, value: &mut String, lines: usize) {
|
||||
Field::new(label).id_salt(salt).show(ui, |ui, _| {
|
||||
Field::new(label.to_owned()).id_salt(salt).show(ui, |ui, _| {
|
||||
TextField::new(label.to_owned(), Bind::bound(&mut *value)).lines(lines).mono().tab_inserts(true).show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
/// A labelled choice among `entries`.
|
||||
pub(super) fn select_row<T: Value>(ui: &mut egui::Ui, salt: &'static str, label: &str, value: &mut T, entries: &[Entry<T>]) {
|
||||
Field::new(label).id_salt(salt).show(ui, |ui, _| {
|
||||
Field::new(label.to_owned()).id_salt(salt).show(ui, |ui, _| {
|
||||
Select::new(label.to_owned(), Bind::bound(&mut *value), entries).show(ui);
|
||||
});
|
||||
}
|
||||
@@ -104,7 +104,7 @@ pub(super) fn number_row(
|
||||
enabled: bool,
|
||||
) {
|
||||
let mut shown = Some(*value);
|
||||
Field::new(label).id_salt(salt).show(ui, |ui, _| {
|
||||
Field::new(label.to_owned()).id_salt(salt).show(ui, |ui, _| {
|
||||
let mut field = NumberField::new(label.to_owned(), Bind::bound(&mut shown)).range(range.clone());
|
||||
if let Some(unit) = unit {
|
||||
field = field.unit(unit.to_owned());
|
||||
|
||||
@@ -137,7 +137,7 @@ impl<'a> PrepareTool<'a> {
|
||||
out
|
||||
}
|
||||
|
||||
fn finish_draw(&mut self, drag: PageBoxDrag, origin: Pos2) {
|
||||
fn finish_draw(&mut self, mut drag: PageBoxDrag, origin: Pos2) {
|
||||
let Some(tool) = self.tool else { return };
|
||||
// PLAN: assumed `PageBoxDrag::release(min: f32) -> Option<(usize, Rect)>` (pdf-canvas-w18 note 7)
|
||||
let Some((page, rect)) = drag.release(CLICK_SIZE) else { return };
|
||||
|
||||
@@ -230,7 +230,7 @@ fn a_password_answered_after_combine_opens_behind_the_combine_tab() {
|
||||
assert!(app.password_prompt.is_some() && app.views.is_empty());
|
||||
app.combine_paths(&[]);
|
||||
assert!(app.combine_showing());
|
||||
app.submit_password(Some("pw".into()));
|
||||
app.submit_password(&egui::Context::default(), Some("pw".into()));
|
||||
assert!(app.password_prompt.is_none());
|
||||
assert_eq!(app.views.len(), 1, "the document is open");
|
||||
assert!(app.combine_showing(), "and the Combine files tab still shows");
|
||||
|
||||
@@ -80,7 +80,8 @@ pub(crate) fn open_compare_dialog(app: &mut PdfCraftApp, ctx: &egui::Context) {
|
||||
let new_name = app.session.get(new).map(|d| d.name.clone()).unwrap_or_default();
|
||||
let count = app.views.get(active_i).map_or(0, |v| v.page_count());
|
||||
let fields = DialogFields::from_pairs([("old", old.unwrap_or_default()), ("pages", app.compare_pages.clone())]);
|
||||
let build = move |fields: &mut DialogFields| {
|
||||
// Passed inline: a closure made apart from the call gets one lifetime for its argument and result.
|
||||
let dialog = HostedParamDialog::new(ctx, DIALOG_KEY, fields, move |fields: &mut DialogFields| {
|
||||
let chosen = fields.text("old").filter(|o| !o.is_empty()).map(str::to_owned);
|
||||
let pages_ok = parse_pages(fields.text("pages").unwrap_or_default(), count).is_ok();
|
||||
let options = others.iter().map(|(key, name)| (key.clone(), name.clone().into())).collect();
|
||||
@@ -104,8 +105,8 @@ pub(crate) fn open_compare_dialog(app: &mut PdfCraftApp, ctx: &egui::Context) {
|
||||
.ok_enabled(chosen.is_some() && pages_ok)
|
||||
.ok_reason(reason.into())
|
||||
.footer_note(tl!("Text is compared word by word; the differences are shown on the new file.").to_string())
|
||||
};
|
||||
crate::dialogs::host::open(app, HostedParamDialog::new(ctx, DIALOG_KEY, fields, build));
|
||||
});
|
||||
crate::dialogs::host::open(app, dialog);
|
||||
}
|
||||
|
||||
/// Once per frame: when the Compare Files dialog answered OK, runs the comparison it asked for.
|
||||
|
||||
@@ -891,7 +891,9 @@ mod tests {
|
||||
for bad in ["../x.pdf", "..", ".", "", "sub/x.pdf", "sub\\x.pdf", "C:x.pdf", "x.pdf.", absolute] {
|
||||
// A plain name first: nothing is written when any name in the batch is refused.
|
||||
app.write_files(&[("ok.pdf".into(), pdf()), (bad.into(), pdf())], "t");
|
||||
assert!(app.toast.as_ref().is_some_and(|t| t.0.contains("not a plain file name")), "{bad}");
|
||||
// A fresh context each time: it holds only the notice this attempt posted.
|
||||
let said = crate::notices::texts(&mut app, &egui::Context::default());
|
||||
assert!(said.iter().any(|t| t.contains("not a plain file name")), "{bad}");
|
||||
}
|
||||
assert!(files.requests().is_empty(), "no folder is asked for");
|
||||
assert!(files.file(&out.join("ok.pdf")).is_none());
|
||||
|
||||
@@ -100,10 +100,11 @@ fn console(app: &mut PdfCraftApp, ui: &mut egui::Ui, open: &mut bool) {
|
||||
submitted = input.submitted;
|
||||
});
|
||||
let picked = shown.output.picked.and_then(|at| actions.get(at)).map(|(a, _)| *a);
|
||||
let ctx = ui.ctx().clone();
|
||||
match picked {
|
||||
Some(Action::Run) => app.run_console(),
|
||||
Some(Action::Run) => app.run_console(&ctx),
|
||||
Some(Action::Clear) => app.js_console.log.clear(),
|
||||
_ if submitted => app.run_console(),
|
||||
_ if submitted => app.run_console(&ctx),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1226,9 +1226,8 @@ mod tests {
|
||||
}
|
||||
|
||||
/// The text of the notices posted so far.
|
||||
fn posted(app: &PdfCraftApp) -> String {
|
||||
// PLAN: assumed `Notices::posted(&self) -> Vec<String>` on the app's `notices` (pdf-chrome-w19).
|
||||
app.notices.posted().join("; ")
|
||||
fn posted(app: &mut PdfCraftApp) -> String {
|
||||
crate::notices::texts(app, &egui::Context::default()).join("; ")
|
||||
}
|
||||
|
||||
/// A page of one confident word.
|
||||
@@ -1538,7 +1537,7 @@ mod tests {
|
||||
app.ocr_files(vec![("scan.pdf".into(), pdf.to_vec()), ("other.pdf".into(), pdf.to_vec()), ("Scan.PDF".into(), pdf.to_vec())]);
|
||||
assert!(app.ocr_batch.is_none(), "the batch never starts");
|
||||
assert_eq!(app.ocr_batches.counts().running + app.ocr_batches.counts().queued, 0, "nothing was submitted");
|
||||
let toast = posted(&app);
|
||||
let toast = posted(&mut app);
|
||||
assert!(toast.contains("same name") && toast.contains("Scan.PDF"), "{toast}");
|
||||
assert_eq!(std::fs::read_dir(&dir).expect("fixture").count(), 0, "nothing was written");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
@@ -1557,7 +1556,7 @@ mod tests {
|
||||
let pdf = s.create_from_text("t", "scanned words here").expect("fixture");
|
||||
app.ocr_files(vec![("a.pdf".into(), pdf.to_vec()), ("b.pdf".into(), pdf.to_vec())]);
|
||||
assert!(app.ocr_batch.is_none(), "the collision stops the batch before anything is read");
|
||||
let toast = posted(&app);
|
||||
let toast = posted(&mut app);
|
||||
assert!(toast.contains("already holds files of these names"), "{toast}");
|
||||
assert!(toast.contains("a.pdf"), "the colliding names are in the error: {toast}");
|
||||
assert_eq!(app.ocr_draft.output_folder.as_deref(), Some(dir.to_string_lossy().as_ref()), "the folder stays remembered for the next batch");
|
||||
@@ -1578,7 +1577,7 @@ mod tests {
|
||||
let after_edit = app.session.get(id).and_then(|d| d.can_undo().map(str::to_owned));
|
||||
let page = one_word_page(Some(95.0), Vec::new());
|
||||
app.land_ocr(id, guard, None, false, Ok(vec![page]));
|
||||
let toast = posted(&app);
|
||||
let toast = posted(&mut app);
|
||||
assert!(toast.contains("changed since recognition started"), "{toast}");
|
||||
assert_eq!(
|
||||
app.session.get(id).and_then(|d| d.can_undo().map(str::to_owned)),
|
||||
@@ -1598,7 +1597,7 @@ mod tests {
|
||||
let page = one_word_page(Some(95.0), vec![note.into()]);
|
||||
let guard = app.session.ocr_guard(id).unwrap();
|
||||
app.land_ocr(id, guard, None, false, Ok(vec![page]));
|
||||
let toast = posted(&app);
|
||||
let toast = posted(&mut app);
|
||||
assert!(toast.contains(note), "{toast}");
|
||||
}
|
||||
|
||||
|
||||
@@ -1747,9 +1747,8 @@ mod tests {
|
||||
}
|
||||
|
||||
/// What the app said to the user, from the notices it posted.
|
||||
// PLAN: assumed `Notices::posted(&self) -> impl Iterator<Item = &Notice>` (pdf-chrome-w19, L-206) on `PdfCraftApp::notices`, and `Notice::text() -> &str`.
|
||||
fn said(app: &PdfCraftApp) -> String {
|
||||
app.notices.posted().map(|n| n.text().to_owned()).collect::<Vec<_>>().join("\n")
|
||||
fn said(app: &mut PdfCraftApp) -> String {
|
||||
crate::notices::texts(app, &egui::Context::default()).join("\n")
|
||||
}
|
||||
|
||||
/// A re-read of page 1 in flight under ticket 1.
|
||||
@@ -2014,7 +2013,7 @@ mod tests {
|
||||
with_state(&mut app, |v, app| v.start_reread(app, 0, Some([10.0, 10.0, 10.0, 60.0])));
|
||||
assert!(app.ocr_verify.reread.is_none(), "nothing runs");
|
||||
assert_eq!(app.ocr_verify.page(0).expect("page").words.len(), 1, "the existing words are intact");
|
||||
assert!(said(&app).contains("empty or outside"));
|
||||
assert!(said(&mut app).contains("empty or outside"));
|
||||
// Nor does one wholly outside the page.
|
||||
with_state(&mut app, |v, app| v.start_reread(app, 0, Some([-50.0, -50.0, -1.0, -1.0])));
|
||||
assert!(app.ocr_verify.reread.is_none());
|
||||
@@ -2267,7 +2266,7 @@ mod tests {
|
||||
assert_eq!(app.active, Some(0), "and comes to the front");
|
||||
assert!(app.ocr_verify.open, "with its review");
|
||||
assert_eq!(app.ocr_verify.text_of((0, 0)), Some("Edited"), "as it was");
|
||||
assert!(!said(&app).is_empty(), "a notice says to accept or reject it first");
|
||||
assert!(!said(&mut app).is_empty(), "a notice says to accept or reject it first");
|
||||
app.ocr_verify.open = false;
|
||||
app.request_close_tab(2);
|
||||
assert_eq!(app.views.len(), 2, "another document closes as usual");
|
||||
@@ -2377,7 +2376,7 @@ mod tests {
|
||||
assert!(matches!(app.close_requested(), CloseDecision::Hold), "the close is held");
|
||||
assert_eq!(app.active, Some(0), "the reviewed document comes to the front");
|
||||
assert!(app.ocr_verify.open, "with its review");
|
||||
assert!(!said(&app).is_empty(), "a notice says to accept or reject it first");
|
||||
assert!(!said(&mut app).is_empty(), "a notice says to accept or reject it first");
|
||||
assert_eq!(app.views.len(), 2, "nothing closed");
|
||||
assert!(app.ocr_verify.reject());
|
||||
assert!(matches!(app.close_requested(), CloseDecision::Close), "after Reject, the close goes ahead");
|
||||
|
||||
@@ -934,32 +934,48 @@ mod tests {
|
||||
let mut app = PdfCraftApp::for_unit_tests();
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.print_tasks = PrintTasks::new(jobs.clone(), Wake::none());
|
||||
// PLAN: assumed `Notices::progress(&self, ProgressKey) -> Option<ProgressNotice>` and `Notices::posted(&self) -> Vec<String>` (the posted messages, oldest first), read through `app.notices` (pdf-chrome-w19, L-206).
|
||||
let card = |app: &PdfCraftApp| app.notices.progress(crate::notices::ProgressKey::Print);
|
||||
// The notices the app queued are posted into one context, as a pass would post them.
|
||||
let ctx = egui::Context::default();
|
||||
let card = |app: &mut PdfCraftApp| {
|
||||
crate::notices::post_queued(app, &ctx);
|
||||
let fraction = crate::notices::progress(app, &ctx, crate::notices::ProgressKey::Print)?;
|
||||
let id = app.progress_cards.get(&crate::notices::ProgressKey::Print)?;
|
||||
let cancellable = crate::notices::posted(&ctx).iter().any(|c| c.id == *id && !c.toast.actions.is_empty());
|
||||
Some((fraction, cancellable))
|
||||
};
|
||||
// The outcome notices: every card but a job's progress card, oldest first.
|
||||
let outcomes = |app: &mut PdfCraftApp| {
|
||||
crate::notices::post_queued(app, &ctx);
|
||||
crate::notices::posted(&ctx)
|
||||
.into_iter()
|
||||
.filter(|c| c.toast.progress.is_none())
|
||||
.map(|c| format!("{} {}", c.toast.title.as_ref().map_or("", |t| t.as_str()), c.toast.message.as_str()))
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
let count = Arc::new(crate::JobCount::default());
|
||||
app.print_tasks.running.push(RunningPrint { ticket: 0, printer: "Office".into(), count: count.clone() });
|
||||
app.show_print_progress("Office", None);
|
||||
let started = card(&app).expect("a card shows while the job runs");
|
||||
assert!(!started.cancellable);
|
||||
let (started, cancellable) = card(&mut app).expect("a card shows while the job runs");
|
||||
assert!(!cancellable);
|
||||
|
||||
count.set(1, 3);
|
||||
app.poll_print();
|
||||
let first = card(&app).unwrap().fraction;
|
||||
assert!(first > started.fraction, "one sheet sent moves the card: {first}");
|
||||
let first = card(&mut app).unwrap().0;
|
||||
assert!(first > started, "one sheet sent moves the card: {first}");
|
||||
|
||||
count.set(2, 3);
|
||||
app.poll_print();
|
||||
let second = card(&app).unwrap().fraction;
|
||||
let second = card(&mut app).unwrap().0;
|
||||
assert!(second > first && second < 1.0, "the card keeps rising with the sheets: {second}");
|
||||
|
||||
let before = app.notices.posted().len();
|
||||
let before = outcomes(&mut app).len();
|
||||
count.set(3, 3);
|
||||
app.print_tasks.jobs.submit(0, Priority::VISIBLE, |_| Ok(String::new()));
|
||||
jobs.run_all();
|
||||
app.poll_print();
|
||||
assert!(card(&app).is_none() && app.print_tasks.running.is_empty());
|
||||
let posted = app.notices.posted();
|
||||
assert!(card(&mut app).is_none() && app.print_tasks.running.is_empty());
|
||||
let posted = outcomes(&mut app);
|
||||
assert_eq!(posted.len(), before + 1, "one outcome notice");
|
||||
assert!(posted.last().is_some_and(|m| m.contains("Office")), "it names the printer: {posted:?}");
|
||||
|
||||
@@ -968,8 +984,8 @@ mod tests {
|
||||
app.print_tasks.jobs.submit(1, Priority::VISIBLE, |_| Err("the spooler refused the job".into()));
|
||||
jobs.run_all();
|
||||
app.poll_print();
|
||||
assert!(card(&app).is_none() && app.print_tasks.running.is_empty());
|
||||
let posted = app.notices.posted();
|
||||
assert!(card(&mut app).is_none() && app.print_tasks.running.is_empty());
|
||||
let posted = outcomes(&mut app);
|
||||
assert_eq!(posted.len(), before + 2, "the refusal is one more notice");
|
||||
assert!(posted.last().is_some_and(|m| m.contains("refused")), "{posted:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user