diff --git a/Cargo.lock b/Cargo.lock
index 037865f87f2..5fc4d1ad899 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3987,6 +3987,7 @@ dependencies = [
name = "lightcraft-ui-egui"
version = "0.18.0"
dependencies = [
+ "chrono",
"craft-ui",
"craft-update",
"craft-window",
@@ -4010,6 +4011,7 @@ dependencies = [
"log",
"serde",
"serde_json",
+ "sys-locale",
"toml",
"web-time",
]
diff --git a/apps/lightcraft-cli/src/main.rs b/apps/lightcraft-cli/src/main.rs
index 7822bbed9a5..e03c5e12435 100644
--- a/apps/lightcraft-cli/src/main.rs
+++ b/apps/lightcraft-cli/src/main.rs
@@ -140,6 +140,15 @@ fn library_error(dir: &str, e: lightcraft_engine::EngineError) -> String {
}
fn main() -> ExitCode {
+ if std::env::args_os().nth(1).as_deref() == Some(std::ffi::OsStr::new(lightcraft_engine::metadata_read::WORKER_ARG)) {
+ return match lightcraft_engine::metadata_read::worker_main() {
+ Ok(()) => ExitCode::SUCCESS,
+ Err(error) => {
+ eprintln!("{error}");
+ ExitCode::FAILURE
+ }
+ };
+ }
// `--features dhat-heap`: count allocations; the profile is written when `_heap` drops
// (LIGHTCRAFT_DHAT_FILE, default dhat-heap.json).
#[cfg(feature = "dhat-heap")]
diff --git a/apps/lightcraft-cli/tests/it/cli.rs b/apps/lightcraft-cli/tests/it/cli.rs
index 613197459cd..c69e2c801e4 100644
--- a/apps/lightcraft-cli/tests/it/cli.rs
+++ b/apps/lightcraft-cli/tests/it/cli.rs
@@ -7,6 +7,29 @@ use serde_json::{Value, json};
use super::binary;
+#[test]
+fn metadata_worker_reads_sidecars_without_starting_the_cli() {
+ let input = tmp("metadata-worker.png");
+ gradient_png(&input);
+ let sidecar = input.with_extension("xmp");
+ std::fs::write(&sidecar, r#""#).unwrap();
+ let mut child = Command::new(binary())
+ .arg(lightcraft_engine::metadata_read::WORKER_ARG)
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .stderr(Stdio::piped())
+ .spawn()
+ .unwrap();
+ let request = json!({"path": input, "sidecar": {"naming": "stem", "owns_stem": true}});
+ child.stdin.take().unwrap().write_all(request.to_string().as_bytes()).unwrap();
+ let output = child.wait_with_output().unwrap();
+ assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr));
+ let result: Value = serde_json::from_slice(&output.stdout).unwrap();
+ assert!(result["Ok"][0]["xmp"].as_array().unwrap().iter().any(|tag| tag["value"] == "Worker title"), "{result}");
+ let _ = std::fs::remove_file(input);
+ let _ = std::fs::remove_file(sidecar);
+}
+
#[test]
fn contact_sheet_exports_pdf_and_protects_originals() {
let input = tmp("contact-sheet-input.png");
diff --git a/apps/lightcraft/src/main.rs b/apps/lightcraft/src/main.rs
index 2f98abafe10..5061d112289 100644
--- a/apps/lightcraft/src/main.rs
+++ b/apps/lightcraft/src/main.rs
@@ -148,6 +148,16 @@ impl eframe::App for App {
const EXIT_WAIT: std::time::Duration = std::time::Duration::from_secs(2);
fn main() -> eframe::Result {
+ // A metadata read runs in a disposable copy of this process, before logging, preferences or
+ // the window are initialised. Its parent can terminate a filesystem call that misses a deadline.
+ if std::env::args_os().nth(1).as_deref() == Some(std::ffi::OsStr::new(lightcraft_engine::metadata_read::WORKER_ARG)) {
+ let result = lightcraft_engine::metadata_read::worker_main();
+ if let Err(error) = result {
+ eprintln!("{error}");
+ std::process::exit(1);
+ }
+ return Ok(());
+ }
// Windows: the update helper is a copy of this program started with `--finish-update`.
#[cfg(windows)]
if let Some(result) = craft_update::self_update::finish(&lightcraft_ui_egui::UPDATE_APP, &std::env::args_os().skip(1).collect::>()) {
diff --git a/contributors/people.toml b/contributors/people.toml
index 836a3d801f2..edee32a1b14 100644
--- a/contributors/people.toml
+++ b/contributors/people.toml
@@ -82,3 +82,6 @@ sync_github_name = true
[people.Peaperfish]
real_name = "Yule Wang"
display_name = "Brian Wang"
+
+[people.pixelpuxel]
+real_name = "Gabriel Schreiber"
diff --git a/crates/engine/src/cmd/query.rs b/crates/engine/src/cmd/query.rs
index 5ceacb9539e..8dee2046781 100644
--- a/crates/engine/src/cmd/query.rs
+++ b/crates/engine/src/cmd/query.rs
@@ -128,29 +128,8 @@ pub fn specs() -> Vec {
}),
cmd!(query "photo.allMetadata", "All Metadata", [], None, "{id?} → {exif: [{group, tag, name, value}], xmp: [{name, value}]} — every EXIF / TIFF / GPS tag of the file and its XMP properties", always, |s, p| {
let id = photo_arg(s, p, "photo.allMetadata")?;
- let ph = s.catalog.photo(id).ok_or_else(|| super::bad("photo.allMetadata", "no such photo"))?.clone();
- let lightcraft_catalog::Source::File { path } = &ph.source else {
- return Ok(json!({"exif": [], "xmp": [], "note": "a generated demo photo has no file"}));
- };
- let bytes = match &s.media.file_bytes {
- Some(r) => r(path),
- None => std::fs::read(path).map_err(|e| format!("{path}: {e}")),
- }
- .map_err(|e| super::bad("photo.allMetadata", e))?;
- let exif: Vec = lightcraft_meta::file_tag_rows(&bytes)
- .into_iter()
- .map(|r| json!({"group": r.group, "tag": r.tag, "name": r.name, "value": r.value}))
- .collect();
- // Keep sidecar precedence; reuse the loaded bytes for embedded XMP.
- let packet = match s.sidecar_lookup(ph.id).find(path) {
- Some(sc) => std::fs::read_to_string(sc).ok(),
- None => lightcraft_meta::embedded(&bytes).xmp,
- };
- let xmp: Vec = packet
- .and_then(|x| lightcraft_meta::parse_xmp(&x).ok())
- .map(|d| d.properties.into_iter().filter(|(k, _)| !k.starts_with("lc:")).map(|(k, v)| json!({"name": k, "value": v.join("; ")})).collect())
- .unwrap_or_default();
- Ok(json!({"exif": exif, "xmp": xmp}))
+ crate::metadata_read::Request::new(s, id).and_then(|request| request.read())
+ .map_err(|e| super::bad("photo.allMetadata", e))
}),
cmd!(query "albums.list", "List Albums", [], None, "{}", always, |s, _| {
let all: Vec = s.catalog.albums().cloned().collect();
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 704602e4beb..bf585459e00 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -57,6 +57,7 @@ pub mod logging;
pub mod media;
pub mod memory;
pub mod merge;
+pub mod metadata_read;
mod model_download;
pub mod open_path;
pub mod originals;
@@ -1138,6 +1139,18 @@ impl Session {
self.shelved_filter.is_some()
}
+ /// Clear matching view rules from both the live filter and the filter put aside by Enable Filters.
+ pub fn clear_view_rules(&mut self, rules: &lightcraft_catalog::RuleSet) {
+ if self.filter.rule_set.as_ref() == Some(rules) {
+ self.filter.rule_set = None;
+ }
+ if let Some(filter) = &mut self.shelved_filter
+ && filter.rule_set.as_ref() == Some(rules)
+ {
+ filter.rule_set = None;
+ }
+ }
+
/// Photos shown in the grid/filmstrip for the current source, filter and sort.
pub fn visible(&mut self) -> &[PhotoId] {
let mut key =
diff --git a/crates/engine/src/metadata_read.rs b/crates/engine/src/metadata_read.rs
new file mode 100644
index 00000000000..1da9b72526d
--- /dev/null
+++ b/crates/engine/src/metadata_read.rs
@@ -0,0 +1,166 @@
+//! A read-only metadata request that can be moved to a UI worker.
+
+use crate::{Session, merge::ByteReader, sidecar::SidecarLookup};
+use lightcraft_catalog::{PhotoId, Source};
+use serde::{Deserialize, Serialize};
+use serde_json::{Value, json};
+
+/// Private desktop subcommand used for a metadata read that the parent can terminate on timeout.
+pub const WORKER_ARG: &str = "--metadata-read-worker";
+
+type ReadResult = Result<(Value, Option), String>;
+
+#[derive(Serialize, Deserialize)]
+struct WorkerInput {
+ path: String,
+ sidecar: SidecarLookup,
+}
+
+/// A detached request for all readable EXIF and XMP attached to one catalog photo.
+pub struct Request {
+ source: Source,
+ read: Option,
+ sidecar: SidecarLookup,
+}
+
+impl Request {
+ /// Capture the photo source, custom byte reader and sidecar policy from the session.
+ pub fn new(session: &Session, id: PhotoId) -> Result {
+ let photo = session.catalog.photo(id).ok_or("no such photo")?;
+ Ok(Self { source: photo.source.clone(), read: session.media.file_bytes.clone(), sidecar: session.sidecar_lookup(id) })
+ }
+
+ /// Return metadata in the command API shape, including a sidecar warning when present.
+ pub fn read(self) -> Result {
+ let (mut value, warning) = self.read_with_diagnostics()?;
+ if let Some(warning) = warning
+ && let Some(fields) = value.as_object_mut()
+ {
+ fields.insert("warning".into(), Value::String(warning));
+ }
+ Ok(value)
+ }
+
+ /// Return metadata and a non-fatal sidecar warning as separate values for the UI.
+ pub fn read_with_diagnostics(self) -> ReadResult {
+ let Source::File { path } = self.source else {
+ return Ok((json!({"exif": [], "xmp": [], "note": "a generated demo photo has no file"}), None));
+ };
+ read_file(path, self.read, self.sidecar)
+ }
+
+ /// Read in a child process so a blocked filesystem call can be terminated at the deadline.
+ /// Custom readers stay in-process because their closures cannot cross a process boundary.
+ #[cfg(not(target_arch = "wasm32"))]
+ pub fn read_with_deadline(self, timeout: std::time::Duration) -> ReadResult {
+ if self.read.is_some() {
+ return self.read_with_diagnostics();
+ }
+ let Source::File { path } = self.source else {
+ return Ok((json!({"exif": [], "xmp": [], "note": "a generated demo photo has no file"}), None));
+ };
+ read_in_worker(WorkerInput { path, sidecar: self.sidecar }, timeout)
+ }
+}
+
+/// Read and parse the original plus its chosen XMP sidecar, if one exists.
+fn read_file(path: String, read: Option, sidecar: SidecarLookup) -> ReadResult {
+ let bytes = match read {
+ Some(read) => read(&path),
+ None => std::fs::read(&path).map_err(|e| format!("{path}: {e}")),
+ }?;
+ let exif: Vec = lightcraft_meta::file_tag_rows(&bytes)
+ .into_iter()
+ .map(|row| json!({"group": row.group, "tag": row.tag, "name": row.name, "value": row.value}))
+ .collect();
+ let packet = match sidecar.find(&path) {
+ Some(sidecar) => std::fs::read_to_string(&sidecar).map(Some).map_err(|error| format!("{}: {error}", sidecar.display())),
+ None => Ok(lightcraft_meta::embedded(&bytes).xmp),
+ };
+ let parsed = packet.and_then(|packet| packet.map(|xmp| lightcraft_meta::parse_xmp(&xmp).map_err(|error| format!("XMP: {error}"))).transpose());
+ let warning = parsed.as_ref().err().cloned();
+ let xmp: Vec = parsed
+ .ok()
+ .flatten()
+ .map(|d| {
+ d.properties
+ .into_iter()
+ .filter(|(key, _)| !key.starts_with("lc:"))
+ .map(|(key, values)| json!({"name": key, "value": values.join("; ")}))
+ .collect()
+ })
+ .unwrap_or_default();
+ Ok((json!({"exif": exif, "xmp": xmp}), warning))
+}
+
+/// Serve one request on standard input/output. The desktop app calls this before initialising UI.
+#[cfg(not(target_arch = "wasm32"))]
+pub fn worker_main() -> Result<(), String> {
+ let input: WorkerInput = serde_json::from_reader(std::io::stdin().lock()).map_err(|error| format!("metadata worker input: {error}"))?;
+ let result = read_file(input.path, None, input.sidecar);
+ serde_json::to_writer(std::io::stdout().lock(), &result).map_err(|error| format!("metadata worker output: {error}"))
+}
+
+/// The task remains alive after the deadline until the killed child is confirmed stopped. This
+/// preserves the read cap even on a filesystem whose kernel call is temporarily uninterruptible.
+#[cfg(not(target_arch = "wasm32"))]
+fn read_in_worker(input: WorkerInput, timeout: std::time::Duration) -> ReadResult {
+ use std::io::{Read as _, Write as _};
+ use std::process::{Command, Stdio};
+
+ // Drop also covers failed pipe setup, writes and polling, which must not orphan a worker.
+ struct Worker(std::process::Child);
+ impl Drop for Worker {
+ fn drop(&mut self) {
+ let _ = self.0.kill();
+ let _ = self.0.wait();
+ }
+ }
+ let payload = serde_json::to_vec(&input).map_err(|error| format!("metadata worker input: {error}"))?;
+ let exe = std::env::current_exe().map_err(|error| format!("metadata worker executable: {error}"))?;
+ let mut worker = Worker(
+ Command::new(exe)
+ .arg(WORKER_ARG)
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .stderr(Stdio::null())
+ .spawn()
+ .map_err(|error| format!("metadata worker: {error}"))?,
+ );
+ let child = &mut worker.0;
+ let Some(mut stdin) = child.stdin.take() else { return Err("metadata worker has no input pipe".into()) };
+ stdin.write_all(&payload).map_err(|error| format!("metadata worker input: {error}"))?;
+ drop(stdin);
+ let Some(mut stdout) = child.stdout.take() else { return Err("metadata worker has no output pipe".into()) };
+ let output = std::thread::Builder::new()
+ .name("metadata-worker-output".into())
+ .spawn(move || {
+ let mut bytes = Vec::new();
+ stdout.read_to_end(&mut bytes).map(|_| bytes)
+ })
+ .map_err(|error| format!("metadata worker output thread: {error}"))?;
+ let started = std::time::Instant::now();
+ let mut timed_out = false;
+ loop {
+ match child.try_wait().map_err(|error| format!("metadata worker: {error}"))? {
+ Some(status) => {
+ let bytes = output
+ .join()
+ .map_err(|_| "metadata worker output thread stopped".to_owned())?
+ .map_err(|error| format!("metadata worker output: {error}"))?;
+ if timed_out {
+ return Err("metadata read timed out. Try Refresh.".into());
+ }
+ if !status.success() {
+ return Err(format!("metadata worker stopped with {status}"));
+ }
+ return serde_json::from_slice(&bytes).map_err(|error| format!("metadata worker output: {error}"))?;
+ }
+ None if !timed_out && started.elapsed() >= timeout => {
+ timed_out = true;
+ let _ = child.kill();
+ }
+ None => std::thread::sleep(std::time::Duration::from_millis(10)),
+ }
+ }
+}
diff --git a/crates/engine/src/sidecar.rs b/crates/engine/src/sidecar.rs
index 252dd911a68..2b10aa78a10 100644
--- a/crates/engine/src/sidecar.rs
+++ b/crates/engine/src/sidecar.rs
@@ -80,7 +80,7 @@ pub fn find_sidecar(original: &str, naming: SidecarNaming) -> Option {
/// may read the shared stem sidecar (`IMG_0001.xmp`) of its stem. A photo that shares its stem
/// with a file that owns that sidecar (see [`Session::sidecar_naming`]) reads its own `.xmp`
/// and never the packet of the sibling that owns the stem one (issue #1523).
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct SidecarLookup {
pub naming: SidecarNaming,
/// False when another file with the same stem owns the stem sidecar.
diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml
index 8e7b77f42f3..8e8303a223a 100644
--- a/crates/ui-egui/Cargo.toml
+++ b/crates/ui-egui/Cargo.toml
@@ -27,6 +27,8 @@ egui = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
log = { workspace = true }
+chrono = { workspace = true }
+sys-locale = { version = "0.3", features = ["js"] }
[dev-dependencies]
# tests record why they skip (`cargo xtask ci` lists the skips)
diff --git a/crates/ui-egui/locales/de.json b/crates/ui-egui/locales/de.json
index 552ce68016c..3cc180b818d 100644
--- a/crates/ui-egui/locales/de.json
+++ b/crates/ui-egui/locales/de.json
@@ -1,4 +1,14 @@
{
+ "Waiting for an earlier metadata read to finish…": "Warte auf einen vorherigen Metadatenzugriff…",
+ "Metadata read timed out. Try Refresh.": "Zeitlimit beim Lesen der Metadaten erreicht. Versuche es mit Aktualisieren.",
+ "Refresh": "Aktualisieren",
+ "Keys": "Keys",
+ "Combine Albums": "Sammlungen verknüpfen",
+ "OR: any album": "ODER: beliebige Sammlung",
+ "AND: every album": "UND: jede Sammlung",
+ "First minus others": "Erste minus weitere",
+ "Only one album": "Nur in einer Sammlung",
+ "Cmd/Ctrl-click albums to combine. A plain click shows one album.": "Sammlungen mit Cmd/Strg-Klick verknüpfen. Ein einfacher Klick zeigt eine Sammlung.",
" (library default)": " (Bibliotheksstandard)",
" (inverted)": " (umgekehrt)",
" · best of its burst": " · bestes Foto der Serie",
diff --git a/crates/ui-egui/src/album_combination.rs b/crates/ui-egui/src/album_combination.rs
new file mode 100644
index 00000000000..02ffe420d7c
--- /dev/null
+++ b/crates/ui-egui/src/album_combination.rs
@@ -0,0 +1,161 @@
+//! Live set operations over albums, expressed as the catalog's existing smart-album rules.
+//! Membership updates are reflected immediately, without duplicating or moving photos.
+
+use crate::LightcraftApp;
+use lightcraft_catalog::rules::Match;
+use lightcraft_catalog::{AlbumId, Rule, RuleSet};
+use lightcraft_engine::LibrarySource;
+use serde_json::{Value, json};
+
+pub const OPERATIONS: &[(&str, &str)] =
+ &[("union", "OR: any album"), ("intersection", "AND: every album"), ("difference", "First minus others"), ("exclusive", "Only one album")];
+
+/// Build one catalog album-membership predicate.
+fn field(id: u64, included: bool) -> Rule {
+ Rule::Field { field: "album".into(), op: if included { "is" } else { "isNot" }.into(), value: json!(id) }
+}
+
+/// Translate a named set operation into the catalog's existing live rules.
+fn rules(ids: &[u64], operation: &str) -> Result {
+ let (mode, rules) = match operation {
+ "union" => (Match::Any, ids.iter().map(|id| field(*id, true)).collect()),
+ "intersection" => (Match::All, ids.iter().map(|id| field(*id, true)).collect()),
+ "difference" => (Match::All, ids.iter().enumerate().map(|(i, id)| field(*id, i == 0)).collect()),
+ // For two albums this is XOR. With more albums, keep photos belonging to exactly one.
+ "exclusive" => (
+ Match::Any,
+ ids.iter()
+ .map(|id| Rule::Group { group: RuleSet { mode: Match::All, rules: ids.iter().map(|other| field(*other, id == other)).collect() } })
+ .collect(),
+ ),
+ _ => return Err("view.combineAlbums: unknown operation (union|intersection|difference|exclusive)".into()),
+ };
+ Ok(RuleSet { mode, rules })
+}
+
+/// Remove only the rules installed by this view, preserving unrelated filters.
+pub fn clear(app: &mut LightcraftApp) {
+ if let Some((ids, operation)) = app.ui.album_combination.take()
+ && let Ok(set) = rules(&ids, &operation)
+ {
+ app.session.clear_view_rules(&set);
+ }
+}
+
+/// Whether the stored combination still exactly describes the current live view.
+pub fn active(app: &LightcraftApp) -> bool {
+ app.ui.album_combination.as_ref().is_some_and(|(ids, op)| {
+ (2..=8).contains(&ids.len())
+ && app.session.source == LibrarySource::All
+ && rules(ids, op).is_ok_and(|set| app.session.filter.rule_set.as_ref() == Some(&set))
+ })
+}
+
+/// Validate and apply `view.combineAlbums`, returning the visible photo count.
+pub fn command(app: &mut LightcraftApp, params: &Value) -> Result {
+ let values = params.get("ids").and_then(Value::as_array).ok_or("view.combineAlbums: ids must be an array")?;
+ if !(2..=8).contains(&values.len()) {
+ return Err("view.combineAlbums: choose 2 to 8 albums".into());
+ }
+ let mut ids = Vec::new();
+ for value in values {
+ let id = value.as_u64().ok_or("view.combineAlbums: invalid album id")?;
+ if app.session.catalog.album(AlbumId(id)).is_none_or(|a| a.folder) {
+ return Err(format!("view.combineAlbums: no album {id}"));
+ }
+ if !ids.contains(&id) {
+ ids.push(id);
+ }
+ }
+ if ids.len() < 2 {
+ return Err("view.combineAlbums: choose two distinct albums".into());
+ }
+ let operation = match params.get("operation") {
+ None => "union",
+ Some(value) => value.as_str().ok_or("view.combineAlbums: operation must be a string")?,
+ };
+ let set = rules(&ids, operation)?;
+ let problems = set.check(&app.session.catalog);
+ if !problems.is_empty() {
+ return Err(problems.iter().map(ToString::to_string).collect::>().join("; "));
+ }
+ let preserve_filters = active(app) && app.ui.album_combination.as_ref().is_some_and(|(current, _)| current == &ids);
+ let filter = if preserve_filters {
+ // Changing only the operation keeps filters applied after the combination was opened.
+ json!({"ruleSet": set})
+ } else {
+ // A source choice starts a fresh view; ordinary filters can be applied to the result next.
+ let filter = lightcraft_catalog::Filter { rule_set: Some(set), ..Default::default() };
+ let mut filter = serde_json::to_value(filter).map_err(|e| e.to_string())?;
+ let fields = filter.as_object_mut().ok_or("view.combineAlbums: couldn't serialize the filter")?;
+ // These defaults are normally omitted by Filter's serializer. library.filter merges a
+ // partial payload, so spell them out to keep a previous Find Similar or multi-select
+ // filter from narrowing the new source view.
+ fields.insert("flags".into(), json!([]));
+ fields.insert("labels".into(), json!([]));
+ fields.insert("only".into(), json!([]));
+ fields.insert("onlyNone".into(), json!(false));
+ filter
+ };
+ app.session.source = LibrarySource::All;
+ app.session.execute("library.filter", &filter).map_err(|e| e.to_string())?;
+ if !preserve_filters {
+ app.ui.search.clear();
+ }
+ app.ui.album_combination = Some((ids, operation.into()));
+ app.session.keep_active_in_view();
+ Ok(json!({"count": app.session.visible().len(), "operation": operation}))
+}
+
+/// A modifier-click adds or removes an album; a plain click still shows just that album.
+pub fn toggle(app: &mut LightcraftApp, id: u64) {
+ let (mut ids, operation) = if active(app) {
+ app.ui.album_combination.clone().unwrap_or_default()
+ } else {
+ let ids = match app.session.source {
+ LibrarySource::Album(a) => vec![a.0],
+ _ => Vec::new(),
+ };
+ (ids, "union".into())
+ };
+ if ids.contains(&id) {
+ ids.retain(|a| *a != id);
+ } else {
+ ids.push(id);
+ }
+ let result = if ids.len() >= 2 {
+ app.run("view.combineAlbums", json!({"ids": ids, "operation": operation}))
+ } else if let Some(id) = ids.first() {
+ app.run("library.source", json!({"kind": "album", "id": id}))
+ } else {
+ app.run("library.source", json!({"kind": "all"}))
+ };
+ if let Err(e) = result {
+ app.toast(&app.tasks.repaint.clone().unwrap_or_default(), e);
+ }
+}
+
+/// Draw operation choices and the ordered names of the albums being combined.
+pub fn controls(app: &mut LightcraftApp, ui: &mut egui::Ui) {
+ if !active(app) {
+ return;
+ }
+ let Some((ids, mut operation)) = app.ui.album_combination.clone() else { return };
+ let before = operation.clone();
+ ui.label(crate::i18n::tr("Combine Albums"));
+ ui.horizontal_wrapped(|ui| {
+ for (id, label) in OPERATIONS {
+ let response = ui.selectable_value(&mut operation, (*id).into(), crate::i18n::tr(label));
+ crate::widgets::register(ui, format!("albumOperation:{id}"), response.rect);
+ }
+ });
+ let names: Vec<_> = ids.iter().filter_map(|id| app.session.catalog.album(AlbumId(*id))).map(|a| a.name.as_str()).collect();
+ ui.label(names.join(" → "));
+ ui.label(crate::i18n::tr("Cmd/Ctrl-click albums to combine. A plain click shows one album."));
+ if before != operation
+ && let Err(e) = app.run("view.combineAlbums", json!({"ids": ids, "operation": operation}))
+ {
+ app.toast(ui.ctx(), e);
+ }
+ ui.separator();
+}
diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs
index bba91d2f717..de5d29c41fd 100644
--- a/crates/ui-egui/src/app.rs
+++ b/crates/ui-egui/src/app.rs
@@ -38,6 +38,7 @@ impl LightcraftApp {
native_menu: false,
native_shortcuts: Default::default(),
recording_shortcut: None,
+ metadata_panel: Default::default(),
text_focus: false,
headless_host: false,
notices: vec![],
@@ -212,7 +213,23 @@ impl LightcraftApp {
} else {
params
};
- let r = self.session.execute(id, ¶ms).map_err(CommandError::from);
+ let combined = self.ui.album_combination.is_some();
+ let mut r = self.session.execute(id, ¶ms).map_err(CommandError::from);
+ let member_removed = combined
+ && self
+ .ui
+ .album_combination
+ .as_ref()
+ .is_some_and(|(ids, _)| ids.iter().any(|id| self.session.catalog.album(lightcraft_catalog::AlbumId(*id)).is_none()));
+ if r.is_ok() && combined && (id == "library.source" || member_removed) {
+ crate::album_combination::clear(self);
+ self.session.keep_active_in_view();
+ if id == "library.source"
+ && let Ok(result) = &mut r
+ {
+ *result = serde_json::json!({"count": self.session.visible().len()});
+ }
+ }
if r.is_ok() && matches!(id, "crop.aspect" | "crop.rotateAspect") {
self.ui.crop_default_aspect = if id == "crop.aspect" && params.get("aspect").and_then(Value::as_str) == Some("original") {
Some(serde_json::json!("original"))
diff --git a/crates/ui-egui/src/dialogs/import/scan.rs b/crates/ui-egui/src/dialogs/import/scan.rs
index 67b1fa176b2..d6369970a16 100644
--- a/crates/ui-egui/src/dialogs/import/scan.rs
+++ b/crates/ui-egui/src/dialogs/import/scan.rs
@@ -89,6 +89,7 @@ pub fn browse(app: &mut LightcraftApp, path: &str, subfolders: Option) ->
if app.scan.as_ref().is_some_and(|t| !t.browse) || app.import.as_ref().is_some_and(|t| !t.browse) {
return Err("an import is running".into());
}
+ crate::album_combination::clear(app);
let dir_s = dir.to_string_lossy().trim_end_matches(['/', '\\']).to_string();
let subfolders = subfolders.unwrap_or_else(|| app.session.browse.as_ref().is_some_and(|b| b.subfolders));
let running = app.scan.as_ref().is_some_and(|t| t.browse) || app.import.as_ref().is_some_and(|t| t.browse);
diff --git a/crates/ui-egui/src/dialogs/keymap.rs b/crates/ui-egui/src/dialogs/keymap.rs
index d0d058afae8..f95b439897d 100644
--- a/crates/ui-egui/src/dialogs/keymap.rs
+++ b/crates/ui-egui/src/dialogs/keymap.rs
@@ -21,11 +21,10 @@ const SHOW_ALL: &str = "shortcuts-show-all";
pub fn body(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
let mac = ui.ctx().os() == egui::os::OperatingSystem::Mac;
capture(app, ui.ctx());
- ui.set_min_width(560.0);
let (search_id, all_id) = (egui::Id::unique(SEARCH), egui::Id::unique(SHOW_ALL));
let mut search: String = ui.data(|d| d.get_temp(search_id)).unwrap_or_default();
let mut show_all: bool = ui.data(|d| d.get_temp(all_id)).unwrap_or(false);
- ui.horizontal(|ui| {
+ ui.horizontal_wrapped(|ui| {
let r = ui.add(egui::TextEdit::singleline(&mut search).hint_text(crate::i18n::tr("Search commands or keys")).desired_width(220.0));
register(ui, "field:shortcutsSearch", r.rect);
let r = ui.checkbox(&mut show_all, crate::i18n::tr("Show commands without a shortcut"));
@@ -63,18 +62,24 @@ pub fn body(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {
// a fixed height, so the dialog doesn't jump around while the search narrows the list
// (shorter on a short window, so the dialog fits it)
let h = crate::panels::dialogs::list_height(ui, 400.0);
- egui::ScrollArea::vertical().max_height(h).min_scrolled_height(h).auto_shrink([false, false]).id_salt("shortcuts-list").show(ui, |ui| {
- egui::Grid::new("shortcuts").striped(true).num_columns(4).spacing([12.0, 4.0]).show(ui, |ui| {
- for (b, sc) in &rows {
- row(app, ui, t, b, sc.as_deref(), mac);
- }
- if rows.is_empty() {
- ui.label(RichText::new(crate::i18n::tr("No matching commands")).color(t.text_dim));
- ui.end_row();
- }
+ egui::ScrollArea::both()
+ .max_width(ui.available_width())
+ .max_height(h)
+ .min_scrolled_height(h)
+ .auto_shrink([false, false])
+ .id_salt("shortcuts-list")
+ .show(ui, |ui| {
+ egui::Grid::new("shortcuts").striped(true).num_columns(4).spacing([12.0, 4.0]).show(ui, |ui| {
+ for (b, sc) in &rows {
+ row(app, ui, t, b, sc.as_deref(), mac);
+ }
+ if rows.is_empty() {
+ ui.label(RichText::new(crate::i18n::tr("No matching commands")).color(t.text_dim));
+ ui.end_row();
+ }
+ });
+ fixed_keys(app, ui, t, mac, &needle);
});
- fixed_keys(app, ui, t, mac, &needle);
- });
}
/// `Cmd+Shift+Z` as menus show it (`⇧⌘Z` on macOS).
diff --git a/crates/ui-egui/src/dialogs/settings.rs b/crates/ui-egui/src/dialogs/settings.rs
index 271b6e7c913..1f109cbf63e 100644
--- a/crates/ui-egui/src/dialogs/settings.rs
+++ b/crates/ui-egui/src/dialogs/settings.rs
@@ -52,6 +52,7 @@ pub const TABS: &[(&str, &str)] = &[
("performance", "Performance"),
("display", "Display"),
("interface", "Interface"),
+ ("keys", "Keys"),
("slideshow", "Slideshow"),
("faces", "Faces"),
("denoise", "AI Denoise"),
@@ -70,6 +71,7 @@ pub fn body(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &str) {
"performance" => performance_tab(app, ui, &t),
"display" => display_tab(app, ui, &t),
"interface" => interface_tab(app, ui, &t),
+ "keys" => super::keymap::body(app, ui, &t),
"slideshow" => slideshow_tab(app, ui, &t, true),
"faces" => crate::panels::faces::settings_tab(app, ui, &t),
"denoise" => crate::panels::denoise::settings_tab(app, ui, &t),
diff --git a/crates/ui-egui/src/dialogs/settings/libraries.rs b/crates/ui-egui/src/dialogs/settings/libraries.rs
index 5e615bfbcbf..a6bf48d7246 100644
--- a/crates/ui-egui/src/dialogs/settings/libraries.rs
+++ b/crates/ui-egui/src/dialogs/settings/libraries.rs
@@ -78,6 +78,7 @@ fn switch_library(app: &mut LightcraftApp, path: &str) -> Result
let previous_dir = app.session.library.as_ref().filter(|l| l.on_disk).map(|l| l.dir.clone());
let previous = previous_dir.as_ref().map(|d| d.to_string_lossy().into_owned());
app.session.close_library().map_err(|e| e.to_string())?;
+ crate::album_combination::clear(app);
let opened = app.session.open_library(&dir, false).map(|_| ()).map_err(|e| format!("{path}: {e}"));
app.lightroom_last = None;
app.lightroom_result = None;
diff --git a/crates/ui-egui/src/docking.rs b/crates/ui-egui/src/docking.rs
index 97cd8ac6914..ac28db2cef2 100644
--- a/crates/ui-egui/src/docking.rs
+++ b/crates/ui-egui/src/docking.rs
@@ -393,11 +393,12 @@ pub fn show(app: &mut crate::LightcraftApp, ui: &mut egui::Ui) {
style.font = t.font(12.0);
// Tool and preset panels publish hover previews before the photo consumes them.
let mut canvas = None;
+ let tools_label = if app.ui.right == crate::state::RightPanel::Metadata { "Metadata" } else { "Tools" };
let output = DockArea::new(egui::Id::unique("lightcraft-docking")).locked(workspace.locked).show_with_limits(
ui,
&workspace.layout,
&style,
- |panel| crate::i18n::tr(panel.label()).into(),
+ |panel| crate::i18n::tr(if *panel == Panel::Tools { tools_label } else { panel.label() }).into(),
permissions,
panel_limits,
|ui, panel| match panel {
@@ -412,7 +413,7 @@ pub fn show(app: &mut crate::LightcraftApp, ui: &mut egui::Ui) {
crate::panels::left::show(app, ui);
}
Panel::Tools => {
- crate::widgets::announce_region(ui, egui::accesskit::Role::Complementary, crate::i18n::tr(Panel::Tools.label()));
+ crate::widgets::announce_region(ui, egui::accesskit::Role::Complementary, crate::i18n::tr(tools_label));
crate::widgets::register(ui, "panel:right_panel", ui.max_rect());
crate::panels::right::show(app, ui);
}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 5e794f105c5..ab576982465 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -15,6 +15,7 @@ pub const UPDATE_APP: craft_update::app::App = craft_update::app::App {
..craft_update::suite::LIGHTCRAFT
};
+mod album_combination;
pub mod brush_live;
pub mod canvas_keys;
mod command_error;
@@ -165,6 +166,7 @@ pub struct LightcraftApp {
/// The keyboard shortcuts editor is waiting for a key press for this command: no shortcut
/// fires (the native menu bar drops its accelerators too) until it gets one or is cancelled.
pub recording_shortcut: Option,
+ pub(crate) metadata_panel: panels::right::MetadataRuntime,
/// A text field had the keyboard at the end of the last frame. egui drops the focus as Esc
/// arrives, before the shortcuts are read, so this is how Esc there stays the field's own.
pub text_focus: bool,
diff --git a/crates/ui-egui/src/menus/menubar.rs b/crates/ui-egui/src/menus/menubar.rs
index 672c7cbccc7..36b6a33c840 100644
--- a/crates/ui-egui/src/menus/menubar.rs
+++ b/crates/ui-egui/src/menus/menubar.rs
@@ -304,6 +304,7 @@ const LAYOUT: &[(&str, &[&str])] = &[
"panel.versions",
"panel.activity",
"panel.info",
+ "panel.metadata",
"panel.keywords",
"---",
"@Edit Sections",
@@ -439,6 +440,7 @@ pub fn checked(app: &LightcraftApp, id: &str) -> Option {
"panel.versions" => panel(RightPanel::Versions),
"panel.activity" => panel(RightPanel::Activity),
"panel.info" => panel(RightPanel::Info),
+ "panel.metadata" => panel(RightPanel::Metadata),
"panel.keywords" => panel(RightPanel::Keywords),
"panel.presets" => Some(u.presets),
"library.toggleAutoWriteXmp" => Some(app.session.xmp.auto_write),
diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs
index ec9835a39f8..5d3e3188a29 100644
--- a/crates/ui-egui/src/menus/run.rs
+++ b/crates/ui-egui/src/menus/run.rs
@@ -146,6 +146,9 @@ fn theme_command(app: &mut LightcraftApp, p: &Value) -> Result {
/// Handle UI commands; `None` means "not a UI command — send it to the engine".
pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option> {
+ if id == "view.combineAlbums" {
+ return Some(crate::album_combination::command(app, p));
+ }
if matches!(id, "ui.dock" | "ui.dock.reset") {
return Some(crate::docking::command(app, id == "ui.dock.reset", p));
}
@@ -964,6 +967,10 @@ fn ui_commands_7(app: &mut LightcraftApp, ctx: &egui::Context, id: &str, p: &Val
panel(app, ctx, RightPanel::Info, "Info");
Ok(Value::Null)
}
+ "panel.metadata" => {
+ panel(app, ctx, RightPanel::Metadata, "Metadata");
+ Ok(Value::Null)
+ }
"panel.keywords" => {
panel(app, ctx, RightPanel::Keywords, "Keywords");
Ok(Value::Null)
diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs
index c803de71939..b5edb887803 100644
--- a/crates/ui-egui/src/menus/ui_commands.rs
+++ b/crates/ui-egui/src/menus/ui_commands.rs
@@ -131,6 +131,8 @@ pub const UI_COMMANDS: &[UiCommand] = &[
("local.restoreHidden", "Show Hidden Local Locations", None, ""),
// {on?}: the Info panel's Target Photo / Selected Photos choice (on = Selected Photos)
("view.infoSelectedPhotos", "Show Metadata for Selected Photos", None, ""),
+ // {ids: [albumId, ...], operation: union|intersection|difference|exclusive}; 2–8 albums.
+ ("view.combineAlbums", "Combine Albums", None, ""),
("view.fullScreenPreview", "Full Screen Preview", Some("F"), "View"),
("view.lightsOut", "Lights Out", Some("Shift+L"), "View"),
("view.enterFullScreen", "Enter Full Screen", Some("Cmd+Shift+F"), "View"),
@@ -149,6 +151,7 @@ pub const UI_COMMANDS: &[UiCommand] = &[
("panel.redeye", "Red Eye", None, "Window"),
("panel.presets", "Presets", Some("Shift+P"), "Window"),
("panel.info", "Info", Some("I"), "Window"),
+ ("panel.metadata", "Metadata", None, "Window"),
("panel.keywords", "Keywords", Some("K"), "Window"),
// the Keywords panel with the cursor in its Add keyword box
("panel.addKeywords", "Add Keywords", Some("Cmd+K"), ""),
diff --git a/crates/ui-egui/src/panels/left/albums.rs b/crates/ui-egui/src/panels/left/albums.rs
index f9a2cf229f2..9717f11644a 100644
--- a/crates/ui-egui/src/panels/left/albums.rs
+++ b/crates/ui-egui/src/panels/left/albums.rs
@@ -5,6 +5,7 @@ use super::{Album, AlbumId, Align2, Icon, LibrarySource, LightcraftApp, Rect, Se
/// Albums: the tree of albums and the folders they are sorted into. `reveal`: an album just made,
/// whose folders open down to it.
pub(super) fn albums_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, reveal: Option) {
+ crate::album_combination::controls(app, ui);
let kids: AlbumKids = app.session.catalog.album_children_by_parent().into_iter().map(|(k, v)| (k, v.into_iter().cloned().collect())).collect();
let cat = &app.session.catalog;
let mut open_to = Vec::new();
@@ -13,14 +14,20 @@ pub(super) fn albums_rows(app: &mut LightcraftApp, ui: &mut egui::Ui, reveal: Op
open_to.push(p);
cur = cat.album(p).and_then(|a| a.parent);
}
- albums_tree(app, ui, &kids, None, 0.0, &open_to);
+ let combined = if crate::album_combination::active(app) {
+ app.ui.album_combination.as_ref().map(|(ids, _)| ids.clone()).unwrap_or_default()
+ } else {
+ Vec::new()
+ };
+ albums_tree(app, ui, &kids, None, 0.0, (&open_to, &combined));
}
/// The albums inside each folder (`None`: the top level), in the order they are listed.
type AlbumKids = std::collections::HashMap