Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #685

Claude9dc0d0b62bf1
diff --cc crates/ui-egui/src/panels/grid.rs
index 37b913d63,e1a962b3b..a63b0b8e9
--- a/crates/ui-egui/src/panels/grid.rs
+++ b/crates/ui-egui/src/panels/grid.rs
@@@ -939,26 -913,26 +939,37 @@@ pub fn context_menu(app: &mut Lightcraf
}
});
ui.menu_button(crate::i18n::tr("Set Color Label"), |ui| label_menu(app, ui));
- let add = ui.menu_button(crate::i18n::tr("Add to Album"), |ui| {
- let albums: Vec<_> = app.session.catalog.albums().filter(|a| !a.folder && !a.is_smart()).map(|a| (a.id.0, a.name.clone())).collect();
- let any = !albums.is_empty();
- for (aid, name) in albums {
- if ui.button(name).clicked() {
- let _ = app.run("album.addPhotos", json!({"id": aid}));
+ if local_only(app, &app.session.targets(&serde_json::Value::Null)) {
+ // albums hold library photos (issue #684): nothing here to add until they join My Photos
+ let add = ui.add_enabled(false, egui::Button::new(crate::i18n::tr("Add to Album"))).on_disabled_hover_text(albums_hint());
+ register(ui.ctx(), "button:contextAddToAlbum", add.rect);
+ } else {
+ let add = ui.menu_button(crate::i18n::tr("Add to Album"), |ui| {
+ let albums: Vec<_> = app.session.catalog.albums().filter(|a| !a.folder && !a.is_smart()).map(|a| (a.id.0, a.name.clone())).collect();
++ let any = !albums.is_empty();
+ for (aid, name) in albums {
+ let b = ui.button(name);
+ register(ui.ctx(), format!("button:contextAlbum:{aid}"), b.rect);
+ if b.clicked() {
+ match app.run("album.addPhotos", json!({"id": aid})) {
+ Ok(r) => toast_skipped(app, ui.ctx(), &r),
+ Err(e) => app.toast(ui.ctx(), e),
+ }
+ }
}
- }
- if any {
- ui.separator();
- }
- // as in the Photo menu: a new album holding the selection, also when there is none yet
- // to pick (issue #676: the submenu came up empty)
- let new = ui.button(crate::i18n::tr("New Album…"));
- register(ui.ctx(), "button:contextNewAlbum", new.rect);
- if new.clicked() {
- let _ = app.run("dialog.newAlbum", json!({}));
- }
- });
- register(ui.ctx(), "button:contextAddToAlbum", add.response.rect);
++ if any {
++ ui.separator();
++ }
++ // as in the Photo menu: a new album holding the selection, also when there is none yet
++ // to pick (issue #676: the submenu came up empty)
++ let new = ui.button(crate::i18n::tr("New Album…"));
++ register(ui.ctx(), "button:contextNewAlbum", new.rect);
++ if new.clicked() {
++ let _ = app.run("dialog.newAlbum", json!({}));
++ }
+ });
+ register(ui.ctx(), "button:contextAddToAlbum", add.response.rect);
+ }
// in a (non-smart) album: take the selection out of it, or make this photo its cover
if let lightcraft_engine::LibrarySource::Album(aid) = app.session.source
&& app.session.catalog.album(aid).is_some_and(|a| !a.folder && !a.is_smart())
diff --cc crates/ui-egui/src/tests_panels.rs
index 684876373,ce7cc2775..f9f93359f
--- a/crates/ui-egui/src/tests_panels.rs
+++ b/crates/ui-egui/src/tests_panels.rs
@@@ -1183,144 -1183,42 +1183,183 @@@ fn the_tracklog_toast_shows_after_a_whi
let _ = std::fs::remove_dir_all(&dir);
}
++<<<<<<< HEAD
+/// Issue #678: Settings ▸ Faces cannot switch recognition on until a recognition model is chosen:
+/// the box is off and clicking it changes nothing. Installing a model switches recognition on by
+/// itself, and from then on the box turns it off and on.
+#[test]
+fn recognise_faces_stays_off_until_a_model_is_chosen() {
+ let mut h = demo([1400.0, 900.0], json!({"view": "photoGrid"}));
+ let dir = std::env::temp_dir().join(format!("lc-ui-faces-toggle-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(&dir).unwrap();
+ h.app.session.face_models_dir = Some(dir.join("models"));
+ let r = h.request("engine.execute", json!({"command": "app.settings", "params": {"tab": "faces"}}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.settle(SETTLE);
+ // (the first request switches the widget list on, the next frame fills it)
+ h.request("ui.widgets", json!({}), T);
+ h.step();
+ let enabled = |h: &mut Headless| h.app.session.execute("faces.models.list", &json!({})).unwrap()["enabled"] == true;
+ let runtime = h.app.session.execute("faces.models.list", &json!({})).unwrap()["runtime"] == true;
+ assert!(!enabled(&mut h));
+ let click = |h: &mut Headless| {
+ let r = h.request("ui.clickWidget", json!({"id": "check:settings.facesEnabled"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ };
+ click(&mut h);
+ assert!(!enabled(&mut h), "nothing to run: the box stays off");
+ assert!(h.app.session.execute("faces.enable", &json!({"enabled": true})).is_err(), "the engine refuses too");
+ if !runtime {
+ let _ = std::fs::remove_dir_all(&dir);
+ return;
+ }
+ // a model: installing it chooses it and switches recognition on; the box then works both ways
+ let f = dir.join("m.onnx");
+ std::fs::write(&f, lightcraft_faces::synthetic::tiny_embedder_model(64)).unwrap();
+ h.app.session.execute("faces.models.install", &json!({"path": f.to_string_lossy(), "acknowledged": true})).unwrap();
+ h.app.caches.faces_epoch += 1;
+ h.step();
+ h.step();
+ assert!(enabled(&mut h));
+ click(&mut h);
+ assert!(!enabled(&mut h), "the box switches recognition off");
+ click(&mut h);
+ assert!(enabled(&mut h), "and on again, with a model chosen");
+}
+
+/// Issue #684: albums hold library photos. For a browsed (Local) photo the grid's right-click
+/// Add to Album is off, Photo ▸ Add to Album says to Add to My Photos first with its entries off,
+/// and a drop onto an album row is refused with that hint; once the photo is in My Photos all
+/// three work.
+#[test]
+fn local_photos_cannot_be_added_to_albums_until_they_join_my_photos() {
+ let mut h = demo([1400.0, 900.0], json!({"view": "photoGrid", "leftPanel": true}));
+ let album = h.app.session.execute("album.create", &json!({"name": "Trip", "addSelected": false})).unwrap()["id"].as_u64().unwrap();
+ let album_id = lightcraft_catalog::AlbumId(album);
+ let dir = std::env::temp_dir().join(format!("lc-ui-albums-local-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(&dir).unwrap();
+ let img = lightcraft_raster::Rgba8::from_fn(24, 16, |x, y| [(x * 9) as u8, (y * 12) as u8, 80, 255]);
+ let o = lightcraft_engine::export::ExportOptions { format: lightcraft_engine::export::ExportFormat::Png, ..Default::default() };
+ std::fs::write(dir.join("a.png"), lightcraft_engine::export::encode_image(&img, &o).unwrap()).unwrap();
+ let r = h.request("engine.execute", json!({"command": "library.browse", "params": {"path": dir.to_string_lossy()}}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.settle(SETTLE);
+ let vis = h.app.session.visible_cloned();
+ assert_eq!(vis.len(), 1, "{vis:?}");
+ let local = vis[0];
+ assert!(h.app.session.catalog.photo(local).unwrap().local);
+ let thumb = widget(&h, &format!("thumb:{}", local.0));
+
+ // right-click: Add to Album is there but off, so hovering opens no album entries
++=======
+ /// Issue #676: right-click ▸ Add to Album offers New Album… like the Photo menu does, also when
+ /// the library has no album yet (the submenu used to come up empty); the new album holds the photo.
+ #[test]
+ fn right_click_add_to_album_offers_a_new_album_when_there_is_none() {
+ let mut h = demo([1400.0, 900.0], json!({"view": "photoGrid", "leftPanel": true}));
+ let plain: Vec<u64> = h.app.session.catalog.albums().filter(|a| !a.folder && !a.is_smart()).map(|a| a.id.0).collect();
+ for id in plain {
+ h.app.session.execute("album.delete", &json!({"id": id})).unwrap();
+ }
+ assert!(h.app.session.catalog.albums().all(|a| a.folder || a.is_smart()), "no plain album is left");
+ let photo = lightcraft_catalog::PhotoId(h.app.session.visible_cloned()[1].0);
+ h.step();
+ let thumb = widget(&h, &format!("thumb:{}", photo.0));
++>>>>>>> pr/685
let r = h.request("ui.click", json!({"x": thumb.center().x, "y": thumb.center().y, "button": "right"}), T);
assert_eq!(r["ok"], true, "{r}");
h.step();
h.step();
++<<<<<<< HEAD
+ assert!(h.app.session.selection.contains(local));
++=======
+ assert!(h.app.session.selection.contains(photo), "right-click selects the photo");
++>>>>>>> pr/685
let r = h.request("ui.hoverWidget", json!({"id": "button:contextAddToAlbum"}), T);
assert_eq!(r["ok"], true, "{r}");
h.step();
h.step();
++<<<<<<< HEAD
+ assert!(!h.app.widgets.iter().any(|(w, _)| w.starts_with("button:contextAlbum:")), "the submenu must not open for a Local photo");
+ let r = h.request("ui.key", json!({"key": "Escape"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+
+ // Photo ▸ Add to Album: the hint item first (off), the album and New Album… off
+ let add_to_album = |app: &LightcraftApp| -> Vec<crate::menubar::MenuNode> {
+ let bar = crate::menubar::menu_bar(app);
+ let photo = &bar.iter().find(|(t, _)| t == "Photo").expect("Photo menu").1;
+ photo
+ .iter()
+ .find_map(|n| match n {
+ crate::menubar::MenuNode::Submenu { label, children } if label == "Add to Album" => Some(children.clone()),
+ _ => None,
+ })
+ .expect("Add to Album submenu")
+ };
+ let enabled_of = |nodes: &[crate::menubar::MenuNode], id: &str| -> Option<bool> {
+ nodes.iter().find_map(|n| match n {
+ crate::menubar::MenuNode::Item { id: i, enabled, .. } if i == id => Some(*enabled),
+ _ => None,
+ })
+ };
+ let nodes = add_to_album(&h.app);
+ assert!(matches!(nodes.first(), Some(crate::menubar::MenuNode::Item { id, enabled: false, .. }) if id == "photo.addToLibrary"), "{nodes:?}");
+ assert_eq!(enabled_of(&nodes, "album.addPhotos"), Some(false), "{nodes:?}");
+ assert_eq!(enabled_of(&nodes, "dialog.newAlbum"), Some(false), "{nodes:?}");
+
+ // a drop onto the album row is refused and says why
+ let row = widget(&h, &format!("source:album:{album}"));
+ let r = h.request("ui.drag", json!({"x": thumb.center().x, "y": thumb.center().y, "toX": row.center().x, "toY": row.center().y, "steps": 12}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.settle(SETTLE);
+ assert!(h.app.session.catalog.album(album_id).unwrap().photos.is_empty(), "nothing invisible was added");
+ assert!(h.app.ui.dragging_photos.is_none(), "the drag ended");
+ let toast = h.app.ui.toast.as_ref().map(|t| t.0.clone()).unwrap_or_default();
+ assert!(toast.contains("Add to My Photos first"), "{toast:?}");
+
+ // in My Photos: the menu entries come on, the submenu opens, and the album takes the photo
+ h.app.run("photo.addToLibrary", json!({"ids": [local.0]})).unwrap();
+ h.step();
+ let nodes = add_to_album(&h.app);
+ assert!(!matches!(nodes.first(), Some(crate::menubar::MenuNode::Item { id, .. }) if id == "photo.addToLibrary"), "{nodes:?}");
+ assert_eq!(enabled_of(&nodes, "album.addPhotos"), Some(true), "{nodes:?}");
+ assert_eq!(enabled_of(&nodes, "dialog.newAlbum"), Some(true), "{nodes:?}");
+ let thumb = widget(&h, &format!("thumb:{}", local.0));
+ let r = h.request("ui.click", json!({"x": thumb.center().x, "y": thumb.center().y, "button": "right"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ let r = h.request("ui.hoverWidget", json!({"id": "button:contextAddToAlbum"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ let r = h.request("ui.clickWidget", json!({"id": format!("button:contextAlbum:{album}")}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ assert_eq!(h.app.session.catalog.album(album_id).unwrap().photos, vec![local]);
+ let _ = std::fs::remove_dir_all(&dir);
++=======
+ let r = h.request("ui.clickWidget", json!({"id": "button:contextNewAlbum"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ match &mut h.app.ui.dialog {
+ Some(crate::state::Dialog::NewAlbum { name, folder: false, parent: None }) => *name = "Trip".into(),
+ other => panic!("New Album dialog expected, got {other:?}"),
+ }
+ h.step();
+ let r = h.request("ui.clickWidget", json!({"id": "button:dialogOk"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ let trip = h.app.session.catalog.albums().find(|a| a.name == "Trip").expect("the album was created");
+ assert!(trip.photos.contains(&photo), "the right-clicked photo is in it: {:?}", trip.photos);
+ assert!(h.app.ui.dialog.is_none(), "{:?}", h.app.ui.dialog);
++>>>>>>> pr/685
}
diff --cc docs/parity-checklist.md
index 33544c2b8,cbfd17206..1e3f4ae15
--- a/docs/parity-checklist.md
+++ b/docs/parity-checklist.md
@@@ -93,7 -93,7 +93,7 @@@ differences and missing bindings are i
| LR-LIB-ALLPHOTOS | All photos | P0 | ✅ | `cmd:library.source`, `crates/ui-egui/src/panels/left.rs` | |
| LR-LIB-RECENT-ADDED | Recently added | P1 | ✅ | `cmd:library.source` (`recentlyAdded`), `crates/engine/src/view.rs` (`RECENT_DAYS`) | photos imported in the 30 days up to the latest import, newest import first, grouped by import day |
| LR-LIB-BYDATE | Browse by date | P1 | ✅ | `cmd:library.filter` (`date`), `crates/ui-egui/src/panels/left.rs` (`date_row`), `crates/catalog/src/query.rs` (`date_groups`) | year → month → day tree with library-wide counts; a row filters the current source by that date. Active filters show as removable chips under the grid header (`crates/ui-egui/src/panels/chips.rs`, with “+N more” and Clear all), the header counts “N of M photos” (matching of the source's total), a badge on the top-bar filter icon counts them, and an empty result says no photos match the active filters |
- | LR-LIB-ALBUM | Albums | P0 | ✅ | `cmd:album.create`, `cmd:album.rename`, `cmd:album.delete`, `cmd:album.addPhotos`, `cmd:album.removePhotos`, `cmd:dialog.newAlbum`, `crates/engine/src/tests_albums_local.rs`, `crates/ui-egui/src/tests_panels.rs` | photos dragged from the grid onto an album row are added to it (LR-BEHAV-DRAGDROP); albums hold library photos (issue #684): `album.create {addSelected}`, `album.addPhotos` and `album.toggleTarget` (B) skip browsed Local photos and return `skipped` (a toast says so), a Local-only selection is an error and leaves Photo ▸ Add to Album, the grid's right-click Add to Album, a folder row's Add Selected Photos and a drop onto an album row off with the hint to Add to My Photos first (`button:contextAddToAlbum`, `button:contextAlbum:<id>`) |
-| LR-LIB-ALBUM | Albums | P0 | ✅ | `cmd:album.create`, `cmd:album.rename`, `cmd:album.delete`, `cmd:album.addPhotos`, `cmd:album.removePhotos`, `cmd:dialog.newAlbum`, `crates/ui-egui/src/panels/grid.rs` (`context_menu`) | photos dragged from the grid onto an album row are added to it (LR-BEHAV-DRAGDROP); right-click a photo ▸ Add to Album lists the albums and ends with New Album…, which creates one holding the selection — also when the library has no album yet (issue #676; `button:contextAddToAlbum`, `button:contextNewAlbum`) |
++| LR-LIB-ALBUM | Albums | P0 | ✅ | `cmd:album.create`, `cmd:album.rename`, `cmd:album.delete`, `cmd:album.addPhotos`, `cmd:album.removePhotos`, `cmd:dialog.newAlbum`, `crates/engine/src/tests_albums_local.rs`, `crates/ui-egui/src/tests_panels.rs` | photos dragged from the grid onto an album row are added to it (LR-BEHAV-DRAGDROP); albums hold library photos (issue #684): `album.create {addSelected}`, `album.addPhotos` and `album.toggleTarget` (B) skip browsed Local photos and return `skipped` (a toast says so), a Local-only selection is an error and leaves Photo ▸ Add to Album, the grid's right-click Add to Album, a folder row's Add Selected Photos and a drop onto an album row off with the hint to Add to My Photos first (`button:contextAddToAlbum`, `button:contextAlbum:<id>`); right-click a photo ▸ Add to Album lists the albums and ends with New Album…, which creates one holding the selection — also when the library has no album yet (issue #676; `button:contextNewAlbum`) |
| LR-LIB-FOLDER | Folders of albums | P0 | ✅ | `cmd:album.create` (`folder`, `parent`), `cmd:album.move`, `cmd:album.reorder`, `cmd:album.sort`, `cmd:dialog.newAlbum` / `cmd:dialog.newFolder` / `cmd:dialog.smartAlbum` / `cmd:dialog.newSmartAlbum` (`parent`), `crates/ui-egui/src/panels/left.rs` (`albums_tree`, `folder_menu`, `disclosure_triangle`), `crates/ui-egui/src/tests_panels.rs` | Delete removes a folder and its nested albums as one undoable edit, keeps photos in the library and returns a deleted album view to All Photos (issue #501); folders nest and fold with the same disclosure triangle as Local / By Date / Folders / Keywords (`albumToggle:<id>`; the row folds them too; open by default); right-click a folder ▸ New ▸ Create Album… / Create Smart Album… / Create Smart Album from Filter… / Create Folder… creates inside it (the `dialog.new*` commands take `parent`), opening the folders down to the new row; creating is only allowed inside folders; moving: drag an album or folder row onto a folder (outlined when allowed; a closed folder opens after 0.6 s under the pointer; the "Albums" header takes an item that sits in a folder back to the top level while it is dragged), the Move to menu or `album.move` — one undo step each; not onto a plain album, itself or something inside it; drop on the top / bottom half of an album or the edge of a folder to place it there by hand (`cmd:album.reorder`, a line shows the place; ordered per folder, folders stay first, new albums go after the ordered ones; right-click ▸ Sort Contents A–Z or + ▸ Sort Albums A–Z = `cmd:album.sort`) |
| LR-LIB-SMARTALBUM | Smart albums | P1 | ✅ | `cmd:album.createSmart`, `cmd:album.setRules`, `crates/catalog/src/query.rs`, `crates/ui-egui/src/panels/filterbar.rs`, `crates/ui-egui/src/lib.rs` (`album_counts`) | saved filters (rating/flag/label/kind/edited/keyword/camera/lens/date range/text/album) or a rule set from the rule editor (match all / any / none, nested groups; see LRC-LIB-SMARTCOLL), live; sidebar counts are cached per catalog revision (and per minute while an “in the last…” rule is used), counted without building id lists |
| LR-LIB-SHARED-ALBUM | Shared albums | P2 | ⬜ | | needs a sharing service |