From a83abddb8de3d5b47f78da84f0182dfe51bb80bd Mon Sep 17 00:00:00 2001 From: ancientastronauttheorist Date: Wed, 25 Nov 2026 21:48:53 -0600 Subject: [PATCH] =?UTF-8?q?Window=20=E2=80=BA=20Options=20shows=20and=20hi?= =?UTF-8?q?des=20the=20options=20bar,=20with=20its=20check=20mark?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Window › Options (`window.panel.options` / `window.toggle.options`) is handled next to Window › Contextual Task Bar: choosing it toggles `ui.panels.options_bar`, the menu item is checked while the bar shows, and `{"show": bool}` sets it from the control channel. `ui.inspect` reports it as `optionsBar.enabled`. It used to put "unknown command `window.toggle.options`" in the status bar and change nothing. Fixes #16795. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Gr84Vw42Y1h9tPLDK7SFRm --- crates/ui-egui/src/control/inspect.rs | 2 + crates/ui-egui/src/lib.rs | 2 + .../ui-egui/src/menus/view_cmds/dispatch.rs | 18 +++++ .../src/window_options_toggle_tests.rs | 77 +++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 crates/ui-egui/src/window_options_toggle_tests.rs diff --git a/crates/ui-egui/src/control/inspect.rs b/crates/ui-egui/src/control/inspect.rs index fab45b9d7a..b55f79e47f 100644 --- a/crates/ui-egui/src/control/inspect.rs +++ b/crates/ui-egui/src/control/inspect.rs @@ -159,6 +159,8 @@ pub fn inspect(app: &PhotocraftApp, ctx: &egui::Context) -> Value { }) }), "panels": legacy.get("panels").cloned().unwrap_or_else(|| json!(app.ui.panels)), + // Window › Options (#16795): whether the options bar is on. + "optionsBar": json!({"enabled": app.ui.panels.options_bar}), // The contextual task bar (#10890): Window › Contextual Task Bar, whether it shows now and // where (screen points), and its place (pinned, dragged-to corner). "taskBar": json!({ diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 20d0f0d1ca..cea781b41a 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1103,6 +1103,8 @@ mod reset_tip_tests; #[cfg(test)] mod rotate_steps_tests; #[cfg(test)] +mod window_options_toggle_tests; +#[cfg(test)] mod zoom_mode_tests; #[cfg(test)] diff --git a/crates/ui-egui/src/menus/view_cmds/dispatch.rs b/crates/ui-egui/src/menus/view_cmds/dispatch.rs index 441d687cec..a8c0313c80 100644 --- a/crates/ui-egui/src/menus/view_cmds/dispatch.rs +++ b/crates/ui-egui/src/menus/view_cmds/dispatch.rs @@ -34,6 +34,12 @@ fn is_context_task_bar(id: &str) -> bool { matches!(id, "window.panel.contextualTaskBar" | "window.toggle.contextualTaskBar") } +/// The Window item and its shell command for the options bar, which is a bar of the window, not a dock panel +/// (#16795). +fn is_options_bar(id: &str) -> bool { + matches!(id, "window.panel.options" | "window.toggle.options") +} + /// Ids handled here (live menu items). pub fn handles(id: &str) -> bool { if let Some(k) = id.strip_prefix("view.show.") { @@ -59,6 +65,7 @@ pub fn handles(id: &str) -> bool { } PANEL_IDS.contains(&id) || is_context_task_bar(id) + || is_options_bar(id) || matches!( id, "view.extras" | "view.flipHorizontal" | "view.pixelAspectRatioCorrection" | "view.patternPreview" | "view.pixelArtPreview" | "view.rotateView" @@ -142,6 +149,9 @@ pub fn checked(app: &PhotocraftApp, id: &str) -> Option { if is_context_task_bar(id) { return Some(app.ui.panels.context_task_bar); } + if is_options_bar(id) { + return Some(app.ui.panels.options_bar); + } if PANEL_IDS.contains(&id) { return Some(crate::panel_docking::toggle_panel(id).is_some_and(|panel| crate::panel_docking::is_checked(app, panel))); } @@ -300,6 +310,14 @@ fn run(app: &mut PhotocraftApp, id: &str, p: &Value) -> Result { *bar = flag_param(p, *bar); return Ok(json!(*bar)); } + if is_options_bar(id) { + let show = match p.get("show").or_else(|| p.get("on")) { + None | Some(Value::Null) => !app.ui.panels.options_bar, + Some(value) => value.as_bool().ok_or("show must be a boolean")?, + }; + app.ui.panels.options_bar = show; + return Ok(json!(show)); + } let o = &mut app.ui.view; if let Some(k) = id.strip_prefix("view.show.") { if k == "all" { diff --git a/crates/ui-egui/src/window_options_toggle_tests.rs b/crates/ui-egui/src/window_options_toggle_tests.rs new file mode 100644 index 0000000000..9152f0c614 --- /dev/null +++ b/crates/ui-egui/src/window_options_toggle_tests.rs @@ -0,0 +1,77 @@ +//! #16795: Window › Options shows and hides the options bar, its check mark follows the bar, and the +//! control channel drives it like the other Window toggles. + +use serde_json::{Value, json}; + +use crate::PhotocraftApp; +use crate::control::{ControlRequest, Reply, handle}; + +/// An app with a document open, so the options bar has a tool to show. +fn app() -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 64, "height": 64})).unwrap(); + app +} + +/// The control channel's whole reply to `method` with `params`. +fn control(app: &mut PhotocraftApp, method: &str, params: Value) -> Value { + let ctx = app.ctx().clone(); + let (request, _reply) = ControlRequest::new(method, params); + let Reply::Done(reply) = handle(app, &ctx, &request) else { panic!("{method} should reply at once") }; + reply +} + +/// Chooses menu item `id` through the control channel with the command's `params`, as a click on it does; its +/// result. +fn invoke(app: &mut PhotocraftApp, id: &str, params: Value) -> Value { + let reply = control(app, "ui.menu.invoke", json!({"id": id, "params": params})); + assert_eq!(reply["ok"], true, "{id}: {reply}"); + reply["result"].clone() +} + +/// Whether the menu shows `id` checked, as `ui.menu.list` reports it. +fn checked(app: &mut PhotocraftApp, id: &str) -> Value { + let list = control(app, "ui.menu.list", json!({})); + let rows = list["result"].as_array().cloned().unwrap_or_default(); + rows.into_iter().find(|row| row["id"] == id).map_or(Value::Null, |row| row["checked"].clone()) +} + +/// Whether the options bar is on (Window › Options), as `ui.inspect` reports it. +fn bar_shown(app: &mut PhotocraftApp) -> Value { + control(app, "ui.inspect", json!({}))["result"]["optionsBar"]["enabled"].clone() +} + +#[test] +fn window_options_hides_and_shows_the_options_bar_with_its_check_mark() { + let mut app = app(); + assert_eq!((checked(&mut app, "window.panel.options"), bar_shown(&mut app)), (json!(true), json!(true)), "checked while the bar shows"); + invoke(&mut app, "window.panel.options", json!({})); + assert_eq!((checked(&mut app, "window.panel.options"), bar_shown(&mut app)), (json!(false), json!(false)), "choosing it hides the bar and unchecks it"); + assert!(!app.ui.status.contains("unknown command"), "no error in the status bar: {}", app.ui.status); + invoke(&mut app, "window.panel.options", json!({})); + assert_eq!((checked(&mut app, "window.panel.options"), bar_shown(&mut app)), (json!(true), json!(true)), "choosing it again brings the bar back"); +} + +#[test] +fn the_control_channel_shows_or_hides_the_options_bar_with_show() { + let mut app = app(); + for (show, want) in [(false, false), (false, false), (true, true), (true, true)] { + invoke(&mut app, "window.panel.options", json!({"show": show})); + assert_eq!(bar_shown(&mut app), json!(want), "show: {show} sets the bar rather than toggling it"); + } + let reply = control(&mut app, "ui.menu.invoke", json!({"id": "window.panel.options", "params": {"show": "no"}})); + assert_eq!(reply["ok"], false, "a show that isn't true or false is refused: {reply}"); + assert_eq!(bar_shown(&mut app), json!(true), "and changes nothing"); +} + +/// Neighbours: the other Window bars beside Options keep toggling on their own. +#[test] +fn window_tools_and_contextual_task_bar_keep_their_own_toggles() { + let mut app = app(); + let tools = checked(&mut app, "window.panel.tools"); + invoke(&mut app, "window.panel.tools", json!({})); + assert_ne!(checked(&mut app, "window.panel.tools"), tools, "Window › Tools toggles the toolbar"); + invoke(&mut app, "window.panel.contextualTaskBar", json!({})); + assert_eq!(checked(&mut app, "window.panel.contextualTaskBar"), json!(false), "Window › Contextual Task Bar toggles its bar"); + assert_eq!(bar_shown(&mut app), json!(true), "neither touches the options bar"); +}