From 20ea753a9542cb95e27e09fa8dbb1049e199ee4e Mon Sep 17 00:00:00 2001 From: rmsff <17902130+rmsff@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:51:20 +0300 Subject: [PATCH] Contact Sheet II: OK without a folder asks for one A fresh dialog no longer starts on the document's folder or `.`: Input is empty and shows [Select Image Folder]. OK without a folder shows the reference alert "Select an Image Folder" and keeps the dialog open with its values (#13692). A folder without images still gets the command's error. --- crates/ui-egui/src/dialogs.rs | 11 +++++--- .../src/dialogs/contact_sheet_layout_tests.rs | 6 ++--- .../ui-egui/src/dialogs/contact_sheet_ui.rs | 26 ++++++++++++++++--- crates/ui-egui/src/dialogs/file_forms.rs | 2 +- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 0cec6b89fa..48ab489f3b 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -28,9 +28,9 @@ pub(crate) mod params { use serde_json::Value; use super::{ - PhotocraftApp, alerts, brush_preset_dialog, canvas_input, channel_options_ui, color_picker_ui, color_table_ui, count_group_name_ui, duplicate_layer_ui, - equalize_ui, file_forms, fill_ui, filter_dialog, history_options_ui, image_processor_ui, merge_channels_ui, new_group_ui, new_layer_ui, - paragraph_text_size, smart_filter_dialog, snapshot_dialog, stack_dialog, stroke_ui, + PhotocraftApp, alerts, brush_preset_dialog, canvas_input, channel_options_ui, color_picker_ui, color_table_ui, contact_sheet_ui, count_group_name_ui, + duplicate_layer_ui, equalize_ui, file_forms, fill_ui, filter_dialog, history_options_ui, image_processor_ui, merge_channels_ui, new_group_ui, + new_layer_ui, paragraph_text_size, smart_filter_dialog, snapshot_dialog, stack_dialog, stroke_ui, }; use crate::canvas::document_display::CanvasHost; @@ -91,6 +91,11 @@ pub(crate) mod params { cancel: Some(filter_dialog::cancel), ..ParamFamily::new(|key| key == "image.mode.colorTable", filter_dialog::run) }, + ParamFamily { + check: Some(contact_sheet_ui::check), + cancel: Some(filter_dialog::cancel), + ..ParamFamily::new(|key| key == contact_sheet_ui::COMMAND, filter_dialog::run) + }, ParamFamily { cancel: Some(filter_dialog::cancel), ..ParamFamily::new(file_forms::owns, filter_dialog::run) }, ParamFamily { listing: Some(stack_dialog::listing), ..ParamFamily::new(stack_dialog::owns, stack_dialog::run) }, ParamFamily { diff --git a/crates/ui-egui/src/dialogs/contact_sheet_layout_tests.rs b/crates/ui-egui/src/dialogs/contact_sheet_layout_tests.rs index 3d4d3a4309..bc6d53e487 100644 --- a/crates/ui-egui/src/dialogs/contact_sheet_layout_tests.rs +++ b/crates/ui-egui/src/dialogs/contact_sheet_layout_tests.rs @@ -57,7 +57,7 @@ fn set(h: &mut H, id: DialogId, key: &str, value: Value) { /// The options of the list row `key`, as `(id, label)`. fn options(key: &str) -> Vec<(String, String)> { - let rows = super::rows(".".into()); + let rows = super::rows(); let row = rows.iter().find(|p| p.key == key).unwrap_or_else(|| panic!("a {key} row")); let ParamKind::Choice { options, .. } = &row.kind else { panic!("{key} is a list") }; options.iter().map(|(id, label)| (id.clone(), label.as_str().to_owned())).collect() @@ -106,7 +106,7 @@ fn mode_bit_depth_place_and_units_list_the_reference_entries() { assert_eq!(labels("mode"), ["Grayscale", "RGB Color", "CMYK Color", "Lab Color"]); assert_eq!(labels("depth"), ["8-bit", "16-bit"]); assert_eq!(labels("place"), ["across first", "down first"]); - let rows = super::rows(".".into()); + let rows = super::rows(); let resolution = rows.iter().find(|p| p.key == "resolution").expect("a Resolution row"); assert_eq!(resolution.unit_key(), Some("resolution.unit"), "Resolution has its own unit list"); } @@ -213,7 +213,7 @@ fn ok_runs_the_command_with_the_same_params() { }; let before = params(&h); for (key, want) in [ - ("input", json!(".")), + ("input", json!("")), ("units", json!("inches")), ("width", json!(8.0)), ("height", json!(10.0)), diff --git a/crates/ui-egui/src/dialogs/contact_sheet_ui.rs b/crates/ui-egui/src/dialogs/contact_sheet_ui.rs index 849af9ebf3..2da91349f7 100644 --- a/crates/ui-egui/src/dialogs/contact_sheet_ui.rs +++ b/crates/ui-egui/src/dialogs/contact_sheet_ui.rs @@ -5,14 +5,19 @@ //! of them are kept in the shape the dialog shows and turned into the command's at OK ([`command_params`]): the //! resolution's unit (the command takes pixels/inch), Bit Depth (`"8"` or `"16"`) and Place (`"across"` or `"down"`). -use craft::ui::patterns::form_dialogs::{CustomContext, DialogFields, NumberUnit, Param, ParamKind}; +use craft::ui::patterns::form_dialogs::{CustomContext, DialogFields, NumberUnit, Param, ParamKind, ParamResult}; use craft::ui::runtime::env::{Label, UnitKind}; use craft::ui::runtime::requests::PathKind; use photocraft_engine::prefs::Unit; use serde_json::{Map, Value, json}; +use crate::PhotocraftApp; + pub(crate) const COMMAND: &str = "file.automate.contactSheetII"; +/// The reference application's alert for OK while no image folder is chosen (#13692). +pub(crate) const NO_FOLDER_ALERT: &str = "Select an Image Folder"; + const UNITS: [(&str, &str); 3] = [("inches", "inches"), ("cm", "cm"), ("pixels", "pixels")]; const MODES: [(&str, &str); 4] = [("gray", "Grayscale"), ("rgb", "RGB Color"), ("cmyk", "CMYK Color"), ("lab", "Lab Color")]; const DEPTHS: [(&str, &str); 2] = [("8", "8-bit"), ("16", "16-bit")]; @@ -23,15 +28,16 @@ fn opts(list: &[(&'static str, &'static str)]) -> Vec<(String, Label)> { list.iter().map(|(id, label)| ((*id).to_owned(), Label::from(tl!(label)))).collect() } -/// The rows of the dialog, opening on the folder `dir`. -pub(crate) fn rows(dir: String) -> Vec { +/// The rows of the dialog. A fresh dialog has no folder chosen (#13692): not the working folder, nor that of the +/// document in front. +pub(crate) fn rows() -> Vec { let resolution = vec![ NumberUnit::new("in", UnitKind::PixelsPerInch, tl!("pixels/inch"), 1.0), NumberUnit::new("cm", UnitKind::PixelsPerCentimetre, tl!("pixels/cm"), 2.54), ]; vec![ Param::section(tl!("Source Images")), - Param::new("input", tl!("Input"), ParamKind::text(dir)).browse(PathKind::Folder), + Param::new("input", tl!("Input"), ParamKind::text("")).browse(PathKind::Folder).hint(tl!("[Select Image Folder]")), // The folder, then Include Subfolders (on) and, right below it, Group Images by Folder (off, greyed while // Include Subfolders is off). Param::new("includeSubfolders", tl!("Include Subfolders"), ParamKind::bool(true)), @@ -60,6 +66,18 @@ pub(crate) fn rows(dir: String) -> Vec { ] } +/// The `ParamFamily::check` of the dialog: OK without a folder shows [`NO_FOLDER_ALERT`] over the dialog, which stays +/// open with its values. A folder that holds no images or is gone still reaches the command and gets its error. +pub(crate) fn check(app: &mut PhotocraftApp, result: &ParamResult) -> Result<(), Label> { + if result.fields.text("input").is_some_and(|dir| !dir.is_empty()) { + return Ok(()); + } + let message = tl!(NO_FOLDER_ALERT); + // Repeated confirms (automation) keep one alert. + crate::dialogs::alerts::alert(app, message); + Err(Label::from(message)) +} + /// The units Width and Height were last shown in, kept by [`follow_units`]. const UNITS_SHOWN: &str = "unitsShown"; diff --git a/crates/ui-egui/src/dialogs/file_forms.rs b/crates/ui-egui/src/dialogs/file_forms.rs index 4352296d22..4ea6a67308 100644 --- a/crates/ui-egui/src/dialogs/file_forms.rs +++ b/crates/ui-egui/src/dialogs/file_forms.rs @@ -72,7 +72,7 @@ fn open_form(app: &mut PhotocraftApp, key: &'static str, title: &str, rows: Vec< /// File › Automate › Contact Sheet II. pub(crate) fn open_contact_sheet(app: &mut PhotocraftApp) -> DialogId { - let rows = crate::dialogs::contact_sheet_ui::rows(default_dir(app)); + let rows = crate::dialogs::contact_sheet_ui::rows(); open_form(app, CONTACT_SHEET, tl!("Contact Sheet II"), rows) }