PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Merge remote-tracking branch 'upstream/main' into feat/bookmarks-from-text-styles
Claude03fdf97cde0c
diff --cc crates/automation/src/dispatch.rsindex 5b9b96c8d,87f47e8eb..b136076bc--- a/crates/automation/src/dispatch.rs+++ b/crates/automation/src/dispatch.rs@@@ -1,7 -1,7 +1,7 @@@use super::error::{Result, ToolError, failed};-use super::json::{Args, document_attachment_keys, info, one_based, parse_style_ranges, security, summary};+use super::json::{Args, document_attachment_keys, info, one_based, parse_style_ranges, security, summary, text_style_levels};use super::paths::{read_input, write_atomic};- use super::*;+ use super::{Arc, Automation, Edit, Value, block_overlapping, comments, json, tools};/// One piece of a tool's result.#[derive(Clone, Debug, PartialEq)]diff --cc crates/ui-egui/src/commands.rsindex 49ce4a232,acccbcc55..c5988567d--- a/crates/ui-egui/src/commands.rs+++ b/crates/ui-egui/src/commands.rs@@@ -301,54 -330,33 +330,34 @@@ impl PdfCraftApp"view.theme.system" => self.set_theme_preference(ThemePreference::System),"view.theme.light" => self.set_theme_preference(ThemePreference::Light),"view.theme.dark" => self.set_theme_preference(ThemePreference::Dark),- "comment.list" => self.choose_right_panel(Some(RightPanel::Comments)),- tool if crate::comments::CommentTool::from_command(tool).is_some() => {- let Some(tool) = crate::comments::CommentTool::from_command(tool) else { return false };- self.comment_prefs.group_tool[tool.group()] = tool;- self.quick_tool = crate::QuickTool::Comment(tool);- // Acrobat opens the Comments panel with the commenting tools, unless the user closed it.- if self.right.is_none() && !self.comments_panel_closed {- self.choose_right_panel(Some(RightPanel::Comments));- }- // A text selection made before picking a markup tool is marked right away.- if let (Some(kind), Some(i)) = (tool.markup(), active)- && let Some(doc) = self.session.get(self.views[i].id)+ "view.fit_visible" => {+ if let Some(i) = self.active+ && let Err(e) = self.fit_visible(i){- let info = &doc.info;- if let Some((page, quads)) = self.views[i].selection_quads(info) {- self.views[i].clear_selection();- let style = self.comment_prefs.style(tool);- let author = self.comment_prefs.author.clone();- let shape = pdfcraft_engine::Shape::TextMarkup { kind, quads };- self.apply_edit(Edit::AddAnnotation(pdfcraft_engine::NewAnnotation { page, shape, style, contents: String::new(), author }));- }- }- }- "form.fields" => self.choose_right_panel(Some(RightPanel::Fields)),- "form.calculation_order" => {- self.left = crate::LeftPanel::CalculationOrder;- // The page edits the fields, so Preview ends; the page grid closes, as for a tool.- self.form_preview = false;- if let Some(v) = active.and_then(|i| self.views.get_mut(i)) {- v.organize = false;- }- self.reveal_tools();- }- "comment.flatten" => {- self.apply_edit(Edit::Flatten { comments: true, fields: false });- }- "form.flatten" => {- // Flatten what's typed in a field too (#166); a refused value flattens nothing.- if self.commit_form_typing() {- self.apply_edit(Edit::Flatten { comments: false, fields: true });+ self.notify_fmt("Couldn't fit the visible content: {e}", &[("e", &e.to_string())]);}}- "form.clear" => {+ "view.marquee_zoom" => self.quick_tool = crate::QuickTool::MarqueeZoom,+ _ => return None,+ }+ Some(true)+ }++ fn run_page_command(&mut self, id: &str, active: Option<usize>, targets: Vec<usize>) -> Option<bool> {+ match id {+ "page.combine" => self.open_combine_tab(),+ "page.number" => {if let Some(i) = active {- self.views[i].forms.focus = None;+ let v = &self.views[i];+ let pages: Vec<usize> = if v.selected.is_empty() { vec![v.current] } else { v.selected.iter().copied().collect() };+ let (lo, hi) = (pages.iter().min().copied().unwrap_or(0), pages.iter().max().copied().unwrap_or(0));+ self.number_draft = crate::NumberDraft { from: lo + 1, to: hi + 1, ..self.number_draft.clone() };}- self.apply_edit(Edit::ResetForm { names: None });+ self.dialog = Some(Dialog::NumberPages);}+ "bookmark.add" => self.bookmark_action(crate::panels::BmAction::New),+ "bookmark.from_structure" => self.bookmark_action(crate::panels::BmAction::FromStructure),++ "bookmark.from_text_styles" => self.bookmark_action(crate::panels::BmAction::FromTextStyles),"page.organize" => {if let Some(v) = active.and_then(|i| self.views.get_mut(i)) {if v.organize {diff --cc crates/ui-egui/src/dialogs.rsindex 3d8ccea81,c21604a4d..ae1d56d62--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@@ -123,704 -128,706 +129,710 @@@ fn dialogs(app: &mut PdfCraftApp, ctx:Dialog::About => 780.0,_ => 520.0,});- match dialog {- Dialog::WordCount => {- close = crate::word_count_ui::body(ui, app);+ if dialog_body(ui, app, dialog, &mut req) {+ dialog_footer(ui, app, dialog, &mut req);+ }+ });+ finish_dialog(app, dialog, modal.should_close(), &mut req);+ }++ /// The dialog's content. Returns `false` when it has its own buttons and no footer is wanted.+ fn dialog_body(ui: &mut egui::Ui, app: &mut PdfCraftApp, dialog: Dialog, req: &mut Pending) -> bool {+ let t = Tokens::get(ui.ctx());+ match dialog {+ Dialog::WordCount => {+ req.close = crate::word_count_ui::body(ui, app);+ }+ Dialog::CreateImages => {+ let (go, cancel) = crate::create_ui::image_import_body(ui, app);+ req.images_now = go;+ req.close = go || cancel;+ return false;+ }+ Dialog::Properties(tab) => {+ if !dialog_properties(ui, app, req, tab) {+ return false;+ }+ }+ Dialog::Split => {+ if !dialog_split(ui, app, req) {+ return false;+ }+ }+ Dialog::ReplacePages => {+ if !dialog_replace_pages(ui, app, req) {+ return false;+ }+ }+ Dialog::RedactPages => {+ let n = app.active_ids().and_then(|(_, id)| app.session.get(id)).map_or(1, |d| d.info.pages.len());+ let (ok, cancel) = crate::redact_ui::pages_body(ui, &mut app.redact_pages_draft, n, &t);+ if ok {+ req.redact_now = Some(dialog);+ }+ req.close = ok || cancel;+ return false;+ }+ Dialog::RedactSearch => {+ let (go, cancel, import) = crate::redact_ui::search_body(ui, &mut app.redact_search, &t);+ if go {+ req.redact_now = Some(dialog);+ }+ req.import_words = import;+ req.close = cancel;+ return false;+ }+ Dialog::RedactProps => {+ if !dialog_redact_props(ui, app, req) {+ return false;+ }+ }+ Dialog::RedactApply => {+ let marks = app.active_ids().and_then(|(_, id)| app.session.get(id)).map_or(0, |d| d.redaction_marks());+ let (ok, cancel) = crate::redact_ui::apply_body(ui, marks, &t);+ if ok {+ req.redact_now = Some(dialog);+ }+ req.close = ok || cancel;+ return false;+ }+ Dialog::LinkProps => {+ let pages = app.active_ids().and_then(|(_, id)| app.session.get(id)).map_or(1, |d| d.info.pages.len());+ let Some(d) = app.link_draft.as_mut() else {+ req.close = true;+ return false;+ };+ let (ok, cancel) = crate::link_ui::body(ui, d, pages, &t);+ if ok {+ req.link_now = Some(crate::link_ui::edit_for(d));+ }+ req.close = ok || cancel;+ return false;+ }+ Dialog::Extract => {+ if !dialog_extract(ui, app, req) {+ return false;+ }+ }+ Dialog::RotatePages => {+ if !dialog_rotate_pages(ui, app, req) {+ return false;+ }+ }+ Dialog::DuplicateField => {+ if !dialog_duplicate_field(ui, app, req) {+ return false;+ }+ }+ // Never reached: `dialogs` shows this movable window above and returns before the modal.+ // The arm keeps the match exhaustive.+ Dialog::FieldTable => req.close = true,+ Dialog::Optimize => {+ let (ok, cancel) = crate::optimize_ui::body(ui, &mut app.optimize_draft, &t);+ req.optimize_now = ok;+ req.close = ok || cancel;+ if std::mem::take(&mut app.optimize_draft.audit) {+ app.refresh_space_audit();+ req.next = Some(Dialog::AuditSpace);+ }+ return false;+ }+ Dialog::CertificateViewer => {+ if !dialog_certificate_viewer(ui, app, req) {+ return false;+ }+ }+ Dialog::AuditSpace => {+ if crate::optimize_ui::audit_body(ui, &app.space_audit, &t) {+ req.next = Some(Dialog::Optimize);+ }+ return false;+ }+ Dialog::Sign => {+ if crate::sign_ui::dialog(ui, app, &t) {+ app.sign_draft = None;+ req.close = true;+ }+ return false;+ }+ Dialog::SummarizeComments => {+ if !dialog_summarize_comments(ui, app, req) {+ return false;+ }+ }+ Dialog::Revert => {+ if !dialog_revert(ui, app, req) {+ return false;+ }+ }+ Dialog::OverwriteChanged => {+ if !dialog_overwrite_changed(ui, app, req) {+ return false;+ }+ }+ Dialog::Print => {+ if !dialog_print(ui, app, req) {+ return false;+ }+ }+ Dialog::RemoveHidden => {+ let (ok, cancel) = crate::redact_ui::hidden_body(ui, &mut app.hidden_draft, &t);+ if ok {+ req.redact_now = Some(dialog);+ }+ req.close = ok || cancel;+ return false;+ }+ Dialog::Sanitize => {+ let (ok, cancel) = crate::redact_ui::sanitize_body(ui, &t);+ if ok {+ req.redact_now = Some(dialog);+ }+ req.close = ok || cancel;+ return false;+ }+ Dialog::FieldProps => {+ let Some(d) = app.field_props.as_mut() else {+ req.close = true;+ return false;+ };+ let (go, cancel) = crate::prepare::body(ui, d, &t);+ req.apply = go;+ req.field_props_now = req.apply;+ req.close = req.apply || cancel;+ return false;+ }+ Dialog::BulkFieldProps => {+ let Some(d) = app.bulk_field_props.as_mut() else {+ req.close = true;+ return false;+ };+ let (go, cancel) = crate::bulk_fields::body(ui, d, &t);+ req.apply = go;+ req.bulk_field_props_now = req.apply;+ req.close = cancel;+ return false;+ }+ Dialog::CommentProps => {+ let (go, cancel) = crate::comment_props::body(ui, app, &t);+ req.apply = go;+ req.props_now = req.apply;+ req.close = req.apply || cancel;+ return false;+ }+ Dialog::Signature => {+ if !dialog_signature(ui, app, req) {+ return false;+ }+ }+ Dialog::AltText => {+ let (save, cancel) = crate::a11y_ui::alt_body(ui, app, &t);+ req.alt_now = save;+ req.close = save || cancel;+ return false;+ }+ Dialog::CreateStamp => {+ let (save, cancel) = crate::stamps_ui::create_body(ui, app, &t);+ req.stamp_now = save;+ req.close = save || cancel;+ return false;+ }+ Dialog::PdfA => {+ req.close = crate::standards_ui::body(ui, app, &t);+ return false;+ }+ Dialog::ActionWizard => {+ ui.set_width(620.0);+ req.close = crate::actions_ui::body(ui, app, &t);+ return false;+ }+ Dialog::CompareFiles => {+ let (go, cancel) = crate::compare_ui::body(ui, app, &t);+ req.compare_now = go;+ req.close = go || cancel;+ return false;+ }+ Dialog::JsConsole => {+ ui.set_width(640.0);+ req.close = crate::js_ui::console_body(ui, app, &t);+ return false;+ }+ Dialog::DocumentJs => {+ ui.set_width(640.0);+ req.close = crate::js_ui::document_js_body(ui, app, &t);+ return false;+ }+ Dialog::Preferences => {+ if !dialog_preferences(ui, app, req) {+ return false;+ }+ }+ Dialog::RecognizeText => {+ let (go, cancel) = crate::ocr_ui::body(ui, app, &t);+ req.ocr_now = go;+ req.close = go || cancel;+ return false;+ }+ Dialog::AccessibilityOptions => {+ let (start, cancel) = crate::a11y_ui::options_body(ui, app, &t);+ req.a11y_now = start;+ req.close = start || cancel;+ return false;+ }+ Dialog::Export(kind) => {+ let (go, cancel) = crate::export_ui::body(ui, app, &t, kind);+ req.apply = go;+ req.export_now = req.apply;+ req.close = req.apply || cancel;+ return false;+ }+ Dialog::Marks(kind) => {+ ui.set_width(720.0);+ let (go, cancel) = crate::marks_ui::body(ui, app, &t, kind);+ req.apply = go;+ req.marks_now = req.apply;+ req.close = req.apply || cancel;+ return false;+ }+ Dialog::PageBoxes => {+ let (go, cancel) = crate::pageboxes::body(ui, app, &t);+ req.apply = go;+ req.boxes_now = req.apply;+ req.close = req.apply || cancel;+ return false;+ }+ Dialog::Protect => {+ let (go, cancel) = crate::protect::body(ui, app, &t);+ req.apply = go;+ req.protect_now = req.apply;+ req.close = req.apply || cancel;+ return false;+ }++ Dialog::BookmarksFromTextStyles => {++ req.close = crate::bookmark_styles_ui::body(ui, app, &t);++ return false;++ }+ Dialog::NumberPages => {+ if !dialog_number_pages(ui, app, req) {+ return false;+ }+ }+ Dialog::Recovery => {+ if !dialog_recovery(ui, app) {+ return false;}- Dialog::CreateImages => {- let (go, cancel) = crate::create_ui::image_import_body(ui, app);- images_now = go;- close = go || cancel;- return;+ }+ Dialog::Shortcuts => {+ if !dialog_shortcuts(ui) {+ return false;+ }+ }+ Dialog::About => {+ if !dialog_about(ui, req) {+ return false;}- Dialog::Properties(tab) => {- ui.label(egui::RichText::new(tl!("Document Properties")).font(theme::semibold(18.0)));- ui.add_space(8.0);- ui.horizontal_wrapped(|ui| {- for (tb, label) in [- (PropsTab::Description, tl!("Description")),- (PropsTab::InitialView, tl!("Initial View")),- (PropsTab::Security, tl!("Security")),- (PropsTab::Fonts, tl!("Fonts")),- (PropsTab::Custom, tl!("Custom")),- (PropsTab::Advanced, tl!("Advanced")),- (PropsTab::SpaceAudit, tl!("Space Audit")),- ] {- if widgets::mode_tab(ui, label, tab == tb).clicked() {- next = Dialog::Properties(tb);+ }+ }+ true+ }++ /// `Dialog::Properties(tab)` content. Returns `false` when it has its own buttons and no footer is wanted.+ fn dialog_properties(ui: &mut egui::Ui, app: &mut PdfCraftApp, req: &mut Pending, tab: PropsTab) -> bool {+ let t = Tokens::get(ui.ctx());+ ui.label(egui::RichText::new(tl!("Document Properties")).font(theme::semibold(18.0)));+ ui.add_space(8.0);+ ui.horizontal_wrapped(|ui| {+ for (tb, label) in [+ (PropsTab::Description, tl!("Description")),+ (PropsTab::InitialView, tl!("Initial View")),+ (PropsTab::Security, tl!("Security")),+ (PropsTab::Fonts, tl!("Fonts")),+ (PropsTab::Custom, tl!("Custom")),+ (PropsTab::Advanced, tl!("Advanced")),+ (PropsTab::SpaceAudit, tl!("Space Audit")),+ ] {+ if widgets::mode_tab(ui, label, tab == tb).clicked() {+ req.next = Some(Dialog::Properties(tb));+ }+ }+ });+ ui.separator();+ let units = app.units;+ let Some((_, id)) = app.active_ids() else { return false };+ let Some(doc) = app.session.get(id) else { return false };+ let i = &doc.info;+ // Description shows plain values among text fields; they start where the fields' text does.+ let editable_info = tab == PropsTab::Description && doc.allows_modification() && app.props_draft.is_some();+ let inset = if editable_info { widgets::FIELD_TEXT_INSET } else { 0.0 };+ let row = |ui: &mut egui::Ui, k: &str, v: String| {+ // Row labels are UI chrome; values are document data and stay as they are.+ ui.label(egui::RichText::new(tl!(k)).color(t.text_muted));+ ui.horizontal(|ui| {+ ui.add_space(inset);+ ui.add(egui::Label::new(if v.is_empty() { egui::RichText::new("—").color(t.text_faint) } else { egui::RichText::new(v) }).wrap());+ });+ ui.end_row();+ };+ // A file name or path is read left to right even in an RTL UI: the extension+ // stays at its visual end, as in the tab strip.+ let path_row = |ui: &mut egui::Ui, k: &str, v: String| {+ ui.label(egui::RichText::new(tl!(k)).color(t.text_muted));+ ui.scope(|ui| {+ ui.set_max_width(420.0);+ // Align path text with editable fields while keeping its LTR text order.+ ui.add_space(inset);+ if v.is_empty() {+ ui.label(egui::RichText::new("—").color(t.text_faint));+ } else {+ crate::widgets::label_ltr(ui, v, crate::theme::regular(13.0), t.text);+ }+ });+ ui.end_row();+ };+ egui::ScrollArea::vertical().max_height(460.0).auto_shrink([false, true]).show(ui, |ui| {+ if tab == PropsTab::SpaceAudit {+ ui.add_space(4.0);+ crate::optimize_ui::audit_table(ui, &app.space_audit, &t);+ return;+ }+ egui::Grid::new("props").num_columns(2).spacing([18.0, 8.0]).min_col_width(140.0).show(ui, |ui| match tab {+ PropsTab::Description => {+ path_row(ui, "File", doc.name.clone());+ match app.props_draft.as_mut() {+ Some((_, draft)) if editable_info => {+ for (k, v) in INFO_KEYS.iter().zip(draft.iter_mut()) {+ let l = ui.label(egui::RichText::new(tl!(k)).color(t.text_muted));+ // Subject and Keywords are often a sentence or a list: they wrap and grow+ // instead of hiding most of the value past the field's edge.+ let field = if matches!(*k, "Subject" | "Keywords") { widgets::block(v).desired_rows(1) } else { widgets::line(v) };+ ui.add(field.desired_width(f32::INFINITY).background_color(t.field).id_salt(("info", *k))).labelled_by(l.id);+ ui.end_row();}}- });- ui.separator();- let units = app.units;- let Some((_, id)) = app.active_ids() else { return };- let Some(doc) = app.session.get(id) else { return };- let i = &doc.info;- // Description shows plain values among text fields; they start where the fields' text does.- let editable_info = tab == PropsTab::Description && doc.allows_modification() && app.props_draft.is_some();- let inset = if editable_info { widgets::FIELD_TEXT_INSET } else { 0.0 };- let row = |ui: &mut egui::Ui, k: &str, v: String| {- // Row labels are UI chrome; values are document data and stay as they are.- ui.label(egui::RichText::new(tl!(k)).color(t.text_muted));- ui.horizontal(|ui| {- ui.add_space(inset);- ui.add(- egui::Label::new(if v.is_empty() { egui::RichText::new("—").color(t.text_faint) } else { egui::RichText::new(v) }).wrap(),- );- });- ui.end_row();- };- // A file name or path is read left to right even in an RTL UI: the extension- // stays at its visual end, as in the tab strip.- let path_row = |ui: &mut egui::Ui, k: &str, v: String| {- ui.label(egui::RichText::new(tl!(k)).color(t.text_muted));- ui.scope(|ui| {- ui.set_max_width(420.0);- // Align path text with editable fields while keeping its LTR text order.- ui.add_space(inset);- if v.is_empty() {- ui.label(egui::RichText::new("—").color(t.text_faint));- } else {- crate::widgets::label_ltr(ui, v, crate::theme::regular(13.0), t.text);- }- });- ui.end_row();- };- egui::ScrollArea::vertical().max_height(460.0).auto_shrink([false, true]).show(ui, |ui| {- if tab == PropsTab::SpaceAudit {- ui.add_space(4.0);- crate::optimize_ui::audit_table(ui, &app.space_audit, &t);- return;+ _ => {+ row(ui, "Title", i.title.clone().unwrap_or_default());+ row(ui, "Author", i.author.clone().unwrap_or_default());+ row(ui, "Subject", i.subject.clone().unwrap_or_default());+ row(ui, "Keywords", i.keywords.clone().unwrap_or_default());}- egui::Grid::new("props").num_columns(2).spacing([18.0, 8.0]).min_col_width(140.0).show(ui, |ui| match tab {- PropsTab::Description => {- path_row(ui, "File", doc.name.clone());- match app.props_draft.as_mut() {- Some((_, draft)) if editable_info => {- for (k, v) in INFO_KEYS.iter().zip(draft.iter_mut()) {- let l = ui.label(egui::RichText::new(tl!(k)).color(t.text_muted));- // Subject and Keywords are often a sentence or a list: they wrap and grow- // instead of hiding most of the value past the field's edge.- let field =- if matches!(*k, "Subject" | "Keywords") { widgets::block(v).desired_rows(1) } else { widgets::line(v) };- ui.add(field.desired_width(f32::INFINITY).background_color(t.field).id_salt(("info", *k))).labelled_by(l.id);- ui.end_row();- }- }- _ => {- row(ui, "Title", i.title.clone().unwrap_or_default());- row(ui, "Author", i.author.clone().unwrap_or_default());- row(ui, "Subject", i.subject.clone().unwrap_or_default());- row(ui, "Keywords", i.keywords.clone().unwrap_or_default());- }- }- row(ui, "Application", i.creator.clone().unwrap_or_default());- row(ui, "PDF producer", i.producer.clone().unwrap_or_default());- }- PropsTab::InitialView => {- use pdfcraft_engine::{InitialLayout as L, Magnification as M, Navigation as N};- let editable = doc.allows_modification();- let pages = i.pages.len();- let Some((_, v)) = app.view_draft.as_mut() else { return };- ui.label(egui::RichText::new(tl!("Layout and Magnification")).font(theme::semibold(12.5)));- ui.end_row();- let label = ui.label(tl!("Navigation tab"));- ui.add_enabled_ui(editable, |ui| {- craft_ui::ComboBox::from_id_salt("iv-nav")- .selected_text(tl!(format!("{:?}", v.navigation)- .replace("PageOnly", "Page Only")- .replace("Pages", "Pages Panel and Page")- .as_str()))- .show_ui(ui, |ui| {- for (n, l) in [- (N::PageOnly, tl!("Page Only")),- (N::Bookmarks, tl!("Bookmarks Panel and Page")),- (N::Pages, tl!("Pages Panel and Page")),- (N::Attachments, tl!("Attachments Panel and Page")),- (N::Layers, tl!("Layers Panel and Page")),- ] {- ui.selectable_value(&mut v.navigation, n, l);- }- })- .response- .labelled_by(label.id);- });- ui.end_row();- let label = ui.label(tl!("Page layout"));- ui.add_enabled_ui(editable, |ui| {- let names = [- (L::Default, tl!("Default")),- (L::SinglePage, tl!("Single Page")),- (L::SinglePageContinuous, tl!("Single Page Continuous")),- (L::TwoUp, tl!("Two-Up (Facing)")),- (L::TwoUpContinuous, tl!("Two-Up Continuous (Facing)")),- (L::TwoUpCoverPage, tl!("Two-Up (Cover Page)")),- (L::TwoUpContinuousCoverPage, tl!("Two-Up Continuous (Cover Page)")),- ];- let shown = names.iter().find(|(l, _)| *l == v.layout).map_or(tl!("Default"), |(_, n)| n);- craft_ui::ComboBox::from_id_salt("iv-layout")- .selected_text(shown)- .show_ui(ui, |ui| {- for (l, n) in names {- ui.selectable_value(&mut v.layout, l, n);- }- })- .response- .labelled_by(label.id);- });- ui.end_row();- let label = ui.label(tl!("Magnification"));- ui.add_enabled_ui(editable, |ui| {- ui.horizontal(|ui| {- let names = [- (M::Default, tl!("Default")),- (M::ActualSize, tl!("Actual Size")),- (M::FitPage, tl!("Fit Page")),- (M::FitWidth, tl!("Fit Width")),- (M::FitHeight, tl!("Fit Height")),- (M::FitVisible, tl!("Fit Visible")),- ];- let shown = match v.magnification {- M::Percent(p) => format!("{p:.0}%"),- m => names.iter().find(|(x, _)| *x == m).map_or(tl!("Default").to_string(), |(_, n)| n.to_string()),- };- craft_ui::ComboBox::from_id_salt("iv-mag")- .selected_text(shown)- .show_ui(ui, |ui| {- for (m, n) in names {- ui.selectable_value(&mut v.magnification, m, n);- }- for p in [50.0, 75.0, 125.0, 150.0, 200.0] {- ui.selectable_value(&mut v.magnification, M::Percent(p), format!("{p:.0}%"));- }- })- .response- .labelled_by(label.id);- });- });- ui.end_row();- let label = ui.label(tl!("Open to page"));- ui.add_enabled_ui(editable, |ui| {- let mut p = v.page + 1;- if ui.add(egui::DragValue::new(&mut p).range(1..=pages.max(1))).labelled_by(label.id).changed() {- v.page = p - 1;- }- ui.label(crate::i18n::fmt(tl!("of {pages}"), &[("pages", &pages.to_string())]));- });- ui.end_row();- ui.label(egui::RichText::new(tl!("Window Options")).font(theme::semibold(12.5)));- ui.end_row();- ui.label("");- ui.add_enabled_ui(editable, |ui| {- ui.vertical(|ui| {- ui.add(widgets::checkbox(&mut v.fit_window, tl!("Resize window to initial page")));- ui.add(widgets::checkbox(&mut v.center_window, tl!("Center window on screen")));- ui.add(widgets::checkbox(&mut v.full_screen, tl!("Open in Full Screen mode")));- ui.horizontal(|ui| {- ui.label(tl!("Show:"));- widgets::radio_value(ui, &mut v.display_title, false, tl!("File Name"));- widgets::radio_value(ui, &mut v.display_title, true, tl!("Document Title"));- });- });- });- ui.end_row();- ui.label(egui::RichText::new(tl!("User Interface Options")).font(theme::semibold(12.5)));- ui.end_row();- ui.label("");- ui.add_enabled_ui(editable, |ui| {- ui.vertical(|ui| {- ui.add(widgets::checkbox(&mut v.hide_menubar, tl!("Hide menu bar")));- ui.add(widgets::checkbox(&mut v.hide_toolbar, tl!("Hide toolbars")));- ui.add(widgets::checkbox(&mut v.hide_window_ui, tl!("Hide window controls")));- });- });- ui.end_row();- }- PropsTab::Security => match doc.security_summary() {- None => {- row(ui, "Security method", tl!("No security").to_string());- row(ui, "Restrictions", tl!("None — everything is allowed").to_string());- if doc.allows_security_change() && ui.button(tl!("Protect using password…")).clicked() {- link_command = Some("protect.password");- }- }- Some(sec) => {- row(ui, "Security method", tl!("Password security").to_string());- row(ui, "Encryption", sec.method.clone());- row(- ui,- "Opened with",- if sec.pending {- tl!("— (protection is applied when you save)").to_string()- } else if sec.owner {- tl!("Owner password (no restrictions apply)").to_string()- } else {- tl!("User password").to_string()- },- );- // A restricted document asks for its permissions password first.- if doc.allows_security_change() || doc.can_unlock() {- ui.horizontal(|ui| {- if doc.can_unlock() && ui.button(tl!("Unlock…")).clicked() {- link_command = Some("protect.unlock");- }- if ui.button(tl!("Change settings…")).clicked() {- link_command = Some("protect.password");- }- if ui.button(tl!("Remove security")).clicked() {- link_command = Some("protect.remove");- }- });- }- let p = sec.permissions;- let yes = |b: bool| tl!(if b { "Allowed" } else { "Not allowed" }).to_string();- row(- ui,- "Printing",- if !p.print() {- tl!("Not allowed").to_string()- } else if p.print_high_quality() {- tl!("High resolution").to_string()- } else {- tl!("Low resolution").to_string()- },- );- row(ui, "Changing the document", yes(p.modify()));- row(ui, "Document assembly", yes(p.assemble()));- row(ui, "Content copying", yes(p.copy()));- row(ui, "Content copying for accessibility", yes(p.extract_for_accessibility()));- row(ui, "Commenting", yes(p.annotate()));- row(ui, "Filling of form fields", yes(p.fill_forms()));- }- },- PropsTab::Fonts => {- if i.fonts.is_empty() {- row(ui, "Fonts", tl!("No fonts are referenced by the pages.").to_string());- }- for f in &i.fonts {- let mut detail = f.kind.clone();- if let Some(e) = &f.encoding {- detail.push_str(&format!(" · {e}"));- }- detail.push_str(if f.subset {- " · Embedded subset"- } else if f.embedded {- " · Embedded"- } else {- " · Not embedded (substituted)"- });- row(ui, &f.name, detail);+ }+ row(ui, "Application", i.creator.clone().unwrap_or_default());+ row(ui, "PDF producer", i.producer.clone().unwrap_or_default());+ }+ PropsTab::InitialView => {+ use pdfcraft_engine::{InitialLayout as L, Magnification as M, Navigation as N};+ let editable = doc.allows_modification();+ let pages = i.pages.len();+ let Some((_, v)) = app.view_draft.as_mut() else { return };+ ui.label(egui::RichText::new(tl!("Layout and Magnification")).font(theme::semibold(12.5)));+ ui.end_row();+ let label = ui.label(tl!("Navigation tab"));+ ui.add_enabled_ui(editable, |ui| {+ craft_ui::ComboBox::from_id_salt("iv-nav")+ .selected_text(tl!(format!("{:?}", v.navigation)+ .replace("PageOnly", "Page Only")+ .replace("Pages", "Pages Panel and Page")+ .as_str()))+ .show_ui(ui, |ui| {+ for (n, l) in [+ (N::PageOnly, tl!("Page Only")),+ (N::Bookmarks, tl!("Bookmarks Panel and Page")),+ (N::Pages, tl!("Pages Panel and Page")),+ (N::Attachments, tl!("Attachments Panel and Page")),+ (N::Layers, tl!("Layers Panel and Page")),+ ] {+ ui.selectable_value(&mut v.navigation, n, l);}- }- PropsTab::Custom => {- // Add takes a new name, Update changes the value of the listed property the- // Name field names, Delete removes it; OK writes the changes as one step.- let editable = doc.allows_modification();- let Some((_, d)) = app.custom_draft.as_mut() else { return };- let l = ui.label(egui::RichText::new(tl!("Name:")).color(t.text_muted));- ui.add_enabled(- editable,- widgets::line(&mut d.name).desired_width(420.0).background_color(t.field).id_salt("custom-name"),- )- .labelled_by(l.id);- ui.end_row();- let l = ui.label(egui::RichText::new(tl!("Value:")).color(t.text_muted));- ui.add_enabled(- editable,- widgets::line(&mut d.value).desired_width(420.0).background_color(t.field).id_salt("custom-value"),- )- .labelled_by(l.id);- ui.end_row();- // Untrimmed: a file's `/Project#20` is not `/Project`, and a typed space is refused.- let name = d.name.clone();- let value = d.value.trim().to_owned();- let listed = d.props.iter().position(|(k, _)| *k == name);- // An entry the list leaves out (not text, only padding, or past its 256) keeps its value.- let file_props = doc.custom_info();- let unlisted = doc.has_info(&name) && !file_props.iter().any(|(k, _)| *k == name);- let refused = pdfcraft_engine::check_custom_key(&name).err().filter(|_| !name.is_empty()).map(|e| e.to_string());- ui.label("");- // A file can hold a custom name that `check_custom_key` refuses, such as one- // with a space: the tab lists it, and Add, Update and Delete stay off for it.- let why = |b: egui::Response| match &refused {- Some(why) => b.on_disabled_hover_text(crate::i18n::words(why)),- None => b,- };- // A name that isn't UTF-8 is listed with U+FFFD and can't be written back as it is.- let editable = editable && refused.is_none() && !name.contains(char::REPLACEMENT_CHARACTER);- // `custom_info` lists at most 256 properties, and a new name goes after the file's- // entries, so Add is off once the draft or the file's own list holds 256.- let room = d.props.len() < 256 && file_props.len() < 256;- ui.horizontal(|ui| {- let add = editable && room && listed.is_none() && !unlisted && !name.is_empty() && !value.is_empty();- if why(ui.add_enabled(add, egui::Button::new(tl!("Add")))).clicked() {- d.props.push((name.clone(), value.clone()));- d.name.clear();- d.value.clear();- }- let update = editable && !value.is_empty() && listed.and_then(|n| d.props.get(n)).is_some_and(|(_, v)| *v != value);- if why(ui.add_enabled(update, egui::Button::new(tl!("Update")))).clicked()- && let Some(p) = listed.and_then(|n| d.props.get_mut(n))- {- p.1 = value.clone();- }- if why(ui.add_enabled(editable && listed.is_some(), egui::Button::new(tl!("Delete")))).clicked()- && let Some(n) = listed.filter(|n| *n < d.props.len())- {- d.props.remove(n);- d.name.clear();- d.value.clear();- }- });- ui.end_row();- if d.props.is_empty() {- ui.label("");- ui.label(egui::RichText::new(tl!("None")).color(t.text_faint));- ui.end_row();+ })+ .response+ .labelled_by(label.id);+ });+ ui.end_row();+ let label = ui.label(tl!("Page layout"));+ ui.add_enabled_ui(editable, |ui| {+ let names = [+ (L::Default, tl!("Default")),+ (L::SinglePage, tl!("Single Page")),+ (L::SinglePageContinuous, tl!("Single Page Continuous")),+ (L::TwoUp, tl!("Two-Up (Facing)")),+ (L::TwoUpContinuous, tl!("Two-Up Continuous (Facing)")),+ (L::TwoUpCoverPage, tl!("Two-Up (Cover Page)")),+ (L::TwoUpContinuousCoverPage, tl!("Two-Up Continuous (Cover Page)")),+ ];+ let shown = names.iter().find(|(l, _)| *l == v.layout).map_or(tl!("Default"), |(_, n)| n);+ craft_ui::ComboBox::from_id_salt("iv-layout")+ .selected_text(shown)+ .show_ui(ui, |ui| {+ for (l, n) in names {+ ui.selectable_value(&mut v.layout, l, n);}- // A click on a property fills the fields with it; values are document data.- let mut picked = None;- for (k, v) in &d.props {- if ui.selectable_label(*k == name, k.as_str()).clicked() {- picked = Some((k.clone(), v.clone()));+ })+ .response+ .labelled_by(label.id);+ });+ ui.end_row();+ let label = ui.label(tl!("Magnification"));+ ui.add_enabled_ui(editable, |ui| {+ ui.horizontal(|ui| {+ let names = [+ (M::Default, tl!("Default")),+ (M::ActualSize, tl!("Actual Size")),+ (M::FitPage, tl!("Fit Page")),+ (M::FitWidth, tl!("Fit Width")),+ (M::FitHeight, tl!("Fit Height")),+ (M::FitVisible, tl!("Fit Visible")),+ ];+ let shown = match v.magnification {+ M::Percent(p) => format!("{p:.0}%"),+ m => names.iter().find(|(x, _)| *x == m).map_or(tl!("Default").to_string(), |(_, n)| n.to_string()),+ };+ craft_ui::ComboBox::from_id_salt("iv-mag")+ .selected_text(shown)+ .show_ui(ui, |ui| {+ for (m, n) in names {+ ui.selectable_value(&mut v.magnification, m, n);}- ui.scope(|ui| {- ui.set_max_width(420.0);- ui.add(egui::Label::new(v.as_str()).wrap());- });- ui.end_row();- }- if let Some((k, v)) = picked {- d.name = k;- d.value = v;- }- }- PropsTab::Advanced => {- row(ui, "PDF version", i.pdf_version.clone());- path_row(ui, "Location", doc.path.clone().unwrap_or_default());- row(ui, "File size", format!("{} ({})", human_size(i.file_size), crate::panels::byte_count(i.file_size)));- let p = &i.pages[0];- row(ui, "Page size", units.size(f64::from(p.width), f64::from(p.height)));- row(ui, "Number of pages", i.pages.len().to_string());- row(ui, "Tagged PDF", yes(i.tagged));- row(ui, "Form fields", i.fields.len().to_string());- row(ui, "Comments", i.annotations.len().to_string());- row(ui, "Layers", i.layers.len().to_string());- row(ui, "Attachments", i.attachments.len().to_string());- row(ui, "JavaScript", yes(i.has_javascript));- // Each incremental update is a revision; earlier ones open as their own document.- let ends = doc.revision_ends();- if ends.len() > 1 {- ui.label(egui::RichText::new(tl!("Revisions")).color(t.text_muted));- // Reserve the full wrapped height before the grid starts the next row.- ui.vertical(|ui| {- ui.horizontal_wrapped(|ui| {- ui.label(ends.len().to_string());- for n in (1..ends.len()).rev().take(12) {- if ui- .small_button(crate::i18n::fmt(tl!("View revision {n}"), &[("n", &n.to_string())]))- .on_hover_text(tl!("Open the file as it was saved then"))- .clicked()- {- open_revision = Some(n);- }- }- });- });- ui.end_row();- }- // Reading Options: binding and language.- if let Some((_, v)) = app.view_draft.as_mut() {- let editable = doc.allows_modification();- ui.label(egui::RichText::new(tl!("Binding")).color(t.text_muted));- ui.add_enabled_ui(editable, |ui| {- ui.horizontal(|ui| {- widgets::radio_value(ui, &mut v.right_to_left, false, tl!("Left Edge"));- widgets::radio_value(ui, &mut v.right_to_left, true, tl!("Right Edge"));- });- });- ui.end_row();- let l = ui.label(egui::RichText::new(tl!("Language")).color(t.text_muted));- let mut lang = v.language.clone().unwrap_or_default();- if ui- .add_enabled(editable, widgets::line(&mut lang).hint_text(tl!("e.g. en-US")).desired_width(160.0))- .labelled_by(l.id)- .changed()- {- v.language = (!lang.trim().is_empty()).then(|| lang.trim().to_string());+ for p in [50.0, 75.0, 125.0, 150.0, 200.0] {+ ui.selectable_value(&mut v.magnification, M::Percent(p), format!("{p:.0}%"));}- ui.end_row();- }- // What was repaired while reading a damaged file (fidelity: never silent).- let repairs = doc.repair_log();- row(ui, "Repairs", if repairs.is_empty() { tl!("None").to_string() } else { repairs.len().to_string() });- if !repairs.is_empty() {- ui.label("");- egui::CollapsingHeader::new(tl!("Repair log")).show(ui, |ui| {- for r in &repairs {- ui.add(egui::Label::new(egui::RichText::new(r).small()).wrap());- }- });- ui.end_row();- }- }- // Laid out above, outside the two-column grid.- PropsTab::SpaceAudit => {}+ })+ .response+ .labelled_by(label.id);});});- }- Dialog::Split => {- ui.label(egui::RichText::new(tl!("Split document")).font(theme::semibold(18.0)));- ui.add_space(8.0);- let Some((vi, id)) = app.active_ids() else { return };- let n = app.session.get(id).map(|d| d.info.pages.len()).unwrap_or(0);- let selected: Vec<usize> = app.views[vi].selected.iter().copied().filter(|p| *p > 0).collect();- let marks = app.session.bookmark_splits(id);- let draft = &mut app.split_draft;- use crate::SplitMode as M;- if selected.is_empty() && draft.mode == M::Selection {- draft.mode = M::Pages;- }- widgets::radio_value(ui, &mut draft.mode, M::Pages, tl!("Number of pages"));- ui.add_enabled_ui(draft.mode == M::Pages, |ui| {- ui.horizontal(|ui| {- ui.add_space(24.0);- ui.label(tl!("Pages per file"));- ui.add(egui::DragValue::new(&mut draft.every).range(1..=n.max(1)));- });+ ui.end_row();+ let label = ui.label(tl!("Open to page"));+ ui.add_enabled_ui(editable, |ui| {+ let mut p = v.page + 1;+ if ui.add(egui::DragValue::new(&mut p).range(1..=pages.max(1))).labelled_by(label.id).changed() {+ v.page = p - 1;+ }+ ui.label(crate::i18n::fmt(tl!("of {pages}"), &[("pages", &pages.to_string())]));});- widgets::radio_value(ui, &mut draft.mode, M::Size, tl!("File size"));- ui.add_enabled_ui(draft.mode == M::Size, |ui| {- ui.horizontal(|ui| {- ui.add_space(24.0);- ui.label(tl!("At most"));- ui.add(egui::DragValue::new(&mut draft.size_mb).range(0.05..=2000.0).speed(0.1).suffix(" MB"));+ ui.end_row();+ ui.label(egui::RichText::new(tl!("Window Options")).font(theme::semibold(12.5)));+ ui.end_row();+ ui.label("");+ ui.add_enabled_ui(editable, |ui| {+ ui.vertical(|ui| {+ ui.add(widgets::checkbox(&mut v.fit_window, tl!("Resize window to initial page")));+ ui.add(widgets::checkbox(&mut v.center_window, tl!("Center window on screen")));+ ui.add(widgets::checkbox(&mut v.full_screen, tl!("Open in Full Screen mode")));+ ui.horizontal(|ui| {+ ui.label(tl!("Show:"));+ widgets::radio_value(ui, &mut v.display_title, false, tl!("File Name"));+ widgets::radio_value(ui, &mut v.display_title, true, tl!("Document Title"));+ });});});- ui.add_enabled_ui(!marks.is_empty(), |ui| {- widgets::radio_value(- ui,- &mut draft.mode,- M::Bookmarks,- crate::i18n::fmt(tl!("Top-level bookmarks ({n})"), &[("n", &marks.len().to_string())]),- )- });- ui.add_enabled_ui(!selected.is_empty(), |ui| {- widgets::radio_value(ui, &mut draft.mode, M::Selection, tl!("Before each selected page (select pages in Organize)"))+ ui.end_row();+ ui.label(egui::RichText::new(tl!("User Interface Options")).font(theme::semibold(12.5)));+ ui.end_row();+ ui.label("");+ ui.add_enabled_ui(editable, |ui| {+ ui.vertical(|ui| {+ ui.add(widgets::checkbox(&mut v.hide_menubar, tl!("Hide menu bar")));+ ui.add(widgets::checkbox(&mut v.hide_toolbar, tl!("Hide toolbars")));+ ui.add(widgets::checkbox(&mut v.hide_window_ui, tl!("Hide window controls")));+ });});- let plan = match draft.mode {- M::Pages => crate::SplitPlan::By(pdfcraft_engine::SplitBy::PageCount(draft.every)),- M::Selection => crate::SplitPlan::By(pdfcraft_engine::SplitBy::Before(selected)),- M::Size => crate::SplitPlan::Size((draft.size_mb * 1_048_576.0) as usize),- M::Bookmarks => crate::SplitPlan::Bookmarks,- };- let files = match &plan {- crate::SplitPlan::By(by) => Some(pdfcraft_engine::split_ranges(n, by).len()),- crate::SplitPlan::Bookmarks => {- Some(pdfcraft_engine::split_ranges(n, &pdfcraft_engine::SplitBy::Before(marks.iter().map(|m| m.0).collect())).len())+ ui.end_row();+ }+ PropsTab::Security => match doc.security_summary() {+ None => {+ row(ui, "Security method", tl!("No security").to_string());+ row(ui, "Restrictions", tl!("None — everything is allowed").to_string());+ if doc.allows_security_change() && ui.button(tl!("Protect using password…")).clicked() {+ req.link_command = Some("protect.password");}- crate::SplitPlan::Size(_) => None,- };- ui.add_space(8.0);- let text = match files {- Some(f) => {- if f == 1 {- crate::i18n::fmt(tl!("Creates 1 file from {n} pages."), &[("n", &n.to_string())])+ }+ Some(sec) => {+ row(ui, "Security method", tl!("Password security").to_string());+ row(ui, "Encryption", sec.method.clone());+ row(+ ui,+ "Opened with",+ if sec.pending {+ tl!("— (protection is applied when you save)").to_string()+ } else if sec.owner {+ tl!("Owner password (no restrictions apply)").to_string()} else {- crate::i18n::fmt(tl!("Creates {f} files from {n} pages."), &[("f", &f.to_string()), ("n", &n.to_string())])- }+ tl!("User password").to_string()+ },+ );+ // A restricted document asks for its permissions password first.+ if doc.allows_security_change() || doc.can_unlock() {+ ui.horizontal(|ui| {+ if doc.can_unlock() && ui.button(tl!("Unlock…")).clicked() {+ req.link_command = Some("protect.unlock");+ }+ if ui.button(tl!("Change settings…")).clicked() {+ req.link_command = Some("protect.password");+ }+ if ui.button(tl!("Remove security")).clicked() {+ req.link_command = Some("protect.remove");+ }+ });}- None => crate::i18n::fmt(tl!("Each file holds as many of the {n} pages as fit."), &[("n", &n.to_string())]),- };- ui.label(egui::RichText::new(text).color(t.text_muted));- if files.is_none_or(|f| f > 1) {- split_ready = Some(plan);+ let p = sec.permissions;+ let yes = |b: bool| tl!(if b { "Allowed" } else { "Not allowed" }).to_string();+ row(+ ui,+ "Printing",+ if !p.print() {+ tl!("Not allowed").to_string()+ } else if p.print_high_quality() {+ tl!("High resolution").to_string()+ } else {+ tl!("Low resolution").to_string()+ },+ );+ row(ui, "Changing the document", yes(p.modify()));+ row(ui, "Document assembly", yes(p.assemble()));+ row(ui, "Content copying", yes(p.copy()));+ row(ui, "Content copying for accessibility", yes(p.extract_for_accessibility()));+ row(ui, "Commenting", yes(p.annotate()));+ row(ui, "Filling of form fields", yes(p.fill_forms()));}- }- Dialog::ReplacePages => {- let count = app.active_ids().and_then(|(_, id)| app.session.get(id)).map(|d| d.info.pages.len()).unwrap_or(1).max(1);- let Some(d) = app.replace_draft.as_mut() else {- close = true;- return;- };- ui.label(egui::RichText::new(tl!("Replace Pages")).font(theme::semibold(18.0)));- ui.add_space(8.0);- d.to = d.to.clamp(1, count);- d.from = d.from.clamp(1, d.to);- ui.horizontal(|ui| {- let from_label = ui.label(tl!("Original: replace pages"));- let from = ui.add(egui::DragValue::new(&mut d.from).range(1..=count)).labelled_by(from_label.id);- let to_label = ui.label(tl!("to"));- let to = ui.add(egui::DragValue::new(&mut d.to).range(1..=count)).labelled_by(to_label.id);- if from.changed() || to.changed() {- d.range_edited = true;+ },+ PropsTab::Fonts => {+ if i.fonts.is_empty() {+ row(ui, "Fonts", tl!("No fonts are referenced by the pages.").to_string());+ }+ for f in &i.fonts {+ let mut detail = f.kind.clone();+ if let Some(e) = &f.encoding {+ detail.push_str(&format!(" · {e}"));}- ui.label(egui::RichText::new(crate::i18n::fmt(tl!("of {name}"), &[("name", &count.to_string())])).color(t.text_muted));- });- let n = if d.range_edited { d.to - d.from + 1 } else { d.pages.len().max(1) };- let max_start = d.src_pages.saturating_sub(n) + 1;- d.src_from = d.src_from.clamp(1, max_start.max(1));- ui.horizontal(|ui| {- let replacement_label = ui.label(crate::i18n::fmt(tl!("Replacement: pages of {name}"), &[("name", &d.name)]));- ui.add(egui::DragValue::new(&mut d.src_from).range(1..=max_start.max(1))).labelled_by(replacement_label.id);- ui.label(crate::i18n::fmt(tl!("to {n}"), &[("n", &(d.src_from + n - 1).to_string())]));- ui.label(egui::RichText::new(crate::i18n::fmt(tl!("of {name}"), &[("name", &d.src_pages.to_string())])).color(t.text_muted));- });- let fits = n <= d.src_pages;- ui.add_space(6.0);- ui.label(- egui::RichText::new(if fits {- tl!("Only the page content changes: links, comments, form fields and bookmarks on the original pages stay.")+ detail.push_str(if f.subset {+ " · Embedded subset"+ } else if f.embedded {+ " · Embedded"} else {- tl!("The replacement file doesn't have that many pages.")- })- .small()- .color(t.text_faint),- );- ui.add_space(10.0);- ui.with_layout(Layout::right_to_left(Align::Center), |ui| {- if ui.add_enabled_ui(fits, |ui| widgets::pill_button(ui, tl!("OK"), true)).inner.clicked() {- replace_now = true;- close = true;- }- if widgets::pill_button(ui, tl!("Cancel"), false).clicked() {- close = true;- }- });- return;- }- Dialog::RedactPages => {- let n = app.active_ids().and_then(|(_, id)| app.session.get(id)).map_or(1, |d| d.info.pages.len());- let (ok, cancel) = crate::redact_ui::pages_body(ui, &mut app.redact_pages_draft, n, &t);- if ok {- redact_now = Some(dialog);- }- close = ok || cancel;- return;- }- Dialog::RedactSearch => {- let (go, cancel, import) = crate::redact_ui::search_body(ui, &mut app.redact_search, &t);- if go {- redact_now = Some(dialog);- }- import_words = import;- close = cancel;- return;- }- Dialog::RedactProps => {- let mut prefs = app.redact_prefs.clone();- let (ok, cancel) = crate::redact_ui::props_body(ui, &mut prefs, &t);- app.redact_prefs = prefs;- if ok && app.redact_prefs.remember {- app.redact_defaults = app.redact_prefs.clone();- }- if cancel && let Some(before) = app.redact_before.take() {- app.redact_prefs = before;- }- if ok {- app.redact_before = None;- }- close = ok || cancel;- return;- }- Dialog::RedactApply => {- let marks = app.active_ids().and_then(|(_, id)| app.session.get(id)).map_or(0, |d| d.redaction_marks());- let (ok, cancel) = crate::redact_ui::apply_body(ui, marks, &t);- if ok {- redact_now = Some(dialog);- }- close = ok || cancel;- return;- }- Dialog::LinkProps => {- let pages = app.active_ids().and_then(|(_, id)| app.session.get(id)).map_or(1, |d| d.info.pages.len());- let Some(d) = app.link_draft.as_mut() else {- close = true;- return;- };- let (ok, cancel) = crate::link_ui::body(ui, d, pages, &t);- if ok {- link_now = Some(crate::link_ui::edit_for(d));+ " · Not embedded (substituted)"+ });+ row(ui, &f.name, detail);}- close = ok || cancel;- return;}- Dialog::Extract => {- let (selected, total) = app.active_ids().map_or((Vec::new(), 0), |(i, _)| (app.views[i].target_pages(), app.views[i].page_count()));- ui.label(egui::RichText::new(tl!("Extract pages")).font(theme::semibold(18.0)));- ui.add_space(8.0);- // Page ranges to take instead of the selection (#3593); the hint is the selection.- let hint = match crate::combine_ui::range_of(&selected, total) {- all if all.is_empty() && total > 1 => format!("1-{total}"),- all if all.is_empty() => "1".to_string(),- some => some,+ PropsTab::Custom => {+ // Add takes a new name, Update changes the value of the listed property the+ // Name field names, Delete removes it; OK writes the changes as one step.+ let editable = doc.allows_modification();+ let Some((_, d)) = app.custom_draft.as_mut() else { return };+ let l = ui.label(egui::RichText::new(tl!("Name:")).color(t.text_muted));+ ui.add_enabled(editable, widgets::line(&mut d.name).desired_width(420.0).background_color(t.field).id_salt("custom-name"))+ .labelled_by(l.id);+ ui.end_row();+ let l = ui.label(egui::RichText::new(tl!("Value:")).color(t.text_muted));+ ui.add_enabled(editable, widgets::line(&mut d.value).desired_width(420.0).background_color(t.field).id_salt("custom-value"))+ .labelled_by(l.id);+ ui.end_row();+ // Untrimmed: a file's `/Project#20` is not `/Project`, and a typed space is refused.+ let name = d.name.clone();+ let value = d.value.trim().to_owned();+ let listed = d.props.iter().position(|(k, _)| *k == name);+ // An entry the list leaves out (not text, only padding, or past its 256) keeps its value.+ let file_props = doc.custom_info();+ let unlisted = doc.has_info(&name) && !file_props.iter().any(|(k, _)| *k == name);+ let refused = pdfcraft_engine::check_custom_key(&name).err().filter(|_| !name.is_empty()).map(|e| e.to_string());+ ui.label("");+ // A file can hold a custom name that `check_custom_key` refuses, such as one+ // with a space: the tab lists it, and Add, Update and Delete stay off for it.+ let why = |b: egui::Response| match &refused {+ Some(why) => b.on_disabled_hover_text(crate::i18n::words(why)),+ None => b,};+ // A name that isn't UTF-8 is listed with U+FFFD and can't be written back as it is.+ let editable = editable && refused.is_none() && !name.contains(char::REPLACEMENT_CHARACTER);+ // `custom_info` lists at most 256 properties, and a new name goes after the file's+ // entries, so Add is off once the draft or the file's own list holds 256.+ let room = d.props.len() < 256 && file_props.len() < 256;ui.horizontal(|ui| {- let l = ui.label(tl!("Pages"));- ui.add(egui::TextEdit::singleline(&mut app.extract_draft.pages).hint_text(hint).desired_width(240.0)).labelled_by(l.id);- });- let chosen = app.extract_draft.pages_to_extract(selected, total);- match &chosen {- Ok(pages) if pages.len() == 1 => {- ui.label(tl!("1 page selected."));+ let add = editable && room && listed.is_none() && !unlisted && !name.is_empty() && !value.is_empty();+ if why(ui.add_enabled(add, egui::Button::new(tl!("Add")))).clicked() {+ d.props.push((name.clone(), value.clone()));+ d.name.clear();+ d.value.clear();}- Ok(pages) => {- ui.label(crate::i18n::fmt(tl!("{n} pages selected."), &[("n", &pages.len().to_string())]));+ let update = editable && !value.is_empty() && listed.and_then(|n| d.props.get(n)).is_some_and(|(_, v)| *v != value);+ if why(ui.add_enabled(update, egui::Button::new(tl!("Update")))).clicked()+ && let Some(p) = listed.and_then(|n| d.props.get_mut(n))+ {+ p.1 = value.clone();}- Err(e) => {- ui.colored_label(ui.visuals().error_fg_color, e);+ if why(ui.add_enabled(editable && listed.is_some(), egui::Button::new(tl!("Delete")))).clicked()+ && let Some(n) = listed.filter(|n| *n < d.props.len())+ {+ d.props.remove(n);+ d.name.clear();+ d.value.clear();}- }- ui.add_space(4.0);- // The name the pages are saved under (#737); separate files add " (page N)".- ui.horizontal(|ui| {- let l = ui.label(tl!("File name"));- ui.add(egui::TextEdit::singleline(&mut app.extract_draft.name).desired_width(240.0)).labelled_by(l.id);});- ui.add(widgets::checkbox(&mut app.extract_draft.delete, tl!("Delete pages after extracting")));- ui.add(widgets::checkbox(&mut app.extract_draft.separate, tl!("Extract pages as separate files")));- ui.add_space(12.0);- ui.with_layout(Layout::right_to_left(Align::Center), |ui| {- if ui.add_enabled_ui(chosen.is_ok(), |ui| widgets::pill_button(ui, tl!("Extract"), true)).inner.clicked() {- extract_now = true;- close = true;- }- if widgets::pill_button(ui, tl!("Cancel"), false).clicked() {- close = true;+ ui.end_row();+ if d.props.is_empty() {+ ui.label("");+ ui.label(egui::RichText::new(tl!("None")).color(t.text_faint));+ ui.end_row();+ }+ // A click on a property fills the fields with it; values are document data.+ let mut picked = None;+ for (k, v) in &d.props {+ if ui.selectable_label(*k == name, k.as_str()).clicked() {+ picked = Some((k.clone(), v.clone()));}- });- return;+ ui.scope(|ui| {+ ui.set_max_width(420.0);+ ui.add(egui::Label::new(v.as_str()).wrap());+ });+ ui.end_row();+ }+ if let Some((k, v)) = picked {+ d.name = k;+ d.value = v;+ }}- Dialog::RotatePages => {- use pdfcraft_engine::{PageOrientation as O, PageParity as P};- let n = app.active_ids().and_then(|(_, id)| app.session.get(id)).map_or(1, |d| d.info.pages.len());- let d = &mut app.rotate_draft;- ui.label(egui::RichText::new(tl!("Rotate Pages")).font(theme::semibold(18.0)));- ui.add_space(8.0);- egui::Grid::new("rotate-pages").num_columns(2).spacing([12.0, 8.0]).show(ui, |ui| {- ui.label(tl!("Direction:"));- craft_ui::ComboBox::from_id_salt("rotate-dir")- .selected_text(match d.degrees {- 270 => tl!("Counterclockwise 90 degrees"),- 180 => tl!("180 degrees"),- _ => tl!("Clockwise 90 degrees"),- })- .show_ui(ui, |ui| {- ui.selectable_value(&mut d.degrees, 90, tl!("Clockwise 90 degrees"));- ui.selectable_value(&mut d.degrees, 270, tl!("Counterclockwise 90 degrees"));- ui.selectable_value(&mut d.degrees, 180, tl!("180 degrees"));+ PropsTab::Advanced => {+ row(ui, "PDF version", i.pdf_version.clone());+ path_row(ui, "Location", doc.path.clone().unwrap_or_default());+ row(ui, "File size", format!("{} ({})", human_size(i.file_size), crate::panels::byte_count(i.file_size)));+ let p = &i.pages[0];+ row(ui, "Page size", units.size(f64::from(p.width), f64::from(p.height)));+ row(ui, "Number of pages", i.pages.len().to_string());+ row(ui, "Tagged PDF", yes(i.tagged));+ row(ui, "Form fields", i.fields.len().to_string());+ row(ui, "Comments", i.annotations.len().to_string());+ row(ui, "Layers", i.layers.len().to_string());+ row(ui, "Attachments", i.attachments.len().to_string());+ row(ui, "JavaScript", yes(i.has_javascript));+ // Each incremental update is a revision; earlier ones open as their own document.+ let ends = doc.revision_ends();+ if ends.len() > 1 {+ ui.label(egui::RichText::new(tl!("Revisions")).color(t.text_muted));+ // Reserve the full wrapped height before the grid starts the next row.+ ui.vertical(|ui| {+ ui.horizontal_wrapped(|ui| {+ ui.label(ends.len().to_string());+ for n in (1..ends.len()).rev().take(12) {+ if ui+ .small_button(crate::i18n::fmt(tl!("View revision {n}"), &[("n", &n.to_string())]))+ .on_hover_text(tl!("Open the file as it was saved then"))+ .clicked()+ {+ req.open_revision = Some(n);+ }+ }});+ });ui.end_row();- ui.label(tl!("Pages:"));- ui.vertical(|ui| {- widgets::radio_value(ui, &mut d.which, 0, tl!("All"));- widgets::radio_value(ui, &mut d.which, 1, tl!("Selection"));+ }+ // Reading Options: binding and language.+ if let Some((_, v)) = app.view_draft.as_mut() {+ let editable = doc.allows_modification();+ ui.label(egui::RichText::new(tl!("Binding")).color(t.text_muted));+ ui.add_enabled_ui(editable, |ui| {ui.horizontal(|ui| {- widgets::radio_value(ui, &mut d.which, 2, tl!("From"));- ui.add_enabled(d.which == 2, egui::DragValue::new(&mut d.from).range(1..=n));- ui.label(tl!("to"));- ui.add_enabled(d.which == 2, egui::DragValue::new(&mut d.to).range(1..=n));- ui.label(crate::i18n::fmt(tl!("of {name}"), &[("name", &n.to_string())]));+ widgets::radio_value(ui, &mut v.right_to_left, false, tl!("Left Edge"));+ widgets::radio_value(ui, &mut v.right_to_left, true, tl!("Right Edge"));});});ui.end_row();