Merge pull request #9246 from dotCooCoo/fix/window-menu-panel-shortcuts

Window menu: panel rows show their panels' shortcuts
This commit is contained in:
BFlat authored and GitHub committed 2026-11-25 15:58:21 +07:00
commit b54bb15b8e
2 files changed
+84 -1

No files matched your search

+11 -1
View File
@@ -86,6 +86,9 @@ pub(crate) fn state_key(app: &VectorcraftApp, input: Option<u64>) -> u64 {
let mut h = DefaultHasher::new();
input.hash(&mut h);
app.run_count.hash(&mut h);
// The window's keymap, which the panel rows read their shortcuts from (`Build::decorate`): the framework builds it
// after the first frame's menus, and builds a new one when the bindings or the catalog change.
app.ui_ctx.as_ref().and_then(craft::ui::runtime::commands::keymap).map(|k| std::sync::Arc::as_ptr(&k).addr()).hash(&mut h);
let s = &app.session;
(s.journal.len(), s.active_index(), s.clipboard.is_empty(), s.tool_composing()).hash(&mut h);
if let Some(d) = s.active() {
@@ -473,11 +476,18 @@ impl Build<'_> {
item_title(self.app, self.lang, id, params, label)
}
/// The alternates (a modifier held as the row is chosen) and the font sample of a row.
/// The alternates (a modifier held as the row is chosen), the font sample and the shortcut of a row.
fn decorate(&self, item: Item, id: &str, params: &Value) -> Item {
let run_with = |mods: Mods, p: Value| Alternate::new(mods, CommandRef::with_params(id, p));
let held = |shift: bool, alt: bool| Mods { cmd: false, ctrl: false, alt, shift };
match id {
// A panel row shows the chord of the panel's shortcut (`panel:<id>`), which binds `window.panel {panel}`;
// a Window row runs it with `toggle: true`, so the framework finds no chord for the row's own command.
"window.panel" => {
let mut item = item;
item.shortcut = super::labels::item_shortcut(self.app, id, params);
item
}
"ui.expandDialog" => item.alternate(run_with(held(false, true), json!({ "immediate": true }))),
crate::addons::select::link_status::COMMAND => {
item.alternate(run_with(held(true, false), crate::addons::select::link_status::with_shift(params.clone())))
+73
View File
@@ -246,6 +246,79 @@ fn named_panel_default_chords_toggle_their_panels() {
}
}
/// Each Window menu row that shows a panel shows the chord of that panel's shortcut, as production's did, and the
/// rows of the panels with a default key show one. The first frame builds the keymap after its menus, so the menus of
/// the next frame show the chords.
#[test]
fn window_menu_panel_rows_show_their_panels_shortcuts() {
let mut app = new_app();
let ctx = ready(&mut app);
key_frame(&mut app, &ctx, vec![]);
let rows: Vec<(craft::keymap::CommandRef, Option<craft::keymap::Chord>)> = app
.menus
.bar
.items()
.into_iter()
.filter(|it| it.command.id == "window.panel" && it.command.params["toggle"] == true)
.map(|it| (it.command.clone(), it.shortcut))
.collect();
assert!(!rows.is_empty(), "the Window menu lists panels");
let mut with_keys = 0;
for (row, chord) in rows {
let panel = row.params["panel"].as_str().expect("a panel row names its panel");
let entry = crate::keymap::command_of(&format!("panel:{panel}"));
assert_eq!(chord, craft::ui::runtime::commands::chord(&ctx, &entry), "{panel}: the row shows its shortcut's chord");
if crate::shortcut_editor::PANEL_SHORTCUTS.iter().any(|(p, _)| *p == panel) {
assert!(chord.is_some(), "{panel} has a default key, and its row shows it");
with_keys += 1;
}
}
assert!(with_keys > 0, "some listed panels have a default key");
}
/// A click on a Window menu row toggles its panel: it puts a showing panel away and shows it again. Libraries is
/// docked in front with no function key, so neither its flyout nor its shortcut toggles it.
#[test]
fn a_window_menu_click_toggles_its_panel() {
use craft::ui::runtime::commands::{FirePhase, FireSource, Fired};
let mut app = new_app();
let ctx = ready(&mut app);
let row = app
.menus
.bar
.items()
.into_iter()
.find(|it| it.command.id == "window.panel" && it.command.params["panel"] == "libraries")
.map(|it| it.command.clone());
let row = row.expect("a Window › Libraries row");
let before = crate::panel_docking::showing(&app.ui, "libraries");
let click = |app: &mut VectorcraftApp| {
crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0));
key_frame(app, &ctx, vec![]);
crate::panel_docking::showing(&app.ui, "libraries")
};
let once = click(&mut app);
assert_ne!(once, before, "the first click toggles Libraries");
assert_eq!(click(&mut app), before, "the second click toggles it back");
}
/// A click on the task bar's More Options › Show Properties Panel, a menu row that runs `window.panel {panel:
/// "properties"}`, leaves a showing docked Properties panel showing: it does not take the toggle of Window › Properties.
#[test]
fn the_task_bar_show_properties_row_keeps_properties_showing() {
use craft::ui::runtime::commands::{FirePhase, FireSource, Fired};
let mut app = new_app();
let ctx = ready(&mut app);
let row = craft::keymap::CommandRef::with_params("window.panel", json!({ "panel": "properties" }));
let click = |app: &mut VectorcraftApp| {
crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0));
key_frame(app, &ctx, vec![]);
crate::panel_docking::showing(&app.ui, "properties")
};
assert!(click(&mut app), "the first click shows Properties");
assert!(click(&mut app), "a second click leaves Properties showing");
}
/// A shortcut on a panel without a function key of its own runs `window.panel` with the params it has: no toggle is
/// added, as production checked.
#[test]