From b59300ba2fc84ce94dccf372892771c80716bdf4 Mon Sep 17 00:00:00 2001 From: NaufalDzz Date: Thu, 26 Nov 2026 14:03:01 +0000 Subject: [PATCH] Window > Arrange: match measured order and active document label (#16888) Reorder the Window > Arrange submenu entries and separators to match the measured layout (Horizontal before Vertical for 2-up and 3-up, Consolidate All to Tabs with the layout group, Float entries grouped with Cascade/Tile, and New Window after Match All). Label the final entry "New Window for " through the translation catalog with English fallback. Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- crates/ui-egui/src/menu_catalog.rs | 11 +-- crates/ui-egui/src/menus.rs | 3 + .../src/menus/arrange_menu_order_tests.rs | 92 +++++++++++++++++++ crates/ui-egui/src/menus/items.rs | 6 ++ crates/ui-egui/src/menus/state.rs | 5 + 5 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/menus/arrange_menu_order_tests.rs diff --git a/crates/ui-egui/src/menu_catalog.rs b/crates/ui-egui/src/menu_catalog.rs index 4fb2750e5f..6b7d71db4f 100644 --- a/crates/ui-egui/src/menu_catalog.rs +++ b/crates/ui-egui/src/menu_catalog.rs @@ -741,27 +741,26 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["View"], "Pixel Art Preview", None, "view.pixelArtPreview"), (&["Window", "Arrange"], "Tile All Vertically", None, "window.arrange.tileAllVertically"), (&["Window", "Arrange"], "Tile All Horizontally", None, "window.arrange.tileAllHorizontally"), - (&["Window", "Arrange"], "2-up Vertical", None, "window.arrange.twoUpVertical"), (&["Window", "Arrange"], "2-up Horizontal", None, "window.arrange.twoUpHorizontal"), - (&["Window", "Arrange"], "3-up Vertical", None, "window.arrange.threeUpVertical"), + (&["Window", "Arrange"], "2-up Vertical", None, "window.arrange.twoUpVertical"), (&["Window", "Arrange"], "3-up Horizontal", None, "window.arrange.threeUpHorizontal"), + (&["Window", "Arrange"], "3-up Vertical", None, "window.arrange.threeUpVertical"), (&["Window", "Arrange"], "3-up Stacked", None, "window.arrange.threeUpStacked"), (&["Window", "Arrange"], "4-up", None, "window.arrange.fourUp"), (&["Window", "Arrange"], "6-up", None, "window.arrange.sixUp"), - (&["Window", "Arrange"], "---", None, "---"), (&["Window", "Arrange"], "Consolidate All to Tabs", None, "window.arrange.consolidateAllToTabs"), + (&["Window", "Arrange"], "---", None, "---"), (&["Window", "Arrange"], "Cascade", None, "window.arrange.cascade"), (&["Window", "Arrange"], "Tile", None, "window.arrange.tile"), - (&["Window", "Arrange"], "---", None, "---"), (&["Window", "Arrange"], "Float in Window", None, "window.arrange.floatInWindow"), (&["Window", "Arrange"], "Float All in Windows", None, "window.arrange.floatAllInWindows"), (&["Window", "Arrange"], "---", None, "---"), - (&["Window", "Arrange"], "New Window", None, "window.arrange.newWindowForDocument"), - (&["Window", "Arrange"], "---", None, "---"), (&["Window", "Arrange"], "Match Zoom", None, "window.arrange.matchZoom"), (&["Window", "Arrange"], "Match Location", None, "window.arrange.matchLocation"), (&["Window", "Arrange"], "Match Rotation", None, "window.arrange.matchRotation"), (&["Window", "Arrange"], "Match All", None, "window.arrange.matchAll"), + (&["Window", "Arrange"], "---", None, "---"), + (&["Window", "Arrange"], "New Window", None, "window.arrange.newWindowForDocument"), (&["Window", "Workspace"], "Essentials", None, "window.workspace.essentials"), (&["Window", "Workspace"], "Photography", None, "window.workspace.photography"), (&["Window", "Workspace"], "Painting", None, "window.workspace.painting"), diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 9da031f57b..2f62301eb7 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -118,6 +118,9 @@ mod open_recent_position_tests; #[cfg(test)] mod export_submenu_separator_tests; +#[cfg(test)] +mod arrange_menu_order_tests; + #[cfg(test)] mod bar_cursor_tests; diff --git a/crates/ui-egui/src/menus/arrange_menu_order_tests.rs b/crates/ui-egui/src/menus/arrange_menu_order_tests.rs new file mode 100644 index 0000000000..51a6ebb728 --- /dev/null +++ b/crates/ui-egui/src/menus/arrange_menu_order_tests.rs @@ -0,0 +1,92 @@ +//! Window › Arrange: measured entry order, separators, and dynamic "New Window for " label (#16888). + +use serde_json::json; + +use super::*; + +#[cfg(not(target_arch = "wasm32"))] +fn new_doc(app: &mut PhotocraftApp, name: &str) { + app.run("file.new", json!({"width": 64, "height": 64, "name": name})).unwrap(); +} + +/// The `Window › Arrange` entries returned by `ui.menu.list` as `(id, label, shortcut)`. +#[cfg(not(target_arch = "wasm32"))] +fn arrange_list(app: &mut PhotocraftApp, ctx: &egui::Context) -> Vec<(String, String, Option)> { + let (req, _rx) = crate::control::ControlRequest::new("ui.menu.list", json!({})); + let reply = match crate::control::handle(app, ctx, &req) { + crate::control::Reply::Done(v) => v, + _ => panic!("ui.menu.list: expected an immediate reply"), + }; + reply["result"] + .as_array() + .expect("ui.menu.list returns an array") + .iter() + .filter(|it| it["path"] == json!(["Window", "Arrange"])) + .map(|it| { + let label = it["label"].as_str().unwrap_or_default().to_string(); + let id = if label == "---" { "---".to_string() } else { it["id"].as_str().unwrap_or_default().to_string() }; + let shortcut = it["shortcut"].as_str().map(str::to_string); + (id, label, shortcut) + }) + .collect() +} + +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn arrange_menu_matches_measured_order_and_active_document_label() { + let ctx = egui::Context::default(); + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + + // Without a document open, the final entry keeps its plain fallback label. + let empty = arrange_list(&mut app, &ctx); + assert_eq!(empty.last().map(|(id, label, _)| (id.as_str(), label.as_str())), Some(("window.arrange.newWindowForDocument", "New Window"))); + + new_doc(&mut app, "W1"); + let got = arrange_list(&mut app, &ctx); + let expected: &[(&str, &str)] = &[ + ("window.arrange.tileAllVertically", "Tile All Vertically"), + ("window.arrange.tileAllHorizontally", "Tile All Horizontally"), + ("window.arrange.twoUpHorizontal", "2-up Horizontal"), + ("window.arrange.twoUpVertical", "2-up Vertical"), + ("window.arrange.threeUpHorizontal", "3-up Horizontal"), + ("window.arrange.threeUpVertical", "3-up Vertical"), + ("window.arrange.threeUpStacked", "3-up Stacked"), + ("window.arrange.fourUp", "4-up"), + ("window.arrange.sixUp", "6-up"), + ("window.arrange.consolidateAllToTabs", "Consolidate All to Tabs"), + ("---", "---"), + ("window.arrange.cascade", "Cascade"), + ("window.arrange.tile", "Tile"), + ("window.arrange.floatInWindow", "Float in Window"), + ("window.arrange.floatAllInWindows", "Float All in Windows"), + ("---", "---"), + ("window.arrange.matchZoom", "Match Zoom"), + ("window.arrange.matchLocation", "Match Location"), + ("window.arrange.matchRotation", "Match Rotation"), + ("window.arrange.matchAll", "Match All"), + ("---", "---"), + ("window.arrange.newWindowForDocument", "New Window for W1"), + ]; + let pairs: Vec<(&str, &str)> = got.iter().map(|(id, label, _)| (id.as_str(), label.as_str())).collect(); + assert_eq!(pairs, expected); + assert!(got.iter().all(|(_, _, shortcut)| shortcut.is_none()), "no Window › Arrange entry carries a shortcut: {got:?}"); + + // Activating another document updates the dynamic label while keeping the command id. + new_doc(&mut app, "W2"); + let second = arrange_list(&mut app, &ctx); + assert_eq!(second.last().map(|(id, label, _)| (id.as_str(), label.as_str())), Some(("window.arrange.newWindowForDocument", "New Window for W2"))); + + app.session.set_active(0); + let back = arrange_list(&mut app, &ctx); + assert_eq!(back.last().map(|(id, label, _)| (id.as_str(), label.as_str())), Some(("window.arrange.newWindowForDocument", "New Window for W1"))); +} + +#[test] +fn new_window_for_document_label_uses_translation_catalog_with_english_fallback() { + let translated = crate::i18n::fixture_lang("fr", "\tNew Window for {name}\tNouvelle fenêtre pour {name}\n"); + let missing = crate::i18n::fixture_lang("fr", ""); + + assert_eq!(translated_menu_label(translated, "window.arrange.newWindowForDocument", "New Window for W1"), "Nouvelle fenêtre pour W1"); + assert_eq!(translated_menu_label(missing, "window.arrange.newWindowForDocument", "New Window for W1"), "New Window for W1"); + assert_eq!(translated_menu_label(crate::i18n::Lang::EN, "window.arrange.newWindowForDocument", "New Window for W1"), "New Window for W1"); +} diff --git a/crates/ui-egui/src/menus/items.rs b/crates/ui-egui/src/menus/items.rs index 35685a392c..767b0cf920 100644 --- a/crates/ui-egui/src/menus/items.rs +++ b/crates/ui-egui/src/menus/items.rs @@ -258,6 +258,12 @@ pub fn base_rows(app: &PhotocraftApp) -> Vec { if let Some(item) = find(&mut rows, "layer.smartObjects.revealInFinder") { item.label = reveal_label().into(); } + // Window › Arrange › New Window names the active document (#16888). + if let Some(st) = app.session.active() + && let Some(item) = find(&mut rows, "window.arrange.newWindowForDocument") + { + item.label = format!("New Window for {}", st.doc.name); + } // File › Open Recent: a dynamic submenu of recently opened files, after Open as Smart Object… (#14053). if let Some(after) = rows.iter().position(|i| i.command.id == "file.openAsSmartObject").or_else(|| rows.iter().position(|i| i.command.id == "file.openAs")) { diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index bf3cd0c253..05acaf5755 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -235,5 +235,10 @@ pub(super) fn translated_menu_label(lang: crate::i18n::Lang, id: &str, label: &s { return crate::i18n::tr_id(lang, id, "Quick Export as PNG").replace("PNG", fmt); } + if id == "window.arrange.newWindowForDocument" + && let Some(name) = label.strip_prefix("New Window for ") + { + return crate::i18n::fmt(crate::i18n::tr(lang, "New Window for {name}"), &[("name", name)]); + } crate::i18n::tr_id(lang, id, label).to_string() }