Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Batch 37: the print commands (#1215) take the Result that Session::targets returns since #1773

Brandon Thomas3c489dc4087a
diff --git a/crates/engine/src/cmd/print.rs b/crates/engine/src/cmd/print.rs
index b9033ad05..05a851893 100644
--- a/crates/engine/src/cmd/print.rs
+++ b/crates/engine/src/cmd/print.rs
@@ -43,7 +43,7 @@ fn state(s: &Session, photos: usize) -> Value {
}
fn reply(s: &Session) -> Result<Value> {
- Ok(state(s, s.targets(&Value::Null).len()))
+ Ok(state(s, s.targets(&Value::Null)?.len()))
}
/// Applies `patch` over `dst`: objects merge key by key, anything else replaces.
@@ -64,7 +64,7 @@ fn merge(dst: &mut Value, patch: &Value, depth: usize) {
}
fn get(s: &mut Session, p: &Value) -> Result<Value> {
- Ok(state(s, s.targets(p).len()))
+ Ok(state(s, s.targets(p)?.len()))
}
fn set(s: &mut Session, p: &Value) -> Result<Value> {
@@ -245,7 +245,7 @@ fn export_pdf(s: &mut Session, p: &Value) -> Result<Value> {
return Err(bad(ID, "id must be a photo id"));
}
s.check_write_target(path).map_err(|e| bad(ID, e))?;
- let ids = s.targets(p);
+ let ids = s.targets(p)?;
let settings = s.print.clone();
// a printer profile that can't be used fails the print before anything renders
crate::print_color::PrintColorJob::new(&settings.job.color).map_err(|e| bad(ID, e))?;
diff --git a/crates/ui-egui/src/export_task.rs b/crates/ui-egui/src/export_task.rs
index 8bcbf532d..d1a1acebc 100644
--- a/crates/ui-egui/src/export_task.rs
+++ b/crates/ui-egui/src/export_task.rs
@@ -143,7 +143,7 @@ pub fn start_print(app: &mut LightcraftApp, params: &Value) -> Result<Value, Str
app.session.check_write_target(&path)?;
let guard = app.session.original_guard();
let settings = app.session.print.clone();
- let ids = app.session.targets(params);
+ let ids = app.session.targets(params).map_err(|e| e.to_string())?;
let prepared = compose::prepare(&mut app.session, &settings, &ids)?;
let total = prepared.len();
let title = std::path::Path::new(&path).file_stem().and_then(|n| n.to_str()).unwrap_or("Print").to_string();
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index e639955fe..3a1dac6c9 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -78,10 +78,10 @@ mod tests_dialog_primary;
#[cfg(test)]
mod tests_dialogs;
#[cfg(test)]
-mod tests_empty_library;
-#[cfg(test)]
mod tests_edit_layout;
#[cfg(test)]
+mod tests_empty_library;
+#[cfg(test)]
mod tests_error_kinds;
#[cfg(test)]
mod tests_filmstrip;
diff --git a/crates/ui-egui/src/print_view.rs b/crates/ui-egui/src/print_view.rs
index b7f6d44aa..71e836bc8 100644
--- a/crates/ui-egui/src/print_view.rs
+++ b/crates/ui-egui/src/print_view.rs
@@ -153,7 +153,8 @@ pub fn body(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens) {
let height = (screen.height() - 190.0).clamp(280.0, 780.0);
let mut pu = std::mem::take(&mut app.ui.print);
let st = app.session.print.clone();
- let ids = app.session.targets(&json!({}));
+ // (no `id`/`ids` given: the selection, which never fails to parse)
+ let ids = app.session.targets(&json!({})).unwrap_or_default();
// the page shown stays inside the print
let pages = st.layout.page_count(ids.len());
pu.page = pu.page.min(pages.saturating_sub(1));