From 51efeba7b46c63ff96824bff41d81b5ed863c551 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 12:05:42 -0800 Subject: [PATCH 1/2] Save PDF: holding Alt turns Cancel into Reset While Alt (Option on macOS) is held, the Save PDF dialog's Cancel button reads Reset. Reset (or ui.dialogReset) puts every option back to the chosen preset's settings, clears the passwords and their checkboxes, and leaves the dialog open with its preset, path, artboard range and section. A saved preset deleted while the dialog is open leaves the options as they are. Choosing a preset now also clears the Security section's password checkboxes, which stayed checked with an empty password before. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/dialogs/save_pdf.rs | 37 +++++++++-- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 65 ++++++++++++++++++++ crates/ui-egui/src/dialogs/tests.rs | 25 ++++++++ crates/ui-egui/src/menus/ui_commands.rs | 2 +- docs/mcp.md | 3 + docs/target-app-parity.md | 1 + 7 files changed, 129 insertions(+), 6 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index f81ea2f7f9..8234aa1ba4 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1336,7 +1336,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.dialogReset", "Reset", "", - "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`): its fields go back to their defaults and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", + "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`; Save PDF, dialog `savePdf`): its fields go back to their defaults (Save PDF: the chosen preset's settings, with the path and artboards kept) and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", ), ( "ui.justification", diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 4f8bdf7667..428a8768ff 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -7,7 +7,9 @@ //! `document.pdfSettings`. Save Preset… names the settings as a preset (`pdf.preset.save`). //! Opened from Export As with Use Artboards off (`__artBounds`), the dialog has no Artboards //! section, and OK writes one page of the visible art's bounds through [`io::export`]; opened -//! from Export Selection (`__selection` too), the page is the selection's crop. +//! from Export Selection (`__selection` too), the page is the selection's crop. While Alt (Option +//! on macOS) is held, Cancel reads Reset, which puts the options back to the chosen preset's +//! settings and leaves the dialog open (`ui.dialogReset`). //! //! The same dialog edits a preset (kind `pdfPreset`, from Edit → PDF Presets): a `name` and //! `description` instead of the preset and artboards, and OK saves the preset. @@ -30,8 +32,15 @@ use crate::{VectorcraftApp, io, widgets}; pub(super) const KIND: &str = "savePdf"; -pub(super) const SPEC: DialogSpec = - DialogSpec { heading: |_| tl!("Save PDF").into(), body, confirm, ok: Some("Save PDF"), inputs: |_| &["path"], ..DialogSpec::FORM }; +pub(super) const SPEC: DialogSpec = DialogSpec { + heading: |_| tl!("Save PDF").into(), + body, + confirm, + ok: Some("Save PDF"), + inputs: |_| &["path"], + reset: Some(reset), + ..DialogSpec::FORM +}; /// The dialog kind of the preset editor (New / Edit in Edit → PDF Presets). pub(super) const PRESET_KIND: &str = "pdfPreset"; @@ -502,13 +511,33 @@ fn preset_rows(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) { fn apply_preset(app: &mut VectorcraftApp, d: &mut Dialog, name: &str) { match settings_fields(app, &json!({ "preset": name })) { Ok(settings) => { - d.fields.extend(settings); + replace_settings(d, settings); d.fields.insert("preset".into(), json!(name)); } Err(e) => app.status(e), } } +/// The UI-only fields that stand for options: the Security section's password checkboxes. +const OPTION_FLAGS: [&str; 2] = ["__requireOpenPassword", "__restrictPermissions"]; + +/// Replace every option with `settings` (from [`settings_fields`]), the password checkboxes +/// included. The preset, the artboard choice, the path and the other UI-only fields (the section, +/// the Save Preset name) stay. +fn replace_settings(d: &mut Dialog, settings: Map) { + d.fields.retain(|k, _| matches!(k.as_str(), "preset" | "range" | "path") || (k.starts_with("__") && !OPTION_FLAGS.contains(&k.as_str()))); + d.fields.extend(settings); +} + +/// Reset (Cancel with Alt or Option held): the options go back to the chosen preset's settings, as +/// choosing that preset sets them, and the dialog stays open. A preset that can no longer be found +/// (a saved one deleted while the dialog is open) leaves the dialog as it is. +fn reset(app: &VectorcraftApp, d: &mut Dialog) { + if let Ok(settings) = settings_fields(app, &json!({ "preset": d.str("preset") })) { + replace_settings(d, settings); + } +} + /// General: the options, then the artboards (Save PDF) or the description (preset editor). fn general(ui: &mut egui::Ui, d: &mut Dialog, editor: bool) { heading(ui, tl!("Options")); diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index b73ec294b1..9315b29f23 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -346,6 +346,71 @@ fn presets_reset_the_settings_and_fields_fall_back_to_defaults() { assert!(app.run("ui.savePdfDialog", json!({"compatibility": "1.0"})).is_err(), "bad options are refused"); } +/// Reset (`ui.dialogReset`, or Cancel with Alt or Option held) puts every option back to the +/// chosen preset's settings, passwords and their checkboxes included, and keeps the preset, the +/// path, the artboard range, the section and the dialog. After another preset is chosen, Reset +/// goes back to that one, and choosing it also clears the password checkboxes. +#[test] +fn reset_puts_the_chosen_presets_settings_back_and_keeps_the_path_and_artboards() { + let (mut app, written, _) = app(); + app.run("pdf.preset.save", json!({"name": "Mine", "compatibility": "1.5", "marks": {"trim": true}})).unwrap(); + app.run("ui.savePdfDialog", json!({"path": "/tmp/reset.pdf", "preset": "Mine"})).unwrap(); + set_field(&mut app, "__allArtboards", json!(false)); + set_field(&mut app, "range", json!("2")); + set_field(&mut app, "__section", json!("Security")); + set_field(&mut app, "compatibility", json!("1.7")); + set_field(&mut app, "marks.trim", json!(false)); + set_field(&mut app, "compression.color.ppi", json!(72)); + set_field(&mut app, OPEN_PASSWORD, json!("secret")); + set_field(&mut app, "__restrictPermissions", json!(true)); + let r = app.run("ui.dialogReset", json!({})).unwrap(); + assert_eq!(r["kind"], KIND); + let d = app.ui.dialog.as_ref().expect("Reset leaves the dialog open"); + assert_eq!(get(d, "compatibility"), "1.5"); + assert_eq!(get(d, "marks.trim"), true); + assert_eq!(get(d, "compression.color.ppi"), 300.0, "a nested option goes back too"); + assert_eq!(get(d, OPEN_PASSWORD).as_str().unwrap_or_default(), "", "the password is cleared"); + assert!(!d.fields.contains_key("__restrictPermissions"), "the checkbox is cleared"); + assert_eq!( + (d.str("preset"), d.str("path"), d.str("range"), d.str("__section")), + ("Mine".to_string(), "/tmp/reset.pdf".to_string(), "2".to_string(), "Security".to_string()) + ); + assert!(!d.bool("__allArtboards")); + + let mut d = d.clone(); + d.fields.insert("__requireOpenPassword".into(), json!(true)); + apply_preset(&mut app, &mut d, pdf::DEFAULT_PRESET); + assert!(!d.fields.contains_key("__requireOpenPassword"), "choosing a preset clears the checkbox"); + app.ui.dialog = Some(d); + set_field(&mut app, "compatibility", json!("1.4")); + app.run("ui.dialogReset", json!({})).unwrap(); + let d = app.ui.dialog.as_ref().expect("the dialog stays open"); + assert_eq!(d.str("preset"), pdf::DEFAULT_PRESET); + assert_eq!(get(d, "compatibility"), "1.7"); + assert_eq!(get(d, "marks.trim"), false); + // OK writes the reset options to the kept path and range. + super::super::confirm(&mut app).unwrap(); + let w = written.borrow(); + assert_eq!((w.len(), w[0].0.as_str()), (1, "/tmp/reset.pdf")); + assert!(w[0].1.starts_with(b"%PDF-1.7")); + assert_eq!(vectorcraft_pdf::import(&w[0].1).unwrap().artboards.len(), 1, "range 2"); +} + +/// Reset with a saved preset deleted while the dialog is open leaves the options as they are, +/// rather than switching to another preset's. +#[test] +fn reset_with_a_deleted_preset_keeps_the_options() { + let (mut app, _, _) = app(); + app.run("pdf.preset.save", json!({"name": "Gone", "compatibility": "1.5"})).unwrap(); + app.run("ui.savePdfDialog", json!({"preset": "Gone"})).unwrap(); + set_field(&mut app, "compatibility", json!("1.6")); + app.run("pdf.preset.delete", json!({"name": "Gone"})).unwrap(); + app.run("ui.dialogReset", json!({})).unwrap(); + let d = app.ui.dialog.as_ref().expect("the dialog stays open"); + assert_eq!(d.str("preset"), "Gone"); + assert_eq!(get(d, "compatibility"), "1.6"); +} + #[test] fn marks_and_bleeds_reach_the_pdf() { let (mut app, written, _) = app(); diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index 201b34171d..9e24b7a276 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -2524,6 +2524,31 @@ fn flare_options_alt_turns_cancel_into_reset() { ); } +/// While Alt is held, Save PDF's Cancel button reads Reset; Reset puts the chosen preset's settings +/// back and leaves the dialog open with its path, letting Alt go shows Cancel again, and Cancel +/// closes the dialog. +#[test] +fn save_pdf_alt_turns_cancel_into_reset() { + let mut app = app(); + app.run("ui.savePdfDialog", json!({"path": "/tmp/alt.pdf"})).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("compatibility".into(), json!("1.4")); + let mut f = Frames::new(); + f.button(&mut app, "Cancel"); + f.run(&mut app, vec![egui::Event::ModifiersChanged(egui::Modifiers::ALT)]); + let reset = f.button(&mut app, "Reset"); + let texts = f.texts(&mut app); + assert!(!texts.iter().any(|(t, _)| t == "Cancel"), "Reset takes Cancel's place: {texts:?}"); + f.press(&mut app, reset, true); + f.press(&mut app, reset, false); + let d = app.ui.dialog.as_ref().expect("Reset leaves the dialog open"); + assert_eq!((d.str("compatibility"), d.str("path")), ("1.7".to_string(), "/tmp/alt.pdf".to_string())); + f.run(&mut app, vec![egui::Event::ModifiersChanged(egui::Modifiers::NONE)]); + let cancel = f.button(&mut app, "Cancel"); + f.press(&mut app, cancel, true); + f.press(&mut app, cancel, false); + assert!(app.ui.dialog.is_none(), "Cancel closes the dialog"); +} + /// Reset Actions' question: OK replaces the action sets with the built-in set, Append adds the /// built-in set after them, and Cancel or Escape (`cancel`) leaves them as they are. #[test] diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 2b285c704b..5e43e8576c 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1337,7 +1337,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.dialogReset", "Reset", "", - "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`): its fields go back to their defaults and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", + "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`; Save PDF, dialog `savePdf`): its fields go back to their defaults (Save PDF: the chosen preset's settings, with the path and artboards kept) and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", ), ( "ui.justification", diff --git a/docs/mcp.md b/docs/mcp.md index bee07110e6..ac1d935cfe 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -1259,6 +1259,9 @@ exporter plug-in's parameters. Other formats are written at once. OK writes the OK returns what `file.exportAs` returns, which has no `format` or `bounds` (Text Export Options: `{path}`). Any option skips the options dialog, but without `path` the save panel still picks the file. To write without a dialog, pass `path`. `file.exportAs {path, exportSelection: true, …options}` writes the selection the same way. +In the Save PDF dialog, `ui.dialogReset {}` (Cancel while Alt, or Option on macOS, is held) puts every option back to +the chosen preset's settings, clears the passwords, and leaves the dialog open with its preset, path, artboard range and +section; `answer_dialog {action: "cancel"}` still closes it without saving. Raster exports default to the document's raster effects resolution. An explicit `scale` sets pixels per point (72 times that value in ppi); `options.ppi` wins over either scale option. CLI `run --export` and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f506da06e1..ebd2c72f7b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1940,6 +1940,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur In a `.ai` opened from its editing data, Bas Relief in an art style takes its Detail, Smoothness and Light direction from the style's settings block, and an object other than type with it opens as itself with the live effect. A settings block that VectorCraft can't read (malformed, another effect's, a value out of range or a key it doesn't know) keeps the object's drawn look (part of #637; [raster effects reference](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-filter-effects/raster-effects-reference.html), [Photoshop File Formats Specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/), [scripting the filter gallery](https://community.adobe.com/questions-712/scripting-support-for-the-filter-gallery-1064646); `crates/eps/src/import/ai/style/tests.rs`, `crates/eps/src/import/ai/tests.rs`). PDF export and `.ai` saves write a page with a side longer than 14,400 pt with a `UserUnit` (PDF 1.6), its longer side divided by 14,400 and rounded up to the next thousandth, so that no side is longer than 14,400 units (ISO 32000-1, Annex C.2); a PDF 1.5 file with such a page is written as PDF 1.6 with PDF 1.5's encryption, PDF/X files and PDF 1.3 and 1.4 files write it in points (in PDF 1.3 and 1.4, a page past 32,767 pt that needs a real number past 32,767 is refused with an error naming it), a page whose short side is 3 pt or longer but would be under 3 units at that `UserUnit` gets a smaller one that keeps the short side at 3 units, and the export's warnings give each such page's size and how it is written (#6382). The Save PDF dialog's "Write pages longer than 200 in at full size in points" (`longPagesInPoints`, on by default; `.ai` saves leave it off) writes such pages in points without a `UserUnit` at every PDF version, in files without a PDF/X or PDF/A standard, so readers that ignore `UserUnit` show them at full size. Export As PDF with Use Artboards off also opens the Save PDF dialog, without its Artboards section, and writes one page of the visible art's bounds with the dialog's options (`document.exportPdf {useArtboards: false}`; `crates/ui-egui/src/dialogs/tests_export.rs`, `crates/engine/src/cmd/fileio/tests_pdf.rs`). + While Alt (Option on macOS) is held, the Save PDF dialog's Cancel button reads Reset, which puts every option back to the chosen preset's settings, passwords included, and leaves the dialog open; letting the key go shows Cancel again (`ui.dialogReset`). [The help page](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf#page=283) says that holding Alt or Option and clicking Reset returns the options to their defaults. Resetting to the chosen preset's settings, and keeping the preset, path, artboard range and section, are VectorCraft's own rules (`crates/ui-egui/src/dialogs/save_pdf/tests.rs`, `crates/ui-egui/src/dialogs/tests.rs`). `document.exportSelection` run without params (a shortcut) takes the same route after its save panel: a picked PDF opens the Save PDF dialog without its Artboards section, and SVG, the raster formats, EPS, DXF, text and exporter plug-ins with parameters open their options, whose OK writes the selection alone, cropped to it, with the chosen options (`crates/ui-egui/src/dialogs/tests_export_selection.rs`). A `.ai` export with Use Artboards off writes one page of the visible art's bounds without the native document or the editing copy for other apps, with a warning, so the file does not reopen with one artboard in place of the document's; without PDF content it is refused (`crates/engine/src/cmd/fileio/tests_pdfedit.rs`). That page, and an HP-GL plot of the art's bounds, are measured on the art the file draws: non-printing layers the PDF or `.ai` file leaves out do not make it larger, and nor do the non-printing layers, objects at 0% opacity, placed images, clear gradient meshes and unpainted paths a plot leaves out; Export As refuses an HP-GL plot of nothing it draws before the save dialog (`crates/engine/src/cmd/fileio/tests_pdf.rs`, `crates/engine/src/cmd/fileio/tests_hpgl.rs`, `crates/ui-egui/src/dialogs/tests_export.rs`). From 4557e102483c45cf9938b32060a5691801e26f80 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 13:14:53 -0800 Subject: [PATCH 2/2] Save PDF: Reset with a deleted preset is an error When the saved preset the Save PDF dialog has chosen is deleted while the dialog is open, Reset now returns an error naming it, shown in the status bar, and leaves every field, passwords included, as it is. A dialog's reset callback returns a Result for this; Flare Tool Options and Objects on Path Options return Ok. The ui.dialogReset params text and docs/mcp.md name the error. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/dialogs.rs | 13 ++++++++----- crates/ui-egui/src/dialogs/flare_options.rs | 3 ++- .../ui-egui/src/dialogs/objects_on_path_options.rs | 9 ++++++--- crates/ui-egui/src/dialogs/save_pdf.rs | 10 +++++----- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 11 +++++++---- crates/ui-egui/src/menus/ui_commands.rs | 2 +- docs/mcp.md | 3 ++- 8 files changed, 32 insertions(+), 21 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 8234aa1ba4..211efdb935 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1336,7 +1336,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.dialogReset", "Reset", "", - "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`; Save PDF, dialog `savePdf`): its fields go back to their defaults (Save PDF: the chosen preset's settings, with the path and artboards kept) and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", + "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`; Save PDF, dialog `savePdf`): its fields go back to their defaults (Save PDF: the chosen preset's settings, with the path and artboards kept) and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open, the open one has no Reset, or Save PDF's chosen preset was deleted (the fields stay as they are)", ), ( "ui.justification", diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 30b02e4380..94cbc7672a 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -179,6 +179,9 @@ use crate::{VectorcraftApp, widgets}; type DialogResult = Result; +/// A dialog's Reset ([`DialogSpec::reset`]). +type ResetFn = fn(&VectorcraftApp, &mut Dialog) -> Result<(), String>; + /// The shared dialog frame's inner margin, and the least room it leaves at the window's edges. const MARGIN: i8 = 22; const EDGE_GAP: f32 = 8.0; @@ -219,8 +222,8 @@ pub(crate) struct DialogSpec { pub alternate: Option<(&'static str, &'static str)>, /// Puts the fields back to their defaults. While Alt (Option on macOS) is held, the Cancel /// button of a dialog with an `ok` reads Reset; Reset (or `ui.dialogReset`) runs this and the - /// dialog stays open. - pub reset: Option, + /// dialog stays open. An error leaves the dialog as it was. + pub reset: Option, pub min_width: f32, pub max_width: Option, /// The body runs a live preview interaction that Cancel rolls back. @@ -722,12 +725,12 @@ pub(crate) fn can_reset(app: &VectorcraftApp) -> bool { } /// Reset (`ui.dialogReset`, or Cancel while Alt or Option is held): the open dialog's fields go -/// back to their defaults and it stays open → the dialog; an error when no dialog is open or the -/// open one has no Reset. +/// back to their defaults and it stays open → the dialog; an error when no dialog is open, the +/// open one has no Reset, or its Reset fails (the dialog is then left as it was). pub(crate) fn reset(app: &mut VectorcraftApp) -> DialogResult { let Some(mut d) = app.ui.dialog.clone() else { return Err("no dialog open".into()) }; let Some(reset) = spec(&d.kind).reset else { return Err("the open dialog has no Reset".into()) }; - reset(app, &mut d); + reset(app, &mut d)?; let out = serde_json::to_value(&d).unwrap_or_default(); app.ui.dialog = Some(d); Ok(out) diff --git a/crates/ui-egui/src/dialogs/flare_options.rs b/crates/ui-egui/src/dialogs/flare_options.rs index b94f6a7c2e..9c374f3cf5 100644 --- a/crates/ui-egui/src/dialogs/flare_options.rs +++ b/crates/ui-egui/src/dialogs/flare_options.rs @@ -136,10 +136,11 @@ fn preview_command(app: &VectorcraftApp, d: &Dialog) -> Option<(String, Value)> /// Reset (Cancel with Alt or Option held): every option goes back to the Flare tool's default /// (`FLARE_OPTIONS`, with Rays and Rings on). The dialog keeps a click's `x` and `y`, so OK still draws there. -fn reset(_: &VectorcraftApp, d: &mut Dialog) { +fn reset(_: &VectorcraftApp, d: &mut Dialog) -> Result<(), String> { if let Value::Object(defaults) = vectorcraft_tools::create("flare").options() { d.fields.extend(defaults); } + Ok(()) } /// OK: set the tool's options; opened by a click, draw a flare there with them. diff --git a/crates/ui-egui/src/dialogs/objects_on_path_options.rs b/crates/ui-egui/src/dialogs/objects_on_path_options.rs index 8a02cd37cf..4726e0762a 100644 --- a/crates/ui-egui/src/dialogs/objects_on_path_options.rs +++ b/crates/ui-egui/src/dialogs/objects_on_path_options.rs @@ -40,9 +40,10 @@ pub fn open(app: &mut VectorcraftApp) -> Value { } /// Reset: the center and 0. -fn reset(_: &VectorcraftApp, d: &mut Dialog) { +fn reset(_: &VectorcraftApp, d: &mut Dialog) -> Result<(), String> { d.fields.insert("pivot".into(), json!(CENTER)); d.fields.insert("rotate".into(), json!(0.0)); + Ok(()) } fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { @@ -61,8 +62,10 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { ui.add_space(8.0); let r = widgets::flat_button(ui, tl!("Reset"), 64.0); r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, ui.is_enabled(), tl!("Reset"))); - if r.clicked() { - reset(app, d); + if r.clicked() + && let Err(e) = reset(app, d) + { + app.status(e); } false } diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 428a8768ff..9a4cbfa364 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -531,11 +531,11 @@ fn replace_settings(d: &mut Dialog, settings: Map) { /// Reset (Cancel with Alt or Option held): the options go back to the chosen preset's settings, as /// choosing that preset sets them, and the dialog stays open. A preset that can no longer be found -/// (a saved one deleted while the dialog is open) leaves the dialog as it is. -fn reset(app: &VectorcraftApp, d: &mut Dialog) { - if let Ok(settings) = settings_fields(app, &json!({ "preset": d.str("preset") })) { - replace_settings(d, settings); - } +/// (a saved one deleted while the dialog is open) is an error, and the dialog is left as it is. +fn reset(app: &VectorcraftApp, d: &mut Dialog) -> Result<(), String> { + let settings = settings_fields(app, &json!({ "preset": d.str("preset") }))?; + replace_settings(d, settings); + Ok(()) } /// General: the options, then the artboards (Save PDF) or the description (preset editor). diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index 9315b29f23..656d88b870 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -396,19 +396,22 @@ fn reset_puts_the_chosen_presets_settings_back_and_keeps_the_path_and_artboards( assert_eq!(vectorcraft_pdf::import(&w[0].1).unwrap().artboards.len(), 1, "range 2"); } -/// Reset with a saved preset deleted while the dialog is open leaves the options as they are, -/// rather than switching to another preset's. +/// Reset with a saved preset deleted while the dialog is open is an error naming the preset, and +/// it leaves the options and the password as they are rather than switching to another preset's. #[test] -fn reset_with_a_deleted_preset_keeps_the_options() { +fn reset_with_a_deleted_preset_is_an_error_and_keeps_the_options() { let (mut app, _, _) = app(); app.run("pdf.preset.save", json!({"name": "Gone", "compatibility": "1.5"})).unwrap(); app.run("ui.savePdfDialog", json!({"preset": "Gone"})).unwrap(); set_field(&mut app, "compatibility", json!("1.6")); + set_field(&mut app, OPEN_PASSWORD, json!("secret")); app.run("pdf.preset.delete", json!({"name": "Gone"})).unwrap(); - app.run("ui.dialogReset", json!({})).unwrap(); + let e = app.run("ui.dialogReset", json!({})).unwrap_err(); + assert!(e.contains("unknown PDF preset `Gone`"), "{e}"); let d = app.ui.dialog.as_ref().expect("the dialog stays open"); assert_eq!(d.str("preset"), "Gone"); assert_eq!(get(d, "compatibility"), "1.6"); + assert_eq!(get(d, OPEN_PASSWORD), "secret"); } #[test] diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 5e43e8576c..d4ddd46ea2 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1337,7 +1337,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.dialogReset", "Reset", "", - "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`; Save PDF, dialog `savePdf`): its fields go back to their defaults (Save PDF: the chosen preset's settings, with the path and artboards kept) and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open or the open one has no Reset", + "{} the open dialog's Reset, which its Cancel button reads while Alt (Option on macOS) is held (Flare Tool Options, dialog `flareOptions`; Save PDF, dialog `savePdf`): its fields go back to their defaults (Save PDF: the chosen preset's settings, with the path and artboards kept) and the dialog stays open, so OK applies them → the dialog; an error when no dialog is open, the open one has no Reset, or Save PDF's chosen preset was deleted (the fields stay as they are)", ), ( "ui.justification", diff --git a/docs/mcp.md b/docs/mcp.md index ac1d935cfe..0b044a547c 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -1261,7 +1261,8 @@ option skips the options dialog, but without `path` the save panel still picks t dialog, pass `path`. `file.exportAs {path, exportSelection: true, …options}` writes the selection the same way. In the Save PDF dialog, `ui.dialogReset {}` (Cancel while Alt, or Option on macOS, is held) puts every option back to the chosen preset's settings, clears the passwords, and leaves the dialog open with its preset, path, artboard range and -section; `answer_dialog {action: "cancel"}` still closes it without saving. +section; `answer_dialog {action: "cancel"}` still closes it without saving. If the chosen saved preset was deleted +while the dialog is open, `ui.dialogReset` returns an error naming it and leaves every field, passwords included, as it is. Raster exports default to the document's raster effects resolution. An explicit `scale` sets pixels per point (72 times that value in ppi); `options.ppi` wins over either scale option. CLI `run --export` and