LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #1429
Brandon Thomasd71e7d11c198
diff --cc crates/ui-egui/src/panels/left.rsindex 469184639,d8cd4eb1b..fcaab2926--- a/crates/ui-egui/src/panels/left.rs+++ b/crates/ui-egui/src/panels/left.rs@@@ -1068,9 -1024,12 +1068,12 @@@ fn folder_treeapp.toast(ui.ctx(), e);}resp.context_menu(|ui| {+ // the library actions of the Folders tree, when this folder (or one inside it) holds library photos+ let library = app.caches.folder_tree(&app.session.catalog);+ let held = library_node_for(&library, path);if (transient || indent > 0.0)&& ui- .button(if transient { "Keep in Local" } else { "Add to Local" })+ .button(crate::i18n::tr(if transient { "Keep in Local" } else { "Add to Local" })).on_hover_text(crate::i18n::tr("List this folder in Local from now on")).clicked(){@@@ -1809,19 -1727,38 +1815,51 @@@ fn row_menu(app: &mut LightcraftApp, re}}+/// Locate Missing Files… of a Folders row: choose where this folder moved, then let the existing+/// background finder relink only this folder's photos (including the folders inside it).+fn locate_missing_item(app: &mut LightcraftApp, ui: &mut egui::Ui, n: &FolderNode) {+ let r = ui.button(crate::i18n::tr("Locate Missing Files…"));+ register(ui.ctx(), "folderLocateMissing", r.rect);+ if r.clicked() {+ if let Err(e) = app.run("file.findMissing", json!({"within": n.path})) {+ app.toast(ui.ctx(), e);+ }+ ui.close();+ }+}++ /// The node Synchronize Folder… of a Local folder `path` works on, with the name its dialog shows:+ /// the Folders row for that very folder, else (a folder above rows) the folder itself, as a folder+ /// holding other folders. `None` when no library photo lies in `path` or inside it. Reads the+ /// cached Folders tree only; the disk is not touched.+ fn library_node_for(tree: &[FolderNode], path: &str) -> Option<(FolderNode, String)> {+ use lightcraft_catalog::query::folder_within;+ fn exact<'a>(tree: &'a [FolderNode], path: &str) -> Option<&'a FolderNode> {+ tree.iter().find_map(|n| if same_folder(&n.path, path) { Some(n) } else { exact(&n.children, path) })+ }+ fn any_inside(tree: &[FolderNode], path: &str) -> bool {+ tree.iter().any(|n| (n.count > 0 && folder_within(&n.path, path)) || any_inside(&n.children, path))+ }+ if let Some(n) = exact(tree, path).filter(|n| n.count > 0) {+ return Some((n.clone(), lightcraft_catalog::folders::folder_label(&n.path)));+ }+ if !any_inside(tree, path) {+ return None;+ }+ let name = std::path::Path::new(path).file_name().map(|f| f.to_string_lossy().to_string()).unwrap_or_else(|| path.to_string());+ let node = FolderNode {+ name: name.clone(),+ path: path.to_string(),+ count: 0,+ own: 0,+ volume: false,+ selectable: false,+ label: None,+ children: Vec::new(),+ };+ Some((node, name))+ }+/// Synchronize Folder… of a Folders row (widget `folderSynchronize`): opens its dialog, which/// scans the folder in the background.fn synchronize_item(app: &mut LightcraftApp, ui: &mut egui::Ui, n: &FolderNode, name: &str) {