Save PDF: the Summary is computed again when a saved preset changes

The cached Summary's stamp now includes the saved PDF presets, so replacing the preset the dialog compares against while the dialog stays open no longer leaves the Summary section and ui.pdfSummary.save showing the old comparison.
This commit is contained in:
dotCooCoo committed 2026-11-16 22:50:28 -08:00
1 parent ab0abba22b
commit 47bfa3d1c5
5 files changed
+30 -11

No files matched your search

+1 -1
View File
@@ -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 `<document> 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 `<document> 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",
+8 -7
View File
@@ -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<Value, String> {
let (key, stamp) = summary_key(app, p);
if let Some((s, v)) = ctx.data(|m| m.get_temp::<(egui::Id, Result<Value, String>)>(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<Value, String> {
let key = "path";
let path = match p.get(key) {
@@ -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.
+1 -1
View File
@@ -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 `<document> 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 `<document> 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",
+2 -2
View File
@@ -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 `<document> 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