From 2bb955062b5301a8a05b40be267c8afac8e93c3b Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:13:23 +0100 Subject: [PATCH] Clone Stamp: refusal alerts in the reference application's words (#12608) A press on a hidden layer, a layer with Lock All, or a shown group with Sample: Current Layer opens the reference's alert with OK and paints nothing. A group with Current & Below or All Layers keeps today's alert; the Brush keeps its own group text. --- crates/ui-egui/src/canvas/paint_tool/tests.rs | 2 + .../src/clone_stamp_refusal_alert_tests.rs | 135 ++++++++++++++++++ .../src/healing_refusal_alert_tests.rs | 6 +- crates/ui-egui/src/hidden_layer_tests.rs | 6 +- crates/ui-egui/src/tools/brush_refusal.rs | 17 ++- .../src/tools/remove_hidden_layer_tests.rs | 3 +- 6 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 crates/ui-egui/src/clone_stamp_refusal_alert_tests.rs diff --git a/crates/ui-egui/src/canvas/paint_tool/tests.rs b/crates/ui-egui/src/canvas/paint_tool/tests.rs index 3a8685f6ad..d67dea1329 100644 --- a/crates/ui-egui/src/canvas/paint_tool/tests.rs +++ b/crates/ui-egui/src/canvas/paint_tool/tests.rs @@ -500,6 +500,8 @@ fn painting_a_group_is_refused_at_the_press_with_a_message() { Tool::MagicEraser => "Could not use the magic eraser because the pixels in a group cannot be edited without merging the group.".to_string(), Tool::Gradient => "Could not use the gradient tool because the pixels in a group cannot be edited without merging the group.".to_string(), Tool::PaintBucket => "Could not use the paint bucket because the pixels in a group cannot be edited without merging the group.".to_string(), + // The Clone Stamp's own text with Sample: Current Layer (#12608). + Tool::CloneStamp => "Could not use the clone stamp tool because the source is a group.".to_string(), _ => format!("Could not use the {} because the target layer is a group.", tool.label()), }; assert_eq!(errors(&app)[seen..], [want], "{tool:?}"); diff --git a/crates/ui-egui/src/clone_stamp_refusal_alert_tests.rs b/crates/ui-egui/src/clone_stamp_refusal_alert_tests.rs new file mode 100644 index 0000000000..68de2c31c6 --- /dev/null +++ b/crates/ui-egui/src/clone_stamp_refusal_alert_tests.rs @@ -0,0 +1,135 @@ +//! #12608: a Clone Stamp press that can't paint opens the reference application's alert with OK and paints nothing: a +//! hidden target layer, a layer with Lock All, and a group active with Sample: Current Layer. A group with Sample: +//! Current & Below or All Layers keeps today's alert, and the Brush keeps its own group text. + +use egui::Modifiers; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::control::{ControlRequest, Reply, handle}; +use crate::state::Tool; +use crate::tools::brush_refusal::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke}; + +const HIDDEN: &str = "Could not use the clone stamp tool because the target layer is hidden."; +const LOCKED: &str = "Could not use the clone stamp tool because the layer is locked."; +const GROUP: &str = "Could not use the clone stamp tool because the source is a group."; +/// Today's group alert (`refuse_group`), kept where the reference was not measured. +const TODAY_GROUP: &str = "Could not use the Clone Stamp Tool because the target layer is a group."; + +/// An Alt-click: the clone source. +fn set_source(app: &mut PhotocraftApp, x: f64, y: f64) { + tool_event(app, ToolEvent::Down { x, y, pressure: 1.0 }, Modifiers::ALT); + tool_event(app, ToolEvent::Up { x, y }, Modifiers::ALT); +} + +/// The Clone Stamp on the painted layer, with a source set. +fn clone_stamp() -> Box { + let mut app = app(Tool::CloneStamp); + set_source(&mut app, 50.0, 32.0); + app +} + +#[test] +fn a_hidden_target_layer() { + let mut app = clone_stamp(); + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + refused(&mut app, HIDDEN); + assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error as well: {:?}", app.ui.status); +} + +#[test] +fn lock_all() { + let mut app = clone_stamp(); + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + refused(&mut app, LOCKED); +} + +#[test] +fn a_group_with_sample_current_layer() { + let mut app = clone_stamp(); + assert_eq!(app.ui.tool_options.clone_sample, "current", "the default Sample"); + app.run("layer.new.group", json!({})).unwrap(); + refused(&mut app, GROUP); +} + +#[test] +fn a_group_with_the_other_sample_settings_keeps_todays_alert() { + for sample in ["currentAndBelow", "all"] { + let mut app = clone_stamp(); + app.ui.tool_options.clone_sample = sample.into(); + app.run("layer.new.group", json!({})).unwrap(); + let before = steps(&app); + stroke(&mut app); + assert_eq!(alerts(&app), [TODAY_GROUP], "{sample}"); + assert_eq!(steps(&app), before, "{sample}: no History step"); + } +} + +#[test] +fn the_brush_keeps_its_own_group_text() { + let mut app = app(Tool::Brush); + app.run("layer.new.group", json!({})).unwrap(); + refused(&mut app, "Could not use the brush tool because the pixels in a group cannot be edited without merging the group."); +} + +#[test] +fn the_alerts_are_listed_in_ui_inspect_and_dismissed_by_ui_dialog_confirm() { + let cases: [(&str, &str); 3] = [("hidden", HIDDEN), ("lock all", LOCKED), ("group", GROUP)]; + for (case, want) in cases { + let mut app = clone_stamp(); + match case { + "hidden" => { + let id = active(&app); + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + } + "lock all" => { + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + } + _ => { + app.run("layer.new.group", json!({})).unwrap(); + } + } + stroke(&mut app); + let ctx = app.ctx().clone(); + let mut call = |method: &str, params: serde_json::Value| { + let (req, _rx) = ControlRequest::new(method, params); + match handle(&mut app, &ctx, &req) { + Reply::Done(v) => v, + _ => panic!("{method}: expected an immediate reply"), + } + }; + let inspect = call("ui.inspect", json!({})); + let dialog = &inspect["result"]["dialogs"][0]; + assert_eq!(dialog["fields"]["message"], want, "{case}: {inspect}"); + assert_eq!(call("ui.dialog.confirm", json!({"dialog": dialog["id"]}))["ok"], true, "{case}"); + assert!(alerts(&app).is_empty(), "{case}: ui.dialog.confirm closed it"); + } +} + +#[test] +fn an_alt_click_on_a_hidden_or_locked_layer_only_sets_the_source() { + for lock in [false, true] { + let mut app = app(Tool::CloneStamp); + let id = active(&app); + if lock { + app.run("layer.lockLayers", json!({"all": true})).unwrap(); + } else { + app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); + } + let before = steps(&app); + set_source(&mut app, 50.0, 32.0); + assert!(alerts(&app).is_empty(), "lock {lock}: {:?}", alerts(&app)); + assert_eq!(steps(&app), before, "lock {lock}: no history step"); + } +} + +#[test] +fn a_shown_unlocked_layer_still_clones() { + let mut app = clone_stamp(); + let before = steps(&app); + stroke(&mut app); + assert!(alerts(&app).is_empty(), "{:?}", alerts(&app)); + assert_eq!(steps(&app), before + 1, "one History step"); +} diff --git a/crates/ui-egui/src/healing_refusal_alert_tests.rs b/crates/ui-egui/src/healing_refusal_alert_tests.rs index c6f163229f..c9525e6439 100644 --- a/crates/ui-egui/src/healing_refusal_alert_tests.rs +++ b/crates/ui-egui/src/healing_refusal_alert_tests.rs @@ -95,14 +95,14 @@ fn an_unlocked_visible_layer_still_heals() { } #[test] -fn the_clone_stamp_keeps_the_status_bar() { +fn the_clone_stamp_has_its_own_wording() { + // Its own alerts since #12608. let mut app = app(Tool::CloneStamp); set_source(&mut app, 50.0, 32.0); let id = active(&app); app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap(); stroke(&mut app); - assert!(alerts(&app).is_empty()); - assert_eq!(app.ui.status, photocraft_engine::hidden_target::HIDDEN); + assert_eq!(alerts(&app), ["Could not use the clone stamp tool because the target layer is hidden."]); } /// Through the real canvas: a press reaches the tool through the host's preflight, which is where diff --git a/crates/ui-egui/src/hidden_layer_tests.rs b/crates/ui-egui/src/hidden_layer_tests.rs index 6b527ab174..b8ee3ccda3 100644 --- a/crates/ui-egui/src/hidden_layer_tests.rs +++ b/crates/ui-egui/src/hidden_layer_tests.rs @@ -82,11 +82,11 @@ fn painting_a_hidden_layer_is_refused_at_the_press() { let n = steps(&app); tool_event(&mut app, ToolEvent::Down { x: 30.0, y: 30.0, pressure: 1.0 }, egui::Modifiers::NONE); assert!(!crate::canvas::testing::in_gesture(&app) && app.live_stroke.is_none(), "{tool:?}: no stroke started"); - // The Brush (#11898), the Classic gradient (#12017) and the Paint Bucket (#12537) say so in - // an alert, the other tools in the status bar. + // The Brush (#11898), the Classic gradient (#12017), the Paint Bucket (#12537) and the Clone + // Stamp (#12608) say so in an alert, the other tools in the status bar. let alerts = alerts(&app); let alert = alerts.iter().any(|m| m.contains("target layer is hidden")); - if matches!(tool, Tool::Brush | Tool::Gradient | Tool::PaintBucket) { + if matches!(tool, Tool::Brush | Tool::Gradient | Tool::PaintBucket | Tool::CloneStamp) { assert!(alert, "{tool:?}: {alerts:?}"); } else { assert!(app.ui.status.contains("target layer is hidden") && alerts.is_empty(), "{tool:?}: {}", app.ui.status); diff --git a/crates/ui-egui/src/tools/brush_refusal.rs b/crates/ui-egui/src/tools/brush_refusal.rs index 4c9a50f3cd..040d248ed9 100644 --- a/crates/ui-egui/src/tools/brush_refusal.rs +++ b/crates/ui-egui/src/tools/brush_refusal.rs @@ -14,6 +14,8 @@ use crate::state::Tool; pub const HIDDEN: &str = "Could not use the {tool} because the target layer is hidden."; pub const LOCKED: &str = "Could not use the {tool} because the layer is locked."; pub const GROUP: &str = "Could not use the {tool} because the pixels in a group cannot be edited without merging the group."; +/// The Clone Stamp's group alert, measured with Sample: Current Layer (#12608): the group is its source. +pub const CLONE_STAMP_GROUP: &str = "Could not use the {tool} because the source is a group."; /// The Remove tool's one measured alert, Lock All (#12552): it doesn't name the tool. pub const REMOVE_LOCKED: &str = "Can't use the tool because the layer is locked."; @@ -39,7 +41,7 @@ fn mode_tool_name(tool: Tool) -> Option<&'static str> { /// The tool's name in the alerts, for the tools whose wording was measured: the Brush, the /// Sharpen tool (#12952), the Sponge (#13030), the Smudge tool (#12965), the Burn tool (#12672), the Healing Brush (#12111), the Art History Brush -/// (#12638), the Paint Bucket (#12537) and the Classic gradient (the live Gradient makes a fill layer and isn't measured, #12017). +/// (#12638), the Clone Stamp (#12608), the Paint Bucket (#12537) and the Classic gradient (the live Gradient makes a fill layer and isn't measured, #12017). pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { match tool { Tool::Brush => Some(tl!("brush tool")), @@ -53,6 +55,7 @@ pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> { Tool::Burn => Some(tl!("burn tool")), Tool::Healing => Some(tl!("healing brush")), Tool::ArtHistoryBrush => Some(tl!("art history brush")), + Tool::CloneStamp => Some(tl!("clone stamp tool")), // The Paint Bucket's click (#12537). Tool::PaintBucket => Some(tl!("paint bucket")), Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")), @@ -103,6 +106,14 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option { if tool == Tool::Healing && app.session.active().and_then(|st| st.doc.layer(st.active_layer?)).is_some_and(photocraft_doc::Layer::is_group) { return None; } + // The Clone Stamp's group alert was measured with Sample: Current Layer and a shown group only (#12608): a hidden + // group, or Current & Below / All Layers, keep today's messages (the status bar, `refuse_group`'s alert). + if tool == Tool::CloneStamp && app.session.active().and_then(|st| st.doc.layer(st.active_layer?)).is_some_and(photocraft_doc::Layer::is_group) { + if hidden || app.ui.tool_options.clone_sample != "current" { + return None; + } + return (layer_refusal(app, tool)? == GROUP).then(|| crate::i18n::fmt(tl!(CLONE_STAMP_GROUP), &[("tool", name)])); + } let template = if hidden { HIDDEN } else { layer_refusal(app, tool)? }; Some(crate::i18n::fmt(tl!(template), &[("tool", name)])) } @@ -191,6 +202,10 @@ mod burn_refusal_alert_tests; #[path = "../healing_refusal_alert_tests.rs"] mod healing_refusal_alert_tests; +#[cfg(test)] +#[path = "../clone_stamp_refusal_alert_tests.rs"] +mod clone_stamp_refusal_alert_tests; + #[cfg(test)] #[path = "../paint_bucket_refusal_alerts_tests.rs"] mod paint_bucket_refusal_alerts_tests; diff --git a/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs b/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs index e448eec978..1f9f26e308 100644 --- a/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs +++ b/crates/ui-egui/src/tools/remove_hidden_layer_tests.rs @@ -50,8 +50,9 @@ fn the_other_tools_keep_their_message() { refused(&mut hidden(Tool::Brush), "Could not use the brush tool because the target layer is hidden."); refused(&mut hidden(Tool::Smudge), "Could not use the smudge tool because the target layer is hidden."); refused(&mut hidden(Tool::Healing), "Could not use the healing brush because the target layer is hidden."); + refused(&mut hidden(Tool::CloneStamp), "Could not use the clone stamp tool because the target layer is hidden."); // The Spot Healing Brush has its own alert since #12581. - for tool in [Tool::Pencil, Tool::Eraser, Tool::CloneStamp] { + for tool in [Tool::Pencil, Tool::Eraser] { let mut app = hidden(tool); let before = steps(&app); stroke(&mut app);