LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-META-INFO: Selected Photos reads the selection when the active photo is outside it
dotCooCooe25cc3ca0b75
diff --git a/crates/ui-egui/src/headless.rs b/crates/ui-egui/src/headless.rsindex e06903fb0..fe4e255d4 100644--- a/crates/ui-egui/src/headless.rs+++ b/crates/ui-egui/src/headless.rs@@ -3047,6 +3047,37 @@ mod tests {assert_eq!(mixed, ["caption", "city", "copyrightStatus", "gps"]);}+ /// Selected Photos with the active photo outside the selection: the fields show what the+ /// selected photos share, not the active photo's values.+ #[test]+ fn info_selected_photos_ignore_an_active_photo_outside_the_selection() {+ let mut h = demo([1300.0, 1000.0]);+ let t = Duration::from_secs(10);+ let ask = |h: &mut Headless, method: &str, params: serde_json::Value| {+ let r = h.request(method, params.clone(), t);+ assert_eq!(r["ok"], true, "{method} {params}: {r}");+ h.step();+ h.step();+ };+ let exec = |h: &mut Headless, command: &str, params: serde_json::Value| {+ ask(h, "engine.execute", json!({"command": command, "params": params}));+ };+ let ids: Vec<u64> = h.app.session.visible_cloned().iter().take(3).map(|p| p.0).collect();+ let title = |h: &Headless, i: usize| h.app.session.catalog.photo(lightcraft_catalog::PhotoId(ids[i])).unwrap().meta.title.clone();+ exec(&mut h, "photo.setMeta", json!({"ids": [ids[0], ids[1]], "title": "Same"}));+ exec(&mut h, "photo.setMeta", json!({"ids": [ids[2]], "title": "Other"}));+ h.request("ui.set", json!({"view": "detail", "right": "info"}), t);+ exec(&mut h, "library.select", json!({"ids": [ids[0], ids[1]], "active": ids[2]}));+ exec(&mut h, "view.infoSelectedPhotos", json!({"on": true}));+ h.settle(SETTLE);+ ask(&mut h, "ui.clickWidget", json!({"id": "field:title"}));+ ask(&mut h, "ui.key", json!({"key": "End"}));+ ask(&mut h, "ui.text", json!({"text": "!"}));+ ask(&mut h, "ui.key", json!({"key": "Tab"}));+ h.settle(SETTLE);+ assert_eq!((title(&h, 0), title(&h, 1), title(&h, 2)), ("Same!".into(), "Same!".into(), "Other".into()));+ }+/// Local: a folder's photos show without joining the library; the breadcrumb, Include/// subfolders and Add to My Photos work from the grid header.#[test]diff --git a/crates/ui-egui/src/panels/right.rs b/crates/ui-egui/src/panels/right.rsindex 4b88aa20f..e5a454559 100644--- a/crates/ui-egui/src/panels/right.rs+++ b/crates/ui-egui/src/panels/right.rs@@ -674,12 +674,13 @@ fn info(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) {});});divider(ui);- let m = p.meta.clone();// with several photos selected: Target Photo shows this photo's values, Selected Photos what// the selection shares (a field where they differ is empty and says Mixed)let selected = app.session.selected();let several = selected.len() > 1;- let mixed = if several && app.ui.settings.info_selected_photos { mixed_meta(&app.session.catalog, &selected, &m) } else { Vec::new() };+ let for_selected = several && app.ui.settings.info_selected_photos;+ let m = shown_meta(&app.session.catalog, &p, &selected, for_selected);+ let mixed = if for_selected { mixed_meta(&app.session.catalog, &selected, &m) } else { Vec::new() };padded(ui, |ui| {if several {metadata_for(app, ui);@@ -971,6 +972,21 @@ fn meta_text<'a>(m: &'a lightcraft_catalog::Meta, key: &str) -> Option<&'a str>})}+/// The metadata the Info panel's fields show: the active photo `p`'s, or with `for_selected`+/// (Selected Photos) the active photo's when it is one of the `selected` photos, else the first+/// selected photo's.+pub(crate) fn shown_meta(+ catalog: &lightcraft_catalog::Catalog,+ p: &lightcraft_catalog::Photo,+ selected: &[PhotoId],+ for_selected: bool,+) -> lightcraft_catalog::Meta {+ if !for_selected || selected.contains(&p.id) {+ return p.meta.clone();+ }+ selected.iter().find_map(|&id| catalog.photo(id)).map_or_else(|| p.meta.clone(), |q| q.meta.clone())+}+/// The Info panel fields (`photo.setMeta` keys, plus `copyrightStatus` and `gps`) where one of/// the photos `ids` has a value other than `shown`'s, the metadata the panel draws.pub(crate) fn mixed_meta(catalog: &lightcraft_catalog::Catalog, ids: &[PhotoId], shown: &lightcraft_catalog::Meta) -> Vec<&'static str> {