Implement default macOS menu items

- `Zed -> Hide`, bound to `cmd-h`
- `Zed -> Hide Others`, bound to `alt-cmd-h`
- `Zed -> Show All`
- `Window -> Minimize`, bound to `cmd-m`
- `Window -> Zoom`
This commit is contained in:
Antonio Scandurra 2022-08-03 15:13:30 +02:00
parent dc9df64078
commit 7cbf76ce80
8 changed files with 124 additions and 1 deletions

View file

@ -45,6 +45,18 @@ pub fn menus() -> Vec<Menu<'static>> {
action: Box::new(super::InstallCommandLineInterface),
},
MenuItem::Separator,
MenuItem::Action {
name: "Hide Zed",
action: Box::new(super::Hide),
},
MenuItem::Action {
name: "Hide Others",
action: Box::new(super::HideOthers),
},
MenuItem::Action {
name: "Show All",
action: Box::new(super::ShowAll),
},
MenuItem::Action {
name: "Quit",
action: Box::new(super::Quit),
@ -244,6 +256,7 @@ pub fn menus() -> Vec<Menu<'static>> {
name: "Diagnostics",
action: Box::new(diagnostics::Deploy),
},
MenuItem::Separator,
],
},
Menu {
@ -299,7 +312,17 @@ pub fn menus() -> Vec<Menu<'static>> {
},
Menu {
name: "Window",
items: vec![MenuItem::Separator],
items: vec![
MenuItem::Action {
name: "Minimize",
action: Box::new(super::Minimize),
},
MenuItem::Action {
name: "Zoom",
action: Box::new(super::Zoom),
},
MenuItem::Separator,
],
},
Menu {
name: "Help",

View file

@ -46,6 +46,11 @@ actions!(
zed,
[
About,
Hide,
HideOthers,
ShowAll,
Minimize,
Zoom,
Quit,
DebugElements,
OpenSettings,
@ -64,6 +69,25 @@ const MIN_FONT_SIZE: f32 = 6.0;
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
cx.add_action(about);
cx.add_global_action(|_: &Hide, cx: &mut gpui::MutableAppContext| {
cx.platform().hide();
});
cx.add_global_action(|_: &HideOthers, cx: &mut gpui::MutableAppContext| {
cx.platform().hide_other_apps();
});
cx.add_global_action(|_: &ShowAll, cx: &mut gpui::MutableAppContext| {
cx.platform().unhide_other_apps();
});
cx.add_action(
|_: &mut Workspace, _: &Minimize, cx: &mut ViewContext<Workspace>| {
cx.minimize_window();
},
);
cx.add_action(
|_: &mut Workspace, _: &Zoom, cx: &mut ViewContext<Workspace>| {
cx.zoom_window();
},
);
cx.add_global_action(quit);
cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url));
cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {