diff --git a/crates/ui-egui/src/dialogs/fill_script_ui.rs b/crates/ui-egui/src/dialogs/fill_script_ui.rs index 77ecf122bc..5108c0bb69 100644 --- a/crates/ui-egui/src/dialogs/fill_script_ui.rs +++ b/crates/ui-egui/src/dialogs/fill_script_ui.rs @@ -178,7 +178,7 @@ pub(crate) fn run(app: &mut PhotocraftApp, ctx: &egui::Context, result: ParamRes let p = params(script_of(&result.key), &result.fields, held.get("fill").unwrap_or(&Value::Null)); match app.run(super::fill_ui::COMMAND, p) { Ok(_) => result.remember(ctx), - Err(e) => crate::notices::error(app, e), + Err(e) => super::fill_ui::report_error(app, e), } } diff --git a/crates/ui-egui/src/dialogs/fill_ui.rs b/crates/ui-egui/src/dialogs/fill_ui.rs index a4405ced98..6b4b1dc92f 100644 --- a/crates/ui-egui/src/dialogs/fill_ui.rs +++ b/crates/ui-egui/src/dialogs/fill_ui.rs @@ -256,11 +256,17 @@ pub(crate) fn run(app: &mut PhotocraftApp, ctx: &egui::Context, result: ParamRes } set_saved_value(ctx, &SaveKey::named(REMEMBER_INKS), Some(inks)); } - // A pattern Indexed Color can't take is an alert with OK, as in the reference (#17476). - Err(e) if e == photocraft_engine::fill_cmds::PATTERN_MODE_REFUSAL => { - let _ = crate::dialogs::alerts::alert(app, tl!(photocraft_engine::fill_cmds::PATTERN_MODE_REFUSAL)); - } - Err(e) => crate::notices::error(app, e), + Err(e) => report_error(app, e), + } +} + +/// Reports a failed `edit.fill` from the Fill dialog or its script dialog: a pattern Indexed Color can't take is an +/// alert with OK, as in the reference (#17476); anything else goes to the status notice. +pub(crate) fn report_error(app: &mut PhotocraftApp, e: String) { + if e == photocraft_engine::fill_cmds::PATTERN_MODE_REFUSAL { + let _ = crate::dialogs::alerts::alert(app, tl!(photocraft_engine::fill_cmds::PATTERN_MODE_REFUSAL)); + } else { + crate::notices::error(app, e); } } diff --git a/crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs b/crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs index 22590aab89..a6f0eaa01e 100644 --- a/crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs +++ b/crates/ui-egui/src/dialogs/fill_ui/fill_threshold_mode_tests.rs @@ -7,7 +7,7 @@ use photocraft_color::BlendMode; use serde_json::json; use super::*; -use crate::smart_filter_dialog::tests::{confirm, set}; +use crate::smart_filter_dialog::tests::{confirm, newest, pass, set}; /// A white 16×12 document of `mode` with a selection, so Content-Aware is greyed only by the colour mode. fn app(mode: &str) -> Box { @@ -74,11 +74,32 @@ fn ok_on_a_pattern_from_another_colour_mode_alerts_and_changes_nothing() { let id = open(&mut app); set(&mut app, id, "contents", json!("pattern")); confirm(&mut app, id); - let alerts: Vec = crate::dialogs::alerts::alerts(&app) + assert_refused(&app, &doc, steps); +} + +/// With Script on, the script dialog's OK runs the fill: the same alert, nothing changed. +#[test] +fn ok_in_the_script_dialog_on_a_pattern_from_another_colour_mode_alerts_too() { + let mut app = app("indexed"); + let (doc, steps) = (app.session.active().unwrap().doc.clone(), app.session.active().unwrap().history.past_len()); + let id = open(&mut app); + set(&mut app, id, "contents", json!("pattern")); + set(&mut app, id, "script", json!(true)); + set(&mut app, id, "scriptName", json!("brickFill")); + confirm(&mut app, id); + pass(&mut app); + let script = newest(&app); + confirm(&mut app, script); + assert_refused(&app, &doc, steps); +} + +/// The refusal alert is the one open alert, and the document and History are as they were. +fn assert_refused(app: &PhotocraftApp, doc: &std::sync::Arc, steps: usize) { + let alerts: Vec = crate::dialogs::alerts::alerts(app) .into_iter() .filter_map(|id| app.framework.dialogs.open_dialogs().into_iter().find(|d| d.id == id)?.fields?.get("message")?.as_str().map(str::to_string)) .collect(); assert_eq!(alerts, [photocraft_engine::fill_cmds::PATTERN_MODE_REFUSAL]); - assert!(std::sync::Arc::ptr_eq(&doc, &app.session.active().unwrap().doc), "document unchanged"); + assert!(std::sync::Arc::ptr_eq(doc, &app.session.active().unwrap().doc), "document unchanged"); assert_eq!(app.session.active().unwrap().history.past_len(), steps, "no history state"); }