mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
fix(ui): the Classic gradient's refusals are the reference application's alerts (#12017)
A Classic gradient drag on a hidden layer, a fully locked layer or a group now opens a modal alert with OK (the texts of the Brush's #11898 alerts, for the gradient tool) and changes nothing, instead of a status-bar line or a command error that named paint.gradient. The live Gradient and the unmeasured cases (partly locked layers) keep their behaviour.
This commit is contained in:
1 parent
c882bfd832
commit
adc4d3356d
6 files changed
+106
-10
No files matched your search
@@ -101,6 +101,6 @@ fn other_tools_keep_the_status_bar() {
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
assert_eq!(app.ui.status, photocraft_engine::hidden_target::HIDDEN);
|
||||
assert_eq!(tool_name(Tool::Pencil), None);
|
||||
assert_eq!(tool_name(Tool::Brush), Some("brush tool"), "the one place that names the tool");
|
||||
assert_eq!(tool_name(&app, Tool::Pencil), None);
|
||||
assert_eq!(tool_name(&app, Tool::Brush), Some("brush tool"), "the one place that names the tool");
|
||||
}
|
||||
@@ -71,9 +71,10 @@ 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!(app.drag.is_none() && app.live_stroke.is_none(), "{tool:?}: no stroke started");
|
||||
// The Brush says so in its alert (#11898), the other tools in the status bar.
|
||||
// The Brush (#11898) and the Classic gradient (#12017) say so in an alert, the other tools
|
||||
// in the status bar.
|
||||
let alert = app.ui.dialogs.iter().any(|d| d.fields.get("message").and_then(|m| m.as_str()).is_some_and(|m| m.contains("target layer is hidden")));
|
||||
if tool == Tool::Brush {
|
||||
if matches!(tool, Tool::Brush | Tool::Gradient) {
|
||||
assert!(alert, "{tool:?}: {:?}", app.ui.dialogs);
|
||||
} else {
|
||||
assert!(app.ui.status.contains("target layer is hidden") && app.ui.dialogs.is_empty(), "{tool:?}: {}", app.ui.status);
|
||||
|
||||
@@ -91,5 +91,5 @@ fn the_brush_and_the_dodge_tool_keep_todays_behaviour() {
|
||||
let mut app = self::app(Tool::Dodge);
|
||||
app.run("layer.lockLayers", json!({"all": true})).unwrap();
|
||||
assert_eq!(alert(&app, Tool::Dodge, false), None);
|
||||
assert_eq!(tool_name(Tool::Dodge), None);
|
||||
assert_eq!(tool_name(&app, Tool::Dodge), None);
|
||||
}
|
||||
@@ -69,3 +69,5 @@ mod count_show_extras_tests;
|
||||
mod crop_options_labels_tests;
|
||||
#[cfg(test)]
|
||||
mod gradient_options_bar_mode_tests;
|
||||
#[cfg(test)]
|
||||
mod gradient_refusal_messages_tests;
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Photoshop's alerts when a painting tool can't paint (#11898): a press on a hidden target
|
||||
//! layer, on a layer with Lock All, or with a group active (its pixels, not its mask) opens a
|
||||
//! modal alert with OK instead of a status-bar message, and paints nothing. Only the tools whose
|
||||
//! wording was measured have a name here ([`tool_name`]); the others keep today's status bar.
|
||||
//! wording was measured have a name here ([`tool_name`]); the others keep today's status bar. The
|
||||
//! Classic gradient has the same three alerts (#12017); the live Gradient keeps today's.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
@@ -29,12 +30,14 @@ 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 and the
|
||||
/// Sharpen tool (#12952).
|
||||
pub fn 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) 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")),
|
||||
Tool::Sharpen => Some(tl!("sharpen tool")),
|
||||
Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -53,7 +56,7 @@ pub fn alert(app: &PhotocraftApp, tool: Tool, hidden: bool) -> Option<String> {
|
||||
{
|
||||
return Some(crate::i18n::fmt(tl!(template), &[("tool", name)]));
|
||||
}
|
||||
let name = tool_name(tool)?;
|
||||
let name = tool_name(app, tool)?;
|
||||
let template = if hidden {
|
||||
HIDDEN
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
//! #12017: a Classic gradient drag on a hidden layer, a fully locked layer or a group opens the
|
||||
//! reference application's alert with OK and changes nothing; the live Gradient keeps today's
|
||||
//! messages.
|
||||
|
||||
use egui::Modifiers;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
use crate::state::{DialogKind, Tool};
|
||||
|
||||
fn app(classic: bool) -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
app.run("edit.fill", json!({"color": "#dc1e1e"})).unwrap();
|
||||
app.ui.tool = Tool::Gradient;
|
||||
app.ui.tool_options.gradient_classic = classic;
|
||||
app.sync_views();
|
||||
app
|
||||
}
|
||||
|
||||
fn active(app: &PhotocraftApp) -> u64 {
|
||||
app.session.active().unwrap().active_layer.unwrap().0
|
||||
}
|
||||
|
||||
fn steps(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
fn drag(app: &mut PhotocraftApp) {
|
||||
tool_event(app, ToolEvent::Down { x: 10.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Move { x: 30.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Move { x: 54.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Up { x: 54.0, y: 32.0 }, Modifiers::NONE);
|
||||
}
|
||||
|
||||
fn alerts(app: &PhotocraftApp) -> Vec<String> {
|
||||
app.ui.dialogs.iter().filter(|d| d.kind == DialogKind::Error).filter_map(|d| d.fields.get("message").and_then(Value::as_str).map(str::to_string)).collect()
|
||||
}
|
||||
|
||||
fn refused(app: &mut PhotocraftApp, want: &str) {
|
||||
let before = steps(app);
|
||||
drag(app);
|
||||
assert_eq!(alerts(app), [want], "the alert, once");
|
||||
assert_eq!(steps(app), before, "nothing changes, no History step");
|
||||
assert!(!app.ui.status.contains("paint.gradient"), "no command id: {:?}", app.ui.status);
|
||||
let id = app.ui.dialogs.iter().find(|d| d.kind == DialogKind::Error).map(|d| d.id).unwrap();
|
||||
crate::dialogs::confirm(app, id).unwrap();
|
||||
assert!(alerts(app).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hidden_target_layer() {
|
||||
let mut app = app(true);
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
refused(&mut app, "Could not use the gradient tool because the target layer is hidden.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fully_locked_layer() {
|
||||
let mut app = app(true);
|
||||
app.run("layer.lockLayers", json!({"all": true})).unwrap();
|
||||
refused(&mut app, "Could not use the gradient tool because the layer is locked.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_is_active() {
|
||||
let mut app = app(true);
|
||||
app.run("layer.new.group", json!({})).unwrap();
|
||||
refused(&mut app, "Could not use the gradient tool because the pixels in a group cannot be edited without merging the group.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_unmeasured_cases_keep_todays_behaviour() {
|
||||
// Lock transparent pixels still paints with the Classic gradient.
|
||||
let mut app = app(true);
|
||||
app.run("layer.lockLayers", json!({"transparency": true})).unwrap();
|
||||
let before = steps(&app);
|
||||
drag(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
assert_eq!(steps(&app), before + 1);
|
||||
// The live Gradient (a fill layer, not measured) opens no alert.
|
||||
let mut app = self::app(false);
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
drag(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
}
|
||||
Reference in new issue
Block a user