From d6539d81481482f861d7b1fd8c074997144e3717 Mon Sep 17 00:00:00 2001 From: crastinator <141459787+crastinator@users.noreply.github.com> Date: Sun, 29 Nov 2026 14:30:24 +0200 Subject: [PATCH] Window menu: Gradients and the other preset panels are enabled and checked (#17721) The items for Gradients, Patterns, Styles, Shapes, Tool Presets, Clone Source, Glyphs, Character Styles, Paragraph Styles and Timeline were drawn greyed because their ids were missing from PANEL_IDS, which decides both whether the view menus handle an item and its check mark. They now are in it; panel_docking already shows and hides all ten. --- .../ui-egui/src/menus/view_cmds/dispatch.rs | 16 ++++- .../menus/window_menu_preset_panels_tests.rs | 62 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/menus/window_menu_preset_panels_tests.rs diff --git a/crates/ui-egui/src/menus/view_cmds/dispatch.rs b/crates/ui-egui/src/menus/view_cmds/dispatch.rs index 441d687ceca..62a94a12779 100644 --- a/crates/ui-egui/src/menus/view_cmds/dispatch.rs +++ b/crates/ui-egui/src/menus/view_cmds/dispatch.rs @@ -8,7 +8,7 @@ use super::screen_mode_names; use super::{LANGUAGE, PIXEL_ASPECTS, PhotocraftApp, SCREEN_MODES, Show, SnapTo, Value, json}; /// The ids `panel_docking::command` runs for Window › panels and the Type menu's Character and Paragraph. -const PANEL_IDS: [&str; 17] = [ +const PANEL_IDS: [&str; 27] = [ "window.panel.layerComps", "window.panel.layers", "window.panel.history", @@ -24,6 +24,16 @@ const PANEL_IDS: [&str; 17] = [ "window.panel.histogram", "window.panel.swatches", "window.panel.adjustments", + "window.panel.gradients", + "window.panel.patterns", + "window.panel.styles", + "window.panel.shapes", + "window.panel.toolPresets", + "window.panel.cloneSource", + "window.panel.glyphs", + "window.panel.characterStyles", + "window.panel.paragraphStyles", + "window.panel.timeline", "type.panels.character", "type.panels.paragraph", ]; @@ -433,3 +443,7 @@ fn apply_params(current: f32, p: &Value) -> Result { } Ok(wrap_deg(r)) } + +#[cfg(test)] +#[path = "../window_menu_preset_panels_tests.rs"] +mod window_menu_preset_panels_tests; diff --git a/crates/ui-egui/src/menus/window_menu_preset_panels_tests.rs b/crates/ui-egui/src/menus/window_menu_preset_panels_tests.rs new file mode 100644 index 00000000000..4b57793e479 --- /dev/null +++ b/crates/ui-egui/src/menus/window_menu_preset_panels_tests.rs @@ -0,0 +1,62 @@ +//! Window › Gradients and the other registered panels' items that were greyed are enabled, and checked while their +//! panel shows (#17721). + +use serde_json::{Value, json}; + +use crate::PhotocraftApp; +use crate::control::{ControlRequest, Reply}; + +/// The issue's six, then the other registered panels that were greyed for the same reason. +const PANELS: [&str; 10] = + ["gradients", "patterns", "styles", "shapes", "toolPresets", "cloneSource", "glyphs", "characterStyles", "paragraphStyles", "timeline"]; + +fn app(doc: bool) -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + if doc { + app.run("file.new", json!({"width": 64, "height": 48})).unwrap(); + app.sync_views(); + } + app +} + +/// The Window menu's items as `ui.menu.list` reports them. +fn window_items(app: &mut PhotocraftApp) -> Vec { + let ctx = app.ctx().clone(); + let (req, _rx) = ControlRequest::new("ui.menu.list", json!({})); + let Reply::Done(listed) = crate::control::handle(app, &ctx, &req) else { panic!("ui.menu.list: expected an immediate reply") }; + listed["result"].as_array().unwrap().iter().filter(|it| it["path"] == json!(["Window"])).cloned().collect() +} + +fn item(app: &mut PhotocraftApp, panel: &str) -> Value { + let id = format!("window.panel.{panel}"); + window_items(app).into_iter().find(|it| it["id"] == id.as_str()).unwrap_or_else(|| panic!("{id} is in the Window menu")) +} + +#[test] +fn panel_items_are_enabled_and_checked_while_their_panel_shows() { + for doc in [false, true] { + let mut a = app(doc); + for panel in PANELS { + let it = item(&mut a, panel); + assert_eq!(it["enabled"], true, "{panel}, document {doc}: {it}"); + assert_eq!(it["checked"], crate::panel_docking::is_checked(&a, panel), "{panel}, document {doc}: {it}"); + } + } +} + +#[test] +fn choosing_a_panel_item_shows_it_when_hidden_and_hides_it_when_shown() { + let mut a = app(true); + for panel in PANELS { + let id = format!("window.panel.{panel}"); + crate::panel_docking::show_panel(&mut a, panel, Some(false)).unwrap(); + assert_eq!(item(&mut a, panel)["checked"], false, "{panel} starts hidden"); + let ctx = a.ctx().clone(); + crate::menus::invoke(&mut a, &ctx, &id, json!({})).unwrap(); + assert!(crate::panel_docking::is_front(&a, panel), "{panel} shows"); + assert_eq!(item(&mut a, panel)["checked"], true, "{panel}: checked while it shows"); + crate::menus::invoke(&mut a, &ctx, &id, json!({})).unwrap(); + assert!(!crate::panel_docking::is_shown(&a, panel), "{panel} hides"); + assert_eq!(item(&mut a, panel)["checked"], false, "{panel}: unchecked once hidden"); + } +}