mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
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 <active document name>" through the translation catalog with English fallback. Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
4a4e3cff33
commit
b59300ba2f
5 files changed
+111
-6
No files matched your search
@@ -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"),
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
//! Window › Arrange: measured entry order, separators, and dynamic "New Window for <doc>" 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<String>)> {
|
||||
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");
|
||||
}
|
||||
@@ -258,6 +258,12 @@ pub fn base_rows(app: &PhotocraftApp) -> Vec<Row> {
|
||||
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"))
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
Reference in new issue
Block a user