From 00d1fc33d5d09b5d469667d9e69b840a3d416ad2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 3 Nov 2026 13:07:40 -0800 Subject: [PATCH] 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. --- crates/ui-egui/src/dialogs/equalize_ui.rs | 7 +++++-- crates/ui-egui/src/dialogs/equalize_ui/tests.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/equalize_ui.rs b/crates/ui-egui/src/dialogs/equalize_ui.rs index f1fe3334762..bf68d9af7e2 100644 --- a/crates/ui-egui/src/dialogs/equalize_ui.rs +++ b/crates/ui-egui/src/dialogs/equalize_ui.rs @@ -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) -> 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(()) } diff --git a/crates/ui-egui/src/dialogs/equalize_ui/tests.rs b/crates/ui-egui/src/dialogs/equalize_ui/tests.rs index 645aa6fb252..3e666d506af 100644 --- a/crates/ui-egui/src/dialogs/equalize_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/equalize_ui/tests.rs @@ -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);