diff --git a/rust/crates/openvector-gui/src/app-input-tests.rs b/rust/crates/openvector-gui/src/app-input-tests.rs index ebc1b9d..e805f03 100644 --- a/rust/crates/openvector-gui/src/app-input-tests.rs +++ b/rust/crates/openvector-gui/src/app-input-tests.rs @@ -420,3 +420,21 @@ fn comparison_keys_release_when_the_window_deactivates(cx: &mut gpui::TestAppCon visual.run_until_parked(); } } + +// Issue #48: Cmd+Q from the app window reaches the Quit action, and the macOS +// app menu lists it. The counter runs before the real handler and passes the +// action on, so the real Quit handler still runs (the test platform's quit is a no-op). +#[gpui::test] +fn cmd_q_dispatches_quit(cx: &mut gpui::TestAppContext) { + let directory = Directory::new(); + cx.update(install_app_menu); + let quits = std::rc::Rc::new(std::cell::Cell::new(0)); + let counted = quits.clone(); + cx.update(|cx| { cx.on_action(move |_: &Quit, cx| { counted.set(counted.get() + 1); cx.propagate(); }); }); + let (app, visual) = cx.add_window_view(|_, cx| OpenVectorApp::with_preferences(directory.0.join("gui.json"), cx).unwrap()); + app.update_in(visual, |app, window, cx| app.focus.focus(window, cx)); + visual.simulate_keystrokes("cmd-q"); + assert_eq!(quits.get(), 1); + let menus = visual.update(|_, cx| cx.get_menus()).unwrap(); + assert!(matches!(&menus[0].items[0], gpui::OwnedMenuItem::Action { name, .. } if name == "Quit OpenVector")); +} diff --git a/rust/crates/openvector-gui/src/app.rs b/rust/crates/openvector-gui/src/app.rs index ba07a8b..3c8609b 100644 --- a/rust/crates/openvector-gui/src/app.rs +++ b/rust/crates/openvector-gui/src/app.rs @@ -9,6 +9,19 @@ use workflows::{Form, WorkflowAction, Workflows}; #[path = "app-drag-result.rs"] mod drag_result; +gpui::actions!(openvector, [Quit]); + +/// Binds Cmd+Q to Quit and installs the app menu that macOS shows its Quit +/// item in. GPUI ships no default Quit, so without this Cmd+Q does nothing +/// (issue #48). main.rs installs it on macOS only: "cmd" is GPUI's platform +/// key, Super elsewhere, and Super+Q must not quit there. Closing the last +/// window quits on every platform. +pub fn install_app_menu(cx: &mut App) { + cx.on_action(|_: &Quit, cx| cx.quit()); + cx.bind_keys([gpui::KeyBinding::new("cmd-q", Quit, None)]); + cx.set_menus([gpui::Menu::new("OpenVector").items([gpui::MenuItem::action("Quit OpenVector", Quit)])]); +} + #[derive(Clone)] enum Action { Open, PasteImage, ConfirmPaste(Arc>), Batch, BatchAdd, BatchRemove(usize), BatchStart, BatchFolder, BatchAutoColors, diff --git a/rust/crates/openvector-gui/src/main.rs b/rust/crates/openvector-gui/src/main.rs index 370a1d1..fc1b77a 100644 --- a/rust/crates/openvector-gui/src/main.rs +++ b/rust/crates/openvector-gui/src/main.rs @@ -24,6 +24,8 @@ fn main() { if let Err(error) = openvector_gui::assets::register_fonts(cx) { eprintln!("Cannot load bundled fonts: {error}"); std::process::exit(1); } + #[cfg(target_os = "macos")] + openvector_gui::app::install_app_menu(cx); let bounds = Bounds::centered(None, size(px(1180.0), px(760.0)), cx); let window = cx.open_window(WindowOptions { window_bounds: Some(WindowBounds::Windowed(bounds)),