Skip to content

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

refactor(ui-egui): split import finish and print settings

Dylan M. Taylor627804c161ae
diff --git a/crates/ui-egui/src/dialogs/import/task.rs b/crates/ui-egui/src/dialogs/import/task.rs
index c41a941a3..da2c1574f 100644
--- a/crates/ui-egui/src/dialogs/import/task.rs
+++ b/crates/ui-egui/src/dialogs/import/task.rs
@@ -422,33 +422,29 @@ fn xmp_warnings_text(warnings: &[ImportWarning]) -> String {
)
}
-/// The import is done (or cancelled): one undo step, show and select the first photo (unless the
-/// user chose another meanwhile), say what happened.
-fn finish(app: &mut LightcraftApp, ctx: &egui::Context, task: ImportTask) {
- let steps = app.session.undo.len().saturating_sub(task.undo0);
- let plural = |n: usize| if n == 1 { "" } else { "s" };
- let label = if task.imported == 0 && task.restored > 0 {
+/// `s` for a count other than one.
+fn plural(n: usize) -> &'static str {
+ if n == 1 { "" } else { "s" }
+}
+
+/// The name of the import's one undo step.
+fn undo_label(task: &ImportTask) -> String {
+ if task.imported == 0 && task.restored > 0 {
crate::i18n::tr_format!("Restore {} Photo{}", task.restored, plural(task.restored))
} else if task.restored > 0 {
crate::i18n::tr_format!("Add {} Photo{}, restore {}", task.imported, plural(task.imported), task.restored)
} else {
- crate::i18n::tr_format!("Add {} Photo{}", task.imported, if task.imported == 1 { "" } else { "s" })
- };
- app.session.merge_undo(steps, &label);
- if task.auto {
- if !task.warnings.is_empty() {
- app.toast_for(ctx, xmp_warnings_text(&task.warnings), 8.0);
- } else if task.imported > 0 {
- app.toast(ctx, crate::i18n::tr_format!("Auto Import: added {} photo{}", task.imported, if task.imported == 1 { "" } else { "s" }));
- }
- return;
+ crate::i18n::tr_format!("Add {} Photo{}", task.imported, plural(task.imported))
}
- if task.browse {
- if !task.warnings.is_empty() {
- app.toast_for(ctx, xmp_warnings_text(&task.warnings), 8.0);
- } else if task.failed > 0 {
- app.toast(ctx, crate::i18n::tr_format!("{} photo{} not readable", task.failed, if task.failed == 1 { "" } else { "s" }));
- }
+}
+
+/// The import is done (or cancelled): one undo step, show and select the first photo (unless the
+/// user chose another meanwhile), say what happened.
+fn finish(app: &mut LightcraftApp, ctx: &egui::Context, task: ImportTask) {
+ let steps = app.session.undo.len().saturating_sub(task.undo0);
+ app.session.merge_undo(steps, &undo_label(&task));
+ if task.auto || task.browse {
+ quiet_finish(app, ctx, &task);
return;
}
if let Some(f) = task.first.filter(|_| !task.moved_on) {
@@ -459,7 +455,6 @@ fn finish(app: &mut LightcraftApp, ctx: &egui::Context, task: ImportTask) {
}
let _ = app.run("library.select", json!({"ids": [f]}));
}
- let plural = |n: usize| if n == 1 { "" } else { "s" };
// nothing new, only files the library already has: show where they are (Recently Deleted is
// easy to miss, and the side panel that lists it starts collapsed)
if task.imported == 0
@@ -471,6 +466,29 @@ fn finish(app: &mut LightcraftApp, ctx: &egui::Context, task: ImportTask) {
{
return;
}
+ let mut msg = import_summary(app, &task);
+ if task.warnings.is_empty() {
+ app.toast(ctx, msg);
+ } else {
+ msg.push_str("\n\n");
+ msg.push_str(&xmp_warnings_text(&task.warnings));
+ app.toast_for(ctx, msg, 8.0);
+ }
+}
+
+/// The end of an automatic import or of one that only browses: a toast only when there is something to warn about.
+fn quiet_finish(app: &mut LightcraftApp, ctx: &egui::Context, task: &ImportTask) {
+ if !task.warnings.is_empty() {
+ app.toast_for(ctx, xmp_warnings_text(&task.warnings), 8.0);
+ } else if task.auto && task.imported > 0 {
+ app.toast(ctx, crate::i18n::tr_format!("Auto Import: added {} photo{}", task.imported, plural(task.imported)));
+ } else if !task.auto && task.failed > 0 {
+ app.toast(ctx, crate::i18n::tr_format!("{} photo{} not readable", task.failed, plural(task.failed)));
+ }
+}
+
+/// What an import did, in a sentence.
+fn import_summary(app: &LightcraftApp, task: &ImportTask) -> String {
let mut msg = if task.cancelled {
crate::i18n::tr_format!("Import cancelled · {} photo{} added", task.imported, plural(task.imported))
} else if task.imported == 0 && task.restored > 0 {
@@ -488,7 +506,7 @@ fn finish(app: &mut LightcraftApp, ctx: &egui::Context, task: ImportTask) {
}
}
if task.duplicates > 0 {
- msg.push_str(&crate::i18n::tr_format!(" · {} duplicate{} skipped", task.duplicates, if task.duplicates == 1 { "" } else { "s" }));
+ msg.push_str(&crate::i18n::tr_format!(" · {} duplicate{} skipped", task.duplicates, plural(task.duplicates)));
let deleted = deleted_of(app, &task.existing).len();
if deleted > 0 {
msg.push_str(&crate::i18n::tr_format!(" ({} in Recently Deleted)", deleted));
@@ -497,13 +515,7 @@ fn finish(app: &mut LightcraftApp, ctx: &egui::Context, task: ImportTask) {
if task.failed > 0 {
msg.push_str(&crate::i18n::tr_format!(" · {} not readable", task.failed));
}
- if task.warnings.is_empty() {
- app.toast(ctx, msg);
- } else {
- msg.push_str("\n\n");
- msg.push_str(&xmp_warnings_text(&task.warnings));
- app.toast_for(ctx, msg, 8.0);
- }
+ msg
}
/// The photos among `ids` that are in Recently Deleted (each once).
diff --git a/crates/ui-egui/src/dialogs/print_view.rs b/crates/ui-egui/src/dialogs/print_view.rs
index 82a2b564d..c9af1d776 100644
--- a/crates/ui-egui/src/dialogs/print_view.rs
+++ b/crates/ui-egui/src/dialogs/print_view.rs
@@ -196,13 +196,9 @@ pub fn body(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens) {
app.ui.print = pu;
}
-fn settings(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, pu: &mut PrintUi, st: &PrintSettings, photos: usize) {
+/// The print templates: save the settings as one, import, and the saved ones to apply, export and delete.
+fn templates_section(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, pu: &mut PrintUi) {
let ctx = ui.ctx().clone();
- let l = &st.layout;
- let unit = st.guides.units;
- ui.spacing_mut().item_spacing.y = 5.0;
- ui.label(egui::RichText::new(crate::i18n::tr_format!("{n} photo{}", if photos == 1 { "" } else { "s" }, n = photos)).color(t.text_dim));
-
heading(ui, t, "Templates");
ui.horizontal(|ui| {
crate::text_field::TextField::singleline("field:printTemplateName", &mut pu.template_name)
@@ -246,17 +242,13 @@ fn settings(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, pu: &mut PrintUi,
});
});
}
+}
- heading(ui, t, "Layout Style");
- let styles =
- [(Style::SingleImage, "Single"), (Style::ContactSheet, "Contact"), (Style::PicturePackage, "Package"), (Style::CustomPackage, "Custom")];
- ui.horizontal_wrapped(|ui| {
- if let Some(s) = choice(ui, "printStyle", &styles, l.style) {
- patch(app, &ctx, json!({"layout": {"style": s}}));
- pu.page = 0;
- }
- });
-
+/// The image settings: zoom, rotation, border and stroke.
+fn image_section(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, st: &PrintSettings) {
+ let ctx = ui.ctx().clone();
+ let l = &st.layout;
+ let unit = st.guides.units;
heading(ui, t, "Image Settings");
let im = &st.image;
if let Some(v) = check(ui, "printZoomFill", "Zoom to Fill Frame", im.zoom_to_fill) {
@@ -292,6 +284,28 @@ fn settings(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, pu: &mut PrintUi,
patch(app, &ctx, json!({"image": {"strokeColor": c}}));
}
});
+}
+
+fn settings(app: &mut LightcraftApp, ui: &mut Ui, t: &Tokens, pu: &mut PrintUi, st: &PrintSettings, photos: usize) {
+ let ctx = ui.ctx().clone();
+ let l = &st.layout;
+ let unit = st.guides.units;
+ ui.spacing_mut().item_spacing.y = 5.0;
+ ui.label(egui::RichText::new(crate::i18n::tr_format!("{n} photo{}", if photos == 1 { "" } else { "s" }, n = photos)).color(t.text_dim));
+
+ templates_section(app, ui, t, pu);
+
+ heading(ui, t, "Layout Style");
+ let styles =
+ [(Style::SingleImage, "Single"), (Style::ContactSheet, "Contact"), (Style::PicturePackage, "Package"), (Style::CustomPackage, "Custom")];
+ ui.horizontal_wrapped(|ui| {
+ if let Some(s) = choice(ui, "printStyle", &styles, l.style) {
+ patch(app, &ctx, json!({"layout": {"style": s}}));
+ pu.page = 0;
+ }
+ });
+
+ image_section(app, ui, t, st);
heading(ui, t, "Layout");
match l.style {