From fa4662f2cb09ff6efe3672d9d368dd24dc73440c Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:48:53 +0900 Subject: [PATCH 1/9] fix(shortcuts): restore the Toolbar visibility tab --- .../prefs/prefs_ui/shortcut_capture_tests.rs | 88 +++++++++++++++++++ .../ui-egui/src/prefs/prefs_ui/shortcuts.rs | 74 ++++++++++++---- 2 files changed, 147 insertions(+), 15 deletions(-) diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs index 7d46727407..ca45658cd4 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs @@ -161,3 +161,91 @@ fn a_user_shortcut_wins_over_a_default_it_was_not_moved_from() { let log = crate::shortcut_dispatch::take_log(&ctx); assert_eq!(log.last().map(|i| i.0.as_str()), Some("select.modify.feather"), "{log:?}"); } + +/// Exercises the PhotoCraft tab body even on a framework pin whose tab strip overflows. +fn open_toolbar(h: &mut Harness<'_, Box>) { + crate::prefs_ui::open_shortcuts(h.state_mut(), 0); + h.state_mut().prefs_rt.shortcuts.as_mut().unwrap().state = craft::menu::shortcuts::DialogState::new().with_tab("toolbar"); + h.run_steps(5); + let session = h.state().prefs_rt.shortcuts.as_ref().unwrap(); + assert_eq!(session.state.snapshot(&session.keymap).unwrap().tab, "toolbar"); +} + +#[test] +fn shortcuts_toolbar_visibility_is_saved_only_on_ok() { + use egui::accesskit::{Role, Toggled}; + use egui_kittest::kittest::{NodeT as _, Queryable as _}; + + let mut h = harness(); + let app = h.state_mut(); + app.run( + "prefs.set", + json!({"path": "toolbar", "value": { + "hidden": ["Artboard Tool", "Future Tool"], "toolbar": [["Move", "Artboard"], ["Brush"]], "extras": [["Patch", "Pen"]] + }}), + ) + .unwrap(); + let initial = app.session.prefs().toolbar.clone(); + + open_toolbar(&mut h); + assert_eq!(h.get_by_role_and_label(Role::CheckBox, "Artboard Tool").accesskit_node().toggled(), Some(Toggled::False)); + h.get_by_role_and_label(Role::CheckBox, "Move Tool").click(); + h.run_steps(3); + assert_eq!(h.get_by_role_and_label(Role::CheckBox, "Move Tool").accesskit_node().toggled(), Some(Toggled::False)); + assert_eq!(h.state().session.prefs().toolbar, initial, "edits stay in the draft"); + h.get_by_label("Cancel").click(); + h.run_steps(5); + assert!(!crate::prefs_ui::shortcuts_open(h.state())); + assert_eq!(h.state().session.prefs().toolbar, initial); + + open_toolbar(&mut h); + h.get_by_role_and_label(Role::CheckBox, "Artboard Tool").click(); + h.get_by_role_and_label(Role::CheckBox, "Move Tool").click(); + h.run_steps(3); + h.get_by_label("OK").click(); + h.run_steps(5); + assert!(!crate::prefs_ui::shortcuts_open(h.state())); + let saved = &h.state().session.prefs().toolbar; + assert_eq!(saved.hidden, ["Future Tool", "Move"]); + assert_eq!(saved.toolbar, initial.toolbar); + assert_eq!(saved.extras, initial.extras); + assert_eq!(saved.layout().toolbar[0], ["Artboard"]); + + open_toolbar(&mut h); + h.get_by_label("Restore Defaults").click(); + h.run_steps(3); + assert_eq!(h.get_by_role_and_label(Role::CheckBox, "Move Tool").accesskit_node().toggled(), Some(Toggled::True)); + h.get_by_label("OK").click(); + h.run_steps(5); + let saved = &h.state().session.prefs().toolbar; + assert!(saved.hidden.is_empty()); + assert_eq!(saved.toolbar, initial.toolbar); + assert_eq!(saved.extras, initial.extras); +} + +#[test] +fn unchanged_shortcuts_toolbar_draft_preserves_newer_toolbar_settings() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable as _; + + for reverted in [false, true] { + let mut h = harness(); + h.state_mut().run("prefs.set", json!({"path": "toolbar.hidden", "value": ["Artboard Tool"]})).unwrap(); + if reverted { + open_toolbar(&mut h); + for _ in 0..2 { + h.get_by_role_and_label(Role::CheckBox, "Artboard Tool").click(); + h.run_steps(3); + } + } else { + crate::prefs_ui::open_shortcuts(h.state_mut(), 0); + h.run_steps(5); + } + // A preferences command can be applied while this dialog is open. + h.state_mut().run("prefs.set", json!({"path": "toolbar.hidden", "value": ["Move"]})).unwrap(); + h.get_by_label("OK").click(); + h.run_steps(5); + assert!(!crate::prefs_ui::shortcuts_open(h.state())); + assert_eq!(h.state().session.prefs().toolbar.hidden, ["Move"], "reverted={reverted}"); + } +} diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs index 282c69dba3..7e991b9a87 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs @@ -1,12 +1,9 @@ //! Edit › Keyboard Shortcuts and Menus: the framework's Keyboard Shortcuts dialog over a draft -//! keymap, with PhotoCraft's Menus tab beside it. +//! keymap, with PhotoCraft's Menus and Toolbar tabs beside it. //! -//! The session holds everything the dialog edits: the draft keymap, the shortcut sets, the Menus -//! draft and the text of a set waiting to be reviewed. Cancel drops it and the runtime never saw -//! a change; OK writes the preferences once ([`save_keys`], then the menus), and the runtime's -//! keymap follows the new preferences revision (`shortcut_dispatch::overrides`). -//! -//! The Toolbar tab is not here: Edit › Toolbar opens the toolbar drawer. +//! Cancel drops the session's draft. OK saves the keymap and sets ([`save_keys`]), then applies +//! the menu and toolbar visibility customizations in one preferences command. The toolbar drawer +//! still owns the toolbar's group layout. use std::collections::{BTreeMap, BTreeSet}; @@ -20,11 +17,12 @@ use craft::ui::pickers::Select; use craft::ui::runtime::env::Env; use craft::ui::runtime::windows; use photocraft_engine::keymap_defs; -use photocraft_engine::prefs::{MenuCustomization, Preferences}; +use photocraft_engine::prefs::{MenuCustomization, Preferences, ToolbarCustomization}; use photocraft_engine::shortcut_sets::DEFAULTS_NAME; use serde_json::{Map, Value, json}; use crate::PhotocraftApp; +use crate::state::Tool; /// The id of the `.kys` format in the dialog's import and export lists. const KYS_FORMAT: &str = "kys"; @@ -43,6 +41,10 @@ pub(crate) struct ShortcutsSession { pub(crate) keymap: Keymap, /// The Menus tab's draft. pub(crate) menus: MenusDraft, + /// The Toolbar tab edits the visibility overrides, independent of the group layout. + toolbar_hidden: Vec, + /// Used to tell whether OK applies a toolbar edit. Other commands can still update preferences. + toolbar_hidden_at_open: Vec, /// The text of a set to review on the next pass, taken by that pass alone: a second pass of /// the same frame finds nothing to review. pub(crate) pending_import: Option, @@ -106,6 +108,8 @@ pub fn open(app: &mut PhotocraftApp, tab: u64) { profiles: profiles_of(prefs), keymap: draft_keymap(app), menus: MenusDraft::of(&prefs.menus), + toolbar_hidden: prefs.toolbar.hidden.clone(), + toolbar_hidden_at_open: prefs.toolbar.hidden.clone(), pending_import: None, remembered: BTreeMap::new(), }; @@ -162,19 +166,20 @@ fn pass(app: &mut PhotocraftApp, ui: &mut egui::Ui, press_ok: bool) { let rows = crate::menus::base_rows(app); let options = options(); let builtins = builtins(); - let ShortcutsSession { state, profiles, keymap, menus, pending_import, remembered } = &mut session; + let ShortcutsSession { state, profiles, keymap, menus, toolbar_hidden, toolbar_hidden_at_open, pending_import, remembered } = &mut session; if let Some(text) = pending_import.take() { review(ui, state, dialog(keymap, profiles, &builtins, &options), &text, remembered); } if press_ok { dialog(keymap, profiles, &builtins, &options).ok(ui, state); } - let mut tabs = [menus_tab(&rows, menus)]; + let mut tabs = [menus_tab(&rows, menus), toolbar_tab(toolbar_hidden)]; let output = dialog(keymap, profiles, &builtins, &options).tabs(&mut tabs).show(ui, state); drop(tabs); match output.outcome { Some(Outcome::Ok) => { - if let Err(e) = save_keys(app, keymap, profiles).and_then(|_| save_menus(app, menus)) { + let changed_toolbar = (toolbar_hidden_names(toolbar_hidden) != toolbar_hidden_names(toolbar_hidden_at_open)).then_some(toolbar_hidden.as_slice()); + if let Err(e) = save_keys(app, keymap, profiles).and_then(|_| save_customizations(app, menus, changed_toolbar)) { app.ui.status = crate::i18n::fmt(tl!("The keyboard shortcuts were not saved: {error}"), &[("error", &e)]); app.ui.status_error = true; } @@ -264,10 +269,49 @@ pub(crate) fn save_keys(app: &mut PhotocraftApp, keymap: &Keymap, profiles: &Pro app.run("edit.keyboardShortcuts", call).map_err(|e| e.to_string()) } -/// Writes the Menus tab's draft to the preferences. -fn save_menus(app: &mut PhotocraftApp, menus: &MenusDraft) -> Result { - let call = json!({"values": {"menus": {"hidden": menus.hidden, "colors": menus.colors}}}); - app.run("prefs.set", call).map_err(|e| e.to_string()) +/// Saves the Menus and Toolbar tabs together. The toolbar layout is edited in its own drawer. +fn save_customizations(app: &mut PhotocraftApp, menus: &MenusDraft, toolbar_hidden: Option<&[String]>) -> Result { + let mut values = json!({"menus": {"hidden": menus.hidden, "colors": menus.colors}}); + if let Some(hidden) = toolbar_hidden { + values["toolbar.hidden"] = json!(hidden); + } + app.run("prefs.set", json!({"values": values})).map_err(|e| e.to_string()) +} + +/// The visibility overrides ignore order and recognise older tool spellings. Keep unknown names +/// in the comparison so Restore Defaults can clear them too. +fn toolbar_hidden_names(hidden: &[String]) -> BTreeSet { + hidden.iter().map(|name| ToolbarCustomization::tool_name(name).unwrap_or_else(|| name.clone())).collect() +} + +/// The Toolbar tab changes each tool's visibility override, leaving custom groups and extras in place. +fn toolbar_tab(hidden: &mut Vec) -> DialogTab<'_> { + DialogTab::new("toolbar", tl!("Toolbar"), move |ui| { + let mut changed = ui.button(tl!("Restore Defaults")).clicked() && !hidden.is_empty(); + if changed { + hidden.clear(); + } + let hidden_tools = toolbar_hidden_names(hidden); + egui::Grid::new("toolbar-visibility").num_columns(2).show(ui, |ui| { + for tool in Tool::ALL { + let name = format!("{tool:?}"); + let visible = !hidden_tools.contains(&name); + let checkbox = ui.push_id(tool, |ui| Checkbox::new(Bind::given(visible)).label(tl!(tool.label())).show(ui)).inner; + if let Some(&visible) = checkbox.events.value() { + if visible { + hidden.retain(|entry| ToolbarCustomization::tool_name(entry).as_deref() != Some(name.as_str())); + } else { + hidden.push(name); + } + changed = true; + } + let key = tool.key(); + ui.label(if key == '\0' { String::new() } else { key.to_string() }); + ui.end_row(); + } + }); + changed + }) } /// The Menus tab: a row per menu item with a Visible check and a colour. From 91ed152d10a1bb40b80eb7d986bdb99de1862b6b Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:05:52 +0900 Subject: [PATCH 2/9] fix(shortcuts): keep toolbar tool labels on one line --- .../prefs/prefs_ui/shortcut_capture_tests.rs | 6 ++- .../ui-egui/src/prefs/prefs_ui/shortcuts.rs | 37 ++++++++++--------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs index ca45658cd4..2b2b4d6ff1 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs @@ -188,7 +188,11 @@ fn shortcuts_toolbar_visibility_is_saved_only_on_ok() { let initial = app.session.prefs().toolbar.clone(); open_toolbar(&mut h); - assert_eq!(h.get_by_role_and_label(Role::CheckBox, "Artboard Tool").accesskit_node().toggled(), Some(Toggled::False)); + let move_tool = h.get_by_role_and_label(Role::CheckBox, "Move Tool").rect(); + let artboard = h.get_by_role_and_label(Role::CheckBox, "Artboard Tool"); + let row_spacing = artboard.rect().top() - move_tool.top(); + assert!((0.0..36.0).contains(&row_spacing), "the first two tool labels fit on single lines: {row_spacing} pt between rows"); + assert_eq!(artboard.accesskit_node().toggled(), Some(Toggled::False)); h.get_by_role_and_label(Role::CheckBox, "Move Tool").click(); h.run_steps(3); assert_eq!(h.get_by_role_and_label(Role::CheckBox, "Move Tool").accesskit_node().toggled(), Some(Toggled::False)); diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs index 7e991b9a87..7056560d84 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs @@ -292,24 +292,27 @@ fn toolbar_tab(hidden: &mut Vec) -> DialogTab<'_> { hidden.clear(); } let hidden_tools = toolbar_hidden_names(hidden); - egui::Grid::new("toolbar-visibility").num_columns(2).show(ui, |ui| { - for tool in Tool::ALL { - let name = format!("{tool:?}"); - let visible = !hidden_tools.contains(&name); - let checkbox = ui.push_id(tool, |ui| Checkbox::new(Bind::given(visible)).label(tl!(tool.label())).show(ui)).inner; - if let Some(&visible) = checkbox.events.value() { - if visible { - hidden.retain(|entry| ToolbarCustomization::tool_name(entry).as_deref() != Some(name.as_str())); - } else { - hidden.push(name); + for tool in Tool::ALL { + ui.push_id(tool, |ui| { + ui.horizontal(|ui| { + let name = format!("{tool:?}"); + let visible = !hidden_tools.contains(&name); + let checkbox = Checkbox::new(Bind::given(visible)).label(tl!(tool.label())).show(ui); + if let Some(&visible) = checkbox.events.value() { + if visible { + hidden.retain(|entry| ToolbarCustomization::tool_name(entry).as_deref() != Some(name.as_str())); + } else { + hidden.push(name); + } + changed = true; } - changed = true; - } - let key = tool.key(); - ui.label(if key == '\0' { String::new() } else { key.to_string() }); - ui.end_row(); - } - }); + let key = tool.key(); + if key != '\0' { + ui.label(key.to_string()); + } + }); + }); + } changed }) } From 453369c6962cd61c5f413ae6e75f8ccb8ba5cd61 Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:38:21 +0900 Subject: [PATCH 3/9] Show draft shortcut bindings in the Toolbar tab --- .../prefs/prefs_ui/shortcut_capture_tests.rs | 45 +++++++++++++++++++ .../ui-egui/src/prefs/prefs_ui/shortcuts.rs | 16 ++++--- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs index 2b2b4d6ff1..d8ab074877 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs @@ -171,6 +171,51 @@ fn open_toolbar(h: &mut Harness<'_, Box>) { assert_eq!(session.state.snapshot(&session.keymap).unwrap().tab, "toolbar"); } +fn toolbar_shows_shortcut(h: &Harness<'_, Box>, tool: &str, shortcut: &str) -> bool { + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT as _, Queryable as _, by}; + + let checkbox = h.get_by_role_and_label(Role::CheckBox, tool).rect(); + h.query_all(by().label(shortcut).include_labels()).any(|node| { + let position = node.rect().center(); + node.accesskit_node().role() == Role::Label && position.x > checkbox.right() && checkbox.y_range().contains(position.y) + }) +} + +#[test] +fn shortcuts_toolbar_shows_the_draft_bindings() { + let mut h = harness(); + open_toolbar(&mut h); + assert!(toolbar_shows_shortcut(&h, "Move Tool", "V")); + assert!(toolbar_shows_shortcut(&h, "Artboard Tool", "V")); + + let move_tool = CommandRef::new("tools.select.move"); + let single_row = CommandRef::new("tools.select.singleRowMarquee"); + rebind(h.state_mut(), &move_tool, Binding::parse("Q").unwrap(), Policy::Steal).unwrap(); + rebind(h.state_mut(), &single_row, Binding::parse("F6").unwrap(), Policy::Steal).unwrap(); + h.run_steps(3); + assert!(toolbar_shows_shortcut(&h, "Move Tool", "Q"), "show the in-dialog edit"); + assert!(!toolbar_shows_shortcut(&h, "Move Tool", "V")); + assert!(toolbar_shows_shortcut(&h, "Single Row Marquee Tool", "F6"), "show a binding for a tool that had no default"); + assert!(!h.state().session.prefs().shortcuts.contains_key("tools.select.move"), "the draft is not saved yet"); + + // A menu command takes the key from the tool. Tools in the same group can share keys. + let feather = CommandRef::new("select.modify.feather"); + rebind(h.state_mut(), &feather, Binding::parse("Q").unwrap(), Policy::Steal).unwrap(); + h.run_steps(3); + assert!(!toolbar_shows_shortcut(&h, "Move Tool", "Q"), "the earlier owner no longer displays the stolen shortcut"); + assert!(toolbar_shows_shortcut(&h, "Artboard Tool", "V"), "an unrelated tool keeps its default"); + + let draft = &mut h.state_mut().prefs_rt.shortcuts.as_mut().unwrap().keymap; + assert!(draft.clear(&CommandRef::new("tools.select.artboard"))); + assert!(draft.reset(&move_tool)); + assert!(draft.reset(&single_row)); + h.run_steps(3); + assert!(!toolbar_shows_shortcut(&h, "Artboard Tool", "V"), "clearing leaves the shortcut empty"); + assert!(toolbar_shows_shortcut(&h, "Move Tool", "V"), "resetting restores the default"); + assert!(!toolbar_shows_shortcut(&h, "Single Row Marquee Tool", "F6")); +} + #[test] fn shortcuts_toolbar_visibility_is_saved_only_on_ok() { use egui::accesskit::{Role, Toggled}; diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs index 7056560d84..943651c45b 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs @@ -173,7 +173,12 @@ fn pass(app: &mut PhotocraftApp, ui: &mut egui::Ui, press_ok: bool) { if press_ok { dialog(keymap, profiles, &builtins, &options).ok(ui, state); } - let mut tabs = [menus_tab(&rows, menus), toolbar_tab(toolbar_hidden)]; + let toolbar_tools = Tool::ALL.map(|tool| { + let command = CommandRef::new(crate::tool_shortcuts::id(tool)); + let shortcut = keymap.bindings(&command).first().map(|binding| binding.trigger.display(keymap.platform())); + (tool, shortcut) + }); + let mut tabs = [menus_tab(&rows, menus), toolbar_tab(toolbar_hidden, &toolbar_tools)]; let output = dialog(keymap, profiles, &builtins, &options).tabs(&mut tabs).show(ui, state); drop(tabs); match output.outcome { @@ -285,14 +290,14 @@ fn toolbar_hidden_names(hidden: &[String]) -> BTreeSet { } /// The Toolbar tab changes each tool's visibility override, leaving custom groups and extras in place. -fn toolbar_tab(hidden: &mut Vec) -> DialogTab<'_> { +fn toolbar_tab<'a>(hidden: &'a mut Vec, tools: &'a [(Tool, Option)]) -> DialogTab<'a> { DialogTab::new("toolbar", tl!("Toolbar"), move |ui| { let mut changed = ui.button(tl!("Restore Defaults")).clicked() && !hidden.is_empty(); if changed { hidden.clear(); } let hidden_tools = toolbar_hidden_names(hidden); - for tool in Tool::ALL { + for (tool, shortcut) in tools { ui.push_id(tool, |ui| { ui.horizontal(|ui| { let name = format!("{tool:?}"); @@ -306,9 +311,8 @@ fn toolbar_tab(hidden: &mut Vec) -> DialogTab<'_> { } changed = true; } - let key = tool.key(); - if key != '\0' { - ui.label(key.to_string()); + if let Some(shortcut) = shortcut { + ui.label(shortcut); } }); }); From 1df78e85bc70919dfbb31126aa820fd5fb5dbfff Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:52:59 +0900 Subject: [PATCH 4/9] fix(shortcuts): preserve independent toolbar visibility edits --- .../prefs/prefs_ui/shortcut_capture_tests.rs | 32 ++++++++++++++ .../ui-egui/src/prefs/prefs_ui/shortcuts.rs | 42 ++++++++++++++++--- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs index d8ab074877..cf05bac1ee 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs @@ -298,3 +298,35 @@ fn unchanged_shortcuts_toolbar_draft_preserves_newer_toolbar_settings() { assert_eq!(h.state().session.prefs().toolbar.hidden, ["Move"], "reverted={reverted}"); } } + +#[test] +fn shortcuts_toolbar_applies_visibility_edits_to_current_settings() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable as _; + + let mut h = harness(); + let set_hidden = |app: &mut PhotocraftApp, hidden: &[&str]| { + app.run("prefs.set", json!({"path": "toolbar.hidden", "value": hidden})).unwrap(); + }; + set_hidden(h.state_mut(), &["Artboard Tool", "Future Tool"]); + open_toolbar(&mut h); + + // A different settings writer adds overrides and uses a canonical spelling for Artboard. + set_hidden(h.state_mut(), &["Patch Tool", "Artboard", "Future Tool", "Unknown Added Tool"]); + h.get_by_role_and_label(Role::CheckBox, "Artboard Tool").click(); + h.get_by_role_and_label(Role::CheckBox, "Move Tool").click(); + h.run_steps(3); + h.get_by_label("OK").click(); + h.run_steps(5); + assert!(!crate::prefs_ui::shortcuts_open(h.state())); + assert_eq!(h.state().session.prefs().toolbar.hidden, ["Patch Tool", "Future Tool", "Unknown Added Tool", "Move"]); + + open_toolbar(&mut h); + set_hidden(h.state_mut(), &["Patch Tool", "Brush Tool", "Future Tool", "Unknown Added Tool", "Move", "Another Future Tool"]); + h.get_by_label("Restore Defaults").click(); + h.run_steps(3); + h.get_by_label("OK").click(); + h.run_steps(5); + assert!(!crate::prefs_ui::shortcuts_open(h.state())); + assert_eq!(h.state().session.prefs().toolbar.hidden, ["Brush Tool", "Another Future Tool"]); +} diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs index 943651c45b..c22d52bb3e 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs @@ -11,6 +11,7 @@ use craft::keymap::import::kys; use craft::keymap::{Builtins, CommandRef, ImportOptions, Keymap, NoneDefined, Overrides, Profiles, Scopes, reserved}; use craft::menu::Row; use craft::menu::shortcuts::{Area, ConflictMode, DialogState, DialogTab, Format, Options, Outcome, ShortcutWords, ShortcutsDialog, kys_error_text}; +use craft::ui::buttons::Button; use craft::ui::choice::Checkbox; use craft::ui::contract::{Bind, Entry, Props as _, Show as _}; use craft::ui::pickers::Select; @@ -43,7 +44,7 @@ pub(crate) struct ShortcutsSession { pub(crate) menus: MenusDraft, /// The Toolbar tab edits the visibility overrides, independent of the group layout. toolbar_hidden: Vec, - /// Used to tell whether OK applies a toolbar edit. Other commands can still update preferences. + /// The opening overrides, used to apply only the user's edits on OK. toolbar_hidden_at_open: Vec, /// The text of a set to review on the next pass, taken by that pass alone: a second pass of /// the same frame finds nothing to review. @@ -183,8 +184,8 @@ fn pass(app: &mut PhotocraftApp, ui: &mut egui::Ui, press_ok: bool) { drop(tabs); match output.outcome { Some(Outcome::Ok) => { - let changed_toolbar = (toolbar_hidden_names(toolbar_hidden) != toolbar_hidden_names(toolbar_hidden_at_open)).then_some(toolbar_hidden.as_slice()); - if let Err(e) = save_keys(app, keymap, profiles).and_then(|_| save_customizations(app, menus, changed_toolbar)) { + let hidden = merge_toolbar_visibility(toolbar_hidden_at_open, toolbar_hidden, &app.session.prefs().toolbar.hidden); + if let Err(e) = save_keys(app, keymap, profiles).and_then(|_| save_customizations(app, menus, hidden.as_deref())) { app.ui.status = crate::i18n::fmt(tl!("The keyboard shortcuts were not saved: {error}"), &[("error", &e)]); app.ui.status_error = true; } @@ -286,13 +287,44 @@ fn save_customizations(app: &mut PhotocraftApp, menus: &MenusDraft, toolbar_hidd /// The visibility overrides ignore order and recognise older tool spellings. Keep unknown names /// in the comparison so Restore Defaults can clear them too. fn toolbar_hidden_names(hidden: &[String]) -> BTreeSet { - hidden.iter().map(|name| ToolbarCustomization::tool_name(name).unwrap_or_else(|| name.clone())).collect() + hidden.iter().map(|name| toolbar_hidden_name(name)).collect() +} + +fn toolbar_hidden_name(name: &str) -> String { + ToolbarCustomization::tool_name(name).unwrap_or_else(|| name.to_owned()) +} + +/// Applies the draft's net edits to the current preferences. Commands can update the same +/// preferences while the dialog is open, so retain entries the user did not change. +fn merge_toolbar_visibility(opened: &[String], draft: &[String], current: &[String]) -> Option> { + let opened = toolbar_hidden_names(opened); + let edited = toolbar_hidden_names(draft); + if opened == edited { + return None; + } + + let mut current_names = BTreeSet::new(); + let mut merged = Vec::new(); + for entry in current { + let name = toolbar_hidden_name(entry); + if !opened.contains(&name) || edited.contains(&name) { + current_names.insert(name); + merged.push(entry.clone()); + } + } + for entry in draft { + let name = toolbar_hidden_name(entry); + if !opened.contains(&name) && current_names.insert(name) { + merged.push(entry.clone()); + } + } + (merged.as_slice() != current).then_some(merged) } /// The Toolbar tab changes each tool's visibility override, leaving custom groups and extras in place. fn toolbar_tab<'a>(hidden: &'a mut Vec, tools: &'a [(Tool, Option)]) -> DialogTab<'a> { DialogTab::new("toolbar", tl!("Toolbar"), move |ui| { - let mut changed = ui.button(tl!("Restore Defaults")).clicked() && !hidden.is_empty(); + let mut changed = Button::new(tl!("Restore Defaults")).show(ui).clicked() && !hidden.is_empty(); if changed { hidden.clear(); } From cb57fd4415eecbf1bff0c232f5b2e52339527842 Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:10:55 +0900 Subject: [PATCH 5/9] test(shortcuts): verify Keyboard Shortcuts and Menus tab layout --- .../prefs/prefs_ui/shortcut_capture_tests.rs | 186 +++--------------- .../ui-egui/src/prefs/prefs_ui/shortcuts.rs | 113 ++--------- 2 files changed, 39 insertions(+), 260 deletions(-) diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs index cd4d3d811f..c78ae1ed1d 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs @@ -194,171 +194,33 @@ fn a_user_shortcut_wins_over_a_default_it_was_not_moved_from() { assert_eq!(log.last().map(|i| i.0.as_str()), Some("select.modify.feather"), "{log:?}"); } -/// Exercises the PhotoCraft tab body even on a framework pin whose tab strip overflows. -fn open_toolbar(h: &mut Harness<'_, Box>) { +/// #15534: Keyboard Shortcuts and Menus lays out both tabs with their full names and switches +/// between them without clipping or overflowing. +#[test] +fn shortcuts_dialog_shows_full_keyboard_shortcuts_and_menus_tabs() { + use egui::accesskit::Role; + use egui_kittest::kittest::{Queryable as _, by}; + + let mut h = harness(); + h.ctx.set_pixels_per_point(1.25); crate::prefs_ui::open_shortcuts(h.state_mut(), 0); - h.state_mut().prefs_rt.shortcuts.as_mut().unwrap().state = craft::menu::shortcuts::DialogState::new().with_tab("toolbar"); h.run_steps(5); + + let shortcuts = h.get_by_role_and_label(Role::Tab, "Keyboard Shortcuts").rect(); + let menus = h.get_by_role_and_label(Role::Tab, "Menus").rect(); + assert!(shortcuts.width() > 0.0 && menus.width() > 0.0); + assert!(shortcuts.right() <= menus.left(), "tabs sit side by side: {shortcuts:?} vs {menus:?}"); + assert!(h.query_by_label("More tabs").is_none(), "two tabs fit without an overflow menu"); + assert!(h.query_by_label("Toolbar").is_none(), "Toolbar is customized in its own dialog (#14616)"); + + h.get_by_role_and_label(Role::Tab, "Menus").click(); + h.run_steps(3); let session = h.state().prefs_rt.shortcuts.as_ref().unwrap(); - assert_eq!(session.state.snapshot(&session.keymap).unwrap().tab, "toolbar"); -} + assert_eq!(session.state.snapshot(&session.keymap).unwrap().tab, "menus"); + assert!(h.query_all(by().label("Show All Menu Items")).next().is_some()); -fn toolbar_shows_shortcut(h: &Harness<'_, Box>, tool: &str, shortcut: &str) -> bool { - use egui::accesskit::Role; - use egui_kittest::kittest::{NodeT as _, Queryable as _, by}; - - let checkbox = h.get_by_role_and_label(Role::CheckBox, tool).rect(); - h.query_all(by().label(shortcut).include_labels()).any(|node| { - let position = node.rect().center(); - node.accesskit_node().role() == Role::Label && position.x > checkbox.right() && checkbox.y_range().contains(position.y) - }) -} - -#[test] -fn shortcuts_toolbar_shows_the_draft_bindings() { - let mut h = harness(); - open_toolbar(&mut h); - assert!(toolbar_shows_shortcut(&h, "Move Tool", "V")); - assert!(toolbar_shows_shortcut(&h, "Artboard Tool", "V")); - - let move_tool = CommandRef::new("tools.select.move"); - let single_row = CommandRef::new("tools.select.singleRowMarquee"); - rebind(h.state_mut(), &move_tool, Binding::parse("Q").unwrap(), Policy::Steal).unwrap(); - rebind(h.state_mut(), &single_row, Binding::parse("F6").unwrap(), Policy::Steal).unwrap(); - h.run_steps(3); - assert!(toolbar_shows_shortcut(&h, "Move Tool", "Q"), "show the in-dialog edit"); - assert!(!toolbar_shows_shortcut(&h, "Move Tool", "V")); - assert!(toolbar_shows_shortcut(&h, "Single Row Marquee Tool", "F6"), "show a binding for a tool that had no default"); - assert!(!h.state().session.prefs().shortcuts.contains_key("tools.select.move"), "the draft is not saved yet"); - - // A menu command takes the key from the tool. Tools in the same group can share keys. - let feather = CommandRef::new("select.modify.feather"); - rebind(h.state_mut(), &feather, Binding::parse("Q").unwrap(), Policy::Steal).unwrap(); - h.run_steps(3); - assert!(!toolbar_shows_shortcut(&h, "Move Tool", "Q"), "the earlier owner no longer displays the stolen shortcut"); - assert!(toolbar_shows_shortcut(&h, "Artboard Tool", "V"), "an unrelated tool keeps its default"); - - let draft = &mut h.state_mut().prefs_rt.shortcuts.as_mut().unwrap().keymap; - assert!(draft.clear(&CommandRef::new("tools.select.artboard"))); - assert!(draft.reset(&move_tool)); - assert!(draft.reset(&single_row)); - h.run_steps(3); - assert!(!toolbar_shows_shortcut(&h, "Artboard Tool", "V"), "clearing leaves the shortcut empty"); - assert!(toolbar_shows_shortcut(&h, "Move Tool", "V"), "resetting restores the default"); - assert!(!toolbar_shows_shortcut(&h, "Single Row Marquee Tool", "F6")); -} - -#[test] -fn shortcuts_toolbar_visibility_is_saved_only_on_ok() { - use egui::accesskit::{Role, Toggled}; - use egui_kittest::kittest::{NodeT as _, Queryable as _}; - - let mut h = harness(); - let app = h.state_mut(); - app.run( - "prefs.set", - json!({"path": "toolbar", "value": { - "hidden": ["Artboard Tool", "Future Tool"], "toolbar": [["Move", "Artboard"], ["Brush"]], "extras": [["Patch", "Pen"]] - }}), - ) - .unwrap(); - let initial = app.session.prefs().toolbar.clone(); - - open_toolbar(&mut h); - let move_tool = h.get_by_role_and_label(Role::CheckBox, "Move Tool").rect(); - let artboard = h.get_by_role_and_label(Role::CheckBox, "Artboard Tool"); - let row_spacing = artboard.rect().top() - move_tool.top(); - assert!((0.0..36.0).contains(&row_spacing), "the first two tool labels fit on single lines: {row_spacing} pt between rows"); - assert_eq!(artboard.accesskit_node().toggled(), Some(Toggled::False)); - h.get_by_role_and_label(Role::CheckBox, "Move Tool").click(); - h.run_steps(3); - assert_eq!(h.get_by_role_and_label(Role::CheckBox, "Move Tool").accesskit_node().toggled(), Some(Toggled::False)); - assert_eq!(h.state().session.prefs().toolbar, initial, "edits stay in the draft"); - h.get_by_label("Cancel").click(); - h.run_steps(5); - assert!(!crate::prefs_ui::shortcuts_open(h.state())); - assert_eq!(h.state().session.prefs().toolbar, initial); - - open_toolbar(&mut h); - h.get_by_role_and_label(Role::CheckBox, "Artboard Tool").click(); - h.get_by_role_and_label(Role::CheckBox, "Move Tool").click(); - h.run_steps(3); - h.get_by_label("OK").click(); - h.run_steps(5); - assert!(!crate::prefs_ui::shortcuts_open(h.state())); - let saved = &h.state().session.prefs().toolbar; - assert_eq!(saved.hidden, ["Future Tool", "Move"]); - assert_eq!(saved.toolbar, initial.toolbar); - assert_eq!(saved.extras, initial.extras); - assert_eq!(saved.layout().toolbar[0], ["Artboard"]); - - open_toolbar(&mut h); - h.get_by_label("Restore Defaults").click(); - h.run_steps(3); - assert_eq!(h.get_by_role_and_label(Role::CheckBox, "Move Tool").accesskit_node().toggled(), Some(Toggled::True)); - h.get_by_label("OK").click(); - h.run_steps(5); - let saved = &h.state().session.prefs().toolbar; - assert!(saved.hidden.is_empty()); - assert_eq!(saved.toolbar, initial.toolbar); - assert_eq!(saved.extras, initial.extras); -} - -#[test] -fn unchanged_shortcuts_toolbar_draft_preserves_newer_toolbar_settings() { - use egui::accesskit::Role; - use egui_kittest::kittest::Queryable as _; - - for reverted in [false, true] { - let mut h = harness(); - h.state_mut().run("prefs.set", json!({"path": "toolbar.hidden", "value": ["Artboard Tool"]})).unwrap(); - if reverted { - open_toolbar(&mut h); - for _ in 0..2 { - h.get_by_role_and_label(Role::CheckBox, "Artboard Tool").click(); - h.run_steps(3); - } - } else { - crate::prefs_ui::open_shortcuts(h.state_mut(), 0); - h.run_steps(5); - } - // A preferences command can be applied while this dialog is open. - h.state_mut().run("prefs.set", json!({"path": "toolbar.hidden", "value": ["Move"]})).unwrap(); - h.get_by_label("OK").click(); - h.run_steps(5); - assert!(!crate::prefs_ui::shortcuts_open(h.state())); - assert_eq!(h.state().session.prefs().toolbar.hidden, ["Move"], "reverted={reverted}"); - } -} - -#[test] -fn shortcuts_toolbar_applies_visibility_edits_to_current_settings() { - use egui::accesskit::Role; - use egui_kittest::kittest::Queryable as _; - - let mut h = harness(); - let set_hidden = |app: &mut PhotocraftApp, hidden: &[&str]| { - app.run("prefs.set", json!({"path": "toolbar.hidden", "value": hidden})).unwrap(); - }; - set_hidden(h.state_mut(), &["Artboard Tool", "Future Tool"]); - open_toolbar(&mut h); - - // A different settings writer adds overrides and uses a canonical spelling for Artboard. - set_hidden(h.state_mut(), &["Patch Tool", "Artboard", "Future Tool", "Unknown Added Tool"]); - h.get_by_role_and_label(Role::CheckBox, "Artboard Tool").click(); - h.get_by_role_and_label(Role::CheckBox, "Move Tool").click(); - h.run_steps(3); - h.get_by_label("OK").click(); - h.run_steps(5); - assert!(!crate::prefs_ui::shortcuts_open(h.state())); - assert_eq!(h.state().session.prefs().toolbar.hidden, ["Patch Tool", "Future Tool", "Unknown Added Tool", "Move"]); - - open_toolbar(&mut h); - set_hidden(h.state_mut(), &["Patch Tool", "Brush Tool", "Future Tool", "Unknown Added Tool", "Move", "Another Future Tool"]); - h.get_by_label("Restore Defaults").click(); + h.get_by_role_and_label(Role::Tab, "Keyboard Shortcuts").click(); h.run_steps(3); - h.get_by_label("OK").click(); - h.run_steps(5); - assert!(!crate::prefs_ui::shortcuts_open(h.state())); - assert_eq!(h.state().session.prefs().toolbar.hidden, ["Brush Tool", "Another Future Tool"]); + let session = h.state().prefs_rt.shortcuts.as_ref().unwrap(); + assert_eq!(session.state.snapshot(&session.keymap).unwrap().tab, "shortcuts"); } diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs index e9d23b4602..cf5fea05e8 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs @@ -1,9 +1,12 @@ //! Edit › Keyboard Shortcuts and Menus: the framework's Keyboard Shortcuts dialog over a draft -//! keymap, with PhotoCraft's Menus and Toolbar tabs beside it. +//! keymap, with PhotoCraft's Menus tab beside it. //! -//! Cancel drops the session's draft. OK saves the keymap and sets ([`save_keys`]), then applies -//! the menu and toolbar visibility customizations in one preferences command. The toolbar drawer -//! still owns the toolbar's group layout. +//! The session holds everything the dialog edits: the draft keymap, the shortcut sets, the Menus +//! draft and the text of a set waiting to be reviewed. Cancel drops it and the runtime never saw +//! a change; OK writes the preferences once ([`save_keys`], then the menus), and the runtime's +//! keymap follows the new shortcut preferences (`shortcut_dispatch::overrides`). +//! +//! The Toolbar tab is not here: Edit › Toolbar opens the toolbar drawer. use std::collections::{BTreeMap, BTreeSet}; @@ -11,7 +14,6 @@ use craft::keymap::import::kys; use craft::keymap::{Builtins, CommandRef, ImportOptions, Keymap, NoneDefined, Overrides, Profiles, Scopes, reserved}; use craft::menu::Row; use craft::menu::shortcuts::{Area, ConflictMode, DialogState, DialogTab, Format, Options, Outcome, ShortcutWords, ShortcutsDialog, kys_error_text}; -use craft::ui::buttons::Button; use craft::ui::choice::Checkbox; use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; use craft::ui::display::Text; @@ -20,12 +22,11 @@ use craft::ui::pickers::Select; use craft::ui::runtime::env::{Env, with_env}; use craft::ui::runtime::windows; use photocraft_engine::keymap_defs; -use photocraft_engine::prefs::{MenuCustomization, Preferences, ToolbarCustomization}; +use photocraft_engine::prefs::{MenuCustomization, Preferences}; use photocraft_engine::shortcut_sets::DEFAULTS_NAME; use serde_json::{Map, Value, json}; use crate::PhotocraftApp; -use crate::state::Tool; /// The id of the `.kys` format in the dialog's import and export lists. const KYS_FORMAT: &str = "kys"; @@ -44,10 +45,6 @@ pub(crate) struct ShortcutsSession { pub(crate) keymap: Keymap, /// The Menus tab's draft. pub(crate) menus: MenusDraft, - /// The Toolbar tab edits the visibility overrides, independent of the group layout. - toolbar_hidden: Vec, - /// The opening overrides, used to apply only the user's edits on OK. - toolbar_hidden_at_open: Vec, /// The text of a set to review on the next pass, taken by that pass alone: a second pass of /// the same frame finds nothing to review. pub(crate) pending_import: Option, @@ -116,8 +113,6 @@ pub fn open(app: &mut PhotocraftApp, tab: u64) { profiles: profiles_of(prefs), keymap: draft_keymap(app), menus: MenusDraft::of(&prefs.menus), - toolbar_hidden: prefs.toolbar.hidden.clone(), - toolbar_hidden_at_open: prefs.toolbar.hidden.clone(), pending_import: None, remembered: BTreeMap::new(), }; @@ -195,25 +190,19 @@ fn pass(app: &mut PhotocraftApp, ui: &mut egui::Ui, press_ok: bool) { let rows = crate::menus::base_rows(app); let options = options(); let builtins = builtins(); - let ShortcutsSession { state, profiles, keymap, menus, toolbar_hidden, toolbar_hidden_at_open, pending_import, remembered } = &mut session; + let ShortcutsSession { state, profiles, keymap, menus, pending_import, remembered } = &mut session; if let Some(text) = pending_import.take() { review(ui, state, dialog(keymap, profiles, &builtins, &options), &text, remembered); } if press_ok { dialog(keymap, profiles, &builtins, &options).ok(ui, state); } - let toolbar_tools = Tool::ALL.map(|tool| { - let command = CommandRef::new(crate::tool_shortcuts::id(tool)); - let shortcut = keymap.bindings(&command).first().map(|binding| binding.trigger.display(keymap.platform())); - (tool, shortcut) - }); - let mut tabs = [menus_tab(&rows, menus), toolbar_tab(toolbar_hidden, &toolbar_tools)]; + let mut tabs = [menus_tab(&rows, menus)]; let output = dialog(keymap, profiles, &builtins, &options).tabs(&mut tabs).show(ui, state); drop(tabs); match output.outcome { Some(Outcome::Ok) => { - let hidden = merge_toolbar_visibility(toolbar_hidden_at_open, toolbar_hidden, &app.session.prefs().toolbar.hidden); - if let Err(e) = save_keys(app, keymap, profiles).and_then(|_| save_customizations(app, menus, hidden.as_deref())) { + if let Err(e) = save_keys(app, keymap, profiles).and_then(|_| save_menus(app, menus)) { app.ui.status = crate::i18n::fmt(tl!("The keyboard shortcuts were not saved: {error}"), &[("error", &e)]); app.ui.status_error = true; } @@ -303,82 +292,10 @@ pub(crate) fn save_keys(app: &mut PhotocraftApp, keymap: &Keymap, profiles: &Pro app.run("edit.keyboardShortcuts", call).map_err(|e| e.to_string()) } -/// Saves the Menus and Toolbar tabs together. The toolbar layout is edited in its own drawer. -fn save_customizations(app: &mut PhotocraftApp, menus: &MenusDraft, toolbar_hidden: Option<&[String]>) -> Result { - let mut values = json!({"menus": {"hidden": menus.hidden, "colors": menus.colors}}); - if let Some(hidden) = toolbar_hidden { - values["toolbar.hidden"] = json!(hidden); - } - app.run("prefs.set", json!({"values": values})).map_err(|e| e.to_string()) -} - -/// The visibility overrides ignore order and recognise older tool spellings. Keep unknown names -/// in the comparison so Restore Defaults can clear them too. -fn toolbar_hidden_names(hidden: &[String]) -> BTreeSet { - hidden.iter().map(|name| toolbar_hidden_name(name)).collect() -} - -fn toolbar_hidden_name(name: &str) -> String { - ToolbarCustomization::tool_name(name).unwrap_or_else(|| name.to_owned()) -} - -/// Applies the draft's net edits to the current preferences. Commands can update the same -/// preferences while the dialog is open, so retain entries the user did not change. -fn merge_toolbar_visibility(opened: &[String], draft: &[String], current: &[String]) -> Option> { - let opened = toolbar_hidden_names(opened); - let edited = toolbar_hidden_names(draft); - if opened == edited { - return None; - } - - let mut current_names = BTreeSet::new(); - let mut merged = Vec::new(); - for entry in current { - let name = toolbar_hidden_name(entry); - if !opened.contains(&name) || edited.contains(&name) { - current_names.insert(name); - merged.push(entry.clone()); - } - } - for entry in draft { - let name = toolbar_hidden_name(entry); - if !opened.contains(&name) && current_names.insert(name) { - merged.push(entry.clone()); - } - } - (merged.as_slice() != current).then_some(merged) -} - -/// The Toolbar tab changes each tool's visibility override, leaving custom groups and extras in place. -fn toolbar_tab<'a>(hidden: &'a mut Vec, tools: &'a [(Tool, Option)]) -> DialogTab<'a> { - DialogTab::new("toolbar", tl!("Toolbar"), move |ui| { - let mut changed = Button::new(tl!("Restore Defaults")).show(ui).clicked() && !hidden.is_empty(); - if changed { - hidden.clear(); - } - let hidden_tools = toolbar_hidden_names(hidden); - for (tool, shortcut) in tools { - ui.push_id(tool, |ui| { - ui.horizontal(|ui| { - let name = format!("{tool:?}"); - let visible = !hidden_tools.contains(&name); - let checkbox = Checkbox::new(Bind::given(visible)).label(tl!(tool.label())).show(ui); - if let Some(&visible) = checkbox.events.value() { - if visible { - hidden.retain(|entry| ToolbarCustomization::tool_name(entry).as_deref() != Some(name.as_str())); - } else { - hidden.push(name); - } - changed = true; - } - if let Some(shortcut) = shortcut { - ui.label(shortcut); - } - }); - }); - } - changed - }) +/// Writes the Menus tab's draft to the preferences. +fn save_menus(app: &mut PhotocraftApp, menus: &MenusDraft) -> Result { + let call = json!({"values": {"menus": {"hidden": menus.hidden, "colors": menus.colors}}}); + app.run("prefs.set", call).map_err(|e| e.to_string()) } /// The Menus tab: a row per menu item with a Visible check and a colour. From 2f86011d142f0da098a8bfec93c9d5cfdd648816 Mon Sep 17 00:00:00 2001 From: dholzric Date: Tue, 1 Dec 2026 01:54:11 -0600 Subject: [PATCH 6/9] Zoom: keep Zoom Out mode across Reset All Tools (#18191) `reset_all` in `crates/ui-egui/src/tools/tool_reset.rs` replaced `app.ui.tool_options` with `ToolOptions::default()`, switching the Zoom tool back to Zoom In (`zoom_in = true`) when it was in Zoom Out mode, whereas Reset Tool already kept `zoom_in`. Carry `zoom_in` across `ToolOptions::default()` in `reset_all` while still resetting Scrubby Zoom and the other tools' options, update `kept_by_reset_tool`'s doc comment, and update the single old assertion in `patch_reset_tool_tests.rs`. Co-authored-by: Cursor --- crates/ui-egui/src/patch_reset_tool_tests.rs | 2 +- crates/ui-egui/src/tools/tool_reset.rs | 13 ++- .../tools/zoom_reset_all_keeps_mode_tests.rs | 107 ++++++++++++++++++ 3 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs diff --git a/crates/ui-egui/src/patch_reset_tool_tests.rs b/crates/ui-egui/src/patch_reset_tool_tests.rs index c1ca920ae7..1f03eefa4e 100644 --- a/crates/ui-egui/src/patch_reset_tool_tests.rs +++ b/crates/ui-egui/src/patch_reset_tool_tests.rs @@ -76,7 +76,7 @@ fn rows() -> Vec { assert!(o.zoom_scrubby, "Scrubby Zoom goes back to on"); }, after_reset_all: |o| { - assert!(o.zoom_in, "Reset All Tools gives Zoom In"); + assert!(!o.zoom_in, "Reset All Tools keeps Zoom Out"); assert!(o.zoom_scrubby); }, }, diff --git a/crates/ui-egui/src/tools/tool_reset.rs b/crates/ui-egui/src/tools/tool_reset.rs index 4e9bf5a5be..2eecaf339d 100644 --- a/crates/ui-egui/src/tools/tool_reset.rs +++ b/crates/ui-egui/src/tools/tool_reset.rs @@ -106,11 +106,12 @@ fn reset_tool(app: &mut PhotocraftApp, tool: Tool) { } } -/// Reset All Tools: every option, the selection mode and every tool's brush. +/// Reset All Tools: every option except Zoom In/Out, the selection mode and every tool's brush. fn reset_all(app: &mut PhotocraftApp) { crate::frame_tool::clear(app); app.ui.frame_tool = Default::default(); - *app.ui.tool_options = ToolOptions::default(); + let zoom_in = app.ui.tool_options.zoom_in; + *app.ui.tool_options = ToolOptions { zoom_in, ..ToolOptions::default() }; app.ui.artboard_tool = Default::default(); app.ui.selection_mode = 0; reset_session_brush(app); @@ -134,8 +135,8 @@ fn reset_session_brush(app: &mut PhotocraftApp) { /// The fields of [`option_keys`] that Reset Tool leaves as they are, as the reference app does /// (Zoom Out, #12066; Patch Structure and Color, #12127; Content-Aware Move Mode, #12183). -/// They stay in [`option_keys`], so a tool preset still stores them, and Reset All Tools still -/// resets them (it starts from the defaults). +/// They stay in [`option_keys`], so a tool preset still stores them; Reset All Tools keeps +/// `zoom_in` (#18191) and still resets the rest (not measured for Reset All Tools). fn kept_by_reset_tool(tool: Tool) -> &'static [&'static str] { match tool { Tool::Zoom => &["zoom_in"], @@ -494,3 +495,7 @@ mod art_history_reset_keeps_pressure_tests; #[cfg(test)] #[path = "bg_eraser_reset_pressure_tests.rs"] mod bg_eraser_reset_pressure_tests; + +#[cfg(test)] +#[path = "zoom_reset_all_keeps_mode_tests.rs"] +mod zoom_reset_all_keeps_mode_tests; diff --git a/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs b/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs new file mode 100644 index 0000000000..e289833201 --- /dev/null +++ b/crates/ui-egui/src/tools/zoom_reset_all_keeps_mode_tests.rs @@ -0,0 +1,107 @@ +//! #18191: Reset All Tools leaves the Zoom tool in Zoom Out mode when it was set, as Reset Tool +//! already does, while resetting Scrubby Zoom and the other tools' options. + +use serde_json::{Value, json}; + +use crate::PhotocraftApp; +use crate::control::{ControlRequest, Reply, handle}; +use crate::state::{Tool, ToolOptions}; + +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.sync_views(); + app +} + +fn invoke(app: &mut PhotocraftApp, id: &str, params: Value) { + let ctx = app.ctx().clone(); + let (req, _rx) = ControlRequest::new("ui.menu.invoke", json!({"id": id, "params": params})); + handle(app, &ctx, &req); + app.sync_views(); +} + +fn answer_dialog(app: &mut PhotocraftApp, method: &str, dialog: &str) -> Value { + let ctx = app.ctx().clone(); + let (req, _rx) = ControlRequest::new(method, json!({"dialog": dialog})); + let out = match handle(app, &ctx, &req) { + Reply::Done(v) => v, + _ => panic!("{method}: expected an immediate reply"), + }; + app.sync_views(); + out +} + +#[test] +fn reset_all_tools_keeps_zoom_out_and_resets_scrubby_zoom() { + let mut app = app(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.zoom_scrubby = false; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + assert!(!app.ui.tool_options.zoom_in, "Zoom Out stays selected"); + assert!(app.ui.tool_options.zoom_scrubby, "Scrubby Zoom goes back to on"); + assert_eq!(app.ui.tool, Tool::Zoom, "Zoom stays the current tool"); +} + +#[test] +fn reset_all_tools_keeps_zoom_in_when_selected() { + let mut app = app(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = true; + app.ui.tool_options.zoom_scrubby = false; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + assert!(app.ui.tool_options.zoom_in); + assert!(app.ui.tool_options.zoom_scrubby); +} + +#[test] +fn reset_all_tools_confirmation_ok_keeps_zoom_out_and_cancel_changes_nothing() { + let mut app = app(); + let ctx = app.ctx().clone(); + app.ui.tool = Tool::Zoom; + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.zoom_scrubby = false; + app.ui.tool_options.feather = 14.0; + + let dialog = crate::menus::invoke(&mut app, &ctx, "tool.resetAll", json!({})).unwrap()["dialog"].as_str().unwrap().to_string(); + assert_eq!(answer_dialog(&mut app, "ui.dialog.cancel", &dialog)["ok"], true); + assert!(!app.ui.tool_options.zoom_in); + assert!(!app.ui.tool_options.zoom_scrubby, "Cancel keeps Scrubby Zoom off"); + assert_eq!(app.ui.tool_options.feather, 14.0, "Cancel keeps other options"); + + let dialog = crate::menus::invoke(&mut app, &ctx, "tool.resetAll", json!({})).unwrap()["dialog"].as_str().unwrap().to_string(); + assert_eq!(answer_dialog(&mut app, "ui.dialog.confirm", &dialog)["ok"], true); + assert!(!app.ui.tool_options.zoom_in, "OK keeps Zoom Out"); + assert!(app.ui.tool_options.zoom_scrubby, "OK resets Scrubby Zoom to on"); + assert_eq!(app.ui.tool_options.feather, ToolOptions::default().feather); + assert_eq!(app.ui.tool, Tool::Zoom); +} + +#[test] +fn reset_all_tools_still_resets_unmeasured_kept_options_and_other_tools() { + let mut app = app(); + app.ui.tool = Tool::Brush; + crate::paint_mouse::sync_tool_brush(&mut app); + app.run("tools.setBrush", json!({"brush": {"size": 45}})).unwrap(); + app.ui.tool_options.zoom_in = false; + app.ui.tool_options.patch_structure = 7.0; + app.ui.tool_options.patch_color = 5.0; + app.ui.tool_options.cam_mode = "extend".into(); + app.ui.tool_options.move_auto_select = false; + app.ui.selection_mode = 2; + + invoke(&mut app, "tool.resetAll", json!({"confirmed": true})); + + let d = ToolOptions::default(); + assert!(!app.ui.tool_options.zoom_in, "Zoom Out stays across Reset All Tools even when another tool is active"); + assert_eq!((app.ui.tool_options.patch_structure, app.ui.tool_options.patch_color), (d.patch_structure, d.patch_color)); + assert_eq!(app.ui.tool_options.cam_mode, d.cam_mode); + assert_eq!(app.ui.tool_options.move_auto_select, d.move_auto_select); + assert_eq!(app.ui.selection_mode, 0); + assert_eq!(app.run("brush.get", json!({})).unwrap()["size"].as_f64().unwrap(), 13.0); +} From 676a82656d4834e516a74c232c9cbf48fa4ccee1 Mon Sep 17 00:00:00 2001 From: dholzric Date: Tue, 1 Dec 2026 01:55:28 -0600 Subject: [PATCH 7/9] Warp: refuse several targets, a linked layer and a group (#18500) edit.transform.warp was enabled by has_layer alone, so over automation it warped the active layer of a several-layer selection, a linked layer without its partner, and the children of a group, each as a "Warp" step. The menu refuses all of these. The command now uses one_warp_target, built on the same engine helpers the menu rule reads (selection_targets, box_targets). It refuses more than one transform target, a layer that linked layers move with, and a group that is not an artboard. Kept as before (not measured): a linked partner that is hidden or locked, and a smart object, type or shape layer among several selected layers. Co-Authored-By: Claude Fable 5.2 --- crates/engine-core/src/cmd/warp_cmds.rs | 34 ++- .../cmd/warp_several_targets_refused_tests.rs | 196 ++++++++++++++++++ 2 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs diff --git a/crates/engine-core/src/cmd/warp_cmds.rs b/crates/engine-core/src/cmd/warp_cmds.rs index f544eb75be..7adcfb4a8d 100644 --- a/crates/engine-core/src/cmd/warp_cmds.rs +++ b/crates/engine-core/src/cmd/warp_cmds.rs @@ -26,6 +26,34 @@ fn has_layer(s: &Session) -> std::result::Result<(), String> { s.active().and_then(|d| d.active_layer).map(|_| ()).ok_or_else(|| "no active layer".into()) } +/// Edit › Transform › Warp takes one layer: not several, not one that linked layers move with, and not a group, the +/// targets the menu greys (#18500). Artboards keep their state, as in the menu rule. Not measured, so as before: a +/// smart object, type or shape layer among several selected layers, and a linked partner that is hidden or locked. +fn one_warp_target(s: &Session) -> std::result::Result<(), String> { + const ONE_LAYER: &str = "Warp works on one layer at a time: select a single layer"; + has_layer(s)?; + let st = s.active().ok_or("no document")?; + let doc = &st.doc; + let targets = crate::transform_cmds::selection_targets(st); + if targets.len() > 1 { + let unmeasured = + |id: &LayerId| doc.layer(*id).is_some_and(|l| matches!(l.content, LayerContent::Smart(_) | LayerContent::Text(_) | LayerContent::Shape(_))); + return if targets.iter().any(unmeasured) { Ok(()) } else { Err(ONE_LAYER.into()) }; + } + if targets.first() != st.active_layer.as_ref() { + return Err(ONE_LAYER.into()); + } + let plain = |id: &LayerId| doc.path_of(*id).is_some_and(|path| doc.shown_at(&path) && doc.locks_at(&path) == Locks::default()); + let mut partners = crate::transform_cmds::box_targets(doc, &targets).into_iter().filter(|id| !targets.contains(id)).peekable(); + if partners.peek().is_some() && partners.all(|id| plain(&id)) { + return Err(ONE_LAYER.into()); + } + match st.active_layer.and_then(|id| doc.layer(id)) { + Some(layer) if layer.is_group() && layer.artboard().is_none() => Err("Warp doesn't work on a group".into()), + _ => Ok(()), + } +} + fn active_smart(s: &Session) -> std::result::Result<(), String> { let d = s.active().ok_or("no document")?; match d.active_layer.and_then(|id| d.doc.layer(id)).map(|l| &l.content) { @@ -796,7 +824,7 @@ pub fn specs() -> Vec { menu: &["Edit", "Transform"], shortcut: None, params: P, - enabled: has_layer, + enabled: one_warp_target, journal: true, run: |s, p| apply(s, p, "edit.transform.warp"), }, @@ -881,3 +909,7 @@ mod warp_remove_split_default_grid_tests; #[cfg(test)] #[path = "warp_pref_hard_edge_tests.rs"] mod warp_pref_hard_edge_tests; + +#[cfg(test)] +#[path = "warp_several_targets_refused_tests.rs"] +mod warp_several_targets_refused_tests; diff --git a/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs b/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs new file mode 100644 index 0000000000..9676bbc5e9 --- /dev/null +++ b/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs @@ -0,0 +1,196 @@ +//! #18500: `edit.transform.warp` refuses, with no History step, the targets the menu greys: more than one layer, a +//! layer that linked layers move with, and a group. One layer still warps. Not measured, so as before: a linked +//! partner that is hidden or locked, and a smart object, type or shape layer among several selected layers. + +use super::*; + +const WARP: &str = "edit.transform.warp"; + +fn arc() -> Value { + json!({"style": "arc", "bend": 50}) +} + +fn doc(s: &Session) -> &Document { + &s.active().unwrap().doc +} + +fn states(s: &Session) -> usize { + s.active().unwrap().history.past_len() +} + +fn document() -> Session { + let mut s = crate::session(); + s.execute("file.new", json!({"width": 200, "height": 160})).unwrap(); + s +} + +/// A new pixel layer with a filled rectangle. +fn pixel_layer(s: &mut Session, r: Rect) -> LayerId { + let id = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap()); + s.edit("fill", |doc, _| { + let surface = doc.layer_mut(id).unwrap().surface_mut().unwrap(); + let px = photocraft_raster::from_rgba(&surface.format(), [1.0, 0.0, 0.0, 1.0]); + surface.fill_rect(r, &px); + Ok(()) + }) + .unwrap(); + id +} + +/// Three pixel layers, bottom to top. +fn three_layers() -> (Session, [LayerId; 3]) { + let mut s = document(); + let ids = [Rect::new(10, 10, 70, 60), Rect::new(80, 20, 150, 70), Rect::new(30, 90, 120, 150)].map(|r| pixel_layer(&mut s, r)); + (s, ids) +} + +/// Selects `ids`; the last one is the active layer. +fn select(s: &mut Session, ids: &[LayerId]) { + s.execute("layer.select", json!({"layer": ids[0].0})).unwrap(); + for id in &ids[1..] { + s.execute("layer.select", json!({"layer": id.0, "mode": "add"})).unwrap(); + } +} + +/// Groups `ids` and returns the group. +fn group(s: &mut Session, ids: &[LayerId]) -> LayerId { + select(s, ids); + LayerId(s.execute("layer.groupLayers", json!({})).unwrap()["layer"].as_u64().unwrap()) +} + +fn link(s: &mut Session, ids: &[LayerId]) { + select(s, ids); + s.execute("layer.linkLayers", json!({})).unwrap(); +} + +/// The warp is refused: the command is disabled for the selection, the call fails, and neither the document nor the +/// History changes. +fn assert_refused(s: &mut Session, params: Value, case: &str) { + let (before, states_before) = (doc(s).clone(), states(s)); + if params.get("layer").is_none() { + assert!(s.disabled_reason(WARP).is_some(), "{case}: the command stays enabled"); + } + let reply = s.execute(WARP, params); + assert!(reply.is_err(), "{case}: the warp ran, {reply:?}"); + assert!(*doc(s) == before, "{case}: nothing changed"); + assert_eq!(states(s), states_before, "{case}: no History state"); +} + +/// The warp runs on `layer` alone: it changes, no other layer does, and one History state is added. +fn assert_warps(s: &mut Session, params: Value, layer: LayerId, case: &str) { + let (before, states_before) = (doc(s).clone(), states(s)); + s.execute(WARP, params).unwrap_or_else(|e| panic!("{case}: {e}")); + // A group holds its layers, so it differs whenever one of them does: compare the layers themselves. + for (_, _, l) in doc(s).walk().into_iter().filter(|(_, _, l)| !l.is_group()) { + assert_eq!(Some(l) != before.layer(l.id), l.id == layer, "{case}: only the warped layer changes, layer {}", l.name); + } + assert_eq!(states(s), states_before + 1, "{case}: one History state"); +} + +#[test] +fn more_than_one_target_is_refused() { + let (mut s, [a, b, _]) = three_layers(); + select(&mut s, &[a, b]); + assert_refused(&mut s, arc(), "two layers"); + // A named layer is checked as the active one, and it is still one of two selected layers. + let mut named = arc(); + named["layer"] = json!(a.0); + assert_refused(&mut s, named, "a named layer among two selected"); + s.execute("select.rect", json!({"x": 20, "y": 20, "width": 100, "height": 40})).unwrap(); + assert_refused(&mut s, arc(), "two layers with a pixel selection"); + + let (mut s, [a, b, c]) = three_layers(); + let g = group(&mut s, &[a, b]); + select(&mut s, &[g, c]); + assert_refused(&mut s, arc(), "a group plus a layer"); + select(&mut s, &[a, b]); + assert_refused(&mut s, arc(), "two layers inside a group"); +} + +#[test] +fn a_group_is_refused() { + let (mut s, [a, b, c]) = three_layers(); + let two = group(&mut s, &[a, b]); + select(&mut s, &[two]); + assert_refused(&mut s, arc(), "a group with two children"); + let one = group(&mut s, &[c]); + select(&mut s, &[one]); + assert_refused(&mut s, arc(), "a group with one child"); + + // A call that names the group, with a pixel layer active. + select(&mut s, &[c]); + let mut params = arc(); + params["layer"] = json!(two.0); + assert_refused(&mut s, params, "a named group"); +} + +#[test] +fn a_layer_that_linked_layers_move_with_is_refused() { + let (mut s, [a, b, _]) = three_layers(); + link(&mut s, &[a, b]); + select(&mut s, &[a]); + assert_refused(&mut s, arc(), "a linked layer"); +} + +#[test] +fn one_layer_keeps_warping() { + let (mut s, [a, b, c]) = three_layers(); + select(&mut s, &[c]); + assert_warps(&mut s, arc(), c, "one pixel layer"); + + group(&mut s, &[a, b]); + select(&mut s, &[a]); + assert_warps(&mut s, arc(), a, "one layer inside a group"); + + select(&mut s, &[b]); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + let smart = s.active().unwrap().active_layer.unwrap(); + assert_warps(&mut s, arc(), smart, "a smart object"); +} + +/// Not measured, so the layer warps alone as before. +#[test] +fn a_hidden_or_locked_linked_partner_keeps_todays_behaviour() { + for hidden in [true, false] { + let (mut s, [a, b, _]) = three_layers(); + link(&mut s, &[a, b]); + s.edit("partner", |doc, _| { + let partner = doc.layer_mut(b).unwrap(); + if hidden { + partner.visible = false; + } else { + partner.locks = Locks { position: true, ..Locks::default() }; + } + Ok(()) + }) + .unwrap(); + select(&mut s, &[a]); + assert_warps(&mut s, arc(), a, if hidden { "a hidden linked partner" } else { "a locked linked partner" }); + } +} + +/// Not measured, so the active layer warps as before. +#[test] +fn a_shape_layer_or_a_smart_object_among_the_selected_layers_keeps_todays_behaviour() { + let (mut s, [a, _, _]) = three_layers(); + let shape = LayerId(s.execute("shape.create", json!({"rect": [130, 100, 40, 30], "fill": "#00ff00"})).unwrap()["layer"].as_u64().unwrap()); + select(&mut s, &[shape, a]); + assert_warps(&mut s, arc(), a, "a shape layer and a pixel layer"); + + let (mut s, [a, b, _]) = three_layers(); + select(&mut s, &[b]); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + let smart = s.active().unwrap().active_layer.unwrap(); + select(&mut s, &[smart, a]); + assert_warps(&mut s, arc(), a, "a smart object and a pixel layer"); +} + +/// A call that names a layer is checked on that layer, so one outside the selection counts alone. +#[test] +fn a_call_naming_a_layer_outside_the_selection_warps_it() { + let (mut s, [a, b, c]) = three_layers(); + select(&mut s, &[a, b]); + let mut params = arc(); + params["layer"] = json!(c.0); + assert_warps(&mut s, params, c, "a named layer outside the selection"); +} From 6ced6b14569267d1eed32d7a37b17917f8c4026c Mon Sep 17 00:00:00 2001 From: dholzric Date: Tue, 1 Dec 2026 02:18:28 -0600 Subject: [PATCH 8/9] Warp: refuse a group before the several-layer exception (#18500) With a group active and a smart object, type or shape layer selected with it, the exception for those unmeasured selections returned before the group check, so the group's layers were still warped. The group check now runs first; the exception still applies when the active layer is not a group. Co-Authored-By: Claude Fable 5.2 --- crates/engine-core/src/cmd/warp_cmds.rs | 9 +++++---- .../src/cmd/warp_several_targets_refused_tests.rs | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/engine-core/src/cmd/warp_cmds.rs b/crates/engine-core/src/cmd/warp_cmds.rs index 7adcfb4a8d..f7117d5acb 100644 --- a/crates/engine-core/src/cmd/warp_cmds.rs +++ b/crates/engine-core/src/cmd/warp_cmds.rs @@ -34,6 +34,10 @@ fn one_warp_target(s: &Session) -> std::result::Result<(), String> { has_layer(s)?; let st = s.active().ok_or("no document")?; let doc = &st.doc; + // A group is refused whatever is selected with it. + if st.active_layer.and_then(|id| doc.layer(id)).is_some_and(|layer| layer.is_group() && layer.artboard().is_none()) { + return Err("Warp doesn't work on a group".into()); + } let targets = crate::transform_cmds::selection_targets(st); if targets.len() > 1 { let unmeasured = @@ -48,10 +52,7 @@ fn one_warp_target(s: &Session) -> std::result::Result<(), String> { if partners.peek().is_some() && partners.all(|id| plain(&id)) { return Err(ONE_LAYER.into()); } - match st.active_layer.and_then(|id| doc.layer(id)) { - Some(layer) if layer.is_group() && layer.artboard().is_none() => Err("Warp doesn't work on a group".into()), - _ => Ok(()), - } + Ok(()) } fn active_smart(s: &Session) -> std::result::Result<(), String> { diff --git a/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs b/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs index 9676bbc5e9..1ae403c846 100644 --- a/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs +++ b/crates/engine-core/src/cmd/warp_several_targets_refused_tests.rs @@ -122,6 +122,16 @@ fn a_group_is_refused() { let mut params = arc(); params["layer"] = json!(two.0); assert_refused(&mut s, params, "a named group"); + + // The group is refused as the active layer of a selection that holds a smart object too. + let (mut s, [a, b, c]) = three_layers(); + let g = group(&mut s, &[a, b]); + select(&mut s, &[c]); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + let smart = s.active().unwrap().active_layer.unwrap(); + select(&mut s, &[smart, g]); + assert!(s.disabled_reason(WARP).is_some_and(|why| why.contains("group")), "the refusal names the group"); + assert_refused(&mut s, arc(), "a group, active, selected with a smart object"); } #[test] From 03f3755de747ed0523a94d4c7a53ef8d75262a45 Mon Sep 17 00:00:00 2001 From: dholzric Date: Tue, 1 Dec 2026 03:31:23 -0600 Subject: [PATCH 9/9] Stack Mode: place None first with a separator below it (#18290) Co-authored-by: Cursor --- crates/ui-egui/src/menu_catalog.rs | 6 +++ .../src/stack_mode_none_position_tests.rs | 52 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 crates/ui-egui/src/stack_mode_none_position_tests.rs diff --git a/crates/ui-egui/src/menu_catalog.rs b/crates/ui-egui/src/menu_catalog.rs index 10d1b57d61..d308bb69ae 100644 --- a/crates/ui-egui/src/menu_catalog.rs +++ b/crates/ui-egui/src/menu_catalog.rs @@ -364,6 +364,8 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Layer", "Smart Objects"], "Convert to Linked…", None, "layer.smartObjects.convertToLinked"), (&["Layer", "Smart Objects"], "Convert to Layers", None, "layer.smartObjects.convertToLayers"), (&["Layer", "Smart Objects"], "---", None, "---"), + (&["Layer", "Smart Objects", "Stack Mode"], "None", None, "layer.smartObjects.stackMode.none"), + (&["Layer", "Smart Objects", "Stack Mode"], "---", None, "---"), (&["Layer", "Smart Objects", "Stack Mode"], "Entropy", None, "layer.smartObjects.stackMode.entropy"), (&["Layer", "Smart Objects", "Stack Mode"], "Kurtosis", None, "layer.smartObjects.stackMode.kurtosis"), (&["Layer", "Smart Objects", "Stack Mode"], "Maximum", None, "layer.smartObjects.stackMode.maximum"), @@ -828,3 +830,7 @@ pub const ARRANGE_ICONS: &[(&str, &str)] = &[ ("window.arrange.sixUp", "arrange-six-up"), ("window.arrange.consolidateAllToTabs", "arrange-consolidate-all-to-tabs"), ]; + +#[cfg(test)] +#[path = "stack_mode_none_position_tests.rs"] +mod stack_mode_none_position_tests; diff --git a/crates/ui-egui/src/stack_mode_none_position_tests.rs b/crates/ui-egui/src/stack_mode_none_position_tests.rs new file mode 100644 index 0000000000..0bb14778e9 --- /dev/null +++ b/crates/ui-egui/src/stack_mode_none_position_tests.rs @@ -0,0 +1,52 @@ +//! #18290: Layer › Smart Objects › Stack Mode lists None first, then a separator, then the eleven +//! modes (Entropy … Variance) in alphabetical order, with `layer.smartObjects.stackMode.none` in +//! `CATALOG` so parity counts it. + +use crate::PhotocraftApp; +use crate::menu_catalog::CATALOG; +use crate::menus::menu_rows; + +const STACK_MODE_PATH: &[&str] = &["Layer", "Smart Objects", "Stack Mode"]; + +const EXPECTED: [(&str, &str); 13] = [ + ("None", "layer.smartObjects.stackMode.none"), + ("---", "---"), + ("Entropy", "layer.smartObjects.stackMode.entropy"), + ("Kurtosis", "layer.smartObjects.stackMode.kurtosis"), + ("Maximum", "layer.smartObjects.stackMode.maximum"), + ("Mean", "layer.smartObjects.stackMode.mean"), + ("Median", "layer.smartObjects.stackMode.median"), + ("Minimum", "layer.smartObjects.stackMode.minimum"), + ("Range", "layer.smartObjects.stackMode.range"), + ("Skewness", "layer.smartObjects.stackMode.skewness"), + ("Standard Deviation", "layer.smartObjects.stackMode.standardDeviation"), + ("Summation", "layer.smartObjects.stackMode.summation"), + ("Variance", "layer.smartObjects.stackMode.variance"), +]; + +#[test] +fn stack_mode_flyout_lists_none_then_separator_then_eleven_modes() { + let app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + let rows: Vec<_> = menu_rows(&app).into_iter().filter(|r| r.path == STACK_MODE_PATH).collect(); + let got: Vec<(String, String)> = + rows.iter().map(|r| if r.label == "---" { ("---".to_string(), "---".to_string()) } else { (r.label.clone(), r.command.id.clone()) }).collect(); + let want: Vec<(String, String)> = EXPECTED.iter().map(|(l, id)| ((*l).to_string(), (*id).to_string())).collect(); + assert_eq!(got, want, "Stack Mode flyout order"); + + for row in rows.iter().filter(|r| r.label != "---") { + assert!(row.shortcut.is_none(), "{} should have no shortcut", row.command.id); + assert!(!row.label.ends_with('…') && !row.label.ends_with("..."), "{} should have no ellipsis: {:?}", row.command.id, row.label); + } +} + +#[test] +fn none_is_a_catalog_row_seen_by_parity() { + let entries: Vec<_> = CATALOG.iter().filter(|&&(path, _, _, _)| path == STACK_MODE_PATH).copied().collect(); + assert_eq!(entries.len(), EXPECTED.len(), "CATALOG has all 13 Stack Mode rows"); + for (got, (label, id)) in entries.iter().zip(EXPECTED.iter()) { + assert_eq!((got.1, got.2, got.3), (*label, None, *id)); + } + let report = crate::menus::parity::compute(); + assert!(report.menus.iter().all(|m| m.missing.is_empty()), "no missing catalog rows: {:?}", report.menus); + assert!(crate::menus::is_live("layer.smartObjects.stackMode.none")); +}