Merge #16279 into the batch branch

# Conflicts:
#	crates/ui-egui/src/hidden_layer_tests.rs
#	crates/ui-egui/src/tools/brush_refusal.rs
This commit is contained in:
David Mann committed 2026-11-30 23:11:26 +01:00
commit fd06de1b1a
3 files changed
+100 -7

No files matched your search

@@ -0,0 +1,84 @@
//! #11924: when the Color Replacement tool can't paint (a hidden target layer, Lock All, a group),
//! a press opens the reference application's alert with OK and changes nothing. Lock transparent
//! pixels still recolours. Other tools keep their alerts.
use serde_json::json;
use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke};
use super::*;
use crate::control::{ControlRequest, Reply, handle};
#[test]
fn a_hidden_target_layer() {
let mut app = app(Tool::ColorReplacement);
let id = active(&app);
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
refused(&mut app, "Could not use the Color Replacement tool because the target layer is hidden.");
assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error as well: {:?}", app.ui.status);
assert_eq!(photocraft_engine::hidden_target::HIDDEN, "Could not complete your request because the target layer is hidden.", "the shared text is unchanged");
}
/// A targeted layer mask on a hidden layer keeps the status-bar refusal: only a pixel target gets the alert (CodeRabbit
/// on #16279).
#[test]
fn a_hidden_layer_with_a_mask_target_keeps_the_status_bar_message() {
let mut app = app(Tool::ColorReplacement);
app.run("layer.layerMask.revealAll", json!({})).unwrap();
let id = active(&app);
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
app.ui.mask_target = true;
stroke(&mut app);
assert!(alerts(&app).is_empty(), "no alert: {:?}", alerts(&app));
assert!(app.ui.status_error, "the status bar says it: {:?}", app.ui.status);
}
#[test]
fn lock_all() {
let mut app = app(Tool::ColorReplacement);
app.run("layer.lockLayers", json!({"all": true})).unwrap();
refused(&mut app, "Could not use the Color Replacement tool because the layer is locked.");
}
#[test]
fn a_group_is_active() {
let mut app = app(Tool::ColorReplacement);
app.run("layer.new.group", json!({})).unwrap();
refused(&mut app, "Could not use the Color Replacement tool because the target is a group.");
}
#[test]
fn lock_transparent_pixels_still_recolours() {
let mut app = app(Tool::ColorReplacement);
app.run("layer.lockLayers", json!({"transparency": true})).unwrap();
let before = steps(&app);
stroke(&mut app);
assert!(alerts(&app).is_empty(), "no refusal: {:?}", alerts(&app));
assert_eq!(steps(&app), before + 1, "the stroke was applied");
}
#[test]
fn the_alert_is_listed_and_confirmed_over_the_control_channel() {
let ctx = egui::Context::default();
let mut app = app(Tool::ColorReplacement);
app.run("layer.lockLayers", json!({"all": true})).unwrap();
stroke(&mut app);
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"], "Could not use the Color Replacement tool because the layer is locked.", "{inspect}");
assert_eq!(call("ui.dialog.confirm", json!({"dialog": dialog["id"]}))["ok"], true);
assert!(alerts(&app).is_empty());
}
#[test]
fn the_brush_keeps_its_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.");
}
+3 -3
View File
@@ -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), the Paint Bucket (#12537) and the Clone
// Stamp (#12608) say so in an alert, the other tools in the status bar.
// The Brush (#11898), the Classic gradient (#12017), the Paint Bucket (#12537), the Clone
// Stamp (#12608) and Color Replacement (#11924) 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 | Tool::CloneStamp) {
if matches!(tool, Tool::Brush | Tool::Gradient | Tool::PaintBucket | Tool::CloneStamp | Tool::ColorReplacement) {
assert!(alert, "{tool:?}: {alerts:?}");
} else {
assert!(app.ui.status.contains("target layer is hidden") && alerts.is_empty(), "{tool:?}: {}", app.ui.status);
+13 -4
View File
@@ -18,6 +18,8 @@ pub const GROUP: &str = "Could not use the {tool} because the pixels in a group
pub const CLONE_STAMP_GROUP: &str = "Could not use the {tool} because the source is a group.";
/// The Brush's alert when an adjustment layer's own content, not its mask, is targeted (#17640).
pub const CONTENT: &str = "Could not use the {tool} because the content of the layer is not directly editable.";
/// The Color Replacement tool's group alert (#11924): its own wording, not the Brush's [`GROUP`].
pub const TARGET_GROUP: &str = "Could not use the {tool} because the target 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.";
@@ -43,7 +45,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 Clone Stamp (#12608), 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), the Color Replacement tool (#11924) 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")),
@@ -60,6 +62,7 @@ pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> {
Tool::CloneStamp => Some(tl!("clone stamp tool")),
// The Paint Bucket's click (#12537).
Tool::PaintBucket => Some(tl!("paint bucket")),
Tool::ColorReplacement => Some(tl!("Color Replacement tool")),
Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")),
_ => None,
}
@@ -98,9 +101,9 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option<String> {
return None;
}
let name = tool_name(app, tool)?;
// The Art History Brush's hidden alert was measured on a layer's pixels only (#12638): a
// hidden mask or channel target keeps the status bar.
if hidden && tool == Tool::ArtHistoryBrush && !pixels_target(&crate::canvas::paint_target(app)) {
// The Art History Brush's (#12638) and the Color Replacement tool's (#11924) hidden alerts were measured on a
// layer's pixels only: a hidden mask or channel target keeps the status bar.
if hidden && matches!(tool, Tool::ArtHistoryBrush | Tool::ColorReplacement) && !pixels_target(&crate::canvas::paint_target(app)) {
return None;
}
// A group is the Healing Brush's no-source alert (#12109), hidden or not: it keeps today's
@@ -123,6 +126,8 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option<String> {
return Some(crate::i18n::fmt(tl!(CONTENT), &[("tool", name)]));
}
let template = if hidden { HIDDEN } else { layer_refusal(app, tool)? };
// The Color Replacement tool says a group differently (#11924).
let template = if tool == Tool::ColorReplacement && template == GROUP { TARGET_GROUP } else { template };
Some(crate::i18n::fmt(tl!(template), &[("tool", name)]))
}
@@ -213,6 +218,10 @@ mod retouch_mode_refusal_alert_tests;
#[path = "../smudge_refusal_alert_tests.rs"]
mod smudge_refusal_alert_tests;
#[cfg(test)]
#[path = "../color_replacement_refusal_alert_tests.rs"]
mod color_replacement_refusal_alert_tests;
#[cfg(test)]
#[path = "remove_hidden_layer_tests.rs"]
mod remove_hidden_layer_tests;