Create an API for assigning the menubar contents

This commit is contained in:
Max Brunsfeld
2021-04-08 16:01:36 -07:00
parent 0a12774680
commit 334de06322
9 changed files with 216 additions and 60 deletions
+1
View File
@@ -1,6 +1,7 @@
pub mod assets;
pub mod editor;
pub mod file_finder;
pub mod menus;
mod operation_queue;
pub mod settings;
mod sum_tree;
+16 -8
View File
@@ -4,7 +4,7 @@ use log::LevelFilter;
use simplelog::SimpleLogger;
use std::{fs, path::PathBuf};
use zed::{
assets, editor, file_finder, settings,
assets, editor, file_finder, menus, settings,
workspace::{self, OpenParams},
};
@@ -14,10 +14,18 @@ fn main() {
let app = gpui::App::new(assets::Assets).unwrap();
let (_, settings_rx) = settings::channel(&app.font_cache()).unwrap();
{
let mut app = app.clone();
platform::runner()
.on_finish_launching(move || {
platform::runner()
.set_menus(menus::MENUS)
.on_menu_command({
let app = app.clone();
move |command| {
log::info!("menu command: {}", command);
app.dispatch_global_action(command, ())
}
})
.on_finish_launching({
let mut app = app.clone();
move || {
workspace::init(&mut app);
editor::init(&mut app);
file_finder::init(&mut app);
@@ -36,9 +44,9 @@ fn main() {
},
);
}
})
.run();
}
}
})
.run();
}
fn init_logger() {
+52
View File
@@ -0,0 +1,52 @@
use gpui::{Menu, MenuItem};
#[cfg(target_os = "macos")]
pub const MENUS: &'static [Menu] = &[
Menu {
name: "Zed",
items: &[
MenuItem::Action {
name: "About Zed...",
keystroke: None,
action: "app:about-zed",
},
MenuItem::Separator,
MenuItem::Action {
name: "Quit",
keystroke: Some("cmd-q"),
action: "app:quit",
},
],
},
Menu {
name: "File",
items: &[
MenuItem::Action {
name: "Undo",
keystroke: Some("cmd-z"),
action: "editor:undo",
},
MenuItem::Action {
name: "Redo",
keystroke: Some("cmd-Z"),
action: "editor:redo",
},
MenuItem::Separator,
MenuItem::Action {
name: "Cut",
keystroke: Some("cmd-x"),
action: "editor:cut",
},
MenuItem::Action {
name: "Copy",
keystroke: Some("cmd-c"),
action: "editor:copy",
},
MenuItem::Action {
name: "Paste",
keystroke: Some("cmd-v"),
action: "editor:paste",
},
],
},
];
+5
View File
@@ -14,6 +14,7 @@ use std::path::PathBuf;
pub fn init(app: &mut App) {
app.add_global_action("workspace:open_paths", open_paths);
app.add_global_action("app:quit", quit);
pane::init(app);
workspace_view::init(app);
}
@@ -50,6 +51,10 @@ fn open_paths(params: &OpenParams, app: &mut MutableAppContext) {
app.add_window(|ctx| WorkspaceView::new(workspace, params.settings.clone(), ctx));
}
fn quit(_: &(), app: &mut MutableAppContext) {
app.platform().quit();
}
#[cfg(test)]
mod tests {
use super::*;