diff --git a/crates/ui-egui/src/browse_field_tests.rs b/crates/ui-egui/src/browse_field_tests.rs index 2aa3ef44f5..09debf418b 100644 --- a/crates/ui-egui/src/browse_field_tests.rs +++ b/crates/ui-egui/src/browse_field_tests.rs @@ -63,3 +63,21 @@ fn install_plugin_path_is_chosen_with_browse() { } assert_eq!(field(&h, "path"), Some(json!("/tmp/blur.wasm"))); } + +/// #9357: Image Processor's source and destination folders are chosen with Browse…, as +/// Photoshop's Select Folder… buttons choose them, instead of being typed. +#[test] +fn image_processor_folders_are_chosen_with_browse() { + let (mut h, asked) = harness(vec![Some(FileDialogAnswer::FolderTo("/tmp/shoot".into())), Some(FileDialogAnswer::FolderTo("/tmp/web".into()))]); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "file.scripts.imageProcessor", json!({})).unwrap(); + h.run_steps(4); + assert_eq!(h.query_all_by_label("Browse…").count(), 2, "one Browse… for the source and one for the destination"); + h.query_all_by_label("Browse…").next().unwrap().click(); + h.run_steps(4); + assert_eq!(field(&h, "input"), Some(json!("/tmp/shoot"))); + h.query_all_by_label("Browse…").nth(1).unwrap().click(); + h.run_steps(4); + assert_eq!(field(&h, "output"), Some(json!("/tmp/web"))); + assert!(matches!(asked.borrow().as_slice(), [FileDialogRequest::Folder { .. }, FileDialogRequest::Folder { .. }])); +} diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index bc658783cd..2c683bce38 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -11,11 +11,18 @@ use crate::widgets::{ButtonRole, DialogButton, dialog_buttons}; /// [`show`] takes it out again and opens the matching file or folder dialog. pub(crate) const BROWSE_FIELD: &str = "__browse"; -/// Browse… beside a path field of dialog `id`: a folder picker for `dir` fields, a `.wasm` picker -/// for Install Plug-in…'s `path`. The answer fills the field. +/// A text field that names a folder: an export's `dir`, and the source (`input`) and destination +/// (`output`) folders of Image Processor, Batch, Lens Correction, Contact Sheet and Create +/// Droplet, which Photoshop picks with Select Folder… / Choose… (#9357). +pub(crate) fn is_folder_field(key: &str) -> bool { + matches!(key, "dir" | "input" | "output") +} + +/// Browse… beside a path field of dialog `id`: a folder picker for folder fields +/// ([`is_folder_field`]), a `.wasm` picker for Install Plug-in…'s `path`. The answer fills the field. fn browse_field(app: &mut PhotocraftApp, id: u64, fields: &serde_json::Map, key: &str) { let key = key.to_string(); - let r = if key == "dir" { + let r = if is_folder_field(&key) { app.ask_folder(move |app, path| fill_field(app, id, &key, path)) } else if fields.get("__command").and_then(Value::as_str) == Some("plugin.install") { let initial_dir = crate::file_dialog::last_used_dir(&app.ui.recent_files); diff --git a/crates/ui-egui/src/view_cmds.rs b/crates/ui-egui/src/view_cmds.rs index 9fdc456569..ebf7540e38 100644 --- a/crates/ui-egui/src/view_cmds.rs +++ b/crates/ui-egui/src/view_cmds.rs @@ -1170,8 +1170,8 @@ pub fn form_body(ui: &mut egui::Ui, f: &mut Map) { None => { ui.horizontal(|ui| { ui.add(egui::TextEdit::singleline(&mut s).desired_width(260.0)); - // A folder field gets the system folder picker (#7942). - if k == "dir" && crate::widgets::secondary_button(ui, tl!("Browse…"), 0.0).clicked() { + // A folder field gets the system folder picker (#7942, #9357). + if crate::dialogs::is_folder_field(&k) && crate::widgets::secondary_button(ui, tl!("Browse…"), 0.0).clicked() { browse = Some(k.clone()); } });