mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Fill: the script dialog alerts on a refused pattern too (#17476)
With Script on, the script dialog's OK runs edit.fill, and its errors went to the status notice. Both dialogs now report through one helper, so a pattern Indexed Color can't take shows the alert with OK there too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
d14bb8bd16
commit
81869639de
3 files changed
+36
-9
No files matched your search
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<PhotocraftApp> {
|
||||
@@ -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<String> = 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<photocraft_doc::Document>, steps: usize) {
|
||||
let alerts: Vec<String> = 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");
|
||||
}
|
||||
Reference in new issue
Block a user