From 9cc813d1d113f9265e884b2434a5f372f52233f8 Mon Sep 17 00:00:00 2001 From: Bobderto <230258561+Bobderto@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:31:56 +0000 Subject: [PATCH 1/6] Name Quick Export PNGs after selected groups and layers --- crates/ui-egui/src/dialogs/export_dialog.rs | 101 ++++++++++++------ .../export_dialog/layer_empty_skip_tests.rs | 16 ++- .../layer_folder_export_tests.rs | 34 ++++++ crates/ui-egui/src/file_dialog.rs | 59 ++++++---- crates/ui-egui/src/file_dialog/tests.rs | 59 +++++++++- 5 files changed, 207 insertions(+), 62 deletions(-) diff --git a/crates/ui-egui/src/dialogs/export_dialog.rs b/crates/ui-egui/src/dialogs/export_dialog.rs index 1fbf7b2217..9d95b52717 100644 --- a/crates/ui-egui/src/dialogs/export_dialog.rs +++ b/crates/ui-egui/src/dialogs/export_dialog.rs @@ -351,8 +351,7 @@ pub fn quick_export_layer_png(app: &mut PhotocraftApp, layer: photocraft_doc::La confirm(app, &f) } -/// Export each selected layer separately, with one destination prompt for the batch. -/// The chosen path names the first file; subsequent files have numbered sibling names. +/// Export each selected layer or group to its own PNG, named after the source. pub fn quick_export_selected_layers_png(app: &mut PhotocraftApp) -> Result { let st = app.session.active().ok_or("no document")?; let layers = st.selected_layers(); @@ -365,28 +364,51 @@ pub fn quick_export_selected_layers_png(app: &mut PhotocraftApp) -> Result = names.iter().flat_map(|name| [name.to_uppercase(), name.to_lowercase()]).collect(); + let paths = names.iter().map(|name| { + let stem = name.strip_suffix(".png").unwrap_or(name); + unused_export_path(dir, stem, "png", |candidate| reserved.contains(&candidate.to_uppercase()) || reserved.contains(&candidate.to_lowercase())) + .to_string_lossy() + .into_owned() + }); + write_quick_pngs(app, &docs, paths) }) } +fn write_quick_pngs(app: &mut PhotocraftApp, docs: &[Document], paths: impl IntoIterator) -> Result { + let mut exported = Vec::new(); + for (doc, path) in docs.iter().zip(paths) { + crate::app::ensure_memory_to_save(doc, &path)?; + let export = app.services.export.as_ref().ok_or("no exporter configured")?; + let (bytes, warnings) = export(doc, &path, &ExportSettings { xmp_all: false, ..Default::default() })?; + let write = app.services.write.as_mut().ok_or("no writer configured")?; + write(&path, &bytes)?; + crate::notices::io_warnings(app, &format!("Exported {}", crate::file_open::display_name(&path)), &warnings); + exported.push(json!({"path": path, "bytes": bytes.len(), "warnings": warnings})); + } + app.ui.status = format!("Exported {} PNG files", exported.len()); + app.ui.status_error = false; + Ok(json!({"files": exported})) +} + /// The first 80 characters of `name`, each control character and each character a file name /// can't hold (`< > : " / \ | ? *`) turned into `_`. fn file_name_chars(name: &str) -> String { @@ -420,27 +442,36 @@ fn batch_paths(path: &str, docs: &[Document]) -> Vec { if i == 0 { return path.to_string(); } - let name = export_name(&doc.name); - let candidate = parent.join(format!("{stem}-{}-{name}.{ext}", i + 1)); + let numbered = format!("{stem}-{}-{}", i + 1, export_name(&doc.name)); // The first file's overwrite is handled by the Save dialog; never overwrite sibling // files silently on desktop. Downloads on the web are named by the browser. #[cfg(not(target_arch = "wasm32"))] - let candidate = { - let mut candidate = candidate; - let mut suffix = 1u64; - // A name any entry occupies is taken, a symlink (even a dangling one) included: the writer - // follows links, so one planted here would redirect the export. - while candidate.symlink_metadata().is_ok() { - candidate = parent.join(format!("{stem}-{}-{name}-{suffix}.{ext}", i + 1)); - suffix = suffix.saturating_add(1); - } - candidate - }; + let candidate = unused_export_path(parent, &numbered, ext, |_| false); + #[cfg(target_arch = "wasm32")] + let candidate = parent.join(format!("{numbered}.{ext}")); candidate.to_string_lossy().into_owned() }) .collect() } +/// Keep existing entries, including links (even dangling ones), when choosing an output path. +#[cfg(not(target_arch = "wasm32"))] +fn unused_export_path(dir: &std::path::Path, stem: &str, ext: &str, reserved: impl Fn(&str) -> bool) -> std::path::PathBuf { + let candidate = dir.join(format!("{stem}.{ext}")); + if candidate.symlink_metadata().is_err() { + return candidate; + } + let mut suffix = 1u64; + loop { + let name = format!("{stem}-{suffix}.{ext}"); + let candidate = dir.join(&name); + if !reserved(&name) && candidate.symlink_metadata().is_err() { + return candidate; + } + suffix = suffix.saturating_add(1); + } +} + /// The document a dialog exports: the whole image, or one layer (`__layer`). fn source_document_from(doc: Arc, f: &Map) -> Result, String> { match f.get("__layer").and_then(Value::as_u64) { @@ -1409,7 +1440,7 @@ fn write_layer_file( /// can't hold becomes `_` (`a/b:c*?` → `a_b_c__`), spaces are kept. fn layer_file_stem(name: &str) -> String { let stem: String = name.chars().map(|c| if c.is_control() || "<>:\"/\\|?*".contains(c) { '_' } else { c }).collect(); - if stem.trim().is_empty() { "layer".into() } else { stem } + if stem.chars().all(|c| c.is_whitespace() || c == '.') { "layer".into() } else { photocraft_engine::file_cmds::portable_device_name(stem) } } /// The names several layers' files get, for `docs` in document order (bottom to top). Equal diff --git a/crates/ui-egui/src/dialogs/export_dialog/layer_empty_skip_tests.rs b/crates/ui-egui/src/dialogs/export_dialog/layer_empty_skip_tests.rs index e9abe4b0bf..46637de01d 100644 --- a/crates/ui-egui/src/dialogs/export_dialog/layer_empty_skip_tests.rs +++ b/crates/ui-egui/src/dialogs/export_dialog/layer_empty_skip_tests.rs @@ -90,11 +90,23 @@ fn the_dialog_opens_on_the_first_layer_with_pixels_and_exports_only_those() { #[test] fn quick_export_skips_the_same_layers() { - let (mut app, l, written) = app("quick.png"); + let dir = tempfile::tempdir().unwrap(); + let (mut app, l, written) = app_answering(crate::FileDialogAnswer::FolderTo(dir.path().to_string_lossy().into_owned())); app.session.active_mut().unwrap().selected_layers = vec![l.empty, l.red, l.adjustment, l.blue, l.gone]; quick_export_selected_layers_png(&mut app).unwrap(); poll(&mut app); - assert_eq!(*written.borrow(), ["quick.png", "quick-2-Blue.png"]); + let want: Vec<_> = ["Red.png", "Blue.png"].iter().map(|name| dir.path().join(name).to_string_lossy().into_owned()).collect(); + assert_eq!(*written.borrow(), want); +} + +#[test] +fn quick_export_with_one_exportable_layer_keeps_the_save_dialog() { + let (mut app, l, written) = app("only.png"); + app.session.active_mut().unwrap().selected_layers = vec![l.empty, l.blue]; + quick_export_selected_layers_png(&mut app).unwrap(); + poll(&mut app); + assert_eq!(*written.borrow(), ["only.png"]); + assert!(!app.ui.status_error, "{}", app.ui.status); } #[test] diff --git a/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs b/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs index 8959a82cbc..14dbaf8f09 100644 --- a/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs +++ b/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs @@ -18,6 +18,8 @@ fn named(name: &str) -> Document { fn names_keep_spaces_replace_illegal_characters_and_number_duplicates_downwards() { assert_eq!(layer_file_stem("a/b:c*?"), "a_b_c__"); assert_eq!(layer_file_stem("Artboard 1"), "Artboard 1"); + assert_eq!(layer_file_stem(" . "), "layer"); + assert_eq!(layer_file_stem("COM1.front"), "COM1_.front"); assert_eq!(layer_file_stem(r#"qo"t|e\s"#), "q_u_o_t_e_s"); // Bottom to top: three `Dup`s under `Top`. The upper `Dup` keeps the name. let docs = [named("Dup"), named("Dup"), named("Dup"), named("Top")]; @@ -116,3 +118,35 @@ fn one_file_keeps_the_save_dialog_with_the_layers_name() { assert!(suggested.as_deref().is_some_and(|s| s.ends_with("a_b_c__.png")), "{suggested:?}"); assert_eq!(*written.borrow(), ["/out/picked.png"]); } + +#[test] +fn quick_export_numbers_outputs_around_existing_files() { + let dir = tempfile::tempdir().unwrap(); + let out = dir.path(); + let existing = out.join("Dup.png"); + std::fs::write(&existing, b"keep").unwrap(); + let (mut app, ids, _, written, _) = app(crate::FileDialogAnswer::FolderTo(out.to_string_lossy().into_owned())); + app.session.active_mut().unwrap().selected_layers = ids; + quick_export_selected_layers_png(&mut app).unwrap(); + app.poll_file_dialog(&egui::Context::default(), None); + let want: Vec<_> = ["a_b_c__.png", "Dup-1.png", "Dup-2.png"].iter().map(|name| out.join(name).to_string_lossy().into_owned()).collect(); + assert_eq!(*written.borrow(), want); + assert_eq!(std::fs::read(existing).unwrap(), b"keep"); +} + +#[cfg(unix)] +#[test] +fn quick_export_chooses_a_new_name_beside_a_dangling_link() { + let dir = tempfile::tempdir().unwrap(); + let out = dir.path(); + let victim = out.join("victim"); + let link = out.join("Dup.png"); + std::os::unix::fs::symlink(&victim, &link).unwrap(); + let (mut app, ids, _, written, _) = app(crate::FileDialogAnswer::FolderTo(out.to_string_lossy().into_owned())); + app.session.active_mut().unwrap().selected_layers = ids; + quick_export_selected_layers_png(&mut app).unwrap(); + app.poll_file_dialog(&egui::Context::default(), None); + assert!(written.borrow().contains(&out.join("Dup-2.png").to_string_lossy().into_owned())); + assert_eq!(std::fs::read_link(link).unwrap(), victim); + assert!(!victim.exists()); +} diff --git a/crates/ui-egui/src/file_dialog.rs b/crates/ui-egui/src/file_dialog.rs index aabff48324..cb29f8e24c 100644 --- a/crates/ui-egui/src/file_dialog.rs +++ b/crates/ui-egui/src/file_dialog.rs @@ -27,7 +27,7 @@ pub enum FileDialogRequest { /// Files to read: several for File › Open, one for a command that reads a file (Place, /// scripts, notes, presets). Starts in `initial_dir` (the last-used folder, UI-217-3). Open { multiple: bool, initial_dir: Option, extensions: Option> }, - /// Which folder to read from. Starts in `initial_dir` when available. + /// Which folder to use. Starts in `initial_dir` when available. Folder { initial_dir: Option }, /// Where to write, starting from `suggested` (a file name, or the document's own path). Save { suggested: String }, @@ -169,16 +169,10 @@ impl PhotocraftApp { // Closed documents' folders are no longer needed. let open: Vec<_> = self.session.documents().iter().map(|d| d.doc.id).collect(); self.save_dirs.retain(|id, _| open.contains(id)); - if suggested.parent().is_some_and(|p| p.as_os_str().is_empty()) { - let document_dir = doc - .and_then(|d| self.save_dirs.get(&d).cloned()) - // An export doesn't start in a folder that is gone. - .filter(|dir| !export || folder_exists(dir)) - .or_else(|| self.session.active().and_then(|d| d.path.as_deref()).and_then(|p| std::path::Path::new(p).parent()).map(Path::to_path_buf)); - let remembered = export.then(|| self.session.prefs().export.last_folder.clone()); - if let Some(dir) = export_start_dir(remembered.as_deref(), document_dir, folder_exists) { - suggested = dir.join(suggested); - } + if suggested.parent().is_some_and(|p| p.as_os_str().is_empty()) + && let Some(dir) = self.save_start_dir(doc, export) + { + suggested = dir.join(suggested); } // The format comes from the extension, so a name typed without one (common where file // extensions are hidden, #5039) gets the suggested file's extension, as Photoshop's @@ -189,18 +183,15 @@ impl PhotocraftApp { FileDialogAnswer::SaveTo(path) => { let path = saved_path(app, &path, suggested_ext.as_deref()); // The web answers a download name, which has no folder to remember. - let dir = doc.zip(Path::new(&path).parent().filter(|p| !p.as_os_str().is_empty()).map(Path::to_path_buf)); + let dir = Path::new(&path).parent().filter(|p| !p.as_os_str().is_empty()); // An export's folder only once it has exported: a failed one doesn't move where // the next export starts. - if !export && let Some((doc, dir)) = dir.clone() { - app.save_dirs.insert(doc, dir); + if !export && let Some((doc, dir)) = doc.zip(dir) { + app.save_dirs.insert(doc, dir.to_path_buf()); } let exported = then(app, path.clone())?; - if export { - if let Some((doc, dir)) = dir { - app.save_dirs.insert(doc, dir); - } - app.remember_export_folder(&path); + if export && let Some(dir) = dir { + app.remember_export_dir(doc, dir); } Ok(exported) } @@ -213,15 +204,39 @@ impl PhotocraftApp { } /// Remember the folder of an export that succeeded as where the next export dialog starts. - /// The web answers a download name, which has no folder, and leaves it alone. - fn remember_export_folder(&mut self, path: &str) { - let Some(dir) = Path::new(path).parent().filter(|p| !p.as_os_str().is_empty()) else { return }; + fn remember_export_dir(&mut self, doc: Option, dir: &Path) { + if let Some(doc) = doc { + self.save_dirs.insert(doc, dir.to_path_buf()); + } let dir = dir.to_string_lossy().into_owned(); if self.session.prefs().export.last_folder != dir { self.session.prefs.edit(|p| p.export.last_folder = dir); } } + /// Pick a destination for several exports with the same folder memory as a single export. + #[cfg(not(target_arch = "wasm32"))] + pub(crate) fn pick_export_folder(&mut self, then: impl FnOnce(&mut Self, String) -> Result + 'static) -> Result { + let doc = self.session.active().map(|d| d.doc.id); + let initial_dir = self.save_start_dir(doc, true).map(|dir| dir.to_string_lossy().into_owned()); + self.ask_file(FileDialogRequest::Folder { initial_dir }, move |app, answer| { + let FileDialogAnswer::FolderTo(dir) = answer else { return Err(UNEXPECTED.into()) }; + let result = then(app, dir.clone())?; + app.remember_export_dir(doc, Path::new(&dir)); + Ok(result) + }) + } + + fn save_start_dir(&self, doc: Option, export: bool) -> Option { + let document_dir = doc + .and_then(|d| self.save_dirs.get(&d).cloned()) + // An export doesn't start in a folder that is gone. + .filter(|dir| !export || folder_exists(dir)) + .or_else(|| self.session.active().and_then(|d| d.path.as_deref()).and_then(|p| Path::new(p).parent()).map(Path::to_path_buf)); + let remembered = self.session.prefs().export.last_folder.as_str(); + export_start_dir(export.then_some(remembered), document_dir, folder_exists) + } + /// Whether a save to `path` replaces a file the save dialog didn't ask about: the dialog /// answered `answered`, and [`saved_path`] changed it. A file at `path` that /// [`Services::same_file`](crate::Services::same_file) finds is the same entry as `answered` (the diff --git a/crates/ui-egui/src/file_dialog/tests.rs b/crates/ui-egui/src/file_dialog/tests.rs index d009b116cd..a02ae54fec 100644 --- a/crates/ui-egui/src/file_dialog/tests.rs +++ b/crates/ui-egui/src/file_dialog/tests.rs @@ -1138,9 +1138,53 @@ fn convert_to_linked_asks_where_to_write_the_contents() { } } +#[test] +fn quick_export_groups_use_their_own_names() { + let (mut app, open, _) = app(); + let dir = tempfile::tempdir().unwrap(); + app.services.export = Some(Box::new(|doc, path, settings| { + let result = photocraft_io::export(doc, path, &settings.io_options()).map_err(|e| e.to_string())?; + Ok((result.bytes, result.warnings)) + })); + app.services.write = Some(Box::new(|path, data| std::fs::write(path, data).map_err(|e| e.to_string()))); + let mut layers = Vec::new(); + for color in ["#ff0000", "#00ff00"] { + app.run("layer.new.layer", json!({})).unwrap(); + app.run("paint.bucket", json!({"x": 0, "y": 0, "color": color})).unwrap(); + layers.push(app.session.active().unwrap().active_layer.unwrap()); + } + let mut groups = Vec::new(); + for (layer, name) in layers.into_iter().zip(["Folder 1", "Folder 2"]) { + app.run("layer.select", json!({"layer": layer.0})).unwrap(); + let group = app.run("layer.new.groupFromLayers", json!({"name": name})).unwrap()["layer"].as_u64().unwrap(); + groups.push(group); + } + app.run("layer.select", json!({"layer": groups[0]})).unwrap(); + app.run("layer.select", json!({"layer": groups[1], "mode": "add"})).unwrap(); + + let ctx = egui::Context::default(); + menus::invoke(&mut app, &ctx, "layer.quickExportAsPng", Value::Null).unwrap(); + app.poll_file_dialog(&ctx, None); + assert!(matches!(open.borrow().as_slice(), [(FileDialogRequest::Folder { .. }, _)]), "the selection asks once for a folder"); + answer(&open, Some(FileDialogAnswer::FolderTo(dir.path().to_string_lossy().into_owned()))); + app.poll_file_dialog(&ctx, None); + assert!(!app.ui.status_error, "{}", app.ui.status); + assert_eq!(std::fs::read_dir(dir.path()).unwrap().count(), 2); + for (name, expected) in [("Folder 1.png", [1.0, 0.0, 0.0, 1.0]), ("Folder 2.png", [0.0, 1.0, 0.0, 1.0])] { + let bytes = std::fs::read(dir.path().join(name)).unwrap(); + let doc = photocraft_io::import(name, &bytes).unwrap().document; + assert_eq!(doc.layers[0].surface().unwrap().rgba(0, 0), expected, "{name}"); + } +} + #[test] fn quick_export_selected_layers_writes_separate_pngs_with_one_prompt() { let (mut app, open, written) = app(); + let remembered = tempfile::tempdir().unwrap(); + let destination = tempfile::tempdir().unwrap(); + let remembered_path = remembered.path().to_str().unwrap().to_string(); + let dir = destination.path(); + app.session.prefs.edit(|p| p.export.last_folder = remembered_path.clone()); app.run("layer.new.layer", json!({"name": "Same/name"})).unwrap(); app.run("paint.bucket", json!({"x": 0, "y": 0, "color": "#ff0000"})).unwrap(); app.run("layer.new.layer", json!({"name": "Same/name"})).unwrap(); @@ -1159,17 +1203,26 @@ fn quick_export_selected_layers_writes_separate_pngs_with_one_prompt() { })); let ctx = egui::Context::default(); assert!(!crate::layer_menu_ui::single_layer_only("layer.quickExportAsPng")); + menus::invoke(&mut app, &ctx, "layer.quickExportAsPng", Value::Null).unwrap(); + app.poll_file_dialog(&ctx, None); + assert!(matches!(open.borrow().as_slice(), [(FileDialogRequest::Folder { initial_dir: Some(path) }, _)] if path == &remembered_path)); + answer(&open, None); + app.poll_file_dialog(&ctx, None); + assert!(written.borrow().is_empty(), "cancel writes nothing"); + assert_eq!(app.session.prefs().export.last_folder, remembered_path); + menus::invoke(&mut app, &ctx, "layer.quickExportAsPng", Value::Null).unwrap(); app.poll_file_dialog(&ctx, None); assert_eq!(open.borrow().len(), 1, "one destination for the entire selection"); // Selection changes while choosing a destination must not change the captured sources. app.run("layer.select", json!({"layer": selected[0].0})).unwrap(); - answer(&open, Some(FileDialogAnswer::SaveTo("selected.png".into()))); + answer(&open, Some(FileDialogAnswer::FolderTo(dir.to_string_lossy().into_owned()))); app.poll_file_dialog(&ctx, None); assert_eq!(written.borrow().len(), selected.len()); assert_eq!(sources.borrow().len(), selected.len()); - assert_eq!(written.borrow()[0], "selected.png"); - assert_eq!(written.borrow()[1], "selected-2-Same_name.png"); + let want: Vec<_> = ["Same_name-1.png", "Same_name.png"].iter().map(|name| dir.join(name).to_string_lossy().into_owned()).collect(); + assert_eq!(*written.borrow(), want); + assert_eq!(app.session.prefs().export.last_folder, dir.to_str().unwrap()); assert_eq!(selected.len(), 2, "Select All Layers leaves the locked Background out"); assert_eq!(app.session.active().unwrap().doc, before); assert!(!app.ui.status_error, "{}", app.ui.status); From 2e9a5460c3a3068fcecc3a7b2d8de52fb707c9f9 Mon Sep 17 00:00:00 2001 From: Bobderto <230258561+Bobderto@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:20:45 +0000 Subject: [PATCH 2/6] Bound generated layer export filenames by UTF-8 byte length --- crates/ui-egui/src/dialogs/export_dialog.rs | 33 +++++++++--- .../layer_folder_export_tests.rs | 54 +++++++++++++++++++ 2 files changed, 79 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/dialogs/export_dialog.rs b/crates/ui-egui/src/dialogs/export_dialog.rs index 9d95b52717..17a1d63aa3 100644 --- a/crates/ui-egui/src/dialogs/export_dialog.rs +++ b/crates/ui-egui/src/dialogs/export_dialog.rs @@ -365,7 +365,7 @@ pub fn quick_export_selected_layers_png(app: &mut PhotocraftApp) -> Result String { if name.chars().all(|c| c.is_whitespace() || c == '.') { "layer".into() } else { name } } +/// Leave room within a 255-byte filename component for the atomic writer's temporary suffix. +const MAX_GENERATED_EXPORT_NAME_BYTES: usize = 200; + +fn generated_export_name(stem: &str, ext: &str, number: Option) -> String { + let suffix = number.map_or_else(String::new, |number| format!("-{number}")); + let limit = MAX_GENERATED_EXPORT_NAME_BYTES.saturating_sub(ext.len()).saturating_sub(1 + suffix.len()); + let name_at = |limit| { + let stem = stem.get(..stem.floor_char_boundary(limit)).unwrap_or_default(); + let stem = if stem.chars().all(|c| c.is_whitespace() || c == '.') { "layer" } else { stem }; + photocraft_engine::file_cmds::portable_device_name(format!("{stem}{suffix}.{ext}")) + }; + let name = name_at(limit); + // Truncation can expose a Windows device name. Its escape adds one byte. + if name.len() > MAX_GENERATED_EXPORT_NAME_BYTES { name_at(limit.saturating_sub(1)) } else { name } +} + /// The files a multi-layer export writes: the chosen path, then numbered siblings named after /// each layer, in the chosen path's format. fn batch_paths(path: &str, docs: &[Document]) -> Vec { @@ -457,13 +473,13 @@ fn batch_paths(path: &str, docs: &[Document]) -> Vec { /// Keep existing entries, including links (even dangling ones), when choosing an output path. #[cfg(not(target_arch = "wasm32"))] fn unused_export_path(dir: &std::path::Path, stem: &str, ext: &str, reserved: impl Fn(&str) -> bool) -> std::path::PathBuf { - let candidate = dir.join(format!("{stem}.{ext}")); + let candidate = dir.join(generated_export_name(stem, ext, None)); if candidate.symlink_metadata().is_err() { return candidate; } let mut suffix = 1u64; loop { - let name = format!("{stem}-{suffix}.{ext}"); + let name = generated_export_name(stem, ext, Some(suffix)); let candidate = dir.join(&name); if !reserved(&name) && candidate.symlink_metadata().is_err() { return candidate; @@ -1252,13 +1268,14 @@ pub fn confirm(app: &mut PhotocraftApp, f: &Map) -> Result 1 { return confirm_sizes(app, f, doc, source_profile, &stem, rows); } - let suggested = format!("{stem}.{ext}"); + let suggested = if is_layer { generated_export_name(&stem, &ext, None) } else { format!("{stem}.{ext}") }; let f = scaled_fields(f, scale_factor(&rows[0].0)); app.pick_export(&suggested, move |app, path| { let r = write_export(app, &doc, &f, &path, &source_profile)?; @@ -1400,7 +1417,7 @@ fn confirm_layers(app: &mut PhotocraftApp, f: &Map, ids: &[photoc } // One file: the save dialog, named after the layer. The web downloads each file as before. let suggested = match docs.as_slice() { - [one] => format!("{}.{ext}", layer_file_stem(&one.name)), + [one] => generated_export_name(&layer_file_stem(&one.name), &ext, None), _ => format!("{}.{ext}", export_name(st.doc.name.rsplit_once('.').map_or(st.doc.name.as_str(), |(a, _)| a))), }; app.pick_export(&suggested, move |app, path| { @@ -1458,10 +1475,10 @@ fn layer_file_names(docs: &[Document], ext: &str) -> Vec { let mut names = vec![String::new(); docs.len()]; for (i, doc) in docs.iter().enumerate().rev() { let stem = layer_file_stem(&doc.name); - let mut name = format!("{stem}.{ext}"); + let mut name = generated_export_name(&stem, ext, None); let mut n = 1u64; while taken(&used, &name) { - name = format!("{stem}-{n}.{ext}"); + name = generated_export_name(&stem, ext, Some(n)); n = n.saturating_add(1); } used.insert(name.to_uppercase()); diff --git a/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs b/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs index 14dbaf8f09..f7455315d7 100644 --- a/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs +++ b/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs @@ -134,6 +134,60 @@ fn quick_export_numbers_outputs_around_existing_files() { assert_eq!(std::fs::read(existing).unwrap(), b"keep"); } +#[test] +fn quick_export_writes_long_layer_names_with_distinct_suffixes() { + for (character, repeats) in [("a", 300), ("é", 150), ("猫", 100), ("🙂", 75)] { + let dir = tempfile::tempdir().unwrap(); + let out = dir.path(); + let prefix = character.repeat(196 / character.len()); + let occupied = out.join(format!("{prefix}.png")); + std::fs::write(&occupied, b"keep").unwrap(); + let (mut app, ids, _, written, _) = app(crate::FileDialogAnswer::FolderTo(out.to_string_lossy().into_owned())); + let files = written.clone(); + app.services.write = Some(Box::new(move |path, bytes| { + photocraft_format::atomic_write(std::path::Path::new(path), bytes).map_err(|e| e.to_string())?; + files.borrow_mut().push(path.to_string()); + Ok(()) + })); + for (label, id) in [" left", " right"].into_iter().zip(&ids) { + let name = character.repeat(repeats) + label; + app.run("layer.renameLayer", json!({"layer": id.0, "name": name})).unwrap(); + } + app.session.active_mut().unwrap().selected_layers = ids; + let ctx = egui::Context::default(); + crate::menus::invoke(&mut app, &ctx, "layer.quickExportAsPng", Value::Null).unwrap(); + app.poll_file_dialog(&ctx, None); + assert!(!app.ui.status_error, "{character}: {}", app.ui.status); + assert_eq!(std::fs::read(occupied).unwrap(), b"keep"); + let numbered_prefix = character.repeat(194 / character.len()); + for (i, expected) in [[1.0, 0.0, 0.0, 1.0], [0.0, 1.0, 0.0, 1.0]].into_iter().enumerate() { + let name = format!("{numbered_prefix}-{}.png", i + 1); + let bytes = std::fs::read(out.join(&name)).unwrap(); + let doc = photocraft_io::import(&name, &bytes).unwrap().document; + assert_eq!(doc.layers[0].surface().unwrap().rgba(0, 0), expected, "{name}"); + } + assert_eq!(written.borrow().len(), 3); + } +} + +#[test] +fn layer_file_names_reserve_space_for_multi_digit_suffixes() { + let stem = "a".repeat(300); + let docs: Vec<_> = (0..11).map(|i| named(&format!("{stem}{i}"))).collect(); + let names = layer_file_names(&docs, "png"); + assert!(names.iter().all(|name| name.len() <= 200)); + assert!(names[0].ends_with("-10.png")); + assert_eq!(names.iter().collect::>().len(), docs.len()); + + let docs = [named(&format!("{}Artwork", " ".repeat(250))), named("layer")]; + assert_eq!(layer_file_names(&docs, "png"), ["layer-1.png", "layer.png"]); + + let docs = [named(&format!("CON{}Artwork", " ".repeat(250)))]; + let names = layer_file_names(&docs, "png"); + assert!(names[0].ends_with("_.png")); + assert!(names[0].len() <= 200); +} + #[cfg(unix)] #[test] fn quick_export_chooses_a_new_name_beside_a_dangling_link() { From a084cbe2e931c578b2d944b57e299157454426ef Mon Sep 17 00:00:00 2001 From: Bobderto <230258561+Bobderto@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:34:55 +0000 Subject: [PATCH 3/6] Retry CI after Windows scratch-disk failure From 8b266109986f3790a92e0e34198752d03b72dd2c Mon Sep 17 00:00:00 2001 From: Bobderto <230258561+Bobderto@users.noreply.github.com> Date: Mon, 16 Nov 2026 14:11:10 +0000 Subject: [PATCH 4/6] Publish generated Quick Export files without replacing existing files --- apps/photocraft/src/services.rs | 5 +- crates/ui-egui/src/dialogs/export_dialog.rs | 15 +++-- .../export_dialog/layer_empty_skip_tests.rs | 1 + .../layer_folder_export_tests.rs | 67 +++++++++++++++++-- crates/ui-egui/src/file_dialog/tests.rs | 3 +- crates/ui-egui/src/services.rs | 2 + 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/apps/photocraft/src/services.rs b/apps/photocraft/src/services.rs index 352321d294..bcbf1ee635 100644 --- a/apps/photocraft/src/services.rs +++ b/apps/photocraft/src/services.rs @@ -413,8 +413,8 @@ fn recovery_dir() -> Option { } /// Write `bytes` crash-safely (temp file beside the target, fsync, rename, directory fsync; see -/// [`photocraft_format::atomic`]). Every document write (Save, Save As, Export, Save for Web) and -/// the preferences go through here, so a failed or interrupted save never destroys the old file. +/// [`photocraft_format::atomic`]). Save, Save As, overwriting exports and preferences use this so +/// a failed or interrupted write never destroys the old file. fn write_atomic(path: &Path, bytes: &[u8]) -> Result<(), String> { photocraft_format::atomic_write(path, bytes).map_err(|e| e.to_string()) } @@ -773,6 +773,7 @@ pub fn native(automation: Option) -> save_file: Some(Arc::new(save_file)), file_dialog: Some(Box::new(show_file_dialog)), write: Some(Box::new(|path: &str, bytes: &[u8]| write_atomic(Path::new(path), bytes))), + write_new: Some(Box::new(|path, bytes| photocraft_format::write_noreplace(Path::new(path), bytes).map_err(|e| format!("{path}: {e}")))), file_stamp: Some(Box::new(|path: &str| { // Follows a symlink, as Save writes through it to the file it points at. let meta = std::fs::metadata(path).ok()?; diff --git a/crates/ui-egui/src/dialogs/export_dialog.rs b/crates/ui-egui/src/dialogs/export_dialog.rs index 17a1d63aa3..7283bc0db0 100644 --- a/crates/ui-egui/src/dialogs/export_dialog.rs +++ b/crates/ui-egui/src/dialogs/export_dialog.rs @@ -370,12 +370,12 @@ pub fn quick_export_selected_layers_png(app: &mut PhotocraftApp) -> Result Result) -> Result { +fn write_quick_pngs(app: &mut PhotocraftApp, docs: &[Document], paths: impl IntoIterator, new_files_only: bool) -> Result { let mut exported = Vec::new(); for (doc, path) in docs.iter().zip(paths) { crate::app::ensure_memory_to_save(doc, &path)?; let export = app.services.export.as_ref().ok_or("no exporter configured")?; let (bytes, warnings) = export(doc, &path, &ExportSettings { xmp_all: false, ..Default::default() })?; - let write = app.services.write.as_mut().ok_or("no writer configured")?; + // A file may have appeared at a generated path while the encoder was running. + let write = if new_files_only { + app.services.write_new.as_mut().ok_or("no exclusive export writer configured")? + } else { + app.services.write.as_mut().ok_or("no writer configured")? + }; write(&path, &bytes)?; crate::notices::io_warnings(app, &format!("Exported {}", crate::file_open::display_name(&path)), &warnings); exported.push(json!({"path": path, "bytes": bytes.len(), "warnings": warnings})); diff --git a/crates/ui-egui/src/dialogs/export_dialog/layer_empty_skip_tests.rs b/crates/ui-egui/src/dialogs/export_dialog/layer_empty_skip_tests.rs index 46637de01d..78378fb913 100644 --- a/crates/ui-egui/src/dialogs/export_dialog/layer_empty_skip_tests.rs +++ b/crates/ui-egui/src/dialogs/export_dialog/layer_empty_skip_tests.rs @@ -92,6 +92,7 @@ fn the_dialog_opens_on_the_first_layer_with_pixels_and_exports_only_those() { fn quick_export_skips_the_same_layers() { let dir = tempfile::tempdir().unwrap(); let (mut app, l, written) = app_answering(crate::FileDialogAnswer::FolderTo(dir.path().to_string_lossy().into_owned())); + app.services.write_new = app.services.write.take(); app.session.active_mut().unwrap().selected_layers = vec![l.empty, l.red, l.adjustment, l.blue, l.gone]; quick_export_selected_layers_png(&mut app).unwrap(); poll(&mut app); diff --git a/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs b/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs index f7455315d7..2ec5cfd8b4 100644 --- a/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs +++ b/crates/ui-egui/src/dialogs/export_dialog/layer_folder_export_tests.rs @@ -45,17 +45,20 @@ fn names_keep_spaces_replace_illegal_characters_and_number_duplicates_downwards( /// an empty layer. fn app(answer: crate::FileDialogAnswer) -> (PhotocraftApp, Vec, photocraft_doc::LayerId, Written, Asked) { let written = Written::default(); - let capture = written.clone(); + let record = |capture: Written| -> crate::services::WriteFn { + Box::new(move |path, _| { + capture.borrow_mut().push(path.to_string()); + Ok(()) + }) + }; let (picker, asked) = crate::file_dialog::fake(vec![Some(answer)]); let services = crate::Services { file_dialog: Some(picker), export: Some(Box::new(|doc, path, settings| { photocraft_io::export(doc, path, &settings.io_options()).map(|r| (r.bytes, r.warnings)).map_err(|e| e.to_string()) })), - write: Some(Box::new(move |path, _| { - capture.borrow_mut().push(path.to_string()); - Ok(()) - })), + write: Some(record(written.clone())), + write_new: Some(record(written.clone())), ..Default::default() }; let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), services); @@ -144,8 +147,8 @@ fn quick_export_writes_long_layer_names_with_distinct_suffixes() { std::fs::write(&occupied, b"keep").unwrap(); let (mut app, ids, _, written, _) = app(crate::FileDialogAnswer::FolderTo(out.to_string_lossy().into_owned())); let files = written.clone(); - app.services.write = Some(Box::new(move |path, bytes| { - photocraft_format::atomic_write(std::path::Path::new(path), bytes).map_err(|e| e.to_string())?; + app.services.write_new = Some(Box::new(move |path, bytes| { + photocraft_format::write_noreplace(std::path::Path::new(path), bytes).map_err(|e| e.to_string())?; files.borrow_mut().push(path.to_string()); Ok(()) })); @@ -204,3 +207,53 @@ fn quick_export_chooses_a_new_name_beside_a_dangling_link() { assert_eq!(std::fs::read_link(link).unwrap(), victim); assert!(!victim.exists()); } + +#[test] +fn quick_export_preserves_a_file_created_during_encoding() { + let dir = tempfile::tempdir().unwrap(); + let out = dir.path(); + let destination = out.join("a_b_c__.png"); + let (mut app, ids, _, _, _) = app(crate::FileDialogAnswer::FolderTo(out.to_string_lossy().into_owned())); + let encode = app.services.export.take().unwrap(); + let occupied = destination.clone(); + app.services.export = Some(Box::new(move |doc, path, settings| { + if std::path::Path::new(path) == occupied { + assert!(!occupied.exists()); + std::fs::write(&occupied, b"created during encoding").unwrap(); + } + encode(doc, path, settings) + })); + app.services.write = Some(Box::new(|path, bytes| photocraft_format::atomic_write(std::path::Path::new(path), bytes).map_err(|e| e.to_string()))); + app.services.write_new = + Some(Box::new(|path, bytes| photocraft_format::write_noreplace(std::path::Path::new(path), bytes).map_err(|e| format!("{path}: {e}")))); + app.session.active_mut().unwrap().selected_layers = ids; + let ctx = egui::Context::default(); + crate::menus::invoke(&mut app, &ctx, "layer.quickExportAsPng", Value::Null).unwrap(); + app.poll_file_dialog(&ctx, None); + assert!(std::fs::read(&destination).unwrap() == b"created during encoding", "Quick Export replaced the other file"); + assert!(app.ui.status_error, "{}", app.ui.status); + assert!(app.ui.status.contains("a_b_c__.png"), "{}", app.ui.status); + assert_eq!(std::fs::read_dir(out).unwrap().count(), 1); +} + +#[test] +fn quick_export_can_replace_a_file_confirmed_in_the_save_dialog() { + for include_empty_layer in [false, true] { + let dir = tempfile::tempdir().unwrap(); + let destination = dir.path().join("chosen.png"); + std::fs::write(&destination, b"previous file").unwrap(); + let (mut app, ids, empty, _, asked) = app(crate::FileDialogAnswer::SaveTo(destination.to_string_lossy().into_owned())); + app.services.write = Some(Box::new(|path, bytes| photocraft_format::atomic_write(std::path::Path::new(path), bytes).map_err(|e| e.to_string()))); + app.services.write_new = Some(Box::new(|path, bytes| photocraft_format::write_noreplace(std::path::Path::new(path), bytes).map_err(|e| e.to_string()))); + let selected = if include_empty_layer { vec![empty, ids[2]] } else { vec![ids[2]] }; + app.session.active_mut().unwrap().selected_layers = selected; + let ctx = egui::Context::default(); + crate::menus::invoke(&mut app, &ctx, "layer.quickExportAsPng", Value::Null).unwrap(); + app.poll_file_dialog(&ctx, None); + assert!(matches!(asked.borrow().as_slice(), [crate::FileDialogRequest::Save { .. }])); + assert!(!app.ui.status_error, "{}", app.ui.status); + let bytes = std::fs::read(destination).unwrap(); + let doc = photocraft_io::import("chosen.png", &bytes).unwrap().document; + assert_eq!(doc.layers[0].surface().unwrap().rgba(0, 0), [0.0, 0.0, 1.0, 1.0]); + } +} diff --git a/crates/ui-egui/src/file_dialog/tests.rs b/crates/ui-egui/src/file_dialog/tests.rs index a02ae54fec..eadd1993ad 100644 --- a/crates/ui-egui/src/file_dialog/tests.rs +++ b/crates/ui-egui/src/file_dialog/tests.rs @@ -1146,7 +1146,7 @@ fn quick_export_groups_use_their_own_names() { let result = photocraft_io::export(doc, path, &settings.io_options()).map_err(|e| e.to_string())?; Ok((result.bytes, result.warnings)) })); - app.services.write = Some(Box::new(|path, data| std::fs::write(path, data).map_err(|e| e.to_string()))); + app.services.write_new = Some(Box::new(|path, data| photocraft_format::write_noreplace(std::path::Path::new(path), data).map_err(|e| e.to_string()))); let mut layers = Vec::new(); for color in ["#ff0000", "#00ff00"] { app.run("layer.new.layer", json!({})).unwrap(); @@ -1180,6 +1180,7 @@ fn quick_export_groups_use_their_own_names() { #[test] fn quick_export_selected_layers_writes_separate_pngs_with_one_prompt() { let (mut app, open, written) = app(); + app.services.write_new = app.services.write.take(); let remembered = tempfile::tempdir().unwrap(); let destination = tempfile::tempdir().unwrap(); let remembered_path = remembered.path().to_str().unwrap().to_string(); diff --git a/crates/ui-egui/src/services.rs b/crates/ui-egui/src/services.rs index ed8092f07d..a2d1bb5e62 100644 --- a/crates/ui-egui/src/services.rs +++ b/crates/ui-egui/src/services.rs @@ -559,6 +559,8 @@ pub struct Services { pub file_dialog: Option, /// Write bytes to a path (native) or trigger a download (web). pub write: Option, + /// Publish a new file on the desktop, leaving any occupied destination intact. + pub write_new: Option, /// Size and modification time of a file (native); `None` on the web, where Save never /// writes back to a file. pub file_stamp: Option, From ec0799412631b8b9f07a1ef4bf2a6f9b4b205181 Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 28 Nov 2026 20:59:25 +0000 Subject: [PATCH 5/6] Keep single-output Quick Export filename suggestions consistent --- crates/ui-egui/src/dialogs/export_dialog.rs | 12 ++++++---- .../layer_name_sanitise_tests.rs | 24 +++++++++++++++++-- docs/control-protocol.md | 8 ++++--- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/dialogs/export_dialog.rs b/crates/ui-egui/src/dialogs/export_dialog.rs index 813dd3ddf3..391c5659b1 100644 --- a/crates/ui-egui/src/dialogs/export_dialog.rs +++ b/crates/ui-egui/src/dialogs/export_dialog.rs @@ -391,7 +391,7 @@ pub fn quick_export_selected_layers_png(app: &mut PhotocraftApp) -> Result String { if name.chars().all(|c| c.is_whitespace() || c == '.') { "layer".into() } else { name } } +fn layer_export_suggestion(name: &str, ext: &str) -> String { + generated_export_name(&layer_export_name(&stem_of(name)), ext, None) +} + /// Leave room within a 255-byte filename component for the atomic writer's temporary suffix. const MAX_GENERATED_EXPORT_NAME_BYTES: usize = 200; @@ -1114,8 +1118,8 @@ fn export_to(app: &mut PhotocraftApp, f: &Map, path: &str) -> Res /// A layer's name may hold characters a file name can't (#14810): `a/b:c*?` suggests `a_b_c__`. fn pick_and_export(app: &mut PhotocraftApp, f: Map) -> Result { let doc = source_document(app, &f)?; - let stem = if f.contains_key("__layer") { layer_export_name(&stem_of(&doc.name)) } else { stem_of(&doc.name) }; - let suggested = format!("{stem}.{}", s_fmt(&f)); + let ext = s_fmt(&f); + let suggested = if f.contains_key("__layer") { layer_export_suggestion(&doc.name, &ext) } else { format!("{}.{ext}", stem_of(&doc.name)) }; app.pick_export(&suggested, move |app, path| export_to(app, &f, &path)) } @@ -1226,7 +1230,7 @@ pub(crate) fn replay(app: &mut PhotocraftApp, params: &Value) -> Result.`, replacing a file of that /// name (#14808). One file is written at `path`; the web downloads each file, the first under -/// `path` and the others named as Quick Export names a selection's files. +/// `path` and the others under numbered names derived from that filename and their layer names. fn export_layers(app: &mut PhotocraftApp, f: &Map, ids: &[LayerId], path: &str) -> Result { let st = app.session.active().ok_or("no document")?; let source_profile = effective_source_profile(app, &st.doc); diff --git a/crates/ui-egui/src/dialogs/export_dialog/layer_name_sanitise_tests.rs b/crates/ui-egui/src/dialogs/export_dialog/layer_name_sanitise_tests.rs index d7006361fc..92e9a7c62a 100644 --- a/crates/ui-egui/src/dialogs/export_dialog/layer_name_sanitise_tests.rs +++ b/crates/ui-egui/src/dialogs/export_dialog/layer_name_sanitise_tests.rs @@ -5,25 +5,45 @@ //! export's `export_name`. use super::*; -use craft::host::ScriptedFiles; +use craft::host::{PickKind, ScriptedFiles}; /// The file name Layer › Quick Export as PNG suggests for a layer named `name` (the Save dialog /// stays open), and the whole save request as text. fn suggested_for(name: &str) -> (String, String) { + suggested_for_selection(name, false) +} + +fn suggested_for_selection(name: &str, include_empty: bool) -> (String, String) { let files = Arc::new(ScriptedFiles::held()); let services = crate::Services { files: Some(files.clone()), ..Default::default() }; let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), services); app.run("file.new", json!({"width": 20, "height": 20})).unwrap(); + app.run("layer.new.layer", json!({"name": "Empty"})).unwrap(); + let empty = app.session.active().unwrap().active_layer.unwrap(); app.run("layer.new.layer", json!({"name": name})).unwrap(); app.run("select.rect", json!({"x": 2, "y": 2, "width": 6, "height": 6})).unwrap(); app.run("edit.fill", json!({"color": "#ff0000"})).unwrap(); let layer = app.session.active().unwrap().active_layer.unwrap(); - quick_export_layer_png(&mut app, layer).unwrap(); + if include_empty { + app.session.restore_layer_selection(Some(layer), &[empty, layer], None).unwrap(); + } + app.run("layer.quickExportAsPng", json!({})).unwrap(); let asked = files.requests(); let [request] = asked.as_slice() else { panic!("one Save dialog: {asked:?}") }; + assert_eq!(request.kind, PickKind::Save); (request.file_name.clone().unwrap_or_default(), format!("{request:?}")) } +#[test] +fn quick_export_suggests_the_same_name_when_an_empty_layer_is_selected() { + for name in ["Hero.v2", "a/b:c*?", "CON", &"界".repeat(100)] { + let (single, _) = suggested_for(name); + let (with_empty, _) = suggested_for_selection(name, true); + assert_eq!(with_empty, single, "{name:?}"); + assert!(single.len() <= MAX_GENERATED_EXPORT_NAME_BYTES); + } +} + #[test] fn a_layer_named_with_illegal_characters_suggests_underscores() { let (file, path) = suggested_for("a/b:c*?"); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 844ed16253..67bb89fcdc 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -812,9 +812,11 @@ else}` is Photoshop's Insert Conditional as a step: it tests the document or act (`always`, `landscape`, `modeIsRGB`, `hasLayers`, `isBackground`, `hasPixelMask`… see its params) and plays the matching action by name, failing the caller when that action fails. -Layer-panel **Quick Export as PNG** exports every selected layer as a separate PNG. A single -Save dialog chooses the first filename; remaining files are numbered siblings with sanitized -layer names. Selection is captured before opening the dialog; an unselected layer is excluded. +Layer-panel **Quick Export as PNG** exports each selected layer or group with exportable pixels +as a separate PNG. With several outputs, desktop asks for one folder and the web downloads each +file. Each PNG uses its source name with unsafe filename characters replaced. Duplicate names +and occupied desktop filenames get numbered alternatives. A single output uses a Save dialog. +Multiple selected sources are captured before opening the picker. ## Shared panel docking From 59abe3368b906d474c84984b6324631e9eac9b11 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 29 Nov 2026 10:14:33 +0000 Subject: [PATCH 6/6] Test Quick Export through the menu and clarify filename collisions --- .../src/dialogs/export_dialog/layer_name_sanitise_tests.rs | 2 +- docs/control-protocol.md | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/dialogs/export_dialog/layer_name_sanitise_tests.rs b/crates/ui-egui/src/dialogs/export_dialog/layer_name_sanitise_tests.rs index 92e9a7c62a..f4ceaad0c2 100644 --- a/crates/ui-egui/src/dialogs/export_dialog/layer_name_sanitise_tests.rs +++ b/crates/ui-egui/src/dialogs/export_dialog/layer_name_sanitise_tests.rs @@ -27,7 +27,7 @@ fn suggested_for_selection(name: &str, include_empty: bool) -> (String, String) if include_empty { app.session.restore_layer_selection(Some(layer), &[empty, layer], None).unwrap(); } - app.run("layer.quickExportAsPng", json!({})).unwrap(); + crate::menus::invoke(&mut app, &egui::Context::default(), "layer.quickExportAsPng", Value::Null).unwrap(); let asked = files.requests(); let [request] = asked.as_slice() else { panic!("one Save dialog: {asked:?}") }; assert_eq!(request.kind, PickKind::Save); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 67bb89fcdc..311e531b07 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -813,9 +813,10 @@ else}` is Photoshop's Insert Conditional as a step: it tests the document or act and plays the matching action by name, failing the caller when that action fails. Layer-panel **Quick Export as PNG** exports each selected layer or group with exportable pixels -as a separate PNG. With several outputs, desktop asks for one folder and the web downloads each -file. Each PNG uses its source name with unsafe filename characters replaced. Duplicate names -and occupied desktop filenames get numbered alternatives. A single output uses a Save dialog. +as a separate PNG. Each PNG uses its source name with unsafe filename characters replaced. +For several outputs, desktop asks for one folder and the web downloads each file. Duplicate +names get numbered alternatives, as do occupied filenames on desktop. A single output uses +a Save dialog that lets you confirm replacing an existing file. Multiple selected sources are captured before opening the picker. ## Shared panel docking