Color Lookup: keep a picked LUT folder file clearable after it leaves the folder

A file picked from the LUT folder is remembered in a private __folderLut field,
so the menu keeps showing it even once a later scan no longer lists it, and
picking another entry still clears file instead of sending a missing path to
the command.
This commit is contained in:
Luis committed 2026-10-27 11:37:57 +01:00
1 parent 3fa692a082
commit fcfabd4878
2 files changed
+30 -3

No files matched your search

+21 -3
View File
@@ -428,9 +428,12 @@ fn apply_command_defaults(app: &PhotocraftApp, command: &str, fields: &mut Map<S
/// Image › Adjustments › Color Lookup: its 3D LUT menu lists the LUT folder's files after the
/// built-in looks (#9754), as the adjustment layer's Properties do. `__lutFolder` is the folder
/// (Preferences › File Handling › LUT Folder); a file picked from it goes to `file`.
/// (Preferences › File Handling › LUT Folder); a file picked from it goes to `file`, and
/// `__folderLut` remembers that pick, so it stays a menu entry even once the file has left the
/// folder.
const COLOR_LOOKUP: &str = "image.adjustments.colorLookup";
const LUT_FOLDER: &str = "__lutFolder";
const FOLDER_LUT_PICK: &str = "__folderLut";
/// The `lut` value to keep after the Color Lookup menu chose `cur`: a LUT folder file is set as
/// `file` with `lut` at `none`. Leaving a folder file the menu showed (`was_folder`) for another
@@ -438,14 +441,24 @@ const LUT_FOLDER: &str = "__lutFolder";
fn pick_folder_lut(f: &mut Map<String, Value>, 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<String, Value>, 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<String, Value>) {
let luts = lut_folder.map(|d| crate::adjust_ui::folder_luts(d, ui.ctx())).unwrap_or_default();
let lut_keys: Vec<String> = 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 {
@@ -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));
}