fix(ui): say why a Straighten Layer click was refused

`PhotocraftApp::run` puts what a command answered into the status line, but a refusal raised
before the command runs - the automation gate a control or MCP-driven click passes through -
returns from `run_command_at_depth` ahead of that report, and the button handler only reacted
to the hidden-layer alert. A denied synthetic click therefore did nothing at all, which reads
as a dead button rather than a refused one. It now reports any error it gets, the way
`eraser_ui` and the toolbar flyout do, and keeps opening the reference's alert for the hidden
layer alone.
This commit is contained in:
Hartmut Nörenberg committed 2026-11-08 01:40:36 +01:00
1 parent 1b0a3e1336
commit c517e295b5
2 files changed
+41 -7

No files matched your search

+14 -7
View File
@@ -535,13 +535,20 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo
// layer locked in place (#12033).
let straighten = app.session.is_enabled("image.analysis.straightenLayer");
if ui.add_enabled_ui(straighten, |ui| crate::widgets::secondary_button(ui, tl!("Straighten Layer"), 0.0)).inner.clicked() {
// A hidden target layer keeps the button on and answers the click with the
// reference's alert (its message and an OK button), changing nothing (#12033).
if let Err(why) = app.run("image.analysis.straightenLayer", json!({}))
&& why == photocraft_engine::analysis_cmds::STRAIGHTEN_HIDDEN_ERROR
{
let message = photocraft_engine::analysis_cmds::STRAIGHTEN_HIDDEN_ERROR;
app.ui.open_dialog(DialogKind::Error, json!({"message": tl!(message)}).as_object().cloned().unwrap_or_default());
let hidden = photocraft_engine::analysis_cmds::STRAIGHTEN_HIDDEN_ERROR;
if let Err(why) = app.run("image.analysis.straightenLayer", json!({})) {
// A hidden target layer keeps the button on and answers the click with the
// reference's alert (its message and an OK button), changing nothing (#12033).
if why == hidden {
app.ui.open_dialog(DialogKind::Error, json!({"message": tl!(hidden)}).as_object().cloned().unwrap_or_default());
}
// Every other refusal goes to the status line, as the eraser tools do. What the
// command itself answered is reported there by `PhotocraftApp::run`, but a
// refusal raised before it runs - the automation gate a control or MCP-driven
// click passes - returns early, and a click that says nothing reads as a dead
// button (#12148).
app.ui.status = why;
app.ui.status_error = true;
}
}
if ui.add_enabled_ui(has, |ui| crate::widgets::secondary_button(ui, tl!("Clear"), 0.0)).inner.clicked() {
@@ -391,6 +391,33 @@ fn the_straighten_layer_button_greys_out_where_the_command_is_off() {
}
}
/// A refused click says so. `PhotocraftApp::run` reports what the *command* answered in the status
/// line, but a refusal raised before it runs - the automation gate a control/MCP-driven click goes
/// through - returns early, so the button has to report it itself. As the toolbar flyout does
/// (`a_failed_edit_toolbar_from_the_flyout_reports_its_error_in_the_status_bar`).
#[test]
fn a_denied_synthetic_click_reports_the_refusal_instead_of_saying_nothing() {
use egui_kittest::kittest::{NodeT, Queryable};
let (mut app, _) = app();
on_a_layer(&mut app);
rule(&mut app);
app.automation_input = true;
app.services.automation_command =
Some(Box::new(|id, _| if id == "image.analysis.straightenLayer" { Err("straightening is denied".into()) } else { Ok(()) }));
let mut h = ruler_bar(app);
assert!(!h.get_by_label("Straighten Layer").accesskit_node().is_disabled(), "the layer is a valid target");
let steps = h.state().session.active().unwrap().history.past_len();
h.get_by_label("Straighten Layer").click();
h.run_steps(2);
let st = h.state();
assert_eq!(st.ui.status, "straightening is denied", "the refusal reaches the status line");
assert!(st.ui.status_error, "as an error");
assert!(alerts(st).is_empty(), "the alert stays the hidden layer's own");
let now = st.session.active().unwrap();
assert!(now.doc.measurement.ruler.is_some(), "nothing ran: the ruler line is still up");
assert_eq!(now.history.past_len(), steps, "and nothing was recorded");
}
/// #12033: a hidden target layer is the one state that keeps its button. The click answers with the
/// reference's alert - its measured message and an OK button - instead of the status line, and the
/// document, its History and the ruler line stay as they were.