Skip to content

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

LR-BEHAV-DIALOGS: ui.dialog.confirm says where a new folder was made, as the dialog's button does

Nathaniel Ledford16b984831b36
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index edf583b5f..48b1ac5db 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -414,9 +414,11 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequest
"ui.dialog.confirm" => match app.ui.dialog.take() {
Some(d) => {
let r = crate::panels::dialogs::confirm_dialog(app, &d);
- // a refused one-line prompt says why on screen, as with its button
- if let (Err(e), crate::state::Dialog::TextPrompt { .. }) = (&r, &d) {
- app.toast_error(ctx, e.clone());
+ // a refused one-line prompt says why on screen, as with its button; a folder made says where
+ match (&r, &d) {
+ (Err(e), crate::state::Dialog::TextPrompt { .. }) => app.toast_error(ctx, e.clone()),
+ (Ok(made), crate::state::Dialog::TextPrompt { .. }) => crate::dialogs::toast_created_folder(app, ctx, &d, made),
+ _ => {}
}
// the import review, the rule editor and the one-line prompts stay open on an error, as with their buttons
if (r.is_err()
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index fc4d06afe..f6a1bd896 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -437,6 +437,17 @@ fn button_row(app: &LightcraftApp, ui: &mut egui::Ui, dlg: &Dialog, close: &mut
}
}
+/// Say where a folder made on disk is: the new folder holds no photos yet, so the Folders list may not show it.
+/// Shared by the dialog's button and `ui.dialog.confirm`.
+pub(crate) fn toast_created_folder(app: &mut LightcraftApp, ctx: &egui::Context, dlg: &Dialog, made: &serde_json::Value) {
+ if let Dialog::TextPrompt { command, params, .. } = dlg
+ && command == "folder.create"
+ {
+ let (path, parent) = (made["path"].as_str().unwrap_or_default(), params["parent"].as_str().unwrap_or_default());
+ app.toast(ctx, crate::panels::left::created_text(path, parent));
+ }
+}
+
/// The dialog's confirm was pressed: do it. Whether the dialog closes.
fn confirmed(app: &mut LightcraftApp, ctx: &egui::Context, dlg: &mut Dialog) -> bool {
let mut closed = false;
@@ -474,10 +485,7 @@ fn confirmed(app: &mut LightcraftApp, ctx: &egui::Context, dlg: &mut Dialog) ->
Err(e) if matches!(dlg, Dialog::TextPrompt { .. }) => app.toast_error(ctx, e),
// a folder made on disk says so (the new folder holds no photos yet)
Ok(r) if matches!(&dlg, Dialog::TextPrompt { command, .. } if command == "folder.create") => {
- if let Dialog::TextPrompt { params, .. } = &dlg {
- let (path, parent) = (r["path"].as_str().unwrap_or_default(), params["parent"].as_str().unwrap_or_default());
- app.toast(ctx, crate::panels::left::created_text(path, parent));
- }
+ toast_created_folder(app, ctx, dlg, &r);
closed = true;
}
Ok(r) if matches!(dlg, Dialog::NewAlbum { .. }) && r.get("skipped").and_then(serde_json::Value::as_u64).is_some_and(|n| n > 0) => {
diff --git a/crates/ui-egui/src/tests/text_prompt.rs b/crates/ui-egui/src/tests/text_prompt.rs
index 87328dedc..81c383fd1 100644
--- a/crates/ui-egui/src/tests/text_prompt.rs
+++ b/crates/ui-egui/src/tests/text_prompt.rs
@@ -112,6 +112,20 @@ fn the_control_channel_keeps_a_refused_prompt_open_too() {
clean(&dir);
}
+#[test]
+fn the_control_channel_says_where_a_new_folder_was_made() {
+ let dir = shoot("control-ok");
+ let mut h = app();
+ h.app.ui.dialog = Some(prompt("folder.create", "Selects", json!({"parent": dir.to_string_lossy()}), "name"));
+ assert!(h.settle(SETTLE), "the prompt renders settled");
+ let r = h.request("ui.dialog.confirm", json!({}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ assert!(dir.join("Selects").is_dir(), "made on disk");
+ let parent = lightcraft_catalog::folders::folder_label(&dir.to_string_lossy());
+ assert_eq!(toast(&h), CREATED.replace("{name}", "Selects").replace("{parent}", &parent));
+ clean(&dir);
+}
+
#[test]
fn a_rename_that_keeps_a_name_with_spaces_at_its_ends_changes_nothing() {
let dir = shoot("rename-padded");