diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index f936f19c2a..90c2a103e8 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1390,7 +1390,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.pdfSummary.save", "Save Summary…", "", - "{path} write the Summary of the open Save PDF dialog (or PDF preset editor) to path as UTF-8 text without a byte order mark, with LF line endings, line for line as the Summary section shows it: Options and each option that differs from the preset (or the line saying none does), a blank line, then Warnings and each warning (or None.). The Summary the section last drew for the same fields and document is used without computing the settings again. The web downloads the file under path's file name. The Summary section's Save Summary… button writes the same text to a file picked in a save panel that suggests ` PDF Summary.txt` in the document's folder. The dialog stays open and the document does not change. No such dialog open, a path that is missing, empty or not a string, a path outside the automation write roots and a failed document.pdfSettings are errors that write nothing; a failed write is an error → {path, bytes}", + "{path} write the Summary of the open Save PDF dialog (or PDF preset editor) to path as UTF-8 text without a byte order mark, with LF line endings, line for line as the Summary section shows it: Options and each option that differs from the preset (or the line saying none does), a blank line, then Warnings and each warning (or None.). The Summary the section last drew for the same fields, document and saved presets is used without computing the settings again. The web downloads the file under path's file name. The Summary section's Save Summary… button writes the same text to a file picked in a save panel that suggests ` PDF Summary.txt` in the document's folder. The dialog stays open and the document does not change. No such dialog open, a path that is missing, empty or not a string, a path outside the automation write roots and a failed document.pdfSettings are errors that write nothing; a failed write is an error → {path, bytes}", ), ( "file.exportAs", diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 6d074c1582..957a3beaf5 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -852,7 +852,7 @@ pub(super) fn option_label(option: &str) -> String { } /// `document.pdfSettings` for the dialog with the document's warnings (an export in memory), -/// cached until a field or the document changes. +/// cached until a field, the document or the saved presets change. fn summary_of(app: &mut VectorcraftApp, ctx: &egui::Context, p: &Value) -> Result { let (key, stamp) = summary_key(app, p); if let Some((s, v)) = ctx.data(|m| m.get_temp::<(egui::Id, Result)>(key)) @@ -865,11 +865,12 @@ fn summary_of(app: &mut VectorcraftApp, ctx: &egui::Context, p: &Value) -> Resul v } -/// Where [`summary_of`] keeps the Summary, and the stamp of the params `p` and the active -/// document and its revision it was computed for. +/// Where [`summary_of`] keeps the Summary, and the stamp of the params `p`, the active document +/// and its revision, and the saved presets (which `preset` can name) it was computed for. fn summary_key(app: &VectorcraftApp, p: &Value) -> (egui::Id, egui::Id) { let document = app.session.active().map(|s| (s.uid, s.revision)); - (egui::Id::unique("save-pdf-summary"), egui::Id::unique((p.to_string(), document))) + let presets = serde_json::to_string(&app.session.prefs.pdf_presets).unwrap_or_default(); + (egui::Id::unique("save-pdf-summary"), egui::Id::unique((p.to_string(), document, presets))) } /// `document.pdfSettings` for the dialog's `document.exportPdf` params `p`, with the document's @@ -967,9 +968,9 @@ pub(crate) fn summary_open(app: &VectorcraftApp) -> bool { /// `ui.pdfSummary.save {path}`: write the open Save PDF dialog's (or preset editor's) Summary as /// text to `path` (the web downloads it under the path's file name). The Summary the section last -/// drew for the same fields and document is used as it is; the settings are computed only when -/// there is none. The dialog stays open and the document is not changed → `{path, bytes}`. A -/// missing, empty or non-string `path` is an error that writes nothing. +/// drew for the same fields, document and saved presets is used as it is; the settings are +/// computed only when there is none. The dialog stays open and the document is not changed → +/// `{path, bytes}`. A missing, empty or non-string `path` is an error that writes nothing. pub(crate) fn save_summary(app: &mut VectorcraftApp, p: &Value) -> Result { let key = "path"; let path = match p.get(key) { diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index 7a72d44dfb..8568d1fbbc 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -220,6 +220,24 @@ fn save_summary_does_not_use_another_documents_summary() { assert!(!text.contains("kept"), "the other document's Summary: {text}"); } +/// The Summary is computed again when the saved preset it compares against is replaced while the +/// dialog stays open. +#[test] +fn save_summary_compares_against_a_replaced_preset() { + let (mut app, written, _) = app(); + app.run("pdf.preset.save", json!({"name": "Mine", "thumbnails": true})).unwrap(); + app.run("ui.savePdfDialog", json!({"preset": "Mine"})).unwrap(); + set_field(&mut app, "thumbnails", json!(false)); + app.ui_ctx = Some(egui::Context::default()); + app.run(SAVE_SUMMARY, json!({"path": "/tmp/a.txt"})).unwrap(); + let text = String::from_utf8(written.borrow()[0].1.clone()).unwrap(); + assert!(text.starts_with("Options\nGeneral › Thumbnails: Off\n"), "{text}"); + app.run("pdf.preset.save", json!({"name": "Mine", "thumbnails": false})).unwrap(); + app.run(SAVE_SUMMARY, json!({"path": "/tmp/b.txt"})).unwrap(); + let text = String::from_utf8(written.borrow()[1].1.clone()).unwrap(); + assert!(text.starts_with("Options\nEvery option matches the preset.\n"), "compared against the replaced preset: {text}"); +} + /// With the desktop's file writer: a file already at the path is replaced whole, a folder's path /// is an error that leaves the folder as it was, and under automation write roots a path outside /// them is refused without writing. diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 6c034b4c7c..8a05f5e4c1 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1391,7 +1391,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.pdfSummary.save", "Save Summary…", "", - "{path} write the Summary of the open Save PDF dialog (or PDF preset editor) to path as UTF-8 text without a byte order mark, with LF line endings, line for line as the Summary section shows it: Options and each option that differs from the preset (or the line saying none does), a blank line, then Warnings and each warning (or None.). The Summary the section last drew for the same fields and document is used without computing the settings again. The web downloads the file under path's file name. The Summary section's Save Summary… button writes the same text to a file picked in a save panel that suggests ` PDF Summary.txt` in the document's folder. The dialog stays open and the document does not change. No such dialog open, a path that is missing, empty or not a string, a path outside the automation write roots and a failed document.pdfSettings are errors that write nothing; a failed write is an error → {path, bytes}", + "{path} write the Summary of the open Save PDF dialog (or PDF preset editor) to path as UTF-8 text without a byte order mark, with LF line endings, line for line as the Summary section shows it: Options and each option that differs from the preset (or the line saying none does), a blank line, then Warnings and each warning (or None.). The Summary the section last drew for the same fields, document and saved presets is used without computing the settings again. The web downloads the file under path's file name. The Summary section's Save Summary… button writes the same text to a file picked in a save panel that suggests ` PDF Summary.txt` in the document's folder. The dialog stays open and the document does not change. No such dialog open, a path that is missing, empty or not a string, a path outside the automation write roots and a failed document.pdfSettings are errors that write nothing; a failed write is an error → {path, bytes}", ), ( "file.exportAs", diff --git a/docs/mcp.md b/docs/mcp.md index c44a85b0bd..f0e23a5587 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -1344,8 +1344,8 @@ to another CMYK profile or to RGB, `preserveNumbers` (and PDF/X-1a) keeps their The Summary section's Save Summary… button writes what the section shows to a text file (UTF-8 without a byte order mark, LF line endings), and its save panel suggests ` PDF Summary.txt` in the document's folder; the web downloads the file under that name. `ui.pdfSummary.save {path}` writes the same text for the open Save PDF dialog or -PDF preset editor to `path` and returns `{path, bytes}`. It uses the Summary the section last drew for the same fields -and document, and computes the settings only when there is none. No such dialog open, a `path` that is missing, empty +PDF preset editor to `path` and returns `{path, bytes}`. It uses the Summary the section last drew for the same fields, +document and saved presets, and computes the settings only when there is none. No such dialog open, a `path` that is missing, empty or not a string, a path outside the automation write roots and settings that `document.pdfSettings` refuses are errors that write nothing. The dialog stays open and the document does not change. `thumbnails: true` embeds each page drawn small (106 px on its long side, without the layers the page leaves out) as