diff --git a/crates/engine/src/session/execute.rs b/crates/engine/src/session/execute.rs index a94504da4f..b524d5a477 100644 --- a/crates/engine/src/session/execute.rs +++ b/crates/engine/src/session/execute.rs @@ -123,7 +123,8 @@ impl Session { /// [`Self::is_enabled`] for a call with `params`: their `"target"` can enable a command, as a /// targeted layer mask enables Image › Adjustments › Invert on an adjustment layer (#780). pub fn is_enabled_with(&self, id: &str, params: &Value) -> bool { - self.disabled_reason_with(id, params).is_none() + // An unknown id is disabled; its reason would rank every command id for "did you mean". + commands::find(id).is_some_and(|spec| self.spec_disabled_reason(spec, id, params).is_none()) } /// Why the command can't run now (None = it can): its own precondition, or a background job @@ -134,8 +135,13 @@ impl Session { /// [`Self::disabled_reason`] for a call with `params`. pub fn disabled_reason_with(&self, id: &str, params: &Value) -> Option { - let Some(s) = commands::find(id) else { return Some(EngineError::UnknownCommand(id.into()).to_string()) }; - self.precondition(s, &channel_cmds::inject_target(self, id, params.clone())).err().or_else(|| self.job_conflict(id, s.journal)) + let Some(spec) = commands::find(id) else { return Some(EngineError::UnknownCommand(id.into()).to_string()) }; + self.spec_disabled_reason(spec, id, params) + } + + /// [`Self::disabled_reason_with`] for the catalogue entry `spec` of `id`. + fn spec_disabled_reason(&self, spec: &commands::CommandSpec, id: &str, params: &Value) -> Option { + self.precondition(spec, &channel_cmds::inject_target(self, id, params.clone())).err().or_else(|| self.job_conflict(id, spec.journal)) } /// The command's own precondition for a call with `params` (their target filled in). diff --git a/crates/ui-egui/src/input/shortcut_dispatch.rs b/crates/ui-egui/src/input/shortcut_dispatch.rs index 2ed03ef4b4..d9ec0910e6 100644 --- a/crates/ui-egui/src/input/shortcut_dispatch.rs +++ b/crates/ui-egui/src/input/shortcut_dispatch.rs @@ -177,7 +177,8 @@ pub(crate) fn is_screen_mode(id: &str) -> bool { /// The PhotoCraft row of a screen-mode command of the shell: the command gate judges the framework command as the /// menus judge that row. pub(crate) fn screen_mode_row(command: &CommandRef) -> Option<&'static str> { - bridge_of(command).filter(|(_, bridged)| matches!(bridged, Bridged::ScreenMode(_))).map(|(id, _)| id) + // The command gate asks this for every command a pass resolves: only the screen-mode rows build their command. + RUNTIME_COMMANDS.iter().find(|(_, bridged)| matches!(bridged, Bridged::ScreenMode(_)) && bridged.command() == *command).map(|(id, _)| *id) } /// The id of the command that steps a tool group to its next tool: the group is named by its key. diff --git a/crates/ui-egui/src/state/tool.rs b/crates/ui-egui/src/state/tool.rs index 66aa7d53f6..ec6be52664 100644 --- a/crates/ui-egui/src/state/tool.rs +++ b/crates/ui-egui/src/state/tool.rs @@ -317,11 +317,21 @@ impl Tool { _ => "•", } } + /// The tool `s` names: its variant name, that name without "marquee", or its label, in any case and with spaces, + /// `_` and `-` ignored. The first tool of [`Tool::ALL`] a spelling names wins. pub fn from_name(s: &str) -> Option { - let n = s.to_ascii_lowercase().replace([' ', '_', '-'], ""); - Tool::ALL.into_iter().find(|t| { - let a = format!("{t:?}").to_ascii_lowercase(); - n == a || n == a.replace("marquee", "") || n == t.label().to_ascii_lowercase().replace(' ', "") - }) + // The toolbar resolves its whole layout through here every frame: one table instead of formatting every tool's names per lookup. + static NAMES: std::sync::OnceLock> = std::sync::OnceLock::new(); + let names = NAMES.get_or_init(|| { + let mut names = std::collections::HashMap::new(); + for t in Tool::ALL { + let a = format!("{t:?}").to_ascii_lowercase(); + for spelling in [a.replace("marquee", ""), t.label().to_ascii_lowercase().replace(' ', ""), a] { + names.entry(spelling).or_insert(t); + } + } + names + }); + names.get(&s.to_ascii_lowercase().replace([' ', '_', '-'], "")).copied() } } diff --git a/crates/ui-egui/tests/it/tone_targets.rs b/crates/ui-egui/tests/it/tone_targets.rs index cedcb8a773..4fdd29ddd1 100644 --- a/crates/ui-egui/tests/it/tone_targets.rs +++ b/crates/ui-egui/tests/it/tone_targets.rs @@ -68,26 +68,28 @@ fn value(app: &PhotocraftApp, target: ChannelTarget) -> f32 { } /// Render real modal controls with accessibility enabled for input-driven assertions. +/// The app's context is set up already ([`PhotocraftApp::new`]). fn harness(app: Box) -> Harness<'static, Box> { - let h = Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1200.0, 900.0)).build_ui_state(|ui, app| dialogs::run(app, ui), app); - PhotocraftApp::setup_context(&h.ctx, Default::default()); - h + Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1200.0, 900.0)).build_ui_state(|ui, app| dialogs::run(app, ui), app) } -/// The whole app, canvas included: the pointer requests of a picker's samples reach the canvas pass only here. -fn canvas_harness(app: Box) -> Harness<'static, Box> { - // The app keeps the context it was made on: the harness runs the frames on it, so the canvas the app reads is the one drawn. - let mut h = Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1200.0, 900.0)).with_max_steps(64).build_eframe(move |cc| { - PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); - app - }); +/// The document canvas and the dialogs over it: a picker's samples are pointer requests the canvas pass takes, as in +/// the app. The rest of the window (panels, menus, bars) plays no part in sampling, so it is left out. +fn canvas_harness(mut app: Box) -> Harness<'static, Box> { + // The window's frame keeps a view per document; the canvas alone draws the views it is given. + app.sync_views(); + let mut h = Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1200.0, 900.0)).with_max_steps(64).build_ui_state( + |ui, app| { + egui::CentralPanel::default().show(ui, |ui| photocraft_ui_egui::canvas::document_area(app, ui)); + dialogs::run(app, ui); + }, + app, + ); h.run_steps(3); - // A 32 px document at 100 % sits under the dialog's centred window, which stops the picker's press: zoom to 12x so the left part of the image lies clear of the dialog (no animation, so the view is final at once). - h.state_mut().run("prefs.set", json!({"values": {"general.animatedZoom": false}})).unwrap(); - for _ in 0..8 { - h.state_mut().run("view.zoomIn", json!({})).unwrap(); - h.run_steps(2); - } + // The dialog's window is centred and stops a press under it: at 12x with the view centred right of the 32 px image, + // the image's top-left part lies clear of the dialog, at the canvas's left. + let reply = control(&mut h, "ui.set", json!({"zoom": 12, "center": [38, 16]})); + assert_eq!(reply["ok"], true, "the view zooms: {reply}"); h }