Start adding project panel context menu actions

This commit is contained in:
Antonio Scandurra 2022-05-26 15:23:40 +02:00
parent 82ddac8e7e
commit 991eb742b0
2 changed files with 76 additions and 10 deletions

View file

@ -30,7 +30,7 @@ use log::error;
pub use pane::*;
pub use pane_group::*;
use postage::prelude::Stream;
use project::{fs, Fs, Project, ProjectEntryId, ProjectPath, Worktree};
use project::{fs, Fs, Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId};
use settings::Settings;
use sidebar::{Side, Sidebar, SidebarButtons, ToggleSidebarItem, ToggleSidebarItemFocus};
use smallvec::SmallVec;
@ -72,6 +72,9 @@ type FollowableItemBuilders = HashMap<
),
>;
#[derive(Clone)]
pub struct RemoveFolderFromProject(pub WorktreeId);
actions!(
workspace,
[
@ -104,7 +107,15 @@ pub struct JoinProject {
pub project_index: usize,
}
impl_internal_actions!(workspace, [OpenPaths, ToggleFollow, JoinProject]);
impl_internal_actions!(
workspace,
[
OpenPaths,
ToggleFollow,
JoinProject,
RemoveFolderFromProject
]
);
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
pane::init(cx);
@ -148,6 +159,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
cx.add_async_action(Workspace::close);
cx.add_async_action(Workspace::save_all);
cx.add_action(Workspace::add_folder_to_project);
cx.add_action(Workspace::remove_folder_from_project);
cx.add_action(
|workspace: &mut Workspace, _: &Unfollow, cx: &mut ViewContext<Workspace>| {
let pane = workspace.active_pane().clone();
@ -1028,6 +1040,15 @@ impl Workspace {
.detach();
}
fn remove_folder_from_project(
&mut self,
RemoveFolderFromProject(worktree_id): &RemoveFolderFromProject,
cx: &mut ViewContext<Self>,
) {
self.project
.update(cx, |project, cx| project.remove_worktree(*worktree_id, cx));
}
fn project_path_for_path(
&self,
abs_path: &Path,