LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #1250
bflatastic94808da369fa
diff --cc crates/ui-egui/src/tests_panels.rsindex 901c36d3d,4d8634ccb..a6f8575ac--- a/crates/ui-egui/src/tests_panels.rs+++ b/crates/ui-egui/src/tests_panels.rs@@@ -2199,114 -2142,51 +2199,161 @@@ fn right_click_add_to_album_offers_a_neassert!(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));+ /// New Album's "Include selected photos" (as in Lightroom): on by default; unticked, the new album+ /// starts empty; with nothing selected the option isn't shown, and a folder never has it.+ #[test]+ fn new_album_can_leave_the_selected_photos_out() {+ let mut h = demo([1400.0, 900.0], json!({"view": "photoGrid", "leftPanel": true}));+ let has = |h: &Headless, id: &str| h.app.widgets.iter().any(|(w, _)| w == id);+ let photo = lightcraft_catalog::PhotoId(h.app.session.visible_cloned()[1].0);+ h.app.session.execute("library.select", &json!({"ids": [photo.0]})).unwrap();+ let create = |h: &mut Headless, command: &str, name: &str| {+ h.app.run(command, json!({"name": name})).unwrap();+ h.step();+ h.step();+ };+ let confirm = |h: &mut Headless| {+ let r = h.request("ui.clickWidget", json!({"id": "button:dialogOk"}), T);+ assert_eq!(r["ok"], true, "{r}");+ h.step();+ h.step();+ assert!(h.app.ui.dialog.is_none(), "{:?}", h.app.ui.dialog);+ };+ let photos = |h: &Headless, name: &str| h.app.session.catalog.albums().find(|a| a.name == name).expect("the album was created").photos.clone();++ // ticked by default: the selection goes in, as before+ create(&mut h, "dialog.newAlbum", "With");+ assert!(has(&h, "check:albumIncludeSelected"), "the option is offered with a selection");+ confirm(&mut h);+ assert_eq!(photos(&h, "With"), vec![photo]);++ // unticked: an empty album+ create(&mut h, "dialog.newAlbum", "Without");+ let r = h.request("ui.clickWidget", json!({"id": "check:albumIncludeSelected"}), T);+ assert_eq!(r["ok"], true, "{r}");+ h.step();+ confirm(&mut h);+ assert!(photos(&h, "Without").is_empty(), "nothing was added");++ // a folder never offers it+ create(&mut h, "dialog.newFolder", "Folder");+ assert!(!has(&h, "check:albumIncludeSelected"), "folders hold no photos");+ confirm(&mut h);++ // nothing selected: no option, an empty album+ h.app.session.selection = lightcraft_engine::Selection { ids: vec![], active: None };+ create(&mut h, "dialog.newAlbum", "Nothing");+ assert!(!has(&h, "check:albumIncludeSelected"), "no selection, no option");+ confirm(&mut h);+ assert!(photos(&h, "Nothing").is_empty());}