LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Folders: review fixes (smart albums, disk guards, deep chains, long titles)
Nathaniel Ledford5d13d595207d
diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rsindex 844bae89c..9c374942c 100644--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@ -271,7 +271,20 @@ pub fn specs() -> Vec<CommandSpec> {"libraryFolder" => {let path = str_param(p, "path").map(str::trim).filter(|d| !lightcraft_catalog::query::folder_key(d).is_empty());let path = path.ok_or_else(|| bad("library.source", "libraryFolder needs the `path` of a folder from library.folders"))?;+ if lightcraft_catalog::folders::is_startup_disk(path) {+ return Err(bad("library.source", "the startup disk's path covers every disk: choose a folder in it"));+ }+ let f = Filter { library_folder: Some(path.to_string()), ..Default::default() };+ let ids = s.catalog.query(&f, &Sort::default());+ if ids.is_empty() {+ return Err(bad("library.source", format!("{path}: no photo in the library was imported from it")));+ }+ if covers_other_disks(s, path, &ids) {+ return Err(bad("library.source", format!("{path} holds other disks as well: choose a disk or a folder on one")));+ }s.library_folder = Some(path.to_string());+ // one folder at a time: a folder filter left over would be ignored+ s.filter.library_folder = None;LibrarySource::LibraryFolder}other => return Err(bad("library.source", format!("unknown source `{other}`"))),@@ -293,7 +306,11 @@ pub fn specs() -> Vec<CommandSpec> {|s, p| {let mut v = serde_json::to_value(&s.filter).unwrap_or_default();lightcraft_develop::presets::deep_merge(&mut v, p);- s.filter = serde_json::from_value(v).map_err(|e| bad("library.filter", e.to_string()))?;+ let f: Filter = serde_json::from_value(v).map_err(|e| bad("library.filter", e.to_string()))?;+ if f.library_folder.is_some() && s.source == LibrarySource::LibraryFolder {+ return Err(bad("library.filter", "a folder is already shown (library.source): show another source first"));+ }+ s.filter = f;Ok(json!({"count": s.visible().len()}))}),@@ -302,7 +319,7 @@ pub fn specs() -> Vec<CommandSpec> {"Library Folders",[],None,- "{} → [{name, path, count, own, children}] the folders the library's photos were imported from, with photo counts (subfolders included in `count`); pass a `path` to library.filter as `libraryFolder`",+ "{} → [{name, path, count, own, volume, selectable, children}] the disks and the folders the library's photos were imported from, with photo counts (subfolders included in `count`); show one with library.source {kind: libraryFolder, path} (rows with selectable false only open)",always,|s, _| Ok(serde_json::to_value(s.catalog.folder_tree()).unwrap_or_default())),@@ -330,10 +347,8 @@ pub fn specs() -> Vec<CommandSpec> {if ids.is_empty() {return Err(bad(C, format!("{path}: no photo in the library was imported from it")));}- let disks: std::collections::BTreeSet<String> =- ids.iter().filter_map(|id| s.catalog.photo(*id)).filter_map(|p| lightcraft_catalog::folders::volume_of(p)).collect();- if disks.len() > 1 && !bool_or(p, "disk", false) {- return Err(bad(C, format!("{path} holds photos of {} disks: pass `disk: true` to remove them all", disks.len())));+ if covers_other_disks(s, path, &ids) && !bool_or(p, "disk", false) {+ return Err(bad(C, format!("{path} holds whole disks: pass `disk: true` to remove everything on them")));}let ops = ids.iter().map(|id| Op::SetDeleted { id: *id, deleted: true }).collect();s.commit("Remove Folder from Library", Op::Batch { ops })?;@@ -1112,6 +1127,16 @@ fn merge_rules(base: &lightcraft_catalog::Filter, patch: &Value, c: &str) -> ResOk(f)}+/// Whether `path` lies above a disk: some of its `ids` photos are on a disk (not the startup+/// disk) that the folder does not lie in. Such a folder (`/Volumes`, `/mnt`…) is not a folder of+/// one disk but a way to reach several.+fn covers_other_disks(s: &Session, path: &str, ids: &[PhotoId]) -> bool {+ ids.iter()+ .filter_map(|id| s.catalog.photo(*id))+ .filter_map(|p| lightcraft_catalog::folders::volume_of(p))+ .any(|v| v != "/" && !lightcraft_catalog::query::folder_within(path, &v))+}+/// The current view (source + filter) as smart-album rules. Viewing a smart album starts from/// its rules with the filter bar's settings on top.fn view_rules(s: &Session) -> lightcraft_catalog::Filter {@@ -1138,6 +1163,9 @@ fn view_rules(s: &Session) -> lightcraft_catalog::Filter {None => {let mut f = s.source.to_filter(&s.filter, &s.catalog);f.deleted = false;+ if s.source == LibrarySource::LibraryFolder {+ f.library_folder = s.library_folder.clone();+ }f}}diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex bfc198dce..97cda1080 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -611,8 +611,8 @@ impl Session {f.subfolders = b.subfolders;}if self.source == LibrarySource::LibraryFolder {- // no folder chosen: nothing (an empty path names no folder)- f.library_folder = Some(self.library_folder.clone().unwrap_or_default());+ // no folder chosen: nothing (`.` names no folder)+ f.library_folder = Some(self.library_folder.clone().unwrap_or_else(|| ".".into()));}let mut visible = self.catalog.query(&f, &self.sort);if matches!(self.source, LibrarySource::Album(_))@@ -666,7 +666,7 @@ impl Session {f.subfolders = b.subfolders;}if self.source == LibrarySource::LibraryFolder {- f.library_folder = Some(self.library_folder.clone().unwrap_or_default());+ f.library_folder = Some(self.library_folder.clone().unwrap_or_else(|| ".".into()));}let n = self.catalog.query(&f, &self.sort).len();self.total = Some((key, n));diff --git a/crates/engine/src/library.rs b/crates/engine/src/library.rsindex b6448380f..ef1c1e368 100644--- a/crates/engine/src/library.rs+++ b/crates/engine/src/library.rs@@ -357,9 +357,14 @@ impl Session {self.source = v.source;self.browse = v.browse;self.library_folder = v.library_folder.filter(|f| !f.trim().is_empty());- if self.source == LibrarySource::LibraryFolder && self.library_folder.is_none() {- // no folder to show: everything, not an empty grid- self.source = LibrarySource::All;+ if self.source == LibrarySource::LibraryFolder {+ // a folder that is gone (or none): everything, not an empty grid+ let f = lightcraft_catalog::Filter { library_folder: self.library_folder.clone(), ..Default::default() };+ let any = self.library_folder.is_some() && !self.catalog.query(&f, &lightcraft_catalog::Sort::default()).is_empty();+ if !any {+ self.source = LibrarySource::All;+ self.library_folder = None;+ }}self.sort = v.sort;self.selection = v.selection;diff --git a/crates/engine/src/tests_folders.rs b/crates/engine/src/tests_folders.rsindex e95774435..5bd6a9a20 100644--- a/crates/engine/src/tests_folders.rs+++ b/crates/engine/src/tests_folders.rs@@ -267,7 +267,8 @@ fn the_folder_source_takes_a_library_folder_path_only() {assert!(s.execute("library.source", ¶ms).is_err(), "{params}");}assert_eq!(s.source, LibrarySource::All, "refused, nothing changed");- assert_eq!(source_folder(&mut s, "/elsewhere")["count"], 0, "a folder with no photos shows nothing, not everything");+ assert!(s.execute("library.source", &json!({"kind": "libraryFolder", "path": "/elsewhere"})).is_err(), "no photo was imported from it");+ assert_eq!(s.source, LibrarySource::All);}#[test]@@ -309,3 +310,70 @@ fn the_shown_folder_follows_reading_both_spellings_the_same_way() {crate::cmd::browse::follow_folder(&mut s, "/a/b", "/a/c");assert_eq!(s.library_folder.as_deref(), Some("/a/c/sub"));}++#[test]+fn switching_from_one_folder_to_another_changes_what_is_shown() {+ let mut s = session();+ assert_eq!(source_folder(&mut s, "/pics/trip")["count"], 2);+ assert_eq!(s.source_total(), Some(2));+ assert_eq!(source_folder(&mut s, "/pics/home")["count"], 1, "same source, another folder");+ assert_eq!(s.visible().len(), 1);+ assert_eq!(s.source_total(), Some(1));+}++#[test]+fn a_smart_album_made_from_a_folder_view_keeps_the_folder() {+ let mut s = session();+ source_folder(&mut s, "/pics/trip");+ assert_eq!(s.visible().len(), 2);+ let r = s.execute("album.createSmart", &json!({"name": "Trip"})).unwrap();+ assert_eq!(r["count"], 2, "the album matches the folder's photos, not the whole library: {r}");+}++#[test]+fn a_folder_source_and_a_folder_filter_never_disagree() {+ let mut s = session();+ s.execute("library.filter", &json!({"libraryFolder": "/pics/home"})).unwrap();+ source_folder(&mut s, "/pics/trip");+ assert_eq!(s.filter.library_folder, None, "choosing a folder drops a folder filter left over");+ assert!(s.execute("library.filter", &json!({"libraryFolder": "/pics/home"})).is_err(), "one folder at a time");+ assert_eq!(s.visible().len(), 2);+ s.execute("library.filter", &json!({"libraryFolder": null, "rating": 0})).unwrap();+ s.execute("library.source", &json!({"kind": "all"})).unwrap();+ assert!(s.execute("library.filter", &json!({"libraryFolder": "/pics/home"})).is_ok(), "fine while no folder is the source");+}++#[test]+fn a_folder_source_with_no_folder_shows_nothing() {+ let mut s = session();+ s.source = LibrarySource::LibraryFolder;+ s.library_folder = None;+ assert_eq!(s.visible().len(), 0, "not everything");+ assert_eq!(s.source_total(), Some(0));+}++#[test]+fn only_a_folder_that_shows_exactly_its_own_photos_can_be_the_source() {+ let mut s = Session::new();+ for p in ["/Volumes/nas/a/1.jpg", "/Users/me/2.jpg", "/Volumes/3.jpg"] {+ add(&mut s, p);+ }+ for path in ["/", "//", "/elsewhere", "/Volumes"] {+ assert!(s.execute("library.source", &json!({"kind": "libraryFolder", "path": path})).is_err(), "{path:?}");+ }+ assert_eq!(s.source, LibrarySource::All, "refused, nothing changed");+ assert_eq!(source_folder(&mut s, "/Volumes/nas")["count"], 1, "a disk is a fine source");+ assert_eq!(source_folder(&mut s, "/Users/me")["count"], 1);+}++#[test]+fn removing_a_folder_above_a_disk_needs_asking_by_name_even_with_one_disk() {+ let mut s = Session::new();+ for p in ["/Volumes/nas/a/1.jpg", "/Users/me/2.jpg"] {+ add(&mut s, p);+ }+ assert!(s.execute("library.removeFolder", &json!({"path": "/Volumes"})).is_err(), "it would take the whole nas");+ assert_eq!(s.visible().len(), 2);+ assert_eq!(s.execute("library.removeFolder", &json!({"path": "/Volumes/nas/a"})).unwrap()["removed"], 1, "a folder on the disk is just a folder");+ assert_eq!(s.visible().len(), 1);+}diff --git a/crates/engine/src/tests_library.rs b/crates/engine/src/tests_library.rsindex 91ae195af..f7b89225e 100644--- a/crates/engine/src/tests_library.rs+++ b/crates/engine/src/tests_library.rs@@ -216,12 +216,28 @@ fn profile_favorites_and_recent_survive_reopen() {fn the_shown_library_folder_survives_reopen() {let dir = temp_dir("libfolder");let mut s = open(&dir, true);+ let id = s.catalog.alloc_photo_id();+ let p = lightcraft_catalog::Photo::new(+ id,+ lightcraft_catalog::Source::File { path: "/pics/trip/a.jpg".into() },+ "a.jpg",+ "JPEG",+ 60,+ 40,+ "2026-01-01T10:00:00",+ );+ s.commit("Add", lightcraft_catalog::Op::AddPhoto { photo: Box::new(p) }).unwrap();s.execute("library.source", &json!({"kind": "libraryFolder", "path": "/pics/trip"})).unwrap();s.save_view();drop(s);let s = open(&dir, false);assert_eq!((s.source, s.library_folder.as_deref()), (crate::LibrarySource::LibraryFolder, Some("/pics/trip")));drop(s);+ // a folder that holds none of the library's photos any more opens on everything too+ std::fs::write(dir.join("view.json"), br#"{"source": {"kind": "libraryFolder"}, "library_folder": "/no/such/folder"}"#).unwrap();+ let s = open(&dir, false);+ assert_eq!((s.source, s.library_folder.clone()), (crate::LibrarySource::All, None));+ drop(s);// a view file that names the source but no folder opens on everything, never an empty gridstd::fs::write(dir.join("view.json"), br#"{"source": {"kind": "libraryFolder"}}"#).unwrap();let s = open(&dir, false);diff --git a/crates/ui-egui/locales/ja.json b/crates/ui-egui/locales/ja.jsonindex d2376d647..cd7aad448 100644--- a/crates/ui-egui/locales/ja.json+++ b/crates/ui-egui/locales/ja.json@@ -1037,5 +1037,10 @@"They move to Recently Deleted and can be restored; no file on disk is touched.": "「最近削除した写真」に移動し、復元できます。ディスク上のファイルには手を加えません","Moves the photos imported from this folder to Recently Deleted; no file is touched": "このフォルダから読み込んだ写真を「最近削除した写真」に移動します。ファイルには手を加えません","Remove Disk from Library…": "ディスクをライブラリから除去…",- "Moves every photo imported from this disk to Recently Deleted; no file is touched": "このディスクから読み込んだすべての写真を「最近削除した写真」に移動します。ファイルには手を加えません"+ "Moves every photo imported from this disk to Recently Deleted; no file is touched": "このディスクから読み込んだすべての写真を「最近削除した写真」に移動します。ファイルには手を加えません",+ "Collapse": "折りたたむ",+ "Expand": "展開",+ "Remove Disk from Library": "ディスクをライブラリから除去",+ "All the photos imported from this disk are included.": "このディスクから読み込んだすべての写真が対象です",+ "That includes the photos in the folders inside it.": "内側のフォルダにある写真も含まれます"}diff --git a/crates/ui-egui/locales/pt-br.json b/crates/ui-egui/locales/pt-br.jsonindex 3b2b3b8d4..7348670f6 100644--- a/crates/ui-egui/locales/pt-br.json+++ b/crates/ui-egui/locales/pt-br.json@@ -42,6 +42,7 @@"All Metadata…": "Todos os metadados…","All Photos": "Todas as fotos","All rights reserved": "Todos os direitos reservados",+ "All the photos imported from this disk are included.": "Todas as fotos importadas deste disco estão incluídas.","All types": "Todos os tipos","Alt Text": "Texto alternativo","Always": "Sempre",@@ -188,6 +189,7 @@"Close all": "Fechar tudo","Close file": "Fechar arquivo","Cloudy": "Nublado",+ "Collapse": "Recolher","Collapse All Stacks": "Recolher todas as pilhas","Color": "Cor","Color Grading": "Graduação de cores",@@ -361,6 +363,7 @@"Every EXIF, GPS and XMP field in the file": "Todos os campos EXIF, GPS e XMP do arquivo","Existing previews": "Prévias existentes","Exit": "Sair",+ "Expand": "Expandir","Expand All Stacks": "Expandir todas as pilhas","Expand/Collapse Stack": "Expandir/recolher pilha","Export": "Exportar",@@ -902,6 +905,7 @@"Remove (H)": "Remover (H)","Remove CA": "Remover AC","Remove Chromatic Aberration": "Remover aberração cromática",+ "Remove Disk from Library": "Remover disco da biblioteca","Remove Disk from Library…": "Remover disco da biblioteca…","Remove Folder from Library": "Remover pasta da biblioteca","Remove from Album": "Remover do álbum",@@ -1146,6 +1150,7 @@"Text": "Texto","Text direction": "Direção do texto","Texture": "Textura",+ "That includes the photos in the folders inside it.": "Isso inclui as fotos das pastas dentro dela.","The SAM 3 model is installed: Object and Describe masks are ready.": "O modelo SAM 3 está instalado: as máscaras Objeto e Descrever estão prontas.","The download didn't work:": "O download não funcionou:","The original files, unchanged, each with an XMP sidecar holding its edits.": "Os arquivos originais, inalterados, cada um com um sidecar XMP contendo suas edições.",diff --git a/crates/ui-egui/locales/zh-hans.json b/crates/ui-egui/locales/zh-hans.jsonindex 9f411f3cc..87c4d4ea8 100644--- a/crates/ui-egui/locales/zh-hans.json+++ b/crates/ui-egui/locales/zh-hans.json@@ -1254,5 +1254,10 @@"They move to Recently Deleted and can be restored; no file on disk is touched.": "它们会移到“最近删除”,可以恢复;磁盘上的文件不会被改动。","Moves the photos imported from this folder to Recently Deleted; no file is touched": "将从此文件夹导入的照片移到“最近删除”;不会改动任何文件","Remove Disk from Library…": "从图库中移除磁盘…",- "Moves every photo imported from this disk to Recently Deleted; no file is touched": "将从此磁盘导入的所有照片移到“最近删除”;不会改动任何文件"+ "Moves every photo imported from this disk to Recently Deleted; no file is touched": "将从此磁盘导入的所有照片移到“最近删除”;不会改动任何文件",+ "Collapse": "折叠",+ "Expand": "展开",+ "Remove Disk from Library": "从图库中移除磁盘",+ "All the photos imported from this disk are included.": "包括从此磁盘导入的所有照片。",+ "That includes the photos in the folders inside it.": "其中文件夹里的照片也包括在内。"}diff --git a/crates/ui-egui/locales/zh-hant.json b/crates/ui-egui/locales/zh-hant.jsonindex 863de2db1..23463f8fd 100644--- a/crates/ui-egui/locales/zh-hant.json+++ b/crates/ui-egui/locales/zh-hant.json@@ -1254,5 +1254,10 @@"They move to Recently Deleted and can be restored; no file on disk is touched.": "它們會移至「最近刪除」,可以還原;磁碟上的檔案不會被更動。","Moves the photos imported from this folder to Recently Deleted; no file is touched": "將從此資料夾匯入的照片移至「最近刪除」;不會更動任何檔案","Remove Disk from Library…": "從照片庫移除磁碟…",- "Moves every photo imported from this disk to Recently Deleted; no file is touched": "將從此磁碟匯入的所有照片移至「最近刪除」;不會更動任何檔案"+ "Moves every photo imported from this disk to Recently Deleted; no file is touched": "將從此磁碟匯入的所有照片移至「最近刪除」;不會更動任何檔案",+ "Collapse": "收合",+ "Expand": "展開",+ "Remove Disk from Library": "從照片庫移除磁碟",+ "All the photos imported from this disk are included.": "包含從此磁碟匯入的所有照片。",+ "That includes the photos in the folders inside it.": "其中資料夾裡的照片也包含在內。"}diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rsindex cfcc476fa..4e71684e4 100644--- a/crates/ui-egui/src/panels/dialogs.rs+++ b/crates/ui-egui/src/panels/dialogs.rs@@ -97,6 +97,7 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) {Dialog::Merge { opts } => opts.title(),Dialog::Settings { .. } => "Settings",Dialog::ConfirmDelete { .. } => "Delete Photos",+ Dialog::RemoveFolder { disk: true, .. } => "Remove Disk from Library",Dialog::RemoveFolder { .. } => "Remove Folder from Library",Dialog::SamModel { .. } => "Download the SAM 3 Model?",Dialog::About => "About LightCraft",@@ -711,7 +712,7 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) {ui.label(crate::i18n::tr_format!("Move {what} to Recently Deleted?", what = what));ui.label(egui::RichText::new(crate::i18n::tr("They can be restored from Recently Deleted until it is emptied.")).color(t.text_dim));}- Dialog::RemoveFolder { name, count, path, .. } => {+ Dialog::RemoveFolder { name, count, path, disk } => {ui.label(crate::i18n::tr_format!("Remove “{name}” and its {count} photo{} from the library?",if *count == 1 { "" } else { "s" },@@ -719,6 +720,8 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) {count = count));ui.label(egui::RichText::new(path.as_str()).color(t.text_dim));+ let scope = if *disk { "All the photos imported from this disk are included." } else { "That includes the photos in the folders inside it." };+ ui.label(egui::RichText::new(crate::i18n::tr(scope)).color(t.text_dim));ui.label(egui::RichText::new(crate::i18n::tr("They move to Recently Deleted and can be restored; no file on disk is touched.")).color(t.text_dim),diff --git a/crates/ui-egui/src/panels/grid.rs b/crates/ui-egui/src/panels/grid.rsindex bb7b27f09..fbc35b6c8 100644--- a/crates/ui-egui/src/panels/grid.rs+++ b/crates/ui-egui/src/panels/grid.rs@@ -150,9 +150,19 @@ fn show_inner(app: &mut LightcraftApp, ui: &mut egui::Ui) {folder_header(app, ui, hr, &b, &ids, local, &cnt)}None => {- let title = crate::i18n::source_title(&app.session);- ui.painter().text(pos2(hr.left() + 20.0, hr.center().y), Align2::LEFT_CENTER, &title, t.semibold(17.0), t.text);- ui.painter().text(pos2(hr.right() - 20.0, hr.center().y), Align2::RIGHT_CENTER, cnt, t.font(12.5), t.text_dim);+ let full = crate::i18n::source_title(&app.session);+ let count_w = ui.painter().layout_no_wrap(cnt.clone(), t.font(12.5), t.text_dim).size().x;+ // the title gives way to the count: a long album or folder name is trimmed, in full on hover+ let room = (hr.width() - 20.0 - count_w - 36.0).max(0.0);+ let font = t.semibold(17.0);+ let title = crate::widgets::elide_head(&full, room, |s| ui.painter().layout_no_wrap(s.to_string(), font.clone(), t.text).size().x);+ let title_rect = ui.painter().text(pos2(hr.left() + 20.0, hr.center().y), Align2::LEFT_CENTER, &title, font, t.text);+ let count_rect = ui.painter().text(pos2(hr.right() - 20.0, hr.center().y), Align2::RIGHT_CENTER, cnt, t.font(12.5), t.text_dim);+ crate::widgets::register(ui.ctx(), "grid:title", title_rect);+ crate::widgets::register(ui.ctx(), "grid:count", count_rect);+ if title != full {+ ui.interact(title_rect, ui.id().with("grid-title"), Sense::hover()).on_hover_text(full);+ }}}super::chips::show(app, ui, &chips);diff --git a/crates/ui-egui/src/panels/left.rs b/crates/ui-egui/src/panels/left.rsindex be47fa212..c3a438d58 100644--- a/crates/ui-egui/src/panels/left.rs+++ b/crates/ui-egui/src/panels/left.rs@@ -749,32 +749,6 @@ fn folders_section(app: &mut LightcraftApp, ui: &mut egui::Ui) {}}-/// `text` shortened to fit `max` (as `width` measures it): leading folders drop first-/// (`Users/me/Pictures/Lightroom` → `…/Pictures/Lightroom`) so the end of a path, which says the-/// most, stays; a single name still too long loses its end (`2024-06-12 Tri…`: folders tend to-/// differ at the start). Cuts fall on characters. The result is never empty.-fn elide_head(text: &str, max: f32, width: impl Fn(&str) -> f32) -> String {- if width(text) <= max {- return text.to_string();- }- let mut rest = text;- while let Some(i) = rest.find('/') {- rest = rest.get(i + 1..).unwrap_or("");- let cand = format!("…/{rest}");- if width(&cand) <= max {- return cand;- }- }- let n = rest.chars().count();- for keep in (1..n).rev() {- let cand: String = rest.chars().take(keep).chain(std::iter::once('…')).collect();- if width(&cand) <= max {- return cand;- }- }- "…".to_string()-}-/// Whenever the shown folder changes (a click, an agent, a rename or its undo), open the rows/// above it so it is on screen; folding one by hand afterwards sticks until the choice changes.fn reveal_chosen(app: &LightcraftApp, ui: &egui::Ui, tree: &[FolderNode]) {@@ -799,6 +773,10 @@ fn reveal_chosen(app: &LightcraftApp, ui: &egui::Ui, tree: &[FolderNode]) {open_above(ui, tree, &chosen);}+/// Deeper folders keep this indent: a chain of a dozen single folders would otherwise push every+/// label out of the sidebar.+const MAX_FOLDER_INDENT: f32 = 16.0 * 5.0;+fn folder_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[FolderNode], indent: f32) {let t = Tokens::get(ui.ctx());for n in nodes {@@ -819,7 +797,8 @@ fn folder_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[FolderNode],let count_w =if app.ui.show_counts { ui.painter().layout_no_wrap(n.count.to_string(), t.font(12.5), egui::Color32::WHITE).size().x } else { 0.0 };let room = ui.available_width() - 42.0 - indent - count_w - 28.0;- let label = elide_head(&name, room, |s| ui.painter().layout_no_wrap(s.to_string(), font.clone(), egui::Color32::WHITE).size().x);+ let label =+ crate::widgets::elide_head(&name, room, |s| ui.painter().layout_no_wrap(s.to_string(), font.clone(), egui::Color32::WHITE).size().x);let resp = row_named(app, ui, &format!("libfolder:{}", n.path), Icon::Folder, &label, Some(&name), Some(n.count), sel, indent);let mut toggled = false;if !n.children.is_empty() {@@ -836,6 +815,9 @@ fn folder_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[FolderNode],};ui.painter().add(egui::Shape::convex_polygon(pts, col, egui::Stroke::NONE));toggled = tr.clicked();+ tr.widget_info(|| {+ egui::WidgetInfo::labeled(egui::WidgetType::Button, true, if open { crate::i18n::tr("Collapse") } else { crate::i18n::tr("Expand") })+ });// the triangle sits on the row and takes its clicks: the menu opens from it toorow_menu(app, &tr, n);}@@ -855,7 +837,7 @@ fn folder_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[FolderNode],}row_menu(app, &resp, n);if open && !n.children.is_empty() {- folder_rows(app, ui, &n.children, indent + 16.0);+ folder_rows(app, ui, &n.children, (indent + 16.0).min(MAX_FOLDER_INDENT));}}}@@ -998,7 +980,8 @@ fn keyword_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, nodes: &[KeywordNode#[cfg(test)]mod tests {- use super::{elide_head, local_places};+ use super::local_places;+ use crate::widgets::elide_head;/// Width = characters, so a limit of 12 is "12 characters".fn fit(text: &str, max: usize) -> String {diff --git a/crates/ui-egui/src/tests_panels.rs b/crates/ui-egui/src/tests_panels.rsindex 585a3e952..b97276f7c 100644--- a/crates/ui-egui/src/tests_panels.rs+++ b/crates/ui-egui/src/tests_panels.rs@@ -202,6 +202,10 @@ fn sidebar_sections_collapse_and_remember_it() {/// A headless app over a library of file-backed photos that exist only in the catalog.fn folders_app(paths: &[&str]) -> Headless {+ folders_app_sized(paths, [1400.0, 900.0])+}++fn folders_app_sized(paths: &[&str], size: [f32; 2]) -> Headless {use lightcraft_catalog::{Op, Photo, Source};let mut session = lightcraft_engine::Session::new();for path in paths {@@ -210,7 +214,7 @@ fn folders_app(paths: &[&str]) -> Headless {session.catalog.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap();}let app = LightcraftApp::new(session, Services { png: None, ..Default::default() });- let mut h = Headless::new(app, [1400.0, 900.0], 1.0);+ let mut h = Headless::new(app, size, 1.0);let r = h.request("ui.set", json!({"view": "photoGrid", "leftPanel": true}), T);assert_eq!(r["ok"], true, "{r}");h.settle(SETTLE);@@ -229,7 +233,7 @@ fn click(h: &mut Headless, id: &str) {}/// Photos imported from two folders: the sidebar's Folders section lists them, choosing one-/// narrows the grid to its photos, and choosing it again shows everything (like By Date).+/// fills the grid with its photos, and All Photos shows everything again.#[test]fn folders_section_lists_where_photos_were_imported_from_and_narrows_the_grid() {let mut h = folders_app(&["/pics/trip/a.jpg", "/pics/trip/b.jpg", "/pics/home/c.jpg"]);@@ -361,8 +365,16 @@ fn the_chosen_folder_is_always_in_view() {#[test]fn a_renamed_folder_keeps_its_place_in_the_tree() {+ /// Removes the folder however the test ends.+ struct Cleanup(std::path::PathBuf);+ impl Drop for Cleanup {+ fn drop(&mut self) {+ let _ = std::fs::remove_dir_all(&self.0);+ }+ }let base = std::env::temp_dir().join(format!("lc-ui-rename-{}", std::process::id()));let _ = std::fs::remove_dir_all(&base);+ let _cleanup = Cleanup(base.clone());std::fs::create_dir_all(base.join("pics/trip")).unwrap();std::fs::create_dir_all(base.join("pics/home")).unwrap();let b = base.to_string_lossy().to_string();@@ -377,7 +389,6 @@ fn a_renamed_folder_keeps_its_place_in_the_tree() {h.step();h.step();assert!(has(&h, &format!("source:libfolder:{b}/pics2/trip")), "the chosen folder is still on screen after the rename");- let _ = std::fs::remove_dir_all(&base);}/// The menu opens from anywhere on a folder row, the disclosure triangle included; a disk row@@ -417,3 +428,35 @@ fn removing_a_disk_from_the_library_asks_first() {assert_eq!(r["ok"], true, "{r}");assert_eq!(h.app.session.visible().len(), 1, "everything on that disk left the library");}++/// However deep the folders go, a row keeps its name, count and click targets inside the panel:+/// the indent stops growing after five levels instead of pushing the label out of the row.+#[test]+fn a_deep_chain_of_folders_keeps_its_rows_usable() {+ let deep = "/a/b/c/d/e/f/g/h/i/j/k/l/m";+ let mut h = folders_app(&[&format!("{deep}/x/1.jpg"), &format!("{deep}/y/2.jpg")]);+ let toggles: Vec<(String, egui::Rect)> = h.app.widgets.iter().filter(|(w, _)| w.starts_with("libraryFolderToggle:")).cloned().collect();+ assert!(toggles.len() >= 12, "the chain opens by itself: {}", toggles.len());+ let row = widget(&h, "source:libfolder:/a");+ for (id, r) in &toggles {+ assert!(r.center().x <= row.left() + 10.0 + 16.0 * 5.0 + 1.0, "{id}: the triangle stays near the left edge ({r:?})");+ }+ // a click in the middle of a deep row chooses it; only the little triangle folds it+ let leaf = format!("source:libfolder:{deep}/x");+ assert!(has(&h, "libraryFolderToggle:/a/b/c/d/e/f/g/h/i/j/k/l/m") || has(&h, &leaf));+ click(&mut h, "source:libfolder:/a/b/c/d/e/f/g/h/i/j/k/l");+ assert_eq!(h.app.session.library_folder.as_deref(), Some("/a/b/c/d/e/f/g/h/i/j/k/l"), "the row's middle is the row, not its triangle");+}++/// A long folder name is trimmed before it can run under the photo count.+#[test]+fn a_long_folder_name_never_runs_under_the_photo_count() {+ let long = "/very/long/2024-06-12 Tripping Through The Extremely Long Named Mountains Of Somewhere";+ let mut h = folders_app_sized(&[&format!("{long}/a.jpg")], [900.0, 700.0]);+ h.app.session.source = lightcraft_engine::LibrarySource::LibraryFolder;+ h.app.session.library_folder = Some(long.into());+ h.step();+ h.step();+ let (title, count) = (widget(&h, "grid:title"), widget(&h, "grid:count"));+ assert!(title.right() + 8.0 <= count.left(), "title {title:?} vs count {count:?}");+}diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rsindex d89a9ce32..b9f463f00 100644--- a/crates/ui-egui/src/widgets.rs+++ b/crates/ui-egui/src/widgets.rs@@ -506,3 +506,29 @@ mod access_tests {assert!(has("Button", "Delete mask"), "{found:?}");}}++/// `text` shortened to fit `max` (as `width` measures it): leading folders drop first+/// (`Users/me/Pictures/Lightroom` → `…/Pictures/Lightroom`) so the end of a path, which says the+/// most, stays; a single name still too long loses its end (`2024-06-12 Tri…`: folders tend to+/// differ at the start). Cuts fall on characters. The result is never empty.+pub(crate) fn elide_head(text: &str, max: f32, width: impl Fn(&str) -> f32) -> String {+ if width(text) <= max {+ return text.to_string();+ }+ let mut rest = text;+ while let Some(i) = rest.find('/') {+ rest = rest.get(i + 1..).unwrap_or("");+ let cand = format!("…/{rest}");+ if width(&cand) <= max {+ return cand;+ }+ }+ let n = rest.chars().count();+ for keep in (1..n).rev() {+ let cand: String = rest.chars().take(keep).chain(std::iter::once('…')).collect();+ if width(&cand) <= max {+ return cand;+ }+ }+ "…".to_string()+}diff --git a/docs/parity.md b/docs/parity.mdindex 206e2c3ec..49dcdf0dc 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -718,7 +718,7 @@ From `08-lightroom-classic-extras.md` (Classic-only features) and part 2 of `06-| LRC-LIB-CATALOG-PANEL | Catalog sets | P1 | ✅ | `cmd:library.source` (`missing`) | all, recently added, picks, recently deleted, missing photos (when any) || LRC-LIB-CATALOG-LOCK | Catalog open in one program at a time | P1 | ✅ | `cmd:app.openLibrary`, `crates/catalog/src/lock.rs`, `crates/engine/src/library.rs` (`open_library`) | exclusive OS lock on `catalog.lock` for the session (app and `lightcraft-cli --library`); a second opener is refused with who has it (`catalog.lock.owner`: program, process, computer); released by the OS on a crash, so never stale; file systems without locks open unprotected with a warning; no read-only mode; the browser build (OPFS) has no guard across tabs yet. A library that can't be opened at launch (locked, unreadable, newer format, drive missing) shows a window — Try Again, Choose Another Library…, Continue Without Saving (then a banner; nothing written), Quit — instead of a silent demo session (`crates/ui-egui/src/panels/library_problem.rs`) || LRC-LIB-FOLDERS | Disk folder tree | P1 | ✅ | `cmd:library.browse`, `cmd:folder.rename`, `cmd:folder.move`, `crates/ui-egui/src/panels/left.rs` (`local_section`, `folder_tree`) | standard places + the browsed folder + Browse Folder…, each an expandable tree of subfolders, breadcrumb navigation; context menu: Rename Folder…, Move Folder To…, Show in Finder (on disk, photos relinked; one undo step each: undo / redo move the folder back and forth, refused when the destination is taken) |-| LRC-LIB-LIBFOLDERS | Library folders | P1 | ✅ | `cmd:library.folders`, `cmd:library.source` (`libraryFolder`), `cmd:library.filter` (`libraryFolder`), `cmd:library.removeFolder`, `cmd:folder.rename`, `cmd:folder.move`, `crates/catalog/src/folders.rs`, `crates/ui-egui/src/panels/left.rs` (`folders_section`, `folder_menu_for_library`, `row_menu`), `crates/ui-egui/src/tests_panels.rs` | sidebar Folders: the folders the library's photos were imported from, with photo counts (subfolders included), as another way to explore the library next to By Date and Keywords; Local stays the way to browse any folder on disk. Each disk is a row of its own and starts open: a drive letter, a Windows share (`\\server\share`, `\\?\UNC\…`, `\\wsl$\…`), a macOS share or disk (`/Volumes/tokyo`), a Linux mount (`/media`, `/run/media`, `/mnt`, gvfs `smb-share:…`, `/net/<host>`), NFS (`/Network/Servers/<host>`), else “This Computer” — told apart from the stored paths alone, so an offline share lists like a mounted one and the sidebar never waits on a network. Only folders that hold imported photos are listed (browsed, deleted and demo photos don't count); every folder is a row of its own (`Users` → `me` → `Pictures`), and a folder that holds nothing itself and leads to one folder starts open; long names are cut at the end with the full path in the tooltip; click makes the folder the source, like an album or a Local folder (its photos and those of the folders inside it fill the grid, titled “photos/travel”; the filter bar narrows it further; `library.source` `libraryFolder` + `path`; kept with the library's view), and its row is always opened into view, also after a rename or move and their undo. A row that would cover other disks' photos too (the startup disk, `/Volumes`, `/mnt`…) only opens. Right-click (row or triangle): Rename Folder…, Move Folder To…, Show in Finder (on disk, photos relinked, as in Local) and Remove from Library… (asks; moves the folder's photos to Recently Deleted, one undo step, no file touched); a disk row offers Remove Disk from Library… (the command needs `disk: true` for a whole disk or a folder spanning several). Limits: names are compared as written (macOS `/Volumes/tokyo` vs `/Volumes/TOKYO` are two disks; `/Volumes/Macintosh HD/…` and `/…` two rows); no disk capacity / online status; no “include subfolders” switch (a folder always includes the ones inside it); creating a folder and moving photos between folders are not here |+| LRC-LIB-LIBFOLDERS | Library folders | P1 | ✅ | `cmd:library.folders`, `cmd:library.source` (`libraryFolder`), `cmd:library.filter` (`libraryFolder`), `cmd:library.removeFolder`, `cmd:folder.rename`, `cmd:folder.move`, `crates/catalog/src/folders.rs`, `crates/ui-egui/src/panels/left.rs` (`folders_section`, `folder_menu_for_library`, `row_menu`), `crates/ui-egui/src/tests_panels.rs` | sidebar Folders: the folders the library's photos were imported from, with photo counts (subfolders included), as another way to explore the library next to By Date and Keywords; Local stays the way to browse any folder on disk. Each disk is a row of its own and starts open: a drive letter, a Windows share (`\\server\share`, `\\?\UNC\…`, `\\wsl$\…`), a macOS share or disk (`/Volumes/tokyo`), a Linux mount (`/media`, `/run/media`, `/mnt`, gvfs `smb-share:…`, `/net/<host>`), NFS (`/Network/Servers/<host>`), else “This Computer” — told apart from the stored paths alone, so an offline share lists like a mounted one and the sidebar never waits on a network. Only folders that hold imported photos are listed (browsed, deleted and demo photos don't count); every folder is a row of its own (`Users` → `me` → `Pictures`), and a folder that holds nothing itself and leads to one folder starts open; deep chains stop indenting after five levels, long names are cut with the full path in the tooltip (the grid title too); click makes the folder the source, like an album or a Local folder (its photos and those of the folders inside it fill the grid, titled “photos/travel”; the filter bar narrows it further; `library.source` `libraryFolder` + `path`; kept with the library's view), and its row is always opened into view; the shown folder follows a rename or move and their undo (engine-tested; the sidebar test covers rename), is dropped back to All Photos when it is removed or no longer holds a photo, and a smart album made from the view keeps it. Only a folder that shows exactly its own photos can be shown (not the startup disk, not `/Volumes`-like folders above disks, not an empty one). A row that would cover other disks' photos too (the startup disk, `/Volumes`, `/mnt`…) only opens. Right-click (row or triangle): Rename Folder…, Move Folder To…, Show in Finder (on disk, photos relinked, as in Local) and Remove from Library… (asks; moves the folder's photos to Recently Deleted, one undo step, no file touched); a disk row offers Remove Disk from Library… (the command needs `disk: true` for a whole disk or a folder spanning several). Limits: names are compared as written (macOS `/Volumes/tokyo` vs `/Volumes/TOKYO` are two disks; `/Volumes/Macintosh HD/…` and `/…` two rows); no disk capacity / online status; no “include subfolders” switch (a folder always includes the ones inside it); creating a folder and moving photos between folders are not here || LRC-LIB-COLLECTIONS | Collections & sets | P1 | ✅ | `cmd:album.create`, `cmd:album.createSmart`, `cmd:album.toggleTarget`, `cmd:album.setTarget`, `cmd:album.clearQuick` | albums + folders (sets), smart albums (rule editor; rules incl. File Path — the whole string, either separator, case-insensitive), Quick Collection and target album (B in the grids adds / removes the selection; album menu ▸ Set as Target Album; the target is marked +) || LRC-LIB-SMARTCOLL | Smart-collection rules | P1 | ✅ | `cmd:album.createSmart`, `cmd:album.setRules`, `cmd:album.ruleFields`, `cmd:dialog.smartAlbum`, `crates/catalog/src/rules.rs`, `crates/ui-egui/src/panels/rules_editor.rs` | rule editor: match all / any / none, nested groups (⌥+ or + Group), 30 fields (rating, flag, label, type, edits, keywords, any text, filename, file path, format, title, caption, camera, lens, location, creator, copyright, copyright status, capture / import / edit date, ISO, aperture, focal length, megapixels, GPS, virtual copy, album) with text / number / date / in-the-last operators; live match count; also usable as a library filter (`ruleSet`) || LRC-LIB-PUBLISH | Publish services | P2 | ⬜ | | |