Skip to content

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

Merge PR #1242

bflatasticedfe7c63511c
diff --cc crates/ui-egui/src/tests_panels.rs
index 56ad96c7d,0fa5a2d45..901c36d3d
--- a/crates/ui-egui/src/tests_panels.rs
+++ b/crates/ui-egui/src/tests_panels.rs
@@@ -2199,74 -2142,44 +2199,114 @@@ fn right_click_add_to_album_offers_a_ne
assert!(h.app.ui.dialog.is_none(), "{:?}", h.app.ui.dialog);
}
+/// An album's context menu ▸ Import ▸ Import from Folder… (and Import Photos…, Import from Device)
+/// opens the import review with that album chosen; a folder row doesn't offer it, and an `album`
+/// the review can't offer (a folder, or an album deleted while the scan ran) leaves its album empty.
+#[test]
+fn an_album_menu_imports_into_that_album() {
+ let dir = std::env::temp_dir().join(format!("lc-ui-album-import-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(&dir).unwrap();
+ for i in 0..2u8 {
+ let (w, h) = (40usize, 30usize);
+ let data: Vec<[u8; 4]> = (0..w * h).map(|k| [(k % w * 6) as u8, i * 90, (k / w * 8) as u8, 255]).collect();
+ let img = lightcraft_raster::Rgba8 { width: w, height: h, data };
+ let png = lightcraft_codecs::encode_png(&lightcraft_codecs::EncodeImage::rgba8(&img), &lightcraft_codecs::EncodeMeta::default()).unwrap();
+ std::fs::write(dir.join(format!("card{i}.png")), png).unwrap();
+ }
+ let picked = dir.to_string_lossy().to_string();
+ let services = Services { png: None, pick_folder: Some(Box::new(move || Some(picked.clone()))), ..Default::default() };
+ let app = LightcraftApp::new(lightcraft_engine::Session::with_demo().with_fs(), services);
+ let mut h = Headless::new(app, [1400.0, 900.0], 1.0);
+ let r = h.request("ui.set", json!({"view": "photoGrid", "leftPanel": true}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.settle(SETTLE);
+ // the demo's top-level album and album folder, both shown in the sidebar
+ let id_of = |name: &str| h.app.session.catalog.albums().find(|a| a.name == name).map(|a| a.id.0).expect(name);
+ let (album, folder) = (id_of("Garden"), id_of("Travel 2026"));
+ let right_click = |h: &mut Headless, id: &str| {
+ let row = widget(h, id);
+ let r = h.request("ui.click", json!({"x": row.center().x, "y": row.center().y, "button": "right"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ };
+ let review_album = |h: &mut Headless| {
+ h.step_until(SETTLE, |h| matches!(h.app.ui.dialog, Some(crate::state::Dialog::Import { .. })));
+ let Some(crate::state::Dialog::Import { opts }) = &h.app.ui.dialog else { panic!("no import review: {:?}", h.app.ui.dialog) };
+ let chosen = opts.album;
+ h.app.ui.dialog = None;
+ chosen
+ };
+
+ // a folder row has no Import
+ right_click(&mut h, &format!("source:folder:{folder}"));
+ assert!(!has(&h, "button:albumImport"), "folders hold no photos");
+ let r = h.request("ui.key", json!({"key": "Escape"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+
+ // an album's menu: Import ▸ Import from Folder… → the (stubbed) folder dialog → the review, album chosen
+ right_click(&mut h, &format!("source:album:{album}"));
+ let r = h.request("ui.hoverWidget", json!({"id": "button:albumImport"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ h.step();
+ for way in ["button:albumImportPhotos", "button:albumImportFolder", "button:albumImportDevice"] {
+ assert!(has(&h, way), "{way} is offered");
+ }
+ let r = h.request("ui.clickWidget", json!({"id": "button:albumImportFolder"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ assert_eq!(review_album(&mut h), Some(album));
+
+ // Import Photos… passes the album the same way
+ let r = h.request("engine.execute", json!({"command": "file.addPhotos", "params": {"paths": [dir.to_string_lossy()], "album": album}}), T);
+ assert_eq!(r["result"]["scanning"], true, "{r}");
+ assert_eq!(review_album(&mut h), Some(album));
+
+ // an album the review can't offer (here a folder) is not chosen
+ let r = h.request("engine.execute", json!({"command": "file.addPhotos", "params": {"paths": [dir.to_string_lossy()], "album": folder}}), T);
+ assert_eq!(r["result"]["scanning"], true, "{r}");
+ assert_eq!(review_album(&mut h), None);
+ let _ = std::fs::remove_dir_all(&dir);
+ /// Delete asks before photos go to Recently Deleted, by default and from every way in: the key, the
+ /// Photo menu and a photo's right-click menu (#1239). With the setting off, it deletes at once.
+ #[test]
+ fn deleting_a_photo_asks_first_from_the_key_the_menu_and_the_right_click_menu() {
+ use crate::state::Dialog;
+ let mut h = demo([1400.0, 900.0], json!({"view": "photoGrid"}));
+ assert!(h.app.ui.settings.confirm_delete, "on by default");
+ let photo = h.app.session.visible_cloned()[0];
+ exec(&mut h, "library.select", json!({"ids": [photo.0]}));
+ let deleted = |h: &Headless| h.app.session.catalog.photo(photo).unwrap().deleted;
+
+ // ⌫ and Photo ▸ Delete Photo ask; Cancel keeps the photo
+ h.request("ui.key", json!({"key": "delete"}), T);
+ assert_eq!(h.app.ui.dialog, Some(Dialog::ConfirmDelete { count: 1 }), "the key asks");
+ h.request("ui.dialog.cancel", json!({}), T);
+ assert!(!deleted(&h));
+ // (what a click on the menu bar's item runs; `ui.menu.invoke` is the agents' engine.execute)
+ crate::menubar::run_item(&mut h.app, "photo.delete", json!({})).unwrap();
+ assert_eq!(h.app.ui.dialog, Some(Dialog::ConfirmDelete { count: 1 }), "the menu asks");
+ h.request("ui.dialog.cancel", json!({}), T);
+ assert!(!deleted(&h));
+
+ // the right-click menu's Delete Photo asks too; OK deletes
+ let thumb = format!("thumb:{}", photo.0);
+ right_click(&mut h, &thumb);
+ click(&mut h, "button:contextDeletePhoto");
+ assert_eq!(h.app.ui.dialog, Some(Dialog::ConfirmDelete { count: 1 }), "the right-click menu asks");
+ assert!(!deleted(&h), "nothing deleted before the answer");
+ let r = h.request("ui.dialog.confirm", json!({}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ assert!(deleted(&h));
+
+ // turned off, the right-click menu deletes at once
+ exec(&mut h, "edit.undo", json!({}));
+ assert!(!deleted(&h));
+ h.app.ui.settings.confirm_delete = false;
+ right_click(&mut h, &thumb);
+ click(&mut h, "button:contextDeletePhoto");
+ assert_eq!(h.app.ui.dialog, None);
+ assert!(deleted(&h));
}
diff --cc docs/parity-checklist.md
index 271e850bf,3de0655db..354827989
--- a/docs/parity-checklist.md
+++ b/docs/parity-checklist.md
@@@ -117,7 -107,7 +117,8 @@@ differences and missing bindings are i
| LR-LIB-PEOPLE | People / faces | P2 | 🟡 | `cmd:faces.detect`, `cmd:view.people`, `cmd:view.faceBoxes`, `cmd:photo.removeRegion`, `cmd:photo.setRegion`, `cmd:library.filter`, `crates/ui-egui/src/panels/people.rs`, `crates/catalog/src/query.rs` (`people`), `crates/engine/src/media.rs` (`face_job`), `crates/meta/src/xmp.rs` | MVP: named face regions read from XMP (MWG-RS, read-only, see `docs/xmp-interop.md`; clipped to the photo; Lightroom's `Rotation` of ±π/2 and π handled, mirrored orientations taken as written; boxes follow Rotate Left/Right and flips; a sidecar stating `mwg-rs:Regions`, even empty, replaces the photo's on re-read, one without leaves them) become cards in the People view (View ▸ People, or the People button in the toolbar): a close-up of the person's largest face, name and photo count; a click filters the grid (`person` in `library.filter`, `person:` search token, filter chip). Face boxes in the loupe can be switched off (View ▸ Face Boxes, toolbar) resized with eight drag handles and removed with the × shown on hover (catalog-only and undoable, one undo step per drag; the sidecar is never rewritten for either); no moving a box by dragging it yet. Photo ▸ Detect Faces (`cmd:faces.detect`) finds faces with the YuNet detector (pure Rust, about 200 ms a photo, matches OpenCV's own YuNet on a 45-photo test set; the 232 KB model is a one-time download offered in the same step, never part of LightCraft) and adds them as unnamed boxes; names are suggested from the faces already named (recognition models are opt-in downloads, run on the CPU in a background thread; a face is named only when you confirm it); a person's page shows their cropped faces and the unnamed faces that look like them (LRC-LIB-PEOPLE); with recognition on, a background scan finds faces in photos that have none and embeds every face (one to three worker threads, raws through their embedded preview); an Unnamed faces section orders faces by likeness and names a selected group at once; no separated clusters, no manual tagging, no writing regions back |
| LR-LIB-STACK | Stacks | P1 | ✅ | `cmd:stack.group`, `cmd:stack.ungroup`, `cmd:stack.toggle`, `cmd:stack.setTop`, `cmd:stack.remove`, `cmd:stack.auto`, `crates/catalog/src/stacks.rs` | grid/filmstrip count badges, expand/collapse, auto-stack by capture time; no visual-similarity auto-stack |
| LR-LIB-VERSIONS | Versions | P1 | ✅ | `cmd:version.create` | see section M |
+| LR-LIB-DELETE | Delete / Recently Deleted | P0 | ✅ | `cmd:photo.delete`, `cmd:photo.restore`, `cmd:photo.deletePermanently` | Delete and Delete Permanently retain surviving selected photos; if none remain, select the next visible survivor (previous at the end) in the current source/filter/sort; permanent deletion removes catalog records, not files on disk; Restore and Delete Permanently in the Photo menu and the photo context menus for photos in Recently Deleted (before, the UI had no way to restore); importing a file that is in Recently Deleted again restores the photo with its edits, rating and albums (issues #298, #706: before, the import skipped it as "already in the library" while the grid showed it deleted) — the review dialog checks it, badges it "Will be restored", counts it as "in Recently Deleted" rather than "already in the library", and its choice Restore them / Import as new / Leave them starts on Restore; with Leave them such a file starts unchecked and Check All and the file-type toggles leave it out, but a click still checks it and it is restored (issue #1285: before, the click did nothing and the "In Recently Deleted" badge was drawn over the checkbox, which now sits above it); dropped files restore too ("Restored 1 photo from Recently Deleted"); a deleted photo matched by content whose file is gone is relinked to the imported file; Photo ▸ Empty Recently Deleted (`cmd:library.emptyRecentlyDeleted`, one undo step, shown while the trash is the source); import takes `onDeleted` restore (default) / skip / fresh for files in the trash (`cmd:library.import`; the report lists `restored`, and with skip flags the duplicate `existingDeleted`); browsing a folder in Local (`cmd:library.browse`), Auto Import and a Lightroom catalog import never restore a deleted photo; no confirmation dialog, no auto-purge after N days (needs a deleted-at date in the catalog) |
+ | LR-LIB-DELETE | Delete / Recently Deleted | P0 | ✅ | `cmd:photo.delete`, `cmd:photo.restore`, `cmd:photo.deletePermanently` | Delete and Delete Permanently retain surviving selected photos; if none remain, select the next visible survivor (previous at the end) in the current source/filter/sort; permanent deletion removes catalog records, not files on disk; Restore and Delete Permanently in the Photo menu and the photo context menus for photos in Recently Deleted (before, the UI had no way to restore); importing a file that is in Recently Deleted again restores the photo with its edits, rating and albums (issues #298, #706: before, the import skipped it as "already in the library" while the grid showed it deleted) — the review dialog checks it, badges it "Will be restored", counts it as "in Recently Deleted" rather than "already in the library", and its choice Restore them / Import as new / Leave them starts on Restore; dropped files restore too ("Restored 1 photo from Recently Deleted"); a deleted photo matched by content whose file is gone is relinked to the imported file; Photo ▸ Empty Recently Deleted (`cmd:library.emptyRecentlyDeleted`, one undo step, shown while the trash is the source); import takes `onDeleted` restore (default) / skip / fresh for files in the trash (`cmd:library.import`; the report lists `restored`, and with skip flags the duplicate `existingDeleted`); browsing a folder in Local (`cmd:library.browse`), Auto Import and a Lightroom catalog import never restore a deleted photo; Delete asks first ("Move this photo to Recently Deleted?") from the key, the Photo menu and the photo context menu, on by default and switched off in Settings ▸ General (#1239: before, it was off by default and the context menu never asked); no auto-purge after N days (needs a deleted-at date in the catalog) |
| LR-LIB-REMOVE-ALBUM | Remove from album | P0 | ✅ | `cmd:album.removePhotos` | |
| LR-LIB-DUPLICATE | Duplicate a photo | P2 | ✅ | `cmd:photo.duplicate` | Photo ▸ Duplicate: a real `-copy` file with the same settings, metadata and albums (virtual copies share the file) |
| LR-LIB-RENAME | Batch rename | P1 | ✅ | `cmd:photo.rename`, `cmd:photo.renamePreview`, `cmd:photo.renameTokens`, `cmd:dialog.rename`, `crates/engine/src/rename.rs` (`TOKENS`) | template tokens {name} {num} {seq:N} {date:%Y%m%d} {folder} {camera} {lens} {iso} {rating} {title} {creator} {ext} (shared with export naming and import rename); a Tags picker beside every template field (Rename Photos, import Rename, export File name) lists each tag with meaning + live example, the date directives and the rules, and inserts the clicked tag at the text cursor; unknown tags are flagged; preview; renames files on disk with their XMP sidecars (a stem sidecar another file still shares, e.g. raw + JPEG, is copied rather than taken), never overwriting (-1, -2… suffixes; a change of letter case only is checked by file identity, so on case-sensitive volumes `img_1.jpg` next to `IMG_1.JPG` is a collision), rolls back on failure (a file that can't be moved back is reported old → new and the library follows it as an undoable partial rename; the same for undo/redo); undo/redo move the files; virtual copies follow |