From c0fd1485035b01dba2b352fd29987dd12e2d4960 Mon Sep 17 00:00:00 2001 From: Codex WORK prep Date: Wed, 11 Nov 2026 05:17:06 -0800 Subject: [PATCH] Fix occurrence shortcut docs and Batch dialog lock --- crates/ui-egui/src/control/dispatch.rs | 7 +++---- crates/ui-egui/src/control/tests.rs | 16 ++++++++++++++++ docs/control-protocol.md | 17 +++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/control/dispatch.rs b/crates/ui-egui/src/control/dispatch.rs index 36959c68af..68168ce242 100644 --- a/crates/ui-egui/src/control/dispatch.rs +++ b/crates/ui-egui/src/control/dispatch.rs @@ -1119,15 +1119,14 @@ fn dialog_set(app: &mut PhotocraftApp, p: &Value) -> Outcome { // A Color Picker previewing in this dialog owns its fields until its OK or Cancel: an edit now // would be undone by the picker putting the dialog back as it was. let previewed = crate::color_picker_ui::live_preview::previewed_dialogs(app).contains(&id); + // Batch occurrence fields are bound to the private dialog ID, not mutable form data. + let batch_dialog = app.ui.actions.batch_dialog_targets.contains_key(&id); match app.ui.dialog_mut(id) { // A continuation belongs to the dialog that paused it, even when another // action has a valid token. Replacing it would resume or cancel that action. Some(_) if field == crate::actions::RESUME => err("the paused action token is read-only"), Some(_) if field == crate::filter_dialog::MATCH_COLOR_DESTINATION => err("the Match Color destination is read-only"), - Some(d) - if matches!(field, crate::actions::BATCH_OCCURRENCE | crate::actions::BATCH_OCCURRENCES) - && d.fields.get("__command").and_then(Value::as_str) == Some("file.automate.batch") => - { + Some(d) if matches!(field, crate::actions::BATCH_OCCURRENCE | crate::actions::BATCH_OCCURRENCES) && batch_dialog => { err("Batch occurrence fields are read-only") } Some(_) if previewed => err("confirm or cancel the color picker first"), diff --git a/crates/ui-egui/src/control/tests.rs b/crates/ui-egui/src/control/tests.rs index f271866e42..09a7b45efd 100644 --- a/crates/ui-egui/src/control/tests.rs +++ b/crates/ui-egui/src/control/tests.rs @@ -20,6 +20,16 @@ fn batch_occurrence_fields_are_read_only_through_control() { assert_eq!(original["__command"], "file.automate.batch"); assert!(original.contains_key(crate::actions::BATCH_OCCURRENCE)); assert!(original.contains_key(crate::actions::BATCH_OCCURRENCES)); + + // The public form command is mutable, but it cannot disable the private dialog binding. + let changed_command = "file.automate.createDroplet"; + assert_eq!(call(&mut app, &ctx, "ui.dialog.set", json!({"dialog": id, "field": "__command", "value": changed_command}))["ok"], true); + let reply = call(&mut app, &ctx, "ui.dialog.set", json!({"dialog": id, "field": crate::actions::BATCH_OCCURRENCE, "value": 1})); + assert_eq!(reply["ok"], false, "changing __command cannot unlock occurrence fields: {reply}"); + assert!(reply["error"].as_str().unwrap().contains("Batch occurrence fields are read-only")); + assert_eq!(app.ui.dialog_mut(id).unwrap().fields[crate::actions::BATCH_OCCURRENCE], original[crate::actions::BATCH_OCCURRENCE]); + assert_eq!(call(&mut app, &ctx, "ui.dialog.set", json!({"dialog": id, "field": "__command", "value": "file.automate.batch"}))["ok"], true); + for (field, value) in [(crate::actions::BATCH_OCCURRENCE, json!(1)), (crate::actions::BATCH_OCCURRENCES, json!([{"action": "Forged", "row": 1}]))] { let reply = call(&mut app, &ctx, "ui.dialog.set", json!({"dialog": id, "field": field, "value": value})); assert_eq!(reply["ok"], false, "{reply}"); @@ -33,6 +43,12 @@ fn batch_occurrence_fields_are_read_only_through_control() { for field in [crate::actions::BATCH_OCCURRENCE, crate::actions::BATCH_OCCURRENCES] { assert_eq!(fields[field], original[field]); } + + // An unrelated, real dialog still accepts its ordinary fields. + let other = call(&mut app, &ctx, "ui.dialog.open", json!({"kind": "newDocument"}))["dialog"].as_u64().unwrap(); + let width = json!(16); + assert_eq!(call(&mut app, &ctx, "ui.dialog.set", json!({"dialog": other, "field": "width", "value": width}))["ok"], true); + assert_eq!(app.ui.dialog_mut(other).unwrap().fields["width"], width); } /// #3674: a guessed name gets a pointer to the right one, in both directions; and every diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 9d54bb6097..a09ebf63f8 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -200,14 +200,15 @@ Select an action and press Record to append steps; the plus button starts a new A final `["view.fitOnScreen", {}]` step fits the resized document when the canvas is laid out. Headless playback reports unsupported view commands as failed steps. -In the desktop Actions panel, right-click an action to assign a function key (F1–F12), -or choose None to remove it. The binding follows the action name, regardless of the selected -row, and is saved in preferences. For example, the existing `edit.keyboardShortcuts` command -accepts `{"set":{"actions.play:My action":"F6"},"allowUnknown":true,"removeConflicts":false}`. -A named action takes precedence over the ordinary menu shortcut while it exists and is bound; -removing its binding or deleting it restores that menu shortcut. The panel moves a key away -from another action when assigning it. Action playback still checks each nested command's -automation permissions. +In the desktop Actions panel, right-click an action occurrence to assign a function key (F1–F12), +or choose None to remove it. The panel stores the binding by stable occurrence ID (`actions.playById:`), +so duplicate names can have independent shortcuts. The name-based `actions.play:` form remains +supported for legacy bindings; for an action with both keys, its valid occurrence binding takes +precedence. For example, `edit.keyboardShortcuts` accepts +`{"set":{"actions.play:My action":"F6"},"allowUnknown":true,"removeConflicts":false}` +for a legacy name-based binding. Removing the applicable binding or deleting the action restores +the ordinary menu shortcut. The panel moves a key away from another action when assigning it. +Action playback still checks each nested command's automation permissions. UI-level commands (`view.zoomIn`, `window.theme.pro`, `edit.search`, …) are also accepted by `engine.execute` and `ui.menu.invoke`.