Files
soundcraft/crates/ui-egui/tests/window_shortcuts.rs
grovebit 6b98c21fed Make the Window menu's shortcuts work
The Window menu's keys never fired: Cmd+1 Transport, Cmd+3 Big Counter,
Cmd+4 Automation, Cmd+5 Memory Locations, Cmd+9 Video, Cmd+Alt+M Narrow
Mix, Cmd+W Close Window, Cmd+Ctrl+W Hide All Floating Windows and
Cmd+Ctrl+= Score Editor. The shortcut handler only looked at engine
commands, and these are window commands. It now falls back to them, and
the menus and the Keyboard Shortcuts window show their keys.

On a Mac, Cmd+Ctrl+= toggled Mix/Edit instead of opening the Score
Editor. The Mix/Edit toggle now needs Cmd+= without Control there.

The two Control chords still have no key on Windows and Linux.
2026-10-10 19:27:16 +01:00

44 lines
2.0 KiB
Rust

use egui::os::OperatingSystem;
use egui::{Key, Modifiers};
use soundcraft_ui_egui::{MainWindow, Services, SoundApp, shortcuts};
const MAC_CMD: Modifiers = Modifiers { mac_cmd: true, command: true, ..Modifiers::NONE };
fn press(ctx: &egui::Context, app: &mut SoundApp, key: Key, modifiers: Modifiers) {
let events = [true, false].map(|pressed| egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers }).to_vec();
ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| shortcuts::handle(app, ui.ctx())).textures_delta.clear();
}
#[test]
fn window_shortcuts_open_and_close_windows() {
let pc_ctrl = Modifiers { ctrl: true, command: true, ..Modifiers::NONE };
for (os, cmd) in [(OperatingSystem::Mac, MAC_CMD), (OperatingSystem::Windows, pc_ctrl), (OperatingSystem::Nix, pc_ctrl)] {
let mut app = SoundApp::new(soundcraft_engine::Engine::default(), None, Services::default());
let ctx = egui::Context::default();
ctx.set_os(os);
for key in [Key::Num1, Key::Num3, Key::Num4, Key::Num5, Key::Num9] {
press(&ctx, &mut app, key, cmd);
}
press(&ctx, &mut app, Key::M, Modifiers { alt: true, ..cmd });
let ui = &app.ui;
assert!(
ui.show_transport && ui.show_big_counter && ui.show_automation && ui.show_memory_locations && ui.show_video && ui.narrow_mix,
"{os:?}"
);
press(&ctx, &mut app, Key::W, cmd);
assert!(!app.ui.show_transport && !app.ui.show_big_counter && !app.ui.show_memory_locations, "{os:?}");
}
}
#[test]
fn cmd_ctrl_equals_opens_the_score_editor_on_a_mac() {
let mut app = SoundApp::new(soundcraft_engine::Engine::default(), None, Services::default());
let ctx = egui::Context::default();
ctx.set_os(OperatingSystem::Mac);
press(&ctx, &mut app, Key::Equals, Modifiers { ctrl: true, ..MAC_CMD });
assert!(app.ui.show_score);
assert_eq!(app.ui.window, MainWindow::Edit);
press(&ctx, &mut app, Key::Equals, MAC_CMD);
assert_eq!(app.ui.window, MainWindow::Mix);
}