From b54a4a8f864efdc5ec152c1173d11fab8d07a3d6 Mon Sep 17 00:00:00 2001 From: Higgs32584 Date: Wed, 14 Oct 2026 18:54:11 -0400 Subject: [PATCH 1/4] Displace: OK asks for the displacement map, as in Photoshop (#5806) Filter > Distort > Displace took its map only from an open document or a path typed into a text field; OK without either ran with no map, and no file picker ever appeared. Confirming the dialog with no map now opens the file picker and runs Displace with the chosen file (smart filters included); Cancel applies nothing. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs.rs | 4 ++ crates/ui-egui/src/filter_dialog.rs | 74 +++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 2930889bab..444f3a0330 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -604,6 +604,10 @@ pub fn confirm(app: &mut PhotocraftApp, id: u64) -> Result { app.filter_preview = None; return Err("dialog has no command".into()); }; + if crate::filter_dialog::needs_displace_map(&cmd, &crate::filter_dialog::params_of(&d.fields)) { + app.filter_preview = None; + return crate::filter_dialog::ask_displace_map(app, cmd, d.fields.clone()); + } let (cmd, params) = crate::smart_ui::confirm_command(&d.fields, cmd, crate::filter_dialog::params_of(&d.fields)); let result = app.run(&cmd, params.clone()); // A filter that runs as a background job keeps its preview on screen until the job diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rs index 3da0735204..fa3336a6cf 100644 --- a/crates/ui-egui/src/filter_dialog.rs +++ b/crates/ui-egui/src/filter_dialog.rs @@ -846,6 +846,42 @@ pub fn params_of(f: &Map) -> Value { Value::Object(f.iter().filter(|(k, v)| !k.starts_with("__") && !unset(k, v)).map(|(k, v)| (k.clone(), v.clone())).collect()) } +/// Filter › Distort › Displace confirmed with no map: no open document picked and no path typed +/// (#5806). Photoshop asks for the displacement map file after OK; so does PhotoCraft. +pub(crate) fn needs_displace_map(command: &str, params: &Value) -> bool { + command == "filter.distort.displace" + && params.get("mapPath").and_then(Value::as_str).is_none_or(|p| p.trim().is_empty()) + && params.get("mapDocument").and_then(Value::as_i64).is_none_or(|i| i < 0) +} + +/// Asks for the displacement map, then runs Displace with the dialog's values and that file, as +/// OK in a dialog that had one would (smart filters included). Cancel applies nothing. In the +/// browser the picker gives contents, not a path the filter can read: the map has to be opened +/// as a document and picked as Map Document there. +pub(crate) fn ask_displace_map(app: &mut PhotocraftApp, command: String, fields: Map) -> Result { + use crate::file_dialog::{FileDialogAnswer, FileDialogRequest}; + let initial_dir = crate::file_dialog::last_used_dir(&app.ui.recent_files); + app.ask_file(FileDialogRequest::Open { multiple: false, initial_dir, extensions: None }, move |app, answer| { + let path = match answer { + FileDialogAnswer::Paths(paths) => paths.into_iter().next().ok_or("no displacement map was chosen")?, + FileDialogAnswer::Unavailable(e) => return Err(e), + FileDialogAnswer::Contents(..) | FileDialogAnswer::ContentsMany(_) => { + return Err("open the displacement map as a document, then choose it as the Map Document".into()); + } + FileDialogAnswer::SaveTo(_) | FileDialogAnswer::FolderTo(_) => return Err("unexpected answer from the file dialog".into()), + }; + let mut fields = fields; + fields.insert("mapPath".into(), json!(path)); + let (cmd, params) = crate::smart_ui::confirm_command(&fields, command, params_of(&fields)); + let result = app.run(&cmd, params); + if result.is_ok() { + remember(app, &cmd, &fields); + crate::actions::resume(app, &fields); + } + result + }) +} + /// Compute a preview document: run `command` with `params` on the proxy (scaled) copy of `doc`. pub fn preview_document(doc: &Document, active: Option, command: &str, params: &Value, k: u32) -> Option { preview_document_with(doc, active, command, params, k, None) @@ -1110,6 +1146,44 @@ mod tests { assert!(app.ui.dialogs.iter().any(|d| d.id == id)); } + /// #5806: OK in Displace with no map asks for the map file, as Photoshop does, and displaces + /// with the chosen file; Cancel in the picker applies nothing; a map already given runs at once. + #[test] + fn displace_asks_for_its_map_after_ok() { + let dir = std::env::temp_dir().join(format!("photocraft-displace-map-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let map = dir.join("map.png"); + let mut m = photocraft_engine::Session::new(); + m.execute("file.new", json!({"width": 16, "height": 16, "background": "white"})).unwrap(); + std::fs::write(&map, photocraft_io::export(&m.active().unwrap().doc, "map.png", &Default::default()).unwrap().bytes).unwrap(); + let answers = vec![Some(crate::file_dialog::FileDialogAnswer::Paths(vec![map.to_string_lossy().into_owned()])), None]; + let (show, asked) = crate::file_dialog::fake(answers); + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services { file_dialog: Some(show), ..Default::default() }); + app.run("file.new", json!({"width": 16, "height": 16, "background": "white"})).unwrap(); + app.run("select.rect", json!({"x": 0, "y": 0, "width": 8, "height": 16})).unwrap(); + app.run("edit.fill", json!({"color": "#000000"})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + let steps = app.session.active().unwrap().history.past_len(); + let ctx = egui::Context::default(); + let id = open(&mut app, "filter.distort.displace").unwrap(); + crate::dialogs::confirm(&mut app, id).unwrap(); + assert_eq!(asked.borrow().len(), 1, "OK asks for the map"); + app.poll_file_dialog(&ctx, None); + assert_eq!(app.session.active().unwrap().history.past_len(), steps + 1, "Displace ran with the chosen map"); + // Cancelled: nothing is applied. + let id = open(&mut app, "filter.distort.displace").unwrap(); + crate::dialogs::confirm(&mut app, id).unwrap(); + app.poll_file_dialog(&ctx, None); + assert_eq!(asked.borrow().len(), 2); + assert_eq!(app.session.active().unwrap().history.past_len(), steps + 1); + // A map given in the dialog runs without asking. + assert!(!needs_displace_map("filter.distort.displace", &json!({"mapPath": "/maps/x.psd"}))); + assert!(!needs_displace_map("filter.distort.displace", &json!({"mapDocument": 0}))); + assert!(needs_displace_map("filter.distort.displace", &json!({"mapDocument": -1, "mapPath": " "}))); + assert!(!needs_displace_map("filter.blur.gaussianBlur", &json!({}))); + let _ = std::fs::remove_dir_all(&dir); + } + #[test] fn remembering_dialogs_never_persists_paths_or_document_indices() { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); From 1f745a9d451b8dd84d17067bc09c4061b9432d81 Mon Sep 17 00:00:00 2001 From: Higgs32584 Date: Wed, 14 Oct 2026 23:35:31 -0400 Subject: [PATCH 2/4] Tests: Displace's map picker is asked when the frame polls it (#5806) ask_file only queues the request; the file dialog service is called from poll_file_dialog, so the request count is checked after the poll that shows the picker and acts on its answer. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/filter_dialog.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rs index fa3336a6cf..fe2fb213f8 100644 --- a/crates/ui-egui/src/filter_dialog.rs +++ b/crates/ui-egui/src/filter_dialog.rs @@ -1167,8 +1167,10 @@ mod tests { let ctx = egui::Context::default(); let id = open(&mut app, "filter.distort.displace").unwrap(); crate::dialogs::confirm(&mut app, id).unwrap(); - assert_eq!(asked.borrow().len(), 1, "OK asks for the map"); + assert!(app.file_dialog_open(), "OK leaves the map picker pending"); + // The frame shows the picker (the service is asked then) and acts on its answer. app.poll_file_dialog(&ctx, None); + assert_eq!(asked.borrow().len(), 1, "OK asks for the map"); assert_eq!(app.session.active().unwrap().history.past_len(), steps + 1, "Displace ran with the chosen map"); // Cancelled: nothing is applied. let id = open(&mut app, "filter.distort.displace").unwrap(); From 5a17d92f031e35e51a2c56aba9f3b19daff931b1 Mon Sep 17 00:00:00 2001 From: Michael Higgins <55243596+Higgs32584@users.noreply.github.com> Date: Mon, 19 Oct 2026 15:51:30 -0400 Subject: [PATCH 3/4] Modify resume action to discard result Change resume action to ignore the result. --- crates/ui-egui/src/filter_dialog.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rs index 2775c77e1d..8329d57912 100644 --- a/crates/ui-egui/src/filter_dialog.rs +++ b/crates/ui-egui/src/filter_dialog.rs @@ -1033,7 +1033,7 @@ pub(crate) fn ask_displace_map(app: &mut PhotocraftApp, command: String, fields: let result = app.run(&cmd, params); if result.is_ok() { remember(app, &cmd, &fields); - crate::actions::resume(app, &fields); + let _ = crate::actions::resume(app, &fields); } result }) From cd6e2888208ce793b978aa301835d5eda4c83993 Mon Sep 17 00:00:00 2001 From: Higgs32584 Date: Tue, 20 Oct 2026 20:51:42 -0400 Subject: [PATCH 4/4] Displace: the map picker's answer displaces the document that asked If another document was activated while the picker was open, the filter ran on that one instead. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/filter_dialog.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rs index 8329d57912..1bc9d107bb 100644 --- a/crates/ui-egui/src/filter_dialog.rs +++ b/crates/ui-egui/src/filter_dialog.rs @@ -1014,9 +1014,11 @@ pub(crate) fn needs_displace_map(command: &str, params: &Value) -> bool { /// Asks for the displacement map, then runs Displace with the dialog's values and that file, as /// OK in a dialog that had one would (smart filters included). Cancel applies nothing. In the /// browser the picker gives contents, not a path the filter can read: the map has to be opened -/// as a document and picked as Map Document there. +/// as a document and picked as Map Document there. It displaces the document that asked, even +/// when another one was activated while the picker was open. pub(crate) fn ask_displace_map(app: &mut PhotocraftApp, command: String, fields: Map) -> Result { use crate::file_dialog::{FileDialogAnswer, FileDialogRequest}; + let doc = app.active_doc_id()?; let initial_dir = crate::file_dialog::last_used_dir(&app.ui.recent_files); app.ask_file(FileDialogRequest::Open { multiple: false, initial_dir, extensions: None }, move |app, answer| { let path = match answer { @@ -1029,6 +1031,7 @@ pub(crate) fn ask_displace_map(app: &mut PhotocraftApp, command: String, fields: }; let mut fields = fields; fields.insert("mapPath".into(), json!(path)); + app.refocus(doc)?; let (cmd, params) = crate::smart_ui::confirm_command(&fields, command, params_of(&fields)); let result = app.run(&cmd, params); if result.is_ok() { @@ -1396,10 +1399,15 @@ mod tests { let id = open(&mut app, "filter.distort.displace").unwrap(); crate::dialogs::confirm(&mut app, id).unwrap(); assert!(app.file_dialog_open(), "OK leaves the map picker pending"); + // Another document activated while the picker is open is left alone. + app.run("file.new", json!({"width": 16, "height": 16, "background": "white"})).unwrap(); + let other_steps = app.session.documents()[1].history.past_len(); // The frame shows the picker (the service is asked then) and acts on its answer. app.poll_file_dialog(&ctx, None); assert_eq!(asked.borrow().len(), 1, "OK asks for the map"); + assert_eq!(app.session.active_index(), Some(0), "the document that asked is shown"); assert_eq!(app.session.active().unwrap().history.past_len(), steps + 1, "Displace ran with the chosen map"); + assert_eq!(app.session.documents()[1].history.past_len(), other_steps, "not on the other document"); // Cancelled: nothing is applied. let id = open(&mut app, "filter.distort.displace").unwrap(); crate::dialogs::confirm(&mut app, id).unwrap();