LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge main into fix/issue-30-import-entry-point
Brandon Thomasb56e40e8d5d3
diff --cc crates/engine/src/cmd/library.rsindex 9077b00ae,dfee9e7cd..3cd795a36--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@@ -732,10 -732,10 +732,10 @@@ pub fn specs() -> Vec<CommandSpec>),cmd!("library.import",- "Add Photos…",+ "Import Photos",["File"],Some("Cmd+Shift+I"),- "{paths: [file or folder (recursive)], mode?: add|copy (add = reference the files in place; copy = into the library's Originals/YYYY/YYYY-MM-DD/), destination?: folder for copies, organize?: date|month|flat, rename?: file-name template for copies ({name} {seq:N} {date:%Y%m%d} {camera} {title}), renameStart?: 1, metadataPreset?: name, dng?: bool (copy raws as DNG), local?: bool (browsing: the photos stay out of the library, like library.browse), album?: albumId, albumName?: new album, preset?: presetId, keywords?: [..]} → {imported, duplicates, failed, album?}",+ "{paths: [file or folder (recursive)], mode?: add|copy (add = reference the files in place; copy = into the library's Originals/YYYY/YYYY-MM-DD/), destination?: folder for copies, organize?: date (YYYY/YYYY-MM-DD) | month (YYYY/YYYY-MM) | flat | a folder template, e.g. `{date:%Y}/{date:%Y%m%d}` → 2026/20260114 (the template's `/` make the folders, each level expanded with the rename tokens and made a safe folder name: never outside the destination; must be relative, no `..`; a level with missing metadata is `unknown`) — dated by capture time, else the import time, rename?: file-name template for copies, original extension added (tokens: {name} {num} {seq} {seq:N} {date} {date:%Y%m%d} {folder} {camera} {lens} {iso} {rating} {title} {creator} {ext}; photo.renameTokens explains each; blank = keep names), renameStart?: 1, metadataPreset?: name, dng?: bool (copy raws as DNG), local?: bool (browsing: the photos stay out of the library, like library.browse), album?: albumId, albumName?: new album, preset?: presetId, keywords?: [..]} → {imported, duplicates, failed, album?}",always,|s, p| {let paths = strs(p, "paths");diff --cc crates/engine/src/devices.rsindex c1953a741,bc82a727d..825ed5f6d--- a/crates/engine/src/devices.rs+++ b/crates/engine/src/devices.rs@@@ -1,6 -1,15 +1,15 @@@//! Cameras and memory cards: mounted volumes with a `DCIM` folder (the DCF layout every camera-//! writes). Listed by `library.devices`; the app offers them under File → Add from Device, and+//! writes). Listed by `library.devices`; the app offers them under File → Import from Device, and//! the import review copies from them into the library.+ //!+ //! Menus are rebuilt every frame (even with their popups closed), so [`devices`] never touches the+ //! disk: it serves the last scan and, when that is older than [`MAX_AGE`], starts one background+ //! rescan (coalesced; no lock is held while it runs). A changed result calls the [`on_change`]+ //! hook, which the UI uses to repaint, so hot-plugged cards still appear. [`devices_now`] scans+ //! synchronously for explicit requests (`library.devices`, Add from Device without a path).++ use std::sync::{Arc, Mutex};+ use std::time::Duration;use serde::Serialize;diff --cc crates/ui-egui/src/import.rsindex 52cf6e87d,72b00c845..e58854a68--- a/crates/ui-egui/src/import.rs+++ b/crates/ui-egui/src/import.rs@@@ -1,6 -1,7 +1,8 @@@-//! The import review dialog (File → Add Photos…): the files found under the chosen files and-//! folders as a grid of thumbnails with checkboxes (duplicates marked and unchecked), the-//! destination (add in place / copy into the library's `Originals/` or a chosen folder, filed by day, by month,-//! into one folder or by a custom folder template, optionally renamed), an album+//! The import review dialog (File → Import Photos… / Import from Folder… / Import from Device):- //! the source it scanned (a scanned folder is *not* added to Local), the files found under it as a grid of thumbnails with checkboxes (duplicates marked and unchecked), the- //! destination (add in place / copy into the library's dated `Originals/` folders), an album++//! the source it scanned (a scanned folder is *not* added to Local), the files found under it as++//! a grid of thumbnails with checkboxes (duplicates marked and unchecked), the destination (add in++//! place / copy into the library's `Originals/` or a chosen folder, filed by day, by month, into++//! one folder or by a custom folder template, optionally renamed), an album//! (existing or new), a preset and keywords to apply. Importing runs in small batches, one per//! frame, with a progress window; the whole import is one undo step.@@@ -628,23 -657,124 +684,141 @@@ fn candidate_cell(app: &mut LightcraftA}}+ /// The "Tags" toggle beside a template field (`button:<key>Tags`); returns whether the tag help+ /// ([`tag_help`]) is open.+ pub(crate) fn tag_toggle(ui: &mut egui::Ui, key: &str) -> bool {+ let id = egui::Id::new((key, "tags-open"));+ let mut open = ui.ctx().data(|d| d.get_temp::<bool>(id)).unwrap_or(false);+ let r = crate::widgets::text_button(ui, &format!("{key}Tags"), "Tags", open).on_hover_text("Show the template tags; click one to insert it");+ if r.clicked() {+ open = !open;+ ui.ctx().data_mut(|d| d.insert_temp(id, open));+ }+ open+ }++ /// "Unknown tag {x} stays as typed" under a template field, when it has one.+ pub(crate) fn unknown_tags_warning(ui: &mut egui::Ui, template: &str) {+ let unknown = lightcraft_engine::rename::unknown_tokens(template);+ if !unknown.is_empty() {+ let s = if unknown.len() == 1 { "" } else { "s" };+ let text = format!("Unknown tag{s} {} stay{} as typed (see Tags)", unknown.join(" "), if unknown.len() == 1 { "s" } else { "" });+ ui.label(egui::RichText::new(text).color(Tokens::get(ui.ctx()).caution));+ }+ }++ /// Insert `tag` into `text` at the text cursor of the field `edit_id` (replacing its selection);+ /// appended when the field never had a cursor. The cursor ends up after the tag.+ pub(crate) fn insert_at_cursor(ctx: &egui::Context, edit_id: egui::Id, text: &mut String, tag: &str) {+ use egui::text::{CCursor, CCursorRange};+ let mut state = egui::text_edit::TextEditState::load(ctx, edit_id).unwrap_or_default();+ let n = text.chars().count();+ let (a, b) = state.cursor.char_range().map_or((n, n), |r| {+ let (x, y) = (r.primary.index.0.min(n), r.secondary.index.0.min(n));+ (x.min(y), x.max(y))+ });+ let byte = |c: usize| text.char_indices().nth(c).map_or(text.len(), |(i, _)| i);+ let (ba, bb) = (byte(a), byte(b));+ text.replace_range(ba..bb, tag);+ state.cursor.set_char_range(Some(CCursorRange::one(CCursor::new(a + tag.chars().count()))));+ state.store(ctx, edit_id);+ ctx.memory_mut(|m| m.request_focus(edit_id));+ }++ /// The template tag help: every tag (from the engine's one list, `rename::TOKENS`) with its+ /// meaning and an example, the `{date:…}` directives and how templates behave. Clicking a tag+ /// (`button:<key>Tag-<i>`) inserts it at the cursor of the field `edit_id`.+ pub(crate) fn tag_help(ui: &mut egui::Ui, key: &str, text: &mut String, edit_id: egui::Id) {+ use lightcraft_engine::rename::{DATE_DIRECTIVES, TEMPLATE_NOTES, TOKENS, token_example};+ let t = Tokens::get(ui.ctx());+ egui::Frame::new().fill(t.inset).corner_radius(4.0).inner_margin(6.0).show(ui, |ui| {+ ui.label(+ egui::RichText::new("Click a tag to insert it. Examples are for IMG_0042.CR3 taken 14 Jan 2026, 05:58:48.").color(t.text_dim).small(),+ );+ egui::ScrollArea::vertical().id_salt((key, "tags")).max_height(170.0).show(ui, |ui| {+ egui::Grid::new((key, "tag-grid")).num_columns(3).spacing([10.0, 2.0]).show(ui, |ui| {+ for (i, tok) in TOKENS.iter().enumerate() {+ let r = ui.add(egui::Button::new(egui::RichText::new(tok.tag).monospace().color(t.text)).small()).on_hover_text(+ if tok.aliases.is_empty() {+ "Insert at the cursor".to_string()+ } else {+ format!("Insert at the cursor (also written {})", tok.aliases.join(", "))+ },+ );+ register(ui.ctx(), format!("button:{key}Tag-{i}"), r.rect);+ if r.clicked() {+ insert_at_cursor(ui.ctx(), edit_id, text, tok.tag);+ }+ ui.label(egui::RichText::new(tok.meaning).color(t.text_label));+ ui.label(egui::RichText::new(token_example(tok.tag)).monospace().color(t.text_dim));+ ui.end_row();+ }+ });+ let directives: Vec<String> = DATE_DIRECTIVES.iter().map(|(d, m)| format!("{d} {m}")).collect();+ ui.label(egui::RichText::new(format!("{{date:…}} directives: {}", directives.join(" · "))).color(t.text_dim).small());+ for n in TEMPLATE_NOTES {+ ui.label(egui::RichText::new(format!("• {n}")).color(t.text_dim).small());+ }+ });+ });+ }++ /// The folder template the Custom choice starts with (`2026/20260114/`).+ pub const DEFAULT_FOLDER_TEMPLATE: &str = "{date:%Y}/{date:%Y%m%d}";++ /// Where the first selected photo would be copied to (destination, folders, name), for the+ /// dialog's example line; `None` without a photo or with an unusable folder template.+ pub fn example_destination(app: &LightcraftApp, d: &ImportDialog) -> Option<String> {+ let c = d.candidates.iter().zip(&d.checked).find(|(c, on)| **on && c.duplicate.is_none() && c.error.is_none()).map(|(c, _)| c)?;+ let organize = match d.organize_param().ok()? {+ Some(o) => lightcraft_engine::import::Organize::parse(&o)?,+ None => Default::default(),+ };+ let mut q = lightcraft_catalog::Photo::new(+ lightcraft_catalog::PhotoId(0),+ lightcraft_catalog::Source::File { path: c.path.clone() },+ &c.name,+ &c.format,+ 0,+ 0,+ // a photo without a capture time is dated by the import (now)+ &(app.session.clock)(),+ );+ q.captured = c.captured.clone();+ // the probe's metadata, so {camera}, {title}… preview as they will import+ if let Some(info) = app.session.import_probes.get(&c.path) {+ q.meta = info.meta.clone();+ }+ let name = if d.rename.trim().is_empty() { c.name.clone() } else { lightcraft_engine::rename::expand(d.rename.trim(), &q, 1) };+ let root = if d.destination.trim().is_empty() {+ app.session.library.as_ref().map_or_else(|| "Originals".to_string(), |l| l.dir.join("Originals").to_string_lossy().to_string())+ } else {+ d.destination.trim().trim_end_matches(['/', '\\']).to_string()+ };+ let sep = std::path::MAIN_SEPARATOR_STR;+ let mut parts = vec![root];+ parts.extend(organize.folders(&q));+ parts.push(name);+ Some(parts.join(sep))+ }++/// The import source in a few words: a folder's name, a file's name, or "N files and folders".+pub fn source_summary(sources: &[String]) -> String {+ let name = |p: &str| std::path::Path::new(p).file_name().map_or_else(|| p.to_string(), |n| n.to_string_lossy().to_string());+ match sources {+ [one] if std::path::Path::new(one).is_dir() => format!("Folder “{}” (and its subfolders)", name(one)),+ [one] => name(one),+ many => {+ let folders = many.iter().filter(|p| std::path::Path::new(p.as_str()).is_dir()).count();+ match folders {+ 0 => format!("{} files", many.len()),+ f if f == many.len() => format!("{f} folders (and their subfolders)"),+ f => format!("{} files and {f} folder{}", many.len() - f, if f == 1 { "" } else { "s" }),+ }+ }+ }+}+/// A labelled row (fixed label column).fn field<R>(ui: &mut egui::Ui, label: &str, add: impl FnOnce(&mut egui::Ui) -> R) -> R {let t = Tokens::get(ui.ctx());diff --cc docs/parity.mdindex 79d72dba3,28075fc89..7fffddfe2--- a/docs/parity.md+++ b/docs/parity.md@@@ -99,10 -99,10 +99,10 @@@ under the UI command that wraps it (a n| Id | Feature | Tier | Status | Evidence | Missing / notes ||---|---|---|---|---|---|-| LR-IMP-ADD-DIALOG | Add photos/folders | P0 | ✅ | `cmd:file.addPhotos`, `cmd:library.importPreview`, `cmd:library.import` (`mode`, `album`, `albumName`, `preset`, `keywords`), `crates/ui-egui/src/import.rs` | review dialog: candidate grid with thumbnails and checkboxes (duplicates by path/content marked and unchecked), destination, album (existing/new), preset, keywords; the folder scan runs on a background thread with a progress window and Cancel (a NAS folder no longer freezes the window); batched import with a progress window; one undo step. Drag-and-drop still imports directly |+| LR-IMP-ADD-DIALOG | Add photos/folders | P0 | ✅ | `cmd:file.addPhotos`, `cmd:library.importPreview`, `cmd:library.import` (`mode`, `album`, `albumName`, `preset`, `keywords`), `crates/ui-egui/src/import.rs` | review dialog (Import Photos): the scanned source (a scanned folder is not added to Local), candidate grid with thumbnails and checkboxes (duplicates by path/content marked and unchecked), transfer mode (add in place / copy, each explained), album (existing/new), preset, keywords; the folder scan runs on a background thread with a progress window and Cancel (a NAS folder no longer freezes the window); batched import with a progress window; one undo step. Drag-and-drop still imports directly || LR-IMP-DRAGDROP | Drop files/folders to import | P0 | ✅ | `crates/ui-egui/src/lib.rs` (dropped files → `cmd:library.import`) | dropping onto a specific album not supported || LR-IMP-DUPES | Skip duplicates by content | P1 | ✅ | `crates/engine/src/import.rs`, `crates/engine/src/tests_import.rs` | |- | LR-IMP-DEVICE | Import from camera/card | P1 | ✅ | `cmd:library.devices`, `cmd:file.addFromDevice`, `crates/engine/src/devices.rs` | mounted volumes with a DCIM folder (macOS /Volumes, Linux /media and /run/media, Windows drive letters); File → Import from Device → the import review, copying into the library by default; no PTP/MTP (cameras that don't mount as a disk) |-| LR-IMP-DEVICE | Import from camera/card | P1 | ✅ | `cmd:library.devices`, `cmd:file.addFromDevice`, `crates/engine/src/devices.rs` | mounted volumes with a DCIM folder (macOS /Volumes, Linux /media and /run/media, Windows drive letters); File → Add from Device → the import review, copying into the library by default; menus serve the last scan and rescan in the background (never blocking a frame; hot-plugs repaint); no PTP/MTP (cameras that don't mount as a disk) |++| LR-IMP-DEVICE | Import from camera/card | P1 | ✅ | `cmd:library.devices`, `cmd:file.addFromDevice`, `crates/engine/src/devices.rs` | mounted volumes with a DCIM folder (macOS /Volumes, Linux /media and /run/media, Windows drive letters); File → Import from Device → the import review, copying into the library by default; menus serve the last scan and rescan in the background (never blocking a frame; hot-plugs repaint); no PTP/MTP (cameras that don't mount as a disk) || LR-IMP-AUTO | Watched-folder auto import | P2 | ✅ | `cmd:library.autoImport`, `cmd:library.autoImportScan`, `crates/ui-egui/src/panels/settings.rs` | Settings ▸ Import ▸ Auto Import: a watched folder whose new photos are added (in place or copied) once complete, into an optional album; scanned every 3 s || LR-IMP-PRESET | Preset on import | P2 | ✅ | `cmd:library.import` (`preset`) | chosen in the import review; one History entry || LR-IMP-RAWDEFAULT | Raw defaults | P1 | ✅ | `cmd:library.preferences`, `crates/engine/src/import.rs`, `crates/ui-egui/src/panels/settings.rs` | LightCraft default / a preset / per camera (make + model); non-raw default too; the preset look counts as unedited and Reset returns to it |@@@ -504,9 -505,9 +505,9 @@@ visible menu bar yet: the menu model i| MENU-APP-SYNC | Sync status / pause | OOS | 🚫 | | || MENU-APP-SIGNOUT | Sign out | OOS | 🚫 | | || MENU-APP-HIDE | Hide / hide others / show all | P1 | ✅ | `apps/lightcraft/src/native_menu.rs` | the system's own items in the app menu (⌘H, ⌥⌘H) |- | MENU-APP-QUIT | Quit | P0 | ✅ | `cmd:app.quit`, `apps/lightcraft/src/native_menu.rs` | macOS: app menu (native); elsewhere: File → Quit LightCraft |+ | MENU-APP-QUIT | Quit | P0 | ✅ | `cmd:app.quit`, `apps/lightcraft/src/native_menu.rs` | macOS: app menu (native); elsewhere: File → Quit LightCraft, always the last item in its own group (after commands the File layout does not list) |-| MENU-FILE-ADDPHOTOS | Add Photos… | P0 | ✅ | `cmd:file.addPhotos` | |-| MENU-FILE-ADDFOLDER | Add Folder… | P0 | ✅ | `cmd:file.addFolder`, `cmd:library.importPreview` | folder picker (desktop) → the import review, subfolders included; `path` param for agents |+| MENU-FILE-ADDPHOTOS | Import Photos… (was Add Photos…) | P0 | ✅ | `cmd:file.addPhotos`, `crates/ui-egui/src/menus.rs` | first item of File, ⇧⌘I; file picker → the import review |+| MENU-FILE-ADDFOLDER | Import from Folder… (was Add Folder…) | P0 | ✅ | `cmd:file.addFolder`, `cmd:library.importPreview` | folder picker (desktop) → the import review, subfolders included; `path` param for agents. Worded as importing: it doesn't save a Local location (that is Local → Browse Folder…) || MENU-FILE-MIGRATE | Migrate photos | OOS | 🚫 | | || MENU-FILE-NEWALBUM | New Album… | P0 | ✅ | `cmd:dialog.newAlbum` | || MENU-FILE-NEWFOLDER | New Folder… | P0 | ✅ | `cmd:dialog.newFolder` | ⇧⌘N |