mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Window › Options shows and hides the options bar, with its check mark
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr84Vw42Y1h9tPLDK7SFRm
This commit is contained in:
1 parent
f0205ae336
commit
a83abddb8d
4 files changed
+99
No files matched your search
@@ -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!({
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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<bool> {
|
||||
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<Value, String> {
|
||||
*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" {
|
||||
|
||||
@@ -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<PhotocraftApp> {
|
||||
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");
|
||||
}
|
||||
Reference in new issue
Block a user