Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ui): disable Batch without a recorded action

Davosd21683cae375
diff --git a/crates/ui-egui/src/view_cmds.rs b/crates/ui-egui/src/view_cmds.rs
index 8acd676f9..b677c5e2f 100644
--- a/crates/ui-egui/src/view_cmds.rs
+++ b/crates/ui-egui/src/view_cmds.rs
@@ -476,6 +476,9 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> Option<bool> {
|| (doc && matches!(&i["window.arrange.".len()..], "floatAllInWindows" | "cascade" | "tile" | "tileAllVertically" | "tileAllHorizontally"))
}
},
+ // Batch's dialog is built from an Actions-panel action. Keep it disabled until one
+ // exists instead of opening a menu item that can only report "record an action".
+ "file.automate.batch" => crate::actions::selected_action(app).is_some(),
i if wraps(i) => app.session.is_enabled(i),
_ => true,
})
diff --git a/crates/ui-egui/src/view_cmds/tests.rs b/crates/ui-egui/src/view_cmds/tests.rs
index 2205b6e15..a8a0f44f4 100644
--- a/crates/ui-egui/src/view_cmds/tests.rs
+++ b/crates/ui-egui/src/view_cmds/tests.rs
@@ -207,6 +207,20 @@ fn type_menu_checkmarks_follow_the_layer() {
assert_eq!(checked(&app, "type.orientation.horizontal"), Some(true));
}
+#[test]
+fn batch_menu_requires_a_recorded_action() {
+ let (mut app, ctx) = app_with(1);
+ assert!(!crate::menus::is_enabled(&app, "file.automate.batch"));
+
+ app.run("actions.record", json!({"name": "Invert"})).unwrap();
+ app.run("image.adjustments.invert", json!({})).unwrap();
+ app.run("actions.stop", json!({})).unwrap();
+
+ assert!(crate::menus::is_enabled(&app, "file.automate.batch"));
+ let dialog = menu(&mut app, &ctx, "file.automate.batch", json!({})).unwrap()["dialog"].as_u64().unwrap();
+ assert_eq!(app.ui.dialog_mut(dialog).unwrap().fields["action"], "Invert");
+}
+
#[test]
fn engine_commands_open_their_dialogs() {
let (mut app, ctx) = app_with(2);