diff --git a/crates/ui-egui/src/dialogs/filter_dialog.rs b/crates/ui-egui/src/dialogs/filter_dialog.rs index 1126e67660..9df3ad8f6d 100644 --- a/crates/ui-egui/src/dialogs/filter_dialog.rs +++ b/crates/ui-egui/src/dialogs/filter_dialog.rs @@ -428,9 +428,12 @@ fn apply_command_defaults(app: &PhotocraftApp, command: &str, fields: &mut Map, cur: String, was_folder: bool) -> String { if let Some(path) = cur.strip_prefix(crate::adjust_ui::FOLDER_LUT) { f.insert("file".into(), json!(path)); + f.insert(FOLDER_LUT_PICK.into(), json!(path)); return "none".into(); } if was_folder { f.insert("file".into(), json!("")); + f.remove(FOLDER_LUT_PICK); } cur } +/// Whether the Color Lookup menu shows `file` as a LUT folder entry: it is in the folder's scan +/// (`luts`), or it was picked from the menu and has left the folder since. +fn shows_folder_lut(f: &Map, cur: &str, luts: &[(String, String)]) -> bool { + let file = f.get("file").and_then(Value::as_str).unwrap_or_default(); + let picked = f.get(FOLDER_LUT_PICK).and_then(Value::as_str) == Some(file); + cur == "none" && !file.is_empty() && (picked || luts.iter().any(|(_, path)| path == file)) +} + /// Assign Profile offers only the profiles the document's colour mode can take (#4951): the /// command refuses one of another colour space. `__profiles` lists them for the `profile` menu, /// and a remembered choice that doesn't fit this document falls back to the working space. @@ -920,11 +933,16 @@ pub fn body(ui: &mut egui::Ui, f: &mut Map) { let luts = lut_folder.map(|d| crate::adjust_ui::folder_luts(d, ui.ctx())).unwrap_or_default(); let lut_keys: Vec = luts.iter().map(|(_, path)| format!("{}{path}", crate::adjust_ui::FOLDER_LUT)).collect(); opts.extend(lut_keys.iter().cloned().zip(luts.iter().map(|(name, _)| name.as_str()))); - // A folder file is kept as `lut: none` + `file`: show it by its name. + // A folder file is kept as `lut: none` + `file`: show it by its name, also once + // it has left the folder, so picking another entry still clears `file`. let file = f.get("file").and_then(Value::as_str).unwrap_or_default(); - let was_folder = cur == "none" && !file.is_empty() && luts.iter().any(|(_, path)| path == file); + let was_folder = shows_folder_lut(f, &cur, &luts); + let gone_name = std::path::Path::new(file).file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default(); if was_folder { cur = format!("{}{file}", crate::adjust_ui::FOLDER_LUT); + if !opts.iter().any(|(v, _)| *v == cur) { + opts.push((cur.clone(), gone_name.as_str())); + } } crate::widgets::dropdown(ui, &format!("flt-{cmd}-{}", p.key), &label(&p.key), &mut cur, &opts, 170.0); if folder_lut { diff --git a/crates/ui-egui/src/dialogs/filter_dialog/tests.rs b/crates/ui-egui/src/dialogs/filter_dialog/tests.rs index fefa6de163..7b62478c1a 100644 --- a/crates/ui-egui/src/dialogs/filter_dialog/tests.rs +++ b/crates/ui-egui/src/dialogs/filter_dialog/tests.rs @@ -504,8 +504,17 @@ fn color_lookup_dialog_lists_and_applies_lut_folder_files() { // Leaving it for a built-in look drops the file, so the look applies. assert_eq!(pick_folder_lut(&mut f, "warm".into(), true), "warm"); assert_eq!(f["file"], json!("")); + // A picked file that has left the folder since (no longer in the scan) still shows as its + // entry, so leaving it for a built-in look still drops the file. + assert_eq!(pick_folder_lut(&mut f, key.clone(), false), "none"); + let was_folder = shows_folder_lut(&f, "none", &[]); + assert!(was_folder); + assert_eq!(pick_folder_lut(&mut f, "warm".into(), was_folder), "warm"); + assert_eq!(f["file"], json!("")); + assert!(!f.contains_key(FOLDER_LUT_PICK)); // A path typed into File isn't touched by a built-in pick. f.insert("file".into(), json!(path)); + assert!(!shows_folder_lut(&f, "none", &[])); assert_eq!(pick_folder_lut(&mut f, "cool".into(), false), "cool"); assert_eq!(f["file"], json!(path)); }