Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions rust/crates/openvector-gui/src/app-input-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
13 changes: 13 additions & 0 deletions rust/crates/openvector-gui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>>), Batch, BatchAdd, BatchRemove(usize), BatchStart, BatchFolder, BatchAutoColors,
Expand Down
2 changes: 2 additions & 0 deletions rust/crates/openvector-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Loading