Implement File > Open menu item

This commit is contained in:
Max Brunsfeld
2021-04-08 22:25:54 -07:00
parent f656b387b3
commit 7ebcbdc0cb
7 changed files with 88 additions and 19 deletions
+19 -4
View File
@@ -1,5 +1,5 @@
use fs::OpenOptions;
use gpui::platform::{current as platform, Runner as _};
use gpui::platform::{current as platform, PathPromptOptions, Runner as _};
use log::LevelFilter;
use simplelog::SimpleLogger;
use std::{fs, path::PathBuf};
@@ -18,9 +18,24 @@ fn main() {
.set_menus(menus::MENUS)
.on_menu_command({
let app = app.clone();
move |command| {
log::info!("menu command: {}", command);
app.dispatch_global_action(command, ())
let settings_rx = settings_rx.clone();
move |command| match command {
"app:open" => {
if let Some(paths) = app.platform().prompt_for_paths(PathPromptOptions {
files: true,
directories: true,
multiple: true,
}) {
app.dispatch_global_action(
"workspace:open_paths",
OpenParams {
paths,
settings: settings_rx.clone(),
},
);
}
}
_ => app.dispatch_global_action(command, ()),
}
})
.on_finish_launching({
+9 -1
View File
@@ -6,7 +6,7 @@ pub const MENUS: &'static [Menu] = &[
name: "Zed",
items: &[
MenuItem::Action {
name: "About Zed...",
name: "About Zed",
keystroke: None,
action: "app:about-zed",
},
@@ -20,6 +20,14 @@ pub const MENUS: &'static [Menu] = &[
},
Menu {
name: "File",
items: &[MenuItem::Action {
name: "Open…",
keystroke: Some("cmd-o"),
action: "app:open",
}],
},
Menu {
name: "Edit",
items: &[
MenuItem::Action {
name: "Undo",