From 52fcf89a80adf35e47b91adc81653257b1cca9d0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 11:47:58 -0800 Subject: [PATCH] Save for Web: holding Alt or Option turns Cancel into Reset While Alt (Option on macOS) is held, the dialog's Cancel button reads Reset. Reset puts the remembered settings back, or the defaults when none are remembered, on the current document's active artboard. It drops a pending preset, a pending Done left by a Done that failed, the preset name being typed and the selected color table entry, and keeps the view, zoom, connection speed and path. It does not remember or write anything, and the dialog stays open. `ui.dialogReset` does the same. --- crates/ui-egui/src/dialogs/save_for_web.rs | 36 +++++++--- crates/ui-egui/src/dialogs/tests.rs | 28 ++++++++ .../ui-egui/src/dialogs/tests_save_for_web.rs | 70 +++++++++++++++++++ docs/mcp.md | 5 +- docs/target-app-parity.md | 1 + 5 files changed, 130 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/dialogs/save_for_web.rs b/crates/ui-egui/src/dialogs/save_for_web.rs index d5ed966f94..fb5e47823f 100644 --- a/crates/ui-egui/src/dialogs/save_for_web.rs +++ b/crates/ui-egui/src/dialogs/save_for_web.rs @@ -11,7 +11,9 @@ //! `__color` (the colour table's selected colour, by source), `__presetName` (shown while saving a //! preset) and `__hasSlices`. Save… remembers //! the settings and writes the files (`file.saveForWeb`); Done only remembers them; Preview in -//! Browser opens the HTML page (`file.saveForWeb.browser`). The previews are what Save writes: +//! Browser opens the HTML page (`file.saveForWeb.browser`). While Alt (Option on macOS) is held, +//! Cancel reads Reset, which puts the remembered settings back and leaves the dialog open +//! (`ui.dialogReset`). The previews are what Save writes: //! [`webexport::preview_image`], decoded back, cached until the art or a setting changes. use std::sync::Arc; @@ -39,6 +41,7 @@ pub(super) const SPEC: DialogSpec = DialogSpec { ok: Some("Save…"), ok_label: Some(|app| if io::is_web(app) { "Download" } else { "Save…" }), discard: Some("Done"), + reset: Some(reset), min_width: PREVIEW_W + GAP + SIDE_W, inputs: |_| &["path", "preset"], ..DialogSpec::FORM @@ -71,14 +74,8 @@ const QUALITIES: [(&str, u8); 5] = [("Low", 10), ("Medium", 30), ("High", 60), ( /// Open on the document's active artboard, keeping the other remembered settings. pub fn open(app: &mut VectorcraftApp) -> Result { - let n = app.session.active().ok_or("no document")?.doc.artboards.len(); - let mut s = app.session.last_web_settings(); - s.artboard = Some(crate::panels::artboards::selected(app, n)); - // A document with no artboards has no valid index. - if s.artboard.is_some_and(|a| a >= n) { - s.artboard = None; - } - let mut fields = settings_fields(&s); + app.session.active().ok_or("no document")?; + let mut fields = settings_fields(&remembered(app)); let slices = app.session.active().is_some_and(|st| !st.doc.slice_layout().is_empty()); fields.extend([ ("__view".into(), json!("2up")), @@ -90,6 +87,27 @@ pub fn open(app: &mut VectorcraftApp) -> Result { Ok(Value::Null) } +/// The remembered settings (the defaults when none are remembered) on the document's active +/// artboard; no artboard when the document has none. +fn remembered(app: &VectorcraftApp) -> WebSettings { + let n = app.session.active().map_or(0, |st| st.doc.artboards.len()); + let mut s = app.session.last_web_settings(); + s.artboard = Some(crate::panels::artboards::selected(app, n)).filter(|a| *a < n); + s +} + +/// Reset (Cancel with Alt or Option held, or `ui.dialogReset`): the settings go back to the +/// remembered ones on the document's active artboard ([`remembered`]), and a pending `preset`, a +/// pending Done (`discard`, which a failed Done leaves), the preset name being typed and the +/// selected color table entry are dropped. The view, zoom, connection speed and `path` stay, +/// nothing is remembered or written, and the dialog stays open. +fn reset(app: &VectorcraftApp, d: &mut Dialog) { + for key in ["preset", "discard", "__presetName", "__color"] { + d.fields.remove(key); + } + d.fields.extend(settings_fields(&remembered(app))); +} + /// The settings as dialog fields. fn settings_fields(s: &WebSettings) -> Map { s.to_json().as_object().cloned().unwrap_or_default() diff --git a/crates/ui-egui/src/dialogs/tests.rs b/crates/ui-egui/src/dialogs/tests.rs index 201b34171d..9a00fceafa 100644 --- a/crates/ui-egui/src/dialogs/tests.rs +++ b/crates/ui-egui/src/dialogs/tests.rs @@ -2524,6 +2524,34 @@ fn flare_options_alt_turns_cancel_into_reset() { ); } +/// While Alt is held, Save for Web's Cancel button reads Reset; Reset puts the remembered settings +/// back without remembering anything and leaves the dialog open, and letting Alt go shows Cancel again. +#[test] +fn save_for_web_alt_turns_cancel_into_reset() { + let mut app = app(); + app.run("webExport.settings", json!({"format": "jpg", "quality": 70})).unwrap(); + let remembered = app.session.last_web_settings().to_json(); + app.run("file.saveForWeb", json!({})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + for (k, v) in [("format", json!("png8")), ("quality", json!(20)), ("colors", json!(16)), ("__view", json!("optimized"))] { + d.fields.insert(k.into(), v); + } + 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("format"), d.f64("quality", 0.0), d.f64("colors", 0.0)), ("jpg".into(), 70.0, 128.0)); + assert_eq!(d.str("__view"), "optimized", "the view stays"); + assert_eq!(app.session.last_web_settings().to_json(), remembered, "Reset remembers nothing"); + f.run(&mut app, vec![egui::Event::ModifiersChanged(egui::Modifiers::NONE)]); + f.button(&mut app, "Cancel"); +} + /// 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/dialogs/tests_save_for_web.rs b/crates/ui-egui/src/dialogs/tests_save_for_web.rs index dd904bfa53..9e92f57cdc 100644 --- a/crates/ui-egui/src/dialogs/tests_save_for_web.rs +++ b/crates/ui-egui/src/dialogs/tests_save_for_web.rs @@ -289,6 +289,76 @@ fn save_remembers_and_writes_and_done_only_remembers() { assert!(!dir.join("Untitled-1.png").exists()); } +/// `ui.dialogReset` puts the remembered settings back (the defaults when none are remembered) on +/// the document's active artboard, drops a pending preset, the preset name being typed and the +/// selected color, keeps the view, zoom, speed and path, writes and remembers nothing, and leaves +/// the dialog open; settings changed after it are remembered as usual. +#[test] +fn reset_puts_the_remembered_settings_back() { + let dir = vectorcraft_testkit::temp_dir("sfw-reset"); + let (mut app, _) = app(&dir, false); + let defaults = vectorcraft_engine::cmd::webexport::WebSettings::default().to_json(); + app.run("file.saveForWeb", json!({})).unwrap(); + for (k, v) in [ + ("format", json!("jpg")), + ("quality", json!(20)), + ("colorTable", json!({"locked": ["nope"]})), + ("preset", json!("PNG-24")), + ("__presetName", json!("Mine")), + ("__color", json!("#cc3300")), + ("__zoom", json!("200")), + ("__kbps", json!(1024)), + ("path", json!("elsewhere.png")), + ] { + set(&mut app, k, v); + } + app.run("ui.dialogReset", json!({})).unwrap(); + let d = app.ui.dialog.as_ref().expect("Reset leaves the dialog open"); + for (k, v) in defaults.as_object().unwrap() { + let want = if k == "artboard" { &json!(0) } else { v }; + assert_eq!(d.fields.get(k), Some(want), "{k}"); + } + for k in ["preset", "__presetName", "__color"] { + assert!(!d.fields.contains_key(k), "{k}"); + } + assert_eq!((d.str("__zoom"), d.f64("__kbps", 0.0), d.str("path")), ("200".into(), 1024.0, "elsewhere.png".into())); + assert_eq!(app.session.last_web_settings().to_json(), defaults, "Reset remembers nothing"); + assert_eq!(std::fs::read_dir(&dir).unwrap().count(), 0, "Reset writes nothing"); + set(&mut app, "quality", json!(55)); + set(&mut app, "discard", json!(true)); + confirm(&mut app).unwrap(); + assert_eq!(app.session.last_web_settings().quality, 55); + + // Remembered on another document's second artboard: Reset keeps this document's active one. + let mut app = two_artboards(&vectorcraft_testkit::temp_dir("sfw-reset-artboard")); + app.run("view.goToArtboard", json!({"index": 1})).unwrap(); + app.run("webExport.settings", json!({"artboard": 1, "quality": 40})).unwrap(); + app.run("file.new", json!({"width": 50, "height": 50})).unwrap(); + app.run("file.saveForWeb", json!({})).unwrap(); + set(&mut app, "quality", json!(90)); + set(&mut app, "artboard", json!(3)); + app.run("ui.dialogReset", json!({})).unwrap(); + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!((d.fields["artboard"].clone(), d.f64("quality", 0.0)), (json!(0), 40.0)); +} + +/// A Done that failed on a bad setting leaves `discard` in the dialog; Reset drops it, so Save… +/// after Reset writes the file instead of only remembering the settings. +#[test] +fn reset_drops_a_done_that_failed() { + let dir = vectorcraft_testkit::temp_dir("sfw-reset-done"); + let (mut app, _) = app(&dir, false); + app.run("file.saveForWeb", json!({})).unwrap(); + set(&mut app, "colorTable", json!({"locked": ["nope"]})); + set(&mut app, "discard", json!(true)); + assert!(confirm(&mut app).is_err()); + app.run("ui.dialogReset", json!({})).unwrap(); + assert!(!app.ui.dialog.as_ref().unwrap().fields.contains_key("discard")); + let r = confirm(&mut app).unwrap(); + let path = r["path"].as_str().expect("Save… writes a file"); + assert!(std::path::Path::new(path).exists(), "{path}"); +} + #[test] fn html_output_with_slices_saves_the_page_and_images() { let dir = vectorcraft_testkit::temp_dir("sfw-html"); diff --git a/docs/mcp.md b/docs/mcp.md index bee07110e6..d8f1ae44c9 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -8888,7 +8888,10 @@ previews one slice; `image: true` adds the file; `warnings` holds the export's w Presets: `webExport.presets.list` (built-in ones, then saved ones), `webExport.presets.save {name, newName?, …settings}`, `webExport.presets.delete {name}`; any name works as `preset` in the other commands (its settings, then the keys given). `webExport.settings {…}` remembers the settings the dialog opens on (`{}` reads them, `reset: true` restores the -defaults); presets and remembered settings are preferences. +defaults); presets and remembered settings are preferences. While Alt (Option on macOS) is held, the dialog's Cancel +button reads Reset. Reset puts the remembered settings (the defaults when none are remembered) back on the document's +active artboard, drops a pending `preset`, keeps the view, zoom, connection speed and `path`, remembers and writes +nothing, and keeps the dialog open; `ui.dialogReset` does the same. ```json {"name":"run_command","arguments":{"command":"document.exportForWeb.preview","params":{"format":"gif","colors":32,"dither":"none"}}} diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f506da06e1..6755650d92 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -866,6 +866,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Export for Screens is laid out as the reference app's dialog: on the left the Artboards and Assets tabs (thumbnails with their checkboxes, number and name, in a grid or a list), Clear Selection and Prefix; on the right Select (All, Range, Include Bleed, Include Artboard Fill, Full Document), Export to, Open Location after Export, Create Sub-folders by Scale or by Format (on by default), Export PDFs As (Single File writes the chosen artboards as the pages of one PDF named after the document, `pdfs: "single"`), and the format rows with the iOS and Android buttons, the format presets (☰) and Format Settings; under them, how many items are selected and how many files the export writes. File name patterns, the Layers and Selection sources and per-item folders stay available through `document.exportForScreens` (scripts and MCP). Tests: `dialogs::tests_screens` (layout, iOS/Android, Clear Selection, sub-folders, Single File) and `fileio::tests_screens::single_file_pdfs_hold_every_chosen_artboard`. - Export for Screens refuses `pdfs: "single"` with `assets`, `layers` or `selection: "each"`, whose files each hold one item's art, instead of writing the first item alone as one PDF named after the document; `pdfs: "multiple"` writes a PDF of each item, and the selection as one file writes one PDF either way. The rule is VectorCraft's own. Tests: `fileio::tests_screens::single_file_pdfs_are_refused_for_assets_layers_and_each_object`. - Save for Web: Preview in Browser writes each preview's page and images to a folder of its own inside `VectorCraft Save for Web` in the system's temporary folder. A later preview, from the same app or another one running, does not overwrite an earlier one. Each preview first removes the preview folders there that are an hour old or older and, on Linux, macOS and FreeBSD, belong to the current user; it leaves other files and folders alone. The folders a preview makes there are open to their owner only on those systems. When `VectorCraft Save for Web` is a link or is not a folder, or on those systems belongs to another user or can be written by other users, the preview goes to a new folder of its own in the temporary folder, which a later preview removes once it is an hour old (`file.saveForWeb.browser`). + - Save for Web: while Alt (Option on macOS) is held, the dialog's Cancel button reads Reset, which puts the remembered settings back on the document's active artboard and leaves the dialog open (`ui.dialogReset`). - Export for Screens, Save for Web (slice images, and files named after the document's title) and the Libraries panel name files with the characters Windows does not allow written as `-` and with a `-` after a Windows device name such as `CON`, on every platform (`document.exportForScreens`, `document.exportForWeb`, `library.create`). - Variables (data merge): text, visibility and image variables bound to objects (an object may carry several), dataset rows applied in one undo step (`variable.*`, `dataset.*`) from a Variables panel and Window › Variables, with dialogs to define, bind and edit, Make Text/Visibility/Image Dynamic, Capture/Update Data Set, CSV import/export (`dataset.import` / `dataset.export`), and a row in italics when an edit leaves the art not matching it; an image dataset value is a file path and apply keeps the object's bounds; bindings let go of deleted art and locked art is left alone except by visibility values; every command, like the rest, is drivable over MCP and the CLI. - Export for Screens numbers distinct row files whose names collide, compared without case, as `-2`, `-3`… instead of leaving them out; identical rows still write one file. It puts row folders that differ only in case into one folder (`document.exportForScreens`).