diff --git a/crates/ui-egui/src/prefs/prefs_ui/fields.rs b/crates/ui-egui/src/prefs/prefs_ui/fields.rs index 1942c3d1e0..d56107481c 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/fields.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/fields.rs @@ -87,6 +87,9 @@ fn language_label(ctx: &egui::Context, native: &str, code: &str) -> String { if can_draw { native.to_string() } else { code.to_string() } } +/// The order RAW Defaults lists its color spaces in; a space not named here comes last. +const RAW_SPACE_ORDER: [&str; 4] = ["adobeRgb", "displayP3", "proPhoto", "srgb"]; + /// The rules of every setting from the engine's schema: choices, ranges, colours, hidden settings, the ones read /// at launch, and the labels and groups the window shows. pub(super) fn rules(ctx: &egui::Context) -> Vec { @@ -108,7 +111,10 @@ pub(super) fn rules(ctx: &egui::Context) -> Vec { let refs: Vec<(&str, &str)> = pairs.iter().map(|(id, label)| (id.as_str(), label.as_str())).collect(); tweak(&mut rules, &path, |r| r.choices(&refs)); } else if let Some(options) = prefs::choices(&path) { - let labelled: Vec<(&str, String)> = options.iter().map(|id| (*id, choice_label(id))).collect(); + let mut labelled: Vec<(&str, String)> = options.iter().map(|id| (*id, choice_label(id))).collect(); + if path == "rawDefaults.colorSpace" { + labelled.sort_by_key(|(id, _)| RAW_SPACE_ORDER.iter().position(|o| o == id).unwrap_or(usize::MAX)); + } let refs: Vec<(&str, &str)> = labelled.iter().map(|(id, label)| (*id, label.as_str())).collect(); tweak(&mut rules, &path, |r| r.choices(&refs)); } else if let Some((lo, hi)) = prefs::range(&path) { @@ -231,6 +237,9 @@ fn label_override(key: &str) -> Option<&'static str> { "lowLatencyDrawing" => "Low-Latency Drawing (vsync off, applies at next launch)", "sizeLimitMb" => "Scratch Size Limit (MB, 0 = No Limit)", "gpuMemoryMb" => "GPU Memory (MB, 0 = Automatic)", + "openInCameraRaw" => "Open in RAW Develop", + "openAsSmartObject" => "Open as Smart Object", + "writeXmpSidecars" => "Write XMP sidecars", _ => return None, }) } @@ -255,6 +264,13 @@ pub(super) fn choice_label(v: &str) -> String { "ahd" => "AHD (adaptive homogeneity)".into(), "mhc" => "Malvar–He–Cutler".into(), "cpu" => "CPU (no GPU acceleration)".into(), + // The print dialog's name for this space, so one catalog key covers both. + "adobeRgb" => "Adobe RGB (1998) compatible".into(), + "displayP3" => "Display P3".into(), + "proPhoto" => "ProPhoto RGB".into(), + "srgb" => "sRGB IEC61966-2.1".into(), + "glossy" => "Glossy Paper".into(), + "matte" => "Matte Paper".into(), v => spelled(v), } } @@ -305,3 +321,7 @@ mod language_label_tests { assert!(!rules(&ctx).is_empty()); } } + +#[cfg(test)] +#[path = "../raw_defaults_labels_tests.rs"] +mod raw_defaults_labels_tests; diff --git a/crates/ui-egui/src/prefs/raw_defaults_labels_tests.rs b/crates/ui-egui/src/prefs/raw_defaults_labels_tests.rs new file mode 100644 index 0000000000..758d2fd24f --- /dev/null +++ b/crates/ui-egui/src/prefs/raw_defaults_labels_tests.rs @@ -0,0 +1,46 @@ +//! Preferences > RAW Defaults shows proper names instead of words spelled out from the stored ids (#17770). + +use craft::i18n::Folder; +use craft::i18n::matcher::Matcher; +use craft::ui::patterns::preferences::{PreferencesModel, RowKind, SettingsDocument, row_matches}; +use photocraft_engine::prefs; + +use super::{PrefPages, choice_label, rules, spelled}; + +/// The labels hang on stored ids written as text, so a renamed id would silently fall back to `spelled`. +#[test] +fn raw_choices_have_names_of_their_own() { + for (path, ids) in [("rawDefaults.colorSpace", &["adobeRgb", "displayP3", "proPhoto", "srgb"][..]), ("rawDefaults.sharpenFor", &["glossy", "matte"][..])] { + let offered = prefs::choices(path).expect("a choice setting"); + for id in ids { + assert!(offered.contains(id), "{path} no longer offers {id}"); + assert_ne!(choice_label(id), spelled(id), "{path}: {id}"); + } + } +} + +#[test] +fn preferences_search_finds_the_raw_develop_switch() { + let doc = SettingsDocument::new(PrefPages::default()).expect("the default preferences").rules(rules(&egui::Context::default())); + let matcher = Matcher::new(&Folder::new("en"), "RAW Develop"); + let pages = PreferencesModel::pages(&doc); + let found: Vec<&str> = pages.iter().flat_map(|p| &p.groups).flat_map(|g| &g.rows).filter(|r| row_matches(&matcher, r)).map(|r| r.key).collect(); + assert!(found.contains(&"rawDefaults.openInCameraRaw"), "{found:?}"); +} + +/// The list is reordered for display only: every stored color space is still offered, each under its own id. +#[test] +fn raw_color_spaces_are_reordered_without_losing_one() { + let doc = SettingsDocument::new(PrefPages::default()).expect("the default preferences").rules(rules(&egui::Context::default())); + let pages = PreferencesModel::pages(&doc); + let row = pages.iter().flat_map(|p| &p.groups).flat_map(|g| &g.rows).find(|r| r.key == "rawDefaults.colorSpace").expect("the row"); + let RowKind::Choice { options, .. } = &row.kind else { panic!("not a choice row") }; + let shown: Vec = options.iter().filter_map(|o| o.value().map(|v| v.to_string())).collect(); + let stored: Vec = prefs::choices("rawDefaults.colorSpace").expect("a choice setting").iter().map(|id| id.to_string()).collect(); + assert_ne!(shown, stored, "the stored order is shown"); + let sorted = |mut ids: Vec| { + ids.sort(); + ids + }; + assert_eq!(sorted(shown), sorted(stored)); +}