Skip to content

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

feat: Alt+Cancel → Reset for opt-in command dialogs (#3871)

Sean Dellis67e4b8a499b5
diff --git a/crates/ui-egui/src/adjust_dialog.rs b/crates/ui-egui/src/adjust_dialog.rs
index 7c9783535..a9235881e 100644
--- a/crates/ui-egui/src/adjust_dialog.rs
+++ b/crates/ui-egui/src/adjust_dialog.rs
@@ -134,19 +134,33 @@ fn dialog_mem(kind: &str) -> egui::Id {
egui::Id::new(("adjust-dialog", kind))
}
-/// Whether holding Alt turns the dialog's Cancel into Reset. Measured in Photoshop 25.4 for Color
-/// Balance; other kinds keep Cancel until checked against Photoshop.
+/// Whether holding Alt turns Cancel into Reset for this adjustment dialog (every kind).
pub fn resets(fields: &Map<String, Value>) -> bool {
- fields.get("__adjust").and_then(Value::as_str) == Some("colorBalance")
+ owns(fields)
}
-/// Alt+Cancel (Reset): back to the defaults Photoshop's Reset restores, dialog stays open.
-pub fn reset(ctx: &egui::Context, fields: &mut Map<String, Value>) {
- if !resets(fields) {
+/// Alt+Cancel (Reset): engine defaults for the kind; Color Balance keeps Preserve Luminosity and
+/// shows Midtones (Photoshop 25.4). Dialog stays open.
+pub fn reset(app: &PhotocraftApp, ctx: &egui::Context, fields: &mut Map<String, Value>) {
+ if !owns(fields) {
return;
}
+ let kind = fields.get("__adjust").and_then(Value::as_str).unwrap_or_default().to_string();
+ let mode = app.session.active().map_or(photocraft_doc::ColorMode::Rgb, |s| s.doc.mode);
+ // Color Balance: Photoshop keeps the user's Preserve Luminosity across Reset.
+ let preserve = if kind == "colorBalance" { fields.get("preserveLuminosity").cloned() } else { None };
+ let Ok(defaults) = photocraft_engine::adjust_params::default_for(&kind, mode) else { return };
+ let values = photocraft_engine::adjust_params::to_params(&defaults);
+ // Replace parameter keys; keep private `__` chrome (preview, command, …).
+ fields.retain(|k, _| k.starts_with("__"));
+ if let Value::Object(v) = values {
+ fields.extend(v);
+ }
+ if let Some(p) = preserve {
+ fields.insert("preserveLuminosity".into(), p);
+ }
let mut values = crate::filter_dialog::params_of(fields);
- adjust_editors::reset_color_balance(ctx, dialog_mem("colorBalance"), &mut values);
+ adjust_editors::reset_adjustment_editor(ctx, &kind, dialog_mem(&kind), &mut values);
if let Value::Object(v) = values {
fields.extend(v);
}
@@ -390,16 +404,29 @@ mod tests {
assert!(h.state().ui.dialogs.is_empty(), "Cancel closes");
}
- /// Alt+Cancel is Reset only where it was checked against Photoshop.
+ /// Every adjustment kind opts into Alt+Reset; Levels restores engine defaults and stays open.
#[test]
- fn other_adjustment_dialogs_keep_cancel_under_alt() {
+ fn levels_alt_reset_restores_defaults() {
use egui_kittest::kittest::Queryable;
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 900.0)).build_ui_state(|ui, app| crate::dialogs::show(app, ui.ctx()), app_with_image());
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
- open(h.state_mut(), "image.adjustments.levels").unwrap();
- h.event(egui::Event::ModifiersChanged(egui::Modifiers::ALT));
- h.run_steps(3);
+ let id = open(h.state_mut(), "image.adjustments.levels").unwrap();
+ h.state_mut().ui.dialog_mut(id).unwrap().fields.insert("inBlack".into(), json!(30));
+ h.state_mut().ui.dialog_mut(id).unwrap().fields.insert("gamma".into(), json!(1.3));
+ h.run_steps(2);
assert!(h.query_by_label("Cancel").is_some() && h.query_by_label("Reset").is_none());
+ h.event(egui::Event::ModifiersChanged(egui::Modifiers::ALT));
+ h.run_steps(2);
+ let reset = h.get_by_label("Reset").rect();
+ assert!(h.query_by_label("Cancel").is_none());
+ let click =
+ |pressed| egui::Event::PointerButton { pos: reset.center(), button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::ALT };
+ input(&mut h, egui::Modifiers::ALT, &[egui::Event::PointerMoved(reset.center()), click(true), click(false)]);
+ assert!(h.state().ui.dialogs.iter().any(|d| d.id == id), "Reset keeps the dialog open");
+ let defaults =
+ photocraft_engine::adjust_params::to_params(&photocraft_engine::adjust_params::default_for("levels", photocraft_doc::ColorMode::Rgb).unwrap());
+ assert_eq!(field(&h, id, "inBlack"), defaults["inBlack"]);
+ assert_eq!(field(&h, id, "gamma"), defaults["gamma"]);
}
fn sample_params(kind: &str) -> Value {
diff --git a/crates/ui-egui/src/adjust_editors.rs b/crates/ui-egui/src/adjust_editors.rs
index 4d25d822c..84fab70b4 100644
--- a/crates/ui-egui/src/adjust_editors.rs
+++ b/crates/ui-egui/src/adjust_editors.rs
@@ -1019,6 +1019,14 @@ pub fn reset_color_balance(ctx: &egui::Context, mem: egui::Id, v: &mut Value) {
ctx.data_mut(|d| d.insert_temp(color_balance_tone_id(mem), 1usize));
}
+/// Kind-specific editor memory after Alt+Reset (or Properties Reset to defaults). Color Balance
+/// shows Midtones; other kinds have no dialog-local temp to clear yet.
+pub fn reset_adjustment_editor(ctx: &egui::Context, kind: &str, mem: egui::Id, v: &mut Value) {
+ if kind == "colorBalance" {
+ reset_color_balance(ctx, mem, v);
+ }
+}
+
fn color_balance(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {
let tone_id = color_balance_tone_id(cx.mem);
let mut tone_ix: usize = ui.data(|d| d.get_temp(tone_id)).unwrap_or(1);
diff --git a/crates/ui-egui/src/color_picker_ui.rs b/crates/ui-egui/src/color_picker_ui.rs
index cfa7183a5..e9729eab6 100644
--- a/crates/ui-egui/src/color_picker_ui.rs
+++ b/crates/ui-egui/src/color_picker_ui.rs
@@ -298,6 +298,15 @@ pub fn owns(f: &Map<String, Value>) -> bool {
f.contains_key("__colorPicker")
}
+/// Alt+Cancel (Reset): restore the colour from when the picker opened (same as clicking Current).
+pub fn reset(f: &mut Map<String, Value>) {
+ if !owns(f) {
+ return;
+ }
+ let orig = f.get("__orig").and_then(Value::as_str).and_then(parse_hex).unwrap_or([0.0; 3]);
+ set_rgb(f, orig, Keep::Nothing);
+}
+
/// The Color Picker, when it is the top dialog (another dialog opened over it takes the input).
pub fn top(app: &PhotocraftApp) -> Option<u64> {
app.ui.dialogs.last().filter(|d| owns(&d.fields)).map(|d| d.id)
@@ -833,6 +842,18 @@ mod tests {
assert_eq!(hex([h.state().session.tools.foreground[0], h.state().session.tools.foreground[1], h.state().session.tools.foreground[2]]), "#ff8800");
}
+ #[test]
+ fn alt_reset_restores_orig_color() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.session.tools.foreground = [0.2, 0.4, 0.6, 1.0];
+ let id = open(&mut app, "foreground");
+ let f = &mut app.ui.dialog_mut(id).unwrap().fields;
+ f.insert("color".into(), json!("#ff0000"));
+ reset(f);
+ assert_eq!(f["color"], json!(hex([0.2, 0.4, 0.6])));
+ assert_eq!(f["__orig"], json!(hex([0.2, 0.4, 0.6])));
+ }
+
#[test]
fn lab_and_cmyk_fields_take_multi_digit_values() {
let base = parse_hex("#336699").unwrap();
diff --git a/crates/ui-egui/src/dialog_alt_reset.rs b/crates/ui-egui/src/dialog_alt_reset.rs
new file mode 100644
index 000000000..71e52ac8f
--- /dev/null
+++ b/crates/ui-egui/src/dialog_alt_reset.rs
@@ -0,0 +1,93 @@
+//! Alt+Cancel → Reset for command dialogs that opt in.
+//!
+//! Holding Alt in the dialog chrome relabels Cancel as Reset and, on click, restores the dialog's
+//! fields without closing it (Photoshop). Each marker implements its own `reset`; this module only
+//! dispatches. Esc stays Cancel (`Modifiers::NONE` in the frame). Opt out with `"__altReset": false`.
+
+use serde_json::{Map, Value};
+
+use crate::PhotocraftApp;
+
+/// Whether holding Alt turns Cancel into Reset for this dialog's fields.
+pub fn supported(fields: &Map<String, Value>) -> bool {
+ if fields.get("__altReset") == Some(&Value::Bool(false)) {
+ return false;
+ }
+ match_arm(fields).is_some()
+}
+
+/// Apply Reset in place. No-op when the dialog has not opted in.
+pub fn apply(app: &mut PhotocraftApp, ctx: &egui::Context, fields: &mut Map<String, Value>) {
+ if fields.get("__altReset") == Some(&Value::Bool(false)) {
+ return;
+ }
+ // Dispatch order matches `dialogs::show` so `__adjust` wins over `__filter`.
+ if crate::guide_layout_ui::owns(fields) {
+ crate::guide_layout_ui::reset(app, fields);
+ } else if crate::fill_ui::owns(fields) {
+ crate::fill_ui::reset(app, fields);
+ } else if crate::variables_ui::owns(fields) {
+ crate::variables_ui::reset(fields);
+ } else if crate::color_picker_ui::owns(fields) {
+ crate::color_picker_ui::reset(fields);
+ } else if fields.contains_key("__sizing") {
+ crate::sizing::reset(fields);
+ } else if crate::adjust_dialog::owns(fields) {
+ crate::adjust_dialog::reset(app, ctx, fields);
+ } else if fields.contains_key("__filter") {
+ crate::filter_dialog::reset_fields(app, fields);
+ } else if fields.contains_key("__form") {
+ crate::view_cmds::reset_form(fields);
+ }
+}
+
+/// First matching opt-in arm, if any (same order as [`apply`]).
+fn match_arm(fields: &Map<String, Value>) -> Option<&'static str> {
+ if crate::guide_layout_ui::owns(fields) {
+ Some("guideLayout")
+ } else if crate::fill_ui::owns(fields) {
+ Some("fill")
+ } else if crate::variables_ui::owns(fields) && fields.contains_key("__variablesOrig") {
+ Some("variables")
+ } else if crate::color_picker_ui::owns(fields) {
+ Some("colorPicker")
+ } else if fields.contains_key("__sizing") {
+ Some("sizing")
+ } else if crate::adjust_dialog::owns(fields) {
+ Some("adjust")
+ } else if fields.contains_key("__filter") {
+ Some("filter")
+ } else if fields.contains_key("__form") && fields.contains_key("__formOrig") {
+ Some("form")
+ } else {
+ None
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+
+ #[test]
+ fn alt_reset_false_opts_out() {
+ let mut f = Map::new();
+ f.insert("__adjust".into(), json!("levels"));
+ f.insert("__altReset".into(), json!(false));
+ assert!(!supported(&f));
+ }
+
+ #[test]
+ fn adjust_marker_opts_in() {
+ let mut f = Map::new();
+ f.insert("__adjust".into(), json!("levels"));
+ assert!(supported(&f));
+ }
+
+ #[test]
+ fn bare_confirm_does_not_opt_in() {
+ let mut f = Map::new();
+ f.insert("__command".into(), json!("edit.purge"));
+ assert!(!supported(&f));
+ }
+}
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 2765d0e2a..1573d5ec3 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -310,7 +310,8 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
let can_ok = crate::crop_presets::can_confirm(app, &fields);
let ok = DialogButton::new(ButtonRole::Default, ok_label, 84.0).enabled(can_ok);
// Photoshop: holding Alt turns Cancel into Reset (the dialog stays open).
- let reset = ui.input(|i| i.modifiers.alt) && crate::adjust_dialog::resets(&fields);
+ // Dialogs opt in via `dialog_alt_reset::supported` (per marker).
+ let reset = ui.input(|i| i.modifiers.alt) && crate::dialog_alt_reset::supported(&fields);
let cancel_label = if reset {
tl!("Reset")
} else if d.kind == DialogKind::NewDocument {
@@ -337,7 +338,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
dialog_buttons(ui, &[ok, cancel])
};
match clicked {
- Some(ButtonRole::Cancel) if reset => crate::adjust_dialog::reset(ui.ctx(), &mut fields),
+ Some(ButtonRole::Cancel) if reset => crate::dialog_alt_reset::apply(app, ui.ctx(), &mut fields),
Some(ButtonRole::Cancel) => outcome = Some(false),
Some(ButtonRole::Apply) => apply_requested = true,
Some(_) => outcome = Some(true),
diff --git a/crates/ui-egui/src/fill_ui.rs b/crates/ui-egui/src/fill_ui.rs
index c44c4b577..faa917f03 100644
--- a/crates/ui-egui/src/fill_ui.rs
+++ b/crates/ui-egui/src/fill_ui.rs
@@ -53,8 +53,8 @@ fn valid(app: &PhotocraftApp, key: &str, v: &Value) -> bool {
}
}
-/// The dialog's fields: Photoshop's defaults, overridden by the last choices.
-pub fn fields(app: &PhotocraftApp) -> Map<String, Value> {
+/// Photoshop's Fill defaults (no last-used prefs). Used by open and Alt+Reset.
+pub fn default_fields(app: &PhotocraftApp) -> Map<String, Value> {
let mut f = Map::new();
f.insert(MARK.into(), json!(true));
f.insert("__command".into(), json!(COMMAND));
@@ -68,6 +68,12 @@ pub fn fields(app: &PhotocraftApp) -> Map<String, Value> {
f.insert("mode".into(), json!("normal"));
f.insert("opacity".into(), json!(100.0));
f.insert("preserveTransparency".into(), json!(false));
+ f
+}
+
+/// The dialog's fields: Photoshop's defaults, overridden by the last choices.
+pub fn fields(app: &PhotocraftApp) -> Map<String, Value> {
+ let mut f = default_fields(app);
if let Some(Value::Object(saved)) = app.session.prefs().dialogs.get(COMMAND) {
for k in KEYS {
if let Some(v) = saved.get(k).filter(|v| valid(app, k, v)) {
@@ -78,6 +84,19 @@ pub fn fields(app: &PhotocraftApp) -> Map<String, Value> {
f
}
+/// Alt+Cancel (Reset): Photoshop Fill defaults, not last-used prefs. Dialog stays open.
+pub fn reset(app: &PhotocraftApp, fields: &mut Map<String, Value>) {
+ if !owns(fields) {
+ return;
+ }
+ let defaults = default_fields(app);
+ for k in KEYS {
+ if let Some(v) = defaults.get(k) {
+ fields.insert(k.into(), v.clone());
+ }
+ }
+}
+
/// Open the Fill dialog; returns its id.
pub fn open(app: &mut PhotocraftApp) -> u64 {
let f = fields(app);
diff --git a/crates/ui-egui/src/fill_ui_tests.rs b/crates/ui-egui/src/fill_ui_tests.rs
index aa5f2772e..5d353127f 100644
--- a/crates/ui-egui/src/fill_ui_tests.rs
+++ b/crates/ui-egui/src/fill_ui_tests.rs
@@ -74,6 +74,22 @@ fn mode_opacity_and_preserve_transparency() {
assert!(close(px(&app, 5, 5), [0.5, 0.5, 0.5, 1.0]));
}
+#[test]
+fn alt_reset_restores_photoshop_defaults_not_last_used() {
+ let mut app = app();
+ // Remember a non-default choice, then open (which restores it) and Reset.
+ fill(&mut app, json!({"contents": "white", "opacity": 40})).unwrap();
+ let id = open(&mut app);
+ assert_eq!(app.ui.dialog_mut(id).unwrap().fields["opacity"].as_f64(), Some(40.0));
+ let mut fields = app.ui.dialog_mut(id).unwrap().fields.clone();
+ reset(&app, &mut fields);
+ app.ui.dialog_mut(id).unwrap().fields = fields;
+ let f = &app.ui.dialog_mut(id).unwrap().fields;
+ assert_eq!(f["opacity"].as_f64(), Some(100.0));
+ assert_eq!(f["contents"], json!("foreground"));
+ assert!(app.ui.dialogs.iter().any(|d| d.id == id));
+}
+
#[test]
fn choices_persist_across_restarts() {
let mut app = app();
diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rs
index 5f2f853fd..29fc436e0 100644
--- a/crates/ui-egui/src/filter_dialog.rs
+++ b/crates/ui-egui/src/filter_dialog.rs
@@ -327,6 +327,70 @@ pub(crate) fn remember(app: &mut PhotocraftApp, command: &str, fields: &Map<Stri
}
}
+/// Schema-default values for one param of `command` (open and Alt+Reset share this).
+fn default_value(app: &PhotocraftApp, command: &str, p: &Param) -> Option<Value> {
+ Some(match &p.kind {
+ Kind::Range { default, .. } if command == "image.mode.indexedColor" && p.key == "colors" => json!(default.round().clamp(2.0, 256.0) as u32),
+ Kind::Range { default, .. } => json!(default),
+ Kind::Choice { options, default } => {
+ let initial = default.as_deref().or_else(|| options.first().map(String::as_str)).unwrap_or("");
+ json!(initial)
+ }
+ Kind::Bool(default) => json!(default),
+ Kind::Int { default } => json!(default),
+ Kind::Text => json!(""),
+ Kind::Document => json!(-1),
+ // Identity kernel: 1 in the centre.
+ Kind::Grid(n) => json!((0..*n).map(|i| i64::from(i == *n / 2)).collect::<Vec<_>>()),
+ Kind::Color(Some(rgb)) => json!(crate::color_picker_ui::hex(*rgb)),
+ Kind::Color(None) => return None,
+ // Colour inputs come from the current swatches, so the proxy preview matches the result.
+ Kind::Json if p.key == "foreground" => json!(app.session.tools.foreground),
+ Kind::Json if p.key == "background" => json!(app.session.tools.background),
+ Kind::Json => return None,
+ })
+}
+
+/// Command-specific open defaults (ruler straighten, warp from layer, …), not remembered prefs.
+fn apply_command_defaults(app: &PhotocraftApp, command: &str, fields: &mut Map<String, Value>) {
+ if command == "image.rotation.arbitrary" {
+ straighten_defaults(app, fields);
+ }
+ if command == "type.warpText" {
+ warp_defaults(app, fields);
+ }
+ // Photoshop's Pattern Name dialog starts from the name the pattern would get anyway.
+ if command == "edit.definePattern" {
+ fields.insert("name".into(), json!(photocraft_engine::pattern_cmds::default_name(&app.session)));
+ }
+ if command == "layer.layerStyle.globalLight" {
+ global_light_defaults(app, fields);
+ }
+ if command == "view.proofSetup" {
+ proof_setup_defaults(app, fields);
+ }
+}
+
+/// Alt+Cancel (Reset): schema defaults + command hooks, without last-used remembered prefs.
+pub fn reset_fields(app: &PhotocraftApp, fields: &mut Map<String, Value>) {
+ if !fields.contains_key("__filter") || fields.contains_key("__adjust") {
+ return;
+ }
+ let Some(command) = fields.get("__command").and_then(Value::as_str).map(str::to_owned) else { return };
+ let spec =
+ fields.get("__spec").and_then(Value::as_str).map(str::to_owned).or_else(|| photocraft_engine::commands::find(&command).map(|c| c.params.to_owned()));
+ let Some(spec) = spec else { return };
+ // Drop user params; keep private `__` chrome (and fixed keys outside the schema for `__spec`).
+ let schema_keys: std::collections::HashSet<String> = parse_spec(&spec).into_iter().map(|p| p.key).collect();
+ fields.retain(|k, _| k.starts_with("__") || !schema_keys.contains(k));
+ for p in parse_spec(&spec) {
+ if let Some(v) = default_value(app, &command, &p) {
+ fields.insert(p.key, v);
+ }
+ }
+ apply_command_defaults(app, &command, fields);
+}
+
pub fn open(app: &mut PhotocraftApp, command: &str) -> Option<u64> {
let spec = photocraft_engine::commands::find(command)?;
let mut fields = Map::new();
@@ -338,45 +402,12 @@ pub fn open(app: &mut PhotocraftApp, command: &str) -> Option<u64> {
fields.insert("__preview".into(), json!(true));
}
for p in parse_spec(spec.params) {
- let v = match &p.kind {
- Kind::Range { default, .. } if command == "image.mode.indexedColor" && p.key == "colors" => json!(default.round().clamp(2.0, 256.0) as u32),
- Kind::Range { default, .. } => json!(default),
- Kind::Choice { options, default } => {
- let initial = default.as_deref().or_else(|| options.first().map(String::as_str)).unwrap_or("");
- json!(initial)
- }
- Kind::Bool(default) => json!(default),
- Kind::Int { default } => json!(default),
- Kind::Text => json!(""),
- Kind::Document => json!(-1),
- // Identity kernel: 1 in the centre.
- Kind::Grid(n) => json!((0..*n).map(|i| i64::from(i == *n / 2)).collect::<Vec<_>>()),
- Kind::Color(Some(rgb)) => json!(crate::color_picker_ui::hex(*rgb)),
- Kind::Color(None) => continue,
- // Colour inputs come from the current swatches, so the proxy preview matches the result.
- Kind::Json if p.key == "foreground" => json!(app.session.tools.foreground),
- Kind::Json if p.key == "background" => json!(app.session.tools.background),
- Kind::Json => continue,
- };
- fields.insert(p.key, v);
+ if let Some(v) = default_value(app, command, &p) {
+ fields.insert(p.key, v);
+ }
}
restore_remembered(app, command, spec.params, &mut fields);
- if command == "image.rotation.arbitrary" {
- straighten_defaults(app, &mut fields);
- }
- if command == "type.warpText" {
- warp_defaults(app, &mut fields);
- }
- // Photoshop's Pattern Name dialog starts from the name the pattern would get anyway.
- if command == "edit.definePattern" {
- fields.insert("name".into(), json!(photocraft_engine::pattern_cmds::default_name(&app.session)));
- }
- if command == "layer.layerStyle.globalLight" {
- global_light_defaults(app, &mut fields);
- }
- if command == "view.proofSetup" {
- proof_setup_defaults(app, &mut fields);
- }
+ apply_command_defaults(app, command, &mut fields);
if parse_spec(spec.params).iter().any(|p| p.kind == Kind::Document) {
// The document picker lists every open document (params refer to them by index).
let names: Vec<String> = app.session.documents().iter().map(|d| d.doc.name.clone()).collect();
@@ -818,6 +849,24 @@ mod tests {
assert_eq!(fields["radius"], json!(2.0));
}
+ #[test]
+ fn alt_reset_restores_schema_defaults_not_remembered() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
+ app.session.prefs.edit(|prefs| {
+ prefs.dialogs.insert("filter.blur.gaussianBlur".into(), json!({"radius": 11.0}));
+ });
+ let id = open(&mut app, "filter.blur.gaussianBlur").unwrap();
+ assert_eq!(app.ui.dialog_mut(id).unwrap().fields["radius"], json!(11.0));
+ let mut fields = app.ui.dialog_mut(id).unwrap().fields.clone();
+ reset_fields(&app, &mut fields);
+ app.ui.dialog_mut(id).unwrap().fields = fields;
+ let f = &app.ui.dialog_mut(id).unwrap().fields;
+ // Registry default for gaussian blur radius is 1.
+ assert_eq!(f["radius"], json!(1.0));
+ assert!(f.contains_key("__filter"));
+ assert!(app.ui.dialogs.iter().any(|d| d.id == id));
+ }
+
#[test]
fn remembering_dialogs_never_persists_paths_or_document_indices() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
diff --git a/crates/ui-egui/src/guide_layout_ui.rs b/crates/ui-egui/src/guide_layout_ui.rs
index d6c5c9fdb..9117baa82 100644
--- a/crates/ui-egui/src/guide_layout_ui.rs
+++ b/crates/ui-egui/src/guide_layout_ui.rs
@@ -31,6 +31,33 @@ pub fn owns(f: &Map<String, Value>) -> bool {
f.contains_key(MARK)
}
+/// Alt+Cancel (Reset): factory New Guide Layout values, not the last-used remembered layout.
+pub fn reset(app: &PhotocraftApp, f: &mut Map<String, Value>) {
+ if !owns(f) {
+ return;
+ }
+ let Value::Object(defaults) = crate::view_cmds::default_guide_layout() else { return };
+ // Drop layout params and interactive toggles; keep dialog chrome (`__command`, …).
+ f.retain(|k, _| {
+ k.starts_with("__")
+ && !matches!(
+ k.as_str(),
+ "__preset" | "__columnsEnabled" | "__rowsEnabled" | "__marginEnabled" | "__previewGuides" | "__previewParams" | "__previewSource"
+ )
+ });
+ f.extend(defaults);
+ f.insert("color".into(), json!(app.session.prefs().guides_grid_and_slices.guide_color));
+ f.insert("target".into(), json!("document"));
+ f.insert("__preset".into(), json!("custom"));
+ f.insert("width".into(), Value::Null);
+ f.insert("height".into(), Value::Null);
+ let margin = f.get("margin").cloned().unwrap_or(json!(0));
+ if !margin.is_array() {
+ f.insert("margin".into(), json!([margin.clone(), margin.clone(), margin.clone(), margin]));
+ }
+ f.insert("__preview".into(), json!(true));
+}
+
fn on(f: &Map<String, Value>, key: &str, fallback: bool) -> bool {
f.get(key).and_then(Value::as_bool).unwrap_or(fallback)
}
diff --git a/crates/ui-egui/src/guide_layout_ui/tests.rs b/crates/ui-egui/src/guide_layout_ui/tests.rs
index 17abf3e38..6ac36cb1d 100644
--- a/crates/ui-egui/src/guide_layout_ui/tests.rs
+++ b/crates/ui-egui/src/guide_layout_ui/tests.rs
@@ -84,6 +84,23 @@ fn app() -> PhotocraftApp {
PhotocraftApp::new(session, crate::Services::default())
}
+#[test]
+fn alt_reset_restores_factory_layout() {
+ let mut app = app();
+ let id = open(&mut app);
+ let mut fields = app.ui.dialog_mut(id).unwrap().fields.clone();
+ fields.insert("columns".into(), json!(3));
+ fields.insert("gutter".into(), json!(99));
+ fields.insert("__preset".into(), json!("twoColumn"));
+ reset(&app, &mut fields);
+ app.ui.dialog_mut(id).unwrap().fields = fields;
+ let f = &app.ui.dialog_mut(id).unwrap().fields;
+ assert_eq!(f["columns"], json!(8));
+ assert_eq!(f["gutter"], json!(20));
+ assert_eq!(f["__preset"], json!("custom"));
+ assert!(app.ui.dialogs.iter().any(|d| d.id == id));
+}
+
fn draw(app: &mut PhotocraftApp, id: u64) {
let mut f = app.ui.dialog_mut(id).unwrap().fields.clone();
let ctx = egui::Context::default();
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index d6309afcc..08e3464dd 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -61,6 +61,7 @@ pub mod crop_size;
pub mod crop_straighten;
pub mod crop_ui;
pub mod delete_layer_prompt;
+pub mod dialog_alt_reset;
pub mod dialog_blend_ui;
pub mod dialogs;
pub mod direct_select;
diff --git a/crates/ui-egui/src/sizing.rs b/crates/ui-egui/src/sizing.rs
index a0fb7557b..f4a9f54f0 100644
--- a/crates/ui-egui/src/sizing.rs
+++ b/crates/ui-egui/src/sizing.rs
@@ -46,6 +46,28 @@ pub fn is_sizing(command: &str) -> bool {
matches!(command, "image.imageSize" | "image.canvasSize")
}
+/// Alt+Cancel (Reset): restore the dimensions and options from when the dialog opened.
+pub fn reset(f: &mut Map<String, Value>) {
+ if !f.contains_key("__sizing") {
+ return;
+ }
+ let w = num(f, "__origW");
+ let h = num(f, "__origH");
+ f.insert("width".into(), json!(w));
+ f.insert("height".into(), json!(h));
+ if f.get("__command").and_then(Value::as_str) == Some("image.imageSize") {
+ f.insert("resolution".into(), json!(num(f, "__origRes")));
+ f.insert("__constrain".into(), json!(true));
+ if let Some(r) = f.get("__resample").cloned() {
+ f.insert("resample".into(), r);
+ }
+ } else {
+ f.insert("relative".into(), json!(false));
+ f.insert("anchor".into(), json!("center"));
+ f.insert("extensionColor".into(), json!("background"));
+ }
+}
+
pub fn open(app: &mut PhotocraftApp, command: &str) -> Option<u64> {
let unit = pref_unit(app.session.prefs().units_and_rulers.rulers);
let resample = pref_resample(app.session.prefs().general.image_interpolation);
@@ -443,6 +465,22 @@ mod tests {
assert_eq!(app.session.active().unwrap().doc.size, photocraft_doc::Size::new(120, 50));
}
+ #[test]
+ fn alt_reset_restores_open_dimensions() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.session.execute("file.new", json!({"width": 200, "height": 100, "resolution": 72})).unwrap();
+ let id = open(&mut app, "image.imageSize").unwrap();
+ let d = app.ui.dialog_mut(id).unwrap();
+ d.fields.insert("width".into(), json!(50));
+ d.fields.insert("height".into(), json!(25));
+ d.fields.insert("resolution".into(), json!(300));
+ d.fields.insert("__constrain".into(), json!(false));
+ reset(&mut d.fields);
+ assert_eq!((num(&d.fields, "width"), num(&d.fields, "height"), num(&d.fields, "resolution")), (200.0, 100.0, 72.0));
+ assert_eq!(d.fields.get("__constrain"), Some(&json!(true)));
+ assert!(app.ui.dialogs.iter().any(|x| x.id == id), "reset leaves the dialog open");
+ }
+
/// The dialog starts on Preferences › General › Image Interpolation: Bicubic Automatic opens
/// as Automatic and the others as themselves (Bicubic Sharper used to open as Lanczos).
#[test]
diff --git a/crates/ui-egui/src/variables_ui.rs b/crates/ui-egui/src/variables_ui.rs
index fc10df402..a4700cdda 100644
--- a/crates/ui-egui/src/variables_ui.rs
+++ b/crates/ui-egui/src/variables_ui.rs
@@ -17,6 +17,16 @@ pub fn owns(fields: &Map<String, Value>) -> bool {
fields.contains_key("__variables")
}
+/// Alt+Cancel (Reset): restore `__variables` from the open-time snapshot.
+pub fn reset(fields: &mut Map<String, Value>) {
+ if !owns(fields) {
+ return;
+ }
+ if let Some(orig) = fields.get("__variablesOrig").cloned() {
+ fields.insert("__variables".into(), orig);
+ }
+}
+
/// Layers available to bind, top to bottom: (id, display name, is-text).
fn layer_options(app: &PhotocraftApp) -> Vec<(u64, String, bool)> {
let Some(st) = app.session.active() else { return Vec::new() };
@@ -31,6 +41,8 @@ pub fn menu(app: &mut PhotocraftApp, id: &str, params: &Value) -> Option<Result<
let page = if id.ends_with("dataSets") { "dataSets" } else { "define" };
let mut f = Map::new();
let state = app.session.active().map(|st| crate::variables_ui::to_state(&st.doc.variables)).unwrap_or_else(|| json!({"defs": [], "dataSets": []}));
+ // Snapshot at open so Alt+Reset restores the document's variables.
+ f.insert("__variablesOrig".into(), state.clone());
f.insert("__variables".into(), state);
f.insert("__page".into(), json!(page));
f.insert("__label".into(), json!("Variables"));
@@ -40,6 +52,7 @@ pub fn menu(app: &mut PhotocraftApp, id: &str, params: &Value) -> Option<Result<
// No data set named: open the dialog on the Data Sets page to pick one.
let mut f = Map::new();
let state = app.session.active().map(|st| crate::variables_ui::to_state(&st.doc.variables)).unwrap_or_else(|| json!({"defs": [], "dataSets": []}));
+ f.insert("__variablesOrig".into(), state.clone());
f.insert("__variables".into(), state);
f.insert("__page".into(), json!("dataSets"));
f.insert("__label".into(), json!("Variables"));
@@ -378,6 +391,16 @@ mod tests {
}
}
+ #[test]
+ fn alt_reset_restores_open_snapshot() {
+ let mut f = Map::new();
+ let orig = json!({"defs": [{"name": "a"}], "dataSets": []});
+ f.insert("__variables".into(), json!({"defs": [{"name": "edited"}], "dataSets": []}));
+ f.insert("__variablesOrig".into(), orig.clone());
+ reset(&mut f);
+ assert_eq!(f["__variables"], orig);
+ }
+
#[test]
fn owns_detects_the_field() {
let mut f = Map::new();
diff --git a/crates/ui-egui/src/view_cmds.rs b/crates/ui-egui/src/view_cmds.rs
index cb75e2803..264550b88 100644
--- a/crates/ui-egui/src/view_cmds.rs
+++ b/crates/ui-egui/src/view_cmds.rs
@@ -98,7 +98,8 @@ pub struct ViewOptions {
pub guide_layout: Value,
}
-fn default_guide_layout() -> Value {
+/// Factory New Guide Layout values (Alt+Reset and a fresh ViewOptions).
+pub(crate) fn default_guide_layout() -> Value {
json!({"columns": 8, "gutter": 20, "rows": 0, "rowGutter": 0, "margin": 0, "centerColumns": false, "clearExisting": false})
}
@@ -933,9 +934,22 @@ fn form(app: &mut PhotocraftApp, command: &str, label: &str, fields: Value, choi
if let Value::Object(m) = fields {
f.extend(m);
}
+ // Snapshot user-facing params at open so Alt+Reset can restore them.
+ let orig: Map<String, Value> = f.iter().filter(|(k, _)| !k.starts_with("__")).map(|(k, v)| (k.clone(), v.clone())).collect();
+ f.insert("__formOrig".into(), Value::Object(orig));
app.ui.open_dialog(DialogKind::Command, f)
}
+/// Alt+Cancel (Reset): restore the `__form` params captured at open.
+pub fn reset_form(f: &mut Map<String, Value>) {
+ if !f.contains_key("__form") {
+ return;
+ }
+ let Some(Value::Object(orig)) = f.get("__formOrig").cloned() else { return };
+ f.retain(|k, _| k.starts_with("__"));
+ f.extend(orig);
+}
+
fn label_of(key: &str) -> String {
let mut out = String::new();
for (i, c) in key.chars().enumerate() {
@@ -971,6 +985,25 @@ mod label_tests {
}
}
+#[cfg(test)]
+mod form_reset_tests {
+ use super::*;
+ use serde_json::json;
+
+ #[test]
+ fn alt_reset_restores_form_orig() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ let id = form(&mut app, "test.form", "Test", json!({"radius": 5.0, "on": true}), json!({}));
+ let f = &mut app.ui.dialog_mut(id).unwrap().fields;
+ f.insert("radius".into(), json!(99.0));
+ f.insert("on".into(), json!(false));
+ reset_form(f);
+ assert_eq!(f["radius"], json!(5.0));
+ assert_eq!(f["on"], json!(true));
+ assert!(f.contains_key("__formOrig"));
+ }
+}
+
/// Body of a `__form` dialog: text fields, number fields, checkboxes and `__choices` dropdowns.
pub fn form_body(ui: &mut egui::Ui, f: &mut Map<String, Value>) {
let choices = f.get("__choices").cloned().unwrap_or(Value::Null);
diff --git a/docs/ui-dialogs.md b/docs/ui-dialogs.md
new file mode 100644
index 000000000..30db03fd1
--- /dev/null
+++ b/docs/ui-dialogs.md
@@ -0,0 +1,219 @@
+# Dialogs
+
+Modal and modeless parameter windows in the egui shell. They mirror Photoshop: no dimmed backdrop,
+canvas pan/zoom under an open dialog, Tab cycles text and number fields only, Esc cancels, Enter
+confirms when OK is enabled. Automation drives the same `fields` map as the UI (`ui.dialog.*` in
+[`control-protocol.md`](control-protocol.md)).
+
+## Architecture
+
+| Piece | Location | Role |
+|---|---|---|
+| Frame, routing, OK/Cancel/Esc, stacking | `crates/ui-egui/src/dialogs.rs` | Single hub for every `UiState::dialogs` entry |
+| Alt+Cancel → Reset (opt-in) | `crates/ui-egui/src/dialog_alt_reset.rs` | Relabels Cancel while Alt is held; dispatches per-marker `reset` |
+| Tab-through-fields | `crates/ui-egui/src/field_tab.rs` | Photoshop-style Tab / ⇧Tab (tests in same file) |
+| State | `crates/ui-egui/src/state.rs` | `Dialog`, `DialogKind`, `open_dialog` |
+| Button row | `crates/ui-egui/src/widgets.rs` | `dialog_buttons`, `focus_first_field`; `number_edit` registers for Tab |
+| Menu / command entry | `dialogs::open_command_dialog`, `menus.rs` | Picks a dedicated module, schema dialog, or bare confirm |
+| Filters | `filter_dialog.rs` | Schema from engine params, live preview |
+| Adjustments | `adjust_dialog.rs` | Shared editors with Properties; preview via `adjust_preview` |
+| Generic forms | `view_cmds.rs` | `__form` grids for simple command params |
+| Dedicated bodies | See **Command routing** below | `body` + usually `open` / `confirm` |
+
+**Routing.** Non-command kinds use `DialogKind` alone. `DialogKind::Command` bodies are chosen by
+marker keys on `fields` (`owns()` or `contains_key("__export")`, etc.); **first match in
+`dialogs::show` wins**, so new markers must not collide with an earlier arm. `show`, `confirm`, and
+`cancel` share the same dispatch table—wire all three when adding a dialog.
+
+**Field contract.** `Dialog.fields` is a JSON map: command parameters agents read and write, plus
+private keys prefixed with `__`. Never use `__` for user-facing or engine params.
+
+### `DialogKind` (top-level stack)
+
+| Kind | Body module | Typical entry |
+|---|---|---|
+| `NewDocument` | `new_doc_ui.rs` | File › New, `file.new` with no size params |
+| `About` | `dialogs.rs` (About / Contributors / Models tabs) | Help › About PhotoCraft; `systemInfo: true` → System Info variant |
+| `Command` | Routed—see below | Most menu commands with parameters |
+| `LayerStyle` | `layer_style.rs` | Layer › Layer Style… |
+| `Error` | inline in `dialogs.rs` | `message` field only (e.g. move lock, locked transform) |
+
+### Command routing (`DialogKind::Command`)
+
+Dispatch order matches `dialogs::show` in `dialogs.rs` (check earlier rows before adding a marker).
+
+| Match | Module | Role |
+|---|---|---|
+| `__guideLayout` | `guide_layout_ui.rs` | View › New Guide Layout… |
+| `__fill` | `fill_ui.rs` | Edit › Fill… |
+| `__patternFill` | `pattern_fill_ui.rs` | Pattern Fill layer / New Fill Layer › Pattern… |
+| `__stroke` | `stroke_ui.rs` | Edit › Stroke… |
+| `__createShape` | `shape_dialog.rs` | Click-with-shape-tool creation (rectangle, ellipse, …) |
+| `__deleteLayer` | `delete_layer_prompt.rs` | Layers panel trash confirmation |
+| `__newLayer` | `new_layer_ui.rs` | Layer › New › Layer… (⇧⌘N) |
+| `__rasterize` | `rasterize_prompt.rs` | Rasterize-before-paint prompt |
+| `__resetAllTools` | `tool_reset.rs` | Reset All Tools confirmation |
+| `__cropPresetNew` / `__cropPresetDelete` | `crop_presets.rs` | New / delete crop preset |
+| `__variables` | `variables_ui.rs` | Image › Variables (Define, Data Sets, Apply) |
+| `__web` / `__print` | `file_ui.rs` | Save for Web, Print |
+| `__colorPicker` | `color_picker_ui.rs` | Foreground/background, nested field/command pickers (see nested keys below) |
+| `__colorRange` | `color_range_ui.rs` | Select › Color Range… |
+| `__prefsui` | `prefs_ui.rs` | Edit › Preferences… and related preset/import subdialogs |
+| `__export` | `export_dialog.rs` | Export As (document or layer) |
+| `__sizing` | `sizing.rs` | Image › Image Size… / Canvas Size… |
+| `__adjust` | `adjust_dialog.rs` | Image › Adjustments… (also sets `__filter` + `__preview` for live preview) |
+| `__filter` | `filter_dialog.rs` (+ `select_mask_view.rs` when `__command` is `select.refineEdge`) | Filter Gallery commands, Edit › Color Settings…, Select and Mask, and other schema dialogs |
+| `__form` | `view_cmds.rs` | Simple param grids (e.g. slice options, many Image › Apply Image-style commands) |
+| (none of the above) | — | **Bare confirm**: title + OK/Cancel only; OK runs `__command` with fields via generic `confirm` |
+
+**Menu shortcut.** `dialogs::open_command_dialog` opens guide layout, stroke, and color range
+directly; then tries `adjust_dialog::open`, then `filter_dialog::open`; otherwise a bare confirm
+with `__command` + `__label`. Other dedicated modules are opened from `menus.rs`, tools, or panel
+actions with their marker already set.
+
+### Shared private keys
+
+| Key | Meaning |
+|---|---|
+| `__command` | Engine command id run on OK (bare confirm, filters, sizing, …) |
+| `__label` | Menu/catalog label for the title |
+| `__document` | Target document id (validate staleness) |
+| `__dialog` / `__field` | Nested color picker: parent dialog id and field name to write on OK |
+| `__params` | Extra command params for command-targeted color pickers |
+| `__preview` | Live canvas preview enabled (filters and adjustments) |
+| `__choices` | Dropdown options for `__form` dialogs |
+| `__filter` | Filter-schema body (`filter_dialog`); also set on adjustments for preview plumbing |
+| `__adjust` | Image › Adjustments editor kind (`adjust_dialog`) |
+| `__form` | Generic `view_cmds::form_body` |
+| `__formOrig` | Snapshot of non-`__` params at open; Alt+Reset restores it for `__form` dialogs |
+| `__variablesOrig` | Snapshot of `__variables` at open; Alt+Reset restores it |
+| `__altReset` | Set to `false` to opt a dialog out of Alt+Cancel → Reset |
+| `__export` | Export As |
+| `__sizing` | Image Size / Canvas Size |
+
+### Routing markers (dedicated `Command` bodies)
+
+| Key | Module |
+|---|---|
+| `__guideLayout` | `guide_layout_ui` |
+| `__fill` | `fill_ui` |
+| `__patternFill` | `pattern_fill_ui` |
+| `__stroke` | `stroke_ui` |
+| `__createShape` | `shape_dialog` |
+| `__deleteLayer` | `delete_layer_prompt` |
+| `__newLayer` | `new_layer_ui` |
+| `__rasterize` | `rasterize_prompt` |
+| `__resetAllTools` | `tool_reset` |
+| `__cropPresetNew`, `__cropPresetDelete` | `crop_presets` |
+| `__variables` | `variables_ui` |
+| `__web`, `__print` | `file_ui` |
+| `__colorPicker` | `color_picker_ui` |
+| `__colorRange` | `color_range_ui` |
+| `__prefsui` | `prefs_ui` (string sub-kind: `prefs`, `presetsIO`, …) |
+
+### Nested color pickers (`__colorPicker` on the stack)
+
+Same hub entry as standalone pickers; `color_picker_ui::confirm` branches on extra keys:
+
+| Extra key | Behaviour |
+|---|---|
+| `__layerStyleColor` | Layer Style child; OK writes effect colour on parent `LayerStyle` dialog |
+| `__textStyleColor` | Character/paragraph style colour (type panels) |
+| `__shapeFill` | Shape layer solid fill via `shape.edit` |
+| `__command` = `layer.fill.solidColor.set` | Solid Color fill layer (no `__shapeFill`) |
+| `__dialog` + `__field` | OK updates one field on a parent command dialog (e.g. Fill › Color…) |
+
+## Parallel modal systems (not the main stack)
+
+| System | Location | When |
+|---|---|---|
+| Unsaved changes | `discard_ui.rs` | Close, Revert, Close Others/All, Exit—Save / Don't Save / Cancel |
+| Shell dialog | `control.rs`, `ui.inspect` id `"shell"` | Workspace, custom pixel aspect, show-extras options |
+| Camera Raw | `camera_raw_ui.rs` | Separate OS window on desktop; see control-protocol § Camera Raw |
+| Error message | `DialogKind::Error` | e.g. `move_lock`—message + OK |
+| Nested pickers | `color_picker_ui` (+ markers in **Nested color pickers**) | Stack on parent; parent confirm refused while child open |
+
+## Rules
+
+### Architecture and commands
+
+1. **Thin UI, engine command on OK.** Run `app.run` or a dedicated `*_ui::confirm`; one history step unless the command itself batches.
+2. **Register in the hub.** Add `owns()` (or a stable marker), `body()`, `open()` if needed, and matching arms in `dialogs::show`, `confirm`, and `cancel` (and `open_command_dialog` when menu-driven).
+3. **Extend existing paths first.** Filters → `filter_dialog`; adjustments → `adjust_dialog`; simple param grids → `__form`; avoid a second modal stack unless product needs Camera Raw–level UX.
+4. **`fields` is the automation contract.** Anything agents must drive lives in named fields, not only in local egui state.
+5. **Remember last-used values** after successful OK where Photoshop does (`filter_dialog::remember`, prefs `dialogs["…"]`, module-specific helpers).
+
+### Chrome and layout
+
+6. **Use `dialog_buttons`** for OK / Cancel / Apply—platform order via `ButtonRole` (macOS default action in the corner).
+7. **Respect width rules** in `dialogs::show` unless `file_ui::dialog_width`, color picker, or kind-specific mins apply (typical 380–440; Layer Style / export / picker up to 600; New Document 800).
+8. **Scroll long bodies** inside the content (`DIALOG_CHROME` for filters); title and button row stay visible.
+9. **Transparent backdrop**—no dimming; previews are judged at true contrast.
+10. **Position:** first open centered; then persist offset (`place_id` per command or kind); title bar drag; clamp on screen.
+11. **Stacking:** only the **top** dialog is interactive; non-top instances render disabled; raise the live dialog if an older modal steals focus.
+
+### Keyboard and focus
+
+12. **Tab / ⇧Tab:** text and number fields only. Frame calls `field_tab::begin` / `end`; each field calls `field_tab::register` (`number_edit` does this; custom `TextEdit` must register manually).
+13. **Do not rely on egui default Tab** through sliders, dropdowns, checkboxes, or preset cards.
+14. **Open on first value:** `first_field_focused` + `widgets::focus_first_field` for value-first dialogs (most filters; Image/Canvas Size; not Select and Mask view keys).
+15. **Select-all on focus** when reached via Tab or field arrows (`field_tab::select_all`; see `value_field`, `new_doc_ui`).
+16. **Enter** confirms when OK is enabled (`can_ok`); exceptions must be explicit (`guide_layout_ui`, color picker).
+17. **Esc** on topmost dialog with no popup open → Cancel. **Click outside does not dismiss** (canvas may still pan/zoom via `free_pointer_over`, `pan_delta`, `free_press`). Esc ignores Alt (it does not become Reset).
+18. **Alt** turns Cancel into **Reset** when the dialog opts in via `dialog_alt_reset::supported` (dialog stays open). Opt-in markers: `__guideLayout`, `__fill`, `__variables`, `__colorPicker`, `__sizing`, `__adjust` (all kinds), `__filter`, `__form`. Each module implements its own `reset`; set `"__altReset": false` to disable.
+
+### Canvas and preview
+
+19. **Live preview** for filters/adjustments uses `filter_preview` / `adjust_preview`; `cancel()` clears preview and related shell state.
+20. **Under-dialog canvas** respects dialog rects and open popups; Hand / Space / middle-button pan on free canvas only.
+
+### Labels and i18n
+
+21. **Titles:** command dialogs use `__label` (catalogued; trailing `…` stripped in chrome); fixed kinds use `dialogs::title` + `tl!`.
+22. **User-visible strings:** `tl!("…")`; command labels from the menu catalog where possible.
+
+### Confirm / cancel safety
+
+23. **Child dialogs first**—refuse parent confirm if a nested color picker is open; cancel parent closes children where implemented.
+24. **Validate before close** when params can be inconsistent (`guide_layout_ui::validate` in `confirm`).
+25. **Disable OK** when required input is missing (`crop_presets::can_confirm`, Preferences Apply when unchanged).
+26. **Preferences over control:** whole-dialog OK/Apply may be refused; safe single prefs via `prefs.set` (see control-protocol).
+
+### Testing
+
+27. **egui_kittest:** open dialog, `run_steps`, key presses, assert `fields` or accessibility roles (`field_tab` tests are the reference harness).
+28. **Tab-order regressions:** add tests when a dialog gains multiple text/number fields.
+29. **Filter preview:** `dialogs.rs` tests for preview persistence across background jobs.
+
+### Anti-patterns
+
+30. No panics in `body` / `confirm` on bad input—errors to status or validation.
+31. No hard-coded colours or radii—`theme::Tokens` and `widgets.rs`.
+32. Do not skip `confirm` dispatch—Enter and `ui.dialog.confirm` use it.
+33. Do not expect click-outside-to-close on `egui::Modal`.
+34. Do not register sliders or dropdowns for `field_tab` unless product explicitly changes Photoshop parity.
+
+## Adding a command dialog (checklist)
+
+1. Choose path: see **Command routing** (`adjust_dialog`, `filter_dialog`, `__form`, `__sizing`, …, or new `*_ui` with a unique marker).
+2. `open`: build `fields` (`__command`, `__label`, params, marker); `app.ui.open_dialog(DialogKind::Command, f)`.
+3. `body(app, ui, &mut fields)`—mutate `fields` only; use shared widgets.
+4. `confirm` / `cancel` arms in `dialogs.rs` (or delegate to module `confirm`).
+5. Tab: register every text/number field; use `value_field` / `number_edit` where possible.
+6. **Alt+Reset (optional):** implement `reset` on the module and add an arm in `dialog_alt_reset` (same dispatch order as `dialogs::show`). Snapshot open values under a `__*Orig` key when Reset should restore “as opened” rather than factory defaults.
+7. Tests: at least open + confirm or Tab sequence if non-trivial; if Alt+Reset is supported, assert Reset restores fields and leaves the dialog open.
+8. If menu-visible: command already in engine; menu id opens dialog via existing menu wiring.
+
+## Known gaps
+
+- **Tab registration** for plain `TextEdit` is manual; generic `__form` string fields may not join `field_tab` unless wired.
+- **“Dialog module”** is any UI routed from `dialogs::show`, not only files named `*dialog*`.
+- **Numeric field parity** (units in expressions, scrubby labels) is tracked in [`ui-parity.md`](ui-parity.md) (Navigation / numeric fields), not duplicated here.
+
+## Revision history
+
+| Date | Change |
+|---|---|
+| 2026-10-11 | Initial doc from dialog codebase audit |
+| 2026-10-11 | Document all `DialogKind` values and `Command` routing markers |
+| 2026-10-11 | Alt+Cancel → Reset hub (`dialog_alt_reset`); opt-in markers |