Add "Add Folder to Project" command to application menu

This commit is contained in:
Max Brunsfeld 2022-05-20 16:19:43 -07:00
parent e72f5cea22
commit 8ed33cadeb
2 changed files with 27 additions and 0 deletions

View file

@ -77,6 +77,7 @@ actions!(
Open, Open,
NewFile, NewFile,
NewWindow, NewWindow,
AddFolderToProject,
Unfollow, Unfollow,
Save, Save,
ActivatePreviousPane, ActivatePreviousPane,
@ -140,6 +141,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
cx.add_async_action(Workspace::toggle_follow); cx.add_async_action(Workspace::toggle_follow);
cx.add_async_action(Workspace::follow_next_collaborator); cx.add_async_action(Workspace::follow_next_collaborator);
cx.add_action(Workspace::add_folder_to_project);
cx.add_action( cx.add_action(
|workspace: &mut Workspace, _: &Unfollow, cx: &mut ViewContext<Workspace>| { |workspace: &mut Workspace, _: &Unfollow, cx: &mut ViewContext<Workspace>| {
let pane = workspace.active_pane().clone(); let pane = workspace.active_pane().clone();
@ -921,6 +923,27 @@ impl Workspace {
}) })
} }
fn add_folder_to_project(&mut self, _: &AddFolderToProject, cx: &mut ViewContext<Self>) {
let mut paths = cx.prompt_for_paths(PathPromptOptions {
files: false,
directories: true,
multiple: true,
});
cx.spawn(|this, mut cx| async move {
if let Some(paths) = paths.recv().await.flatten() {
let results = this
.update(&mut cx, |this, cx| this.open_paths(paths, cx))
.await;
for result in results {
if let Some(result) = result {
result.log_err();
}
}
}
})
.detach();
}
fn project_path_for_path( fn project_path_for_path(
&self, &self,
abs_path: &Path, abs_path: &Path,

View file

@ -42,6 +42,10 @@ pub fn menus() -> Vec<Menu<'static>> {
name: "Open…", name: "Open…",
action: Box::new(workspace::Open), action: Box::new(workspace::Open),
}, },
MenuItem::Action {
name: "Add Folder to Project…",
action: Box::new(workspace::AddFolderToProject),
},
MenuItem::Action { MenuItem::Action {
name: "Save", name: "Save",
action: Box::new(workspace::Save), action: Box::new(workspace::Save),