diff --git a/crates/engine-core/src/cmd/warp_cmds.rs b/crates/engine-core/src/cmd/warp_cmds.rs index 445e71bb25..c1f0532d39 100644 --- a/crates/engine-core/src/cmd/warp_cmds.rs +++ b/crates/engine-core/src/cmd/warp_cmds.rs @@ -26,6 +26,35 @@ fn has_layer(s: &Session) -> std::result::Result<(), String> { s.active().and_then(|d| d.active_layer).map(|_| ()).ok_or_else(|| "no active layer".into()) } +/// Edit › Transform › Warp takes one layer: not several, not one that linked layers move with, and not a group, the +/// targets the menu greys (#18500). Artboards keep their state, as in the menu rule. Not measured, so as before: a +/// smart object, type or shape layer among several selected layers, and a linked partner that is hidden or locked. +fn one_warp_target(s: &Session) -> std::result::Result<(), String> { + const ONE_LAYER: &str = "Warp works on one layer at a time: select a single layer"; + has_layer(s)?; + let st = s.active().ok_or("no document")?; + let doc = &st.doc; + // A group is refused whatever is selected with it. + if st.active_layer.and_then(|id| doc.layer(id)).is_some_and(|layer| layer.is_group() && layer.artboard().is_none()) { + return Err("Warp doesn't work on a group".into()); + } + let targets = crate::transform_cmds::selection_targets(st); + if targets.len() > 1 { + let unmeasured = + |id: &LayerId| doc.layer(*id).is_some_and(|l| matches!(l.content, LayerContent::Smart(_) | LayerContent::Text(_) | LayerContent::Shape(_))); + return if targets.iter().any(unmeasured) { Ok(()) } else { Err(ONE_LAYER.into()) }; + } + if targets.first() != st.active_layer.as_ref() { + return Err(ONE_LAYER.into()); + } + let plain = |id: &LayerId| doc.path_of(*id).is_some_and(|path| doc.shown_at(&path) && doc.locks_at(&path) == Locks::default()); + let mut partners = crate::transform_cmds::box_targets(doc, &targets).into_iter().filter(|id| !targets.contains(id)).peekable(); + if partners.peek().is_some() && partners.all(|id| plain(&id)) { + return Err(ONE_LAYER.into()); + } + Ok(()) +} + fn active_smart(s: &Session) -> std::result::Result<(), String> { let d = s.active().ok_or("no document")?; match d.active_layer.and_then(|id| d.doc.layer(id)).map(|l| &l.content) { @@ -800,7 +829,7 @@ pub fn specs() -> Vec { menu: &["Edit", "Transform"], shortcut: None, params: P, - enabled: has_layer, + enabled: one_warp_target, journal: true, run: |s, p| apply(s, p, "edit.transform.warp"), }, @@ -885,3 +914,7 @@ mod warp_remove_split_default_grid_tests; #[cfg(test)] #[path = "warp_pref_hard_edge_tests.rs"] mod warp_pref_hard_edge_tests; + +#[cfg(test)] +#[path = "warp_several_targets_refused_tests.rs"] +mod warp_several_targets_refused_tests; diff --git a/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs b/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs new file mode 100644 index 0000000000..1ae403c846 --- /dev/null +++ b/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs @@ -0,0 +1,206 @@ +//! #18500: `edit.transform.warp` refuses, with no History step, the targets the menu greys: more than one layer, a +//! layer that linked layers move with, and a group. One layer still warps. Not measured, so as before: a linked +//! partner that is hidden or locked, and a smart object, type or shape layer among several selected layers. + +use super::*; + +const WARP: &str = "edit.transform.warp"; + +fn arc() -> Value { + json!({"style": "arc", "bend": 50}) +} + +fn doc(s: &Session) -> &Document { + &s.active().unwrap().doc +} + +fn states(s: &Session) -> usize { + s.active().unwrap().history.past_len() +} + +fn document() -> Session { + let mut s = crate::session(); + s.execute("file.new", json!({"width": 200, "height": 160})).unwrap(); + s +} + +/// A new pixel layer with a filled rectangle. +fn pixel_layer(s: &mut Session, r: Rect) -> LayerId { + let id = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap()); + s.edit("fill", |doc, _| { + let surface = doc.layer_mut(id).unwrap().surface_mut().unwrap(); + let px = photocraft_raster::from_rgba(&surface.format(), [1.0, 0.0, 0.0, 1.0]); + surface.fill_rect(r, &px); + Ok(()) + }) + .unwrap(); + id +} + +/// Three pixel layers, bottom to top. +fn three_layers() -> (Session, [LayerId; 3]) { + let mut s = document(); + let ids = [Rect::new(10, 10, 70, 60), Rect::new(80, 20, 150, 70), Rect::new(30, 90, 120, 150)].map(|r| pixel_layer(&mut s, r)); + (s, ids) +} + +/// Selects `ids`; the last one is the active layer. +fn select(s: &mut Session, ids: &[LayerId]) { + s.execute("layer.select", json!({"layer": ids[0].0})).unwrap(); + for id in &ids[1..] { + s.execute("layer.select", json!({"layer": id.0, "mode": "add"})).unwrap(); + } +} + +/// Groups `ids` and returns the group. +fn group(s: &mut Session, ids: &[LayerId]) -> LayerId { + select(s, ids); + LayerId(s.execute("layer.groupLayers", json!({})).unwrap()["layer"].as_u64().unwrap()) +} + +fn link(s: &mut Session, ids: &[LayerId]) { + select(s, ids); + s.execute("layer.linkLayers", json!({})).unwrap(); +} + +/// The warp is refused: the command is disabled for the selection, the call fails, and neither the document nor the +/// History changes. +fn assert_refused(s: &mut Session, params: Value, case: &str) { + let (before, states_before) = (doc(s).clone(), states(s)); + if params.get("layer").is_none() { + assert!(s.disabled_reason(WARP).is_some(), "{case}: the command stays enabled"); + } + let reply = s.execute(WARP, params); + assert!(reply.is_err(), "{case}: the warp ran, {reply:?}"); + assert!(*doc(s) == before, "{case}: nothing changed"); + assert_eq!(states(s), states_before, "{case}: no History state"); +} + +/// The warp runs on `layer` alone: it changes, no other layer does, and one History state is added. +fn assert_warps(s: &mut Session, params: Value, layer: LayerId, case: &str) { + let (before, states_before) = (doc(s).clone(), states(s)); + s.execute(WARP, params).unwrap_or_else(|e| panic!("{case}: {e}")); + // A group holds its layers, so it differs whenever one of them does: compare the layers themselves. + for (_, _, l) in doc(s).walk().into_iter().filter(|(_, _, l)| !l.is_group()) { + assert_eq!(Some(l) != before.layer(l.id), l.id == layer, "{case}: only the warped layer changes, layer {}", l.name); + } + assert_eq!(states(s), states_before + 1, "{case}: one History state"); +} + +#[test] +fn more_than_one_target_is_refused() { + let (mut s, [a, b, _]) = three_layers(); + select(&mut s, &[a, b]); + assert_refused(&mut s, arc(), "two layers"); + // A named layer is checked as the active one, and it is still one of two selected layers. + let mut named = arc(); + named["layer"] = json!(a.0); + assert_refused(&mut s, named, "a named layer among two selected"); + s.execute("select.rect", json!({"x": 20, "y": 20, "width": 100, "height": 40})).unwrap(); + assert_refused(&mut s, arc(), "two layers with a pixel selection"); + + let (mut s, [a, b, c]) = three_layers(); + let g = group(&mut s, &[a, b]); + select(&mut s, &[g, c]); + assert_refused(&mut s, arc(), "a group plus a layer"); + select(&mut s, &[a, b]); + assert_refused(&mut s, arc(), "two layers inside a group"); +} + +#[test] +fn a_group_is_refused() { + let (mut s, [a, b, c]) = three_layers(); + let two = group(&mut s, &[a, b]); + select(&mut s, &[two]); + assert_refused(&mut s, arc(), "a group with two children"); + let one = group(&mut s, &[c]); + select(&mut s, &[one]); + assert_refused(&mut s, arc(), "a group with one child"); + + // A call that names the group, with a pixel layer active. + select(&mut s, &[c]); + let mut params = arc(); + params["layer"] = json!(two.0); + assert_refused(&mut s, params, "a named group"); + + // The group is refused as the active layer of a selection that holds a smart object too. + let (mut s, [a, b, c]) = three_layers(); + let g = group(&mut s, &[a, b]); + select(&mut s, &[c]); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + let smart = s.active().unwrap().active_layer.unwrap(); + select(&mut s, &[smart, g]); + assert!(s.disabled_reason(WARP).is_some_and(|why| why.contains("group")), "the refusal names the group"); + assert_refused(&mut s, arc(), "a group, active, selected with a smart object"); +} + +#[test] +fn a_layer_that_linked_layers_move_with_is_refused() { + let (mut s, [a, b, _]) = three_layers(); + link(&mut s, &[a, b]); + select(&mut s, &[a]); + assert_refused(&mut s, arc(), "a linked layer"); +} + +#[test] +fn one_layer_keeps_warping() { + let (mut s, [a, b, c]) = three_layers(); + select(&mut s, &[c]); + assert_warps(&mut s, arc(), c, "one pixel layer"); + + group(&mut s, &[a, b]); + select(&mut s, &[a]); + assert_warps(&mut s, arc(), a, "one layer inside a group"); + + select(&mut s, &[b]); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + let smart = s.active().unwrap().active_layer.unwrap(); + assert_warps(&mut s, arc(), smart, "a smart object"); +} + +/// Not measured, so the layer warps alone as before. +#[test] +fn a_hidden_or_locked_linked_partner_keeps_todays_behaviour() { + for hidden in [true, false] { + let (mut s, [a, b, _]) = three_layers(); + link(&mut s, &[a, b]); + s.edit("partner", |doc, _| { + let partner = doc.layer_mut(b).unwrap(); + if hidden { + partner.visible = false; + } else { + partner.locks = Locks { position: true, ..Locks::default() }; + } + Ok(()) + }) + .unwrap(); + select(&mut s, &[a]); + assert_warps(&mut s, arc(), a, if hidden { "a hidden linked partner" } else { "a locked linked partner" }); + } +} + +/// Not measured, so the active layer warps as before. +#[test] +fn a_shape_layer_or_a_smart_object_among_the_selected_layers_keeps_todays_behaviour() { + let (mut s, [a, _, _]) = three_layers(); + let shape = LayerId(s.execute("shape.create", json!({"rect": [130, 100, 40, 30], "fill": "#00ff00"})).unwrap()["layer"].as_u64().unwrap()); + select(&mut s, &[shape, a]); + assert_warps(&mut s, arc(), a, "a shape layer and a pixel layer"); + + let (mut s, [a, b, _]) = three_layers(); + select(&mut s, &[b]); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + let smart = s.active().unwrap().active_layer.unwrap(); + select(&mut s, &[smart, a]); + assert_warps(&mut s, arc(), a, "a smart object and a pixel layer"); +} + +/// A call that names a layer is checked on that layer, so one outside the selection counts alone. +#[test] +fn a_call_naming_a_layer_outside_the_selection_warps_it() { + let (mut s, [a, b, c]) = three_layers(); + select(&mut s, &[a, b]); + let mut params = arc(); + params["layer"] = json!(c.0); + assert_warps(&mut s, params, c, "a named layer outside the selection"); +} diff --git a/crates/ui-egui/src/menu_catalog.rs b/crates/ui-egui/src/menu_catalog.rs index b84e5adeef..479e8e0368 100644 --- a/crates/ui-egui/src/menu_catalog.rs +++ b/crates/ui-egui/src/menu_catalog.rs @@ -364,6 +364,8 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Layer", "Smart Objects"], "Convert to Linked…", None, "layer.smartObjects.convertToLinked"), (&["Layer", "Smart Objects"], "Convert to Layers", None, "layer.smartObjects.convertToLayers"), (&["Layer", "Smart Objects"], "---", None, "---"), + (&["Layer", "Smart Objects", "Stack Mode"], "None", None, "layer.smartObjects.stackMode.none"), + (&["Layer", "Smart Objects", "Stack Mode"], "---", None, "---"), (&["Layer", "Smart Objects", "Stack Mode"], "Entropy", None, "layer.smartObjects.stackMode.entropy"), (&["Layer", "Smart Objects", "Stack Mode"], "Kurtosis", None, "layer.smartObjects.stackMode.kurtosis"), (&["Layer", "Smart Objects", "Stack Mode"], "Maximum", None, "layer.smartObjects.stackMode.maximum"), @@ -831,6 +833,10 @@ pub const ARRANGE_ICONS: &[(&str, &str)] = &[ ("window.arrange.consolidateAllToTabs", "arrange-consolidate-all-to-tabs"), ]; +#[cfg(test)] +#[path = "stack_mode_none_position_tests.rs"] +mod stack_mode_none_position_tests; + #[cfg(test)] #[path = "menus/type_menu_groups_tests.rs"] mod type_menu_groups_tests; diff --git a/crates/ui-egui/src/patch_reset_tool_tests.rs b/crates/ui-egui/src/patch_reset_tool_tests.rs index c1ca920ae7..1f03eefa4e 100644 --- a/crates/ui-egui/src/patch_reset_tool_tests.rs +++ b/crates/ui-egui/src/patch_reset_tool_tests.rs @@ -76,7 +76,7 @@ fn rows() -> Vec { assert!(o.zoom_scrubby, "Scrubby Zoom goes back to on"); }, after_reset_all: |o| { - assert!(o.zoom_in, "Reset All Tools gives Zoom In"); + assert!(!o.zoom_in, "Reset All Tools keeps Zoom Out"); assert!(o.zoom_scrubby); }, }, diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs index ecfe95aa8c..13271e0fa5 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs @@ -194,3 +194,34 @@ fn a_user_shortcut_wins_over_a_default_it_was_not_moved_from() { let log = crate::shortcut_dispatch::take_log(&ctx); assert_eq!(log.last().map(|i| i.0.as_str()), Some("select.modify.feather"), "{log:?}"); } + +/// #15534: Keyboard Shortcuts and Menus lays out both tabs with their full names and switches +/// between them without clipping or overflowing. +#[test] +fn shortcuts_dialog_shows_full_keyboard_shortcuts_and_menus_tabs() { + use egui::accesskit::Role; + use egui_kittest::kittest::{Queryable as _, by}; + + let mut h = harness(); + h.ctx.set_pixels_per_point(1.25); + crate::prefs_ui::open_shortcuts(h.state_mut(), 0); + h.run_steps(5); + + let shortcuts = h.get_by_role_and_label(Role::Tab, "Keyboard Shortcuts").rect(); + let menus = h.get_by_role_and_label(Role::Tab, "Menus").rect(); + assert!(shortcuts.width() > 0.0 && menus.width() > 0.0); + assert!(shortcuts.right() <= menus.left(), "tabs sit side by side: {shortcuts:?} vs {menus:?}"); + assert!(h.query_by_label("More tabs").is_none(), "two tabs fit without an overflow menu"); + assert!(h.query_by_label("Toolbar").is_none(), "Toolbar is customized in its own dialog (#14616)"); + + h.get_by_role_and_label(Role::Tab, "Menus").click(); + h.run_steps(3); + let session = h.state().prefs_rt.shortcuts.as_ref().unwrap(); + assert_eq!(session.state.snapshot(&session.keymap).unwrap().tab, "menus"); + assert!(h.query_all(by().label("Show All Menu Items")).next().is_some()); + + h.get_by_role_and_label(Role::Tab, "Keyboard Shortcuts").click(); + h.run_steps(3); + let session = h.state().prefs_rt.shortcuts.as_ref().unwrap(); + assert_eq!(session.state.snapshot(&session.keymap).unwrap().tab, "shortcuts"); +} diff --git a/crates/ui-egui/src/stack_mode_none_position_tests.rs b/crates/ui-egui/src/stack_mode_none_position_tests.rs new file mode 100644 index 0000000000..0bb14778e9 --- /dev/null +++ b/crates/ui-egui/src/stack_mode_none_position_tests.rs @@ -0,0 +1,52 @@ +//! #18290: Layer › Smart Objects › Stack Mode lists None first, then a separator, then the eleven +//! modes (Entropy … Variance) in alphabetical order, with `layer.smartObjects.stackMode.none` in +//! `CATALOG` so parity counts it. + +use crate::PhotocraftApp; +use crate::menu_catalog::CATALOG; +use crate::menus::menu_rows; + +const STACK_MODE_PATH: &[&str] = &["Layer", "Smart Objects", "Stack Mode"]; + +const EXPECTED: [(&str, &str); 13] = [ + ("None", "layer.smartObjects.stackMode.none"), + ("---", "---"), + ("Entropy", "layer.smartObjects.stackMode.entropy"), + ("Kurtosis", "layer.smartObjects.stackMode.kurtosis"), + ("Maximum", "layer.smartObjects.stackMode.maximum"), + ("Mean", "layer.smartObjects.stackMode.mean"), + ("Median", "layer.smartObjects.stackMode.median"), + ("Minimum", "layer.smartObjects.stackMode.minimum"), + ("Range", "layer.smartObjects.stackMode.range"), + ("Skewness", "layer.smartObjects.stackMode.skewness"), + ("Standard Deviation", "layer.smartObjects.stackMode.standardDeviation"), + ("Summation", "layer.smartObjects.stackMode.summation"), + ("Variance", "layer.smartObjects.stackMode.variance"), +]; + +#[test] +fn stack_mode_flyout_lists_none_then_separator_then_eleven_modes() { + let app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + let rows: Vec<_> = menu_rows(&app).into_iter().filter(|r| r.path == STACK_MODE_PATH).collect(); + let got: Vec<(String, String)> = + rows.iter().map(|r| if r.label == "---" { ("---".to_string(), "---".to_string()) } else { (r.label.clone(), r.command.id.clone()) }).collect(); + let want: Vec<(String, String)> = EXPECTED.iter().map(|(l, id)| ((*l).to_string(), (*id).to_string())).collect(); + assert_eq!(got, want, "Stack Mode flyout order"); + + for row in rows.iter().filter(|r| r.label != "---") { + assert!(row.shortcut.is_none(), "{} should have no shortcut", row.command.id); + assert!(!row.label.ends_with('…') && !row.label.ends_with("..."), "{} should have no ellipsis: {:?}", row.command.id, row.label); + } +} + +#[test] +fn none_is_a_catalog_row_seen_by_parity() { + let entries: Vec<_> = CATALOG.iter().filter(|&&(path, _, _, _)| path == STACK_MODE_PATH).copied().collect(); + assert_eq!(entries.len(), EXPECTED.len(), "CATALOG has all 13 Stack Mode rows"); + for (got, (label, id)) in entries.iter().zip(EXPECTED.iter()) { + assert_eq!((got.1, got.2, got.3), (*label, None, *id)); + } + let report = crate::menus::parity::compute(); + assert!(report.menus.iter().all(|m| m.missing.is_empty()), "no missing catalog rows: {:?}", report.menus); + assert!(crate::menus::is_live("layer.smartObjects.stackMode.none")); +} diff --git a/crates/ui-egui/src/tools/tool_reset.rs b/crates/ui-egui/src/tools/tool_reset.rs index 17c4a6100a..c087010a3b 100644 --- a/crates/ui-egui/src/tools/tool_reset.rs +++ b/crates/ui-egui/src/tools/tool_reset.rs @@ -106,11 +106,12 @@ fn reset_tool(app: &mut PhotocraftApp, tool: Tool) { } } -/// Reset All Tools: every option, the selection mode and every tool's brush. +/// Reset All Tools: every option except Zoom In/Out, the selection mode and every tool's brush. fn reset_all(app: &mut PhotocraftApp) { crate::frame_tool::clear(app); app.ui.frame_tool = Default::default(); - *app.ui.tool_options = ToolOptions::default(); + let zoom_in = app.ui.tool_options.zoom_in; + *app.ui.tool_options = ToolOptions { zoom_in, ..ToolOptions::default() }; app.ui.artboard_tool = Default::default(); app.ui.selection_mode = 0; reset_session_brush(app); @@ -134,8 +135,8 @@ fn reset_session_brush(app: &mut PhotocraftApp) { /// The fields of [`option_keys`] that Reset Tool leaves as they are, as the reference app does /// (Zoom Out, #12066; Patch Structure and Color, #12127; Content-Aware Move Mode, #12183). -/// They stay in [`option_keys`], so a tool preset still stores them, and Reset All Tools still -/// resets them (it starts from the defaults). +/// They stay in [`option_keys`], so a tool preset still stores them; Reset All Tools keeps +/// `zoom_in` (#18191) and still resets the rest (not measured for Reset All Tools). fn kept_by_reset_tool(tool: Tool) -> &'static [&'static str] { match tool { Tool::Zoom => &["zoom_in"], @@ -494,3 +495,7 @@ mod art_history_reset_keeps_pressure_tests; #[cfg(test)] #[path = "bg_eraser_reset_pressure_tests.rs"] mod bg_eraser_reset_pressure_tests; + +#[cfg(test)] +#[path = "zoom_reset_all_keeps_mode_tests.rs"] +mod zoom_reset_all_keeps_mode_tests; diff --git a/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs b/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs new file mode 100644 index 0000000000..e289833201 --- /dev/null +++ b/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs @@ -0,0 +1,107 @@ +//! #18191: Reset All Tools leaves the Zoom tool in Zoom Out mode when it was set, as Reset Tool +//! already does, while resetting Scrubby Zoom and the other tools' options. + +use serde_json::{Value, json}; + +use crate::PhotocraftApp; +use crate::control::{ControlRequest, Reply, handle}; +use crate::state::{Tool, ToolOptions}; + +fn app() -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 64, "height": 64})).unwrap(); + app.sync_views(); + app +} + +fn invoke(app: &mut PhotocraftApp, id: &str, params: Value) { + let ctx = app.ctx().clone(); + let (req, _rx) = ControlRequest::new("ui.menu.invoke", json!({"id": id, "params": params})); + handle(app, &ctx, &req); + app.sync_views(); +} + +fn answer_dialog(app: &mut PhotocraftApp, method: &str, dialog: &str) -> Value { + let ctx = app.ctx().clone(); + let (req, _rx) = ControlRequest::new(method, json!({"dialog": dialog})); + let out = match handle(app, &ctx, &req) { + Reply::Done(v) => v, + _ => panic!("{method}: expected an immediate reply"), + }; + app.sync_views(); + out +} + +#[test] +fn reset_all_tools_keeps_zoom_out_and_resets_scrubby_zoom() { + let mut app = app(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.zoom_scrubby = false; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + assert!(!app.ui.tool_options.zoom_in, "Zoom Out stays selected"); + assert!(app.ui.tool_options.zoom_scrubby, "Scrubby Zoom goes back to on"); + assert_eq!(app.ui.tool, Tool::Zoom, "Zoom stays the current tool"); +} + +#[test] +fn reset_all_tools_keeps_zoom_in_when_selected() { + let mut app = app(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = true; + app.ui.tool_options.zoom_scrubby = false; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + assert!(app.ui.tool_options.zoom_in); + assert!(app.ui.tool_options.zoom_scrubby); +} + +#[test] +fn reset_all_tools_confirmation_ok_keeps_zoom_out_and_cancel_changes_nothing() { + let mut app = app(); + let ctx = app.ctx().clone(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.zoom_scrubby = false; + app.ui.tool_options.feather = 14.0; + + let dialog = crate::menus::invoke(&mut app, &ctx, "tool.resetAll", json!({})).unwrap()["dialog"].as_str().unwrap().to_string(); + assert_eq!(answer_dialog(&mut app, "ui.dialog.cancel", &dialog)["ok"], true); + assert!(!app.ui.tool_options.zoom_in); + assert!(!app.ui.tool_options.zoom_scrubby, "Cancel keeps Scrubby Zoom off"); + assert_eq!(app.ui.tool_options.feather, 14.0, "Cancel keeps other options"); + + let dialog = crate::menus::invoke(&mut app, &ctx, "tool.resetAll", json!({})).unwrap()["dialog"].as_str().unwrap().to_string(); + assert_eq!(answer_dialog(&mut app, "ui.dialog.confirm", &dialog)["ok"], true); + assert!(!app.ui.tool_options.zoom_in, "OK keeps Zoom Out"); + assert!(app.ui.tool_options.zoom_scrubby, "OK resets Scrubby Zoom to on"); + assert_eq!(app.ui.tool_options.feather, ToolOptions::default().feather); + assert_eq!(app.ui.tool, Tool::Zoom); +} + +#[test] +fn reset_all_tools_still_resets_unmeasured_kept_options_and_other_tools() { + let mut app = app(); + app.ui.tool = Tool::Brush; + crate::paint_mouse::sync_tool_brush(&mut app); + app.run("tools.setBrush", json!({"brush": {"size": 45}})).unwrap(); + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.patch_structure = 7.0; + app.ui.tool_options.patch_color = 5.0; + app.ui.tool_options.cam_mode = "extend".into(); + app.ui.tool_options.move_auto_select = false; + app.ui.selection_mode = 2; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + let d = ToolOptions::default(); + assert!(!app.ui.tool_options.zoom_in, "Zoom Out stays across Reset All Tools even when another tool is active"); + assert_eq!((app.ui.tool_options.patch_structure, app.ui.tool_options.patch_color), (d.patch_structure, d.patch_color)); + assert_eq!(app.ui.tool_options.cam_mode, d.cam_mode); + assert_eq!(app.ui.tool_options.move_auto_select, d.move_auto_select); + assert_eq!(app.ui.selection_mode, 0); + assert_eq!(app.run("brush.get", json!({})).unwrap()["size"].as_f64().unwrap(), 13.0); +}