Adjustments: Equalize's dialog refuses OK once its selection is cleared

A control command can clear the selection while the dialog is open. OK then ran Equalize on the whole layer under a choice that names a selection. The dialog stays open until the selection is back or the dialog is canceled.
This commit is contained in:
dotCooCoo committed 2026-11-03 13:07:40 -08:00
1 parent 4a7342ab5d
commit 00d1fc33d5
2 files changed
+17 -2

No files matched your search

+5 -2
View File
@@ -35,13 +35,16 @@ pub fn open(app: &mut PhotocraftApp) -> u64 {
app.ui.open_dialog(DialogKind::Command, f)
}
/// OK runs only while the document the dialog was opened for is active; otherwise the dialog
/// stays open.
/// OK runs only while the document the dialog was opened for is active and still has a selection;
/// otherwise the dialog stays open.
pub fn validate(app: &PhotocraftApp, f: &Map<String, Value>) -> Result<(), String> {
let st = app.session.active().ok_or("no document")?;
if f.get("__document") != Some(&json!(st.doc.id)) {
return Err("the Equalize dialog belongs to another document".into());
}
if st.doc.selection.is_none() {
return Err("the selection was cleared while the Equalize dialog was open".into());
}
Ok(())
}
@@ -85,6 +85,18 @@ fn ok_refuses_while_another_document_is_active() {
assert!(gray(&app, 1, 1) < 0.05, "OK runs once its document is active again");
}
/// OK on a dialog whose selection was cleared while it was open equalizes nothing and leaves the
/// dialog open, so the choice is never applied to the whole layer.
#[test]
fn ok_refuses_after_the_selection_is_cleared() {
let (mut app, ctx) = setup(true);
let d = menu(&mut app, &ctx, COMMAND, json!({})).unwrap()["dialog"].as_u64().unwrap();
app.run("select.deselect", json!({})).unwrap();
assert!(crate::dialogs::confirm(&mut app, d).is_err());
assert!(app.ui.dialogs.iter().any(|x| x.id == d), "the dialog stays open");
assert!((gray(&app, 1, 1) - 0.4).abs() < 0.01 && (gray(&app, 30, 20) - 0.5).abs() < 0.01, "the layer is unchanged");
}
#[test]
fn cancel_leaves_the_layer_unchanged() {
let (mut app, ctx) = setup(true);