mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 21:32:40 +00:00
project panel: Add RemoveFromProject
action (#20360)
This fixes #15995 by adding a `project panel: remove from project` action that can be used in a keybinding. Release Notes: - Added a `project panel: remove from project` action so that users can now add a keybinding to trigger it: `project_panel::RemoveFromProject`.
This commit is contained in:
parent
71aeb6a636
commit
454c9dc06d
1 changed files with 12 additions and 12 deletions
|
@ -163,6 +163,7 @@ actions!(
|
|||
CopyRelativePath,
|
||||
Duplicate,
|
||||
RevealInFileManager,
|
||||
RemoveFromProject,
|
||||
OpenWithSystem,
|
||||
Cut,
|
||||
Paste,
|
||||
|
@ -492,7 +493,6 @@ impl ProjectPanel {
|
|||
entry_id: ProjectEntryId,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let this = cx.view().clone();
|
||||
let project = self.project.read(cx);
|
||||
|
||||
let worktree_id = if let Some(id) = project.worktree_id_for_entry(entry_id, cx) {
|
||||
|
@ -513,12 +513,11 @@ impl ProjectPanel {
|
|||
let is_dir = entry.is_dir();
|
||||
let is_foldable = auto_fold_dirs && self.is_foldable(entry, worktree);
|
||||
let is_unfoldable = auto_fold_dirs && self.is_unfoldable(entry, worktree);
|
||||
let worktree_id = worktree.id();
|
||||
let is_read_only = project.is_read_only(cx);
|
||||
let is_remote = project.is_via_collab();
|
||||
let is_local = project.is_local();
|
||||
|
||||
let context_menu = ContextMenu::build(cx, |menu, cx| {
|
||||
let context_menu = ContextMenu::build(cx, |menu, _| {
|
||||
menu.context(self.focus_handle.clone()).map(|menu| {
|
||||
if is_read_only {
|
||||
menu.when(is_dir, |menu| {
|
||||
|
@ -575,15 +574,7 @@ impl ProjectPanel {
|
|||
"Add Folder to Project…",
|
||||
Box::new(workspace::AddFolderToProject),
|
||||
)
|
||||
.entry(
|
||||
"Remove from Project",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| {
|
||||
this.project.update(cx, |project, cx| {
|
||||
project.remove_worktree(worktree_id, cx)
|
||||
});
|
||||
}),
|
||||
)
|
||||
.action("Remove from Project", Box::new(RemoveFromProject))
|
||||
})
|
||||
.when(is_root, |menu| {
|
||||
menu.separator()
|
||||
|
@ -1586,6 +1577,14 @@ impl ProjectPanel {
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_from_project(&mut self, _: &RemoveFromProject, cx: &mut ViewContext<Self>) {
|
||||
if let Some((worktree, _)) = self.selected_sub_entry(cx) {
|
||||
let worktree_id = worktree.read(cx).id();
|
||||
self.project
|
||||
.update(cx, |project, cx| project.remove_worktree(worktree_id, cx));
|
||||
}
|
||||
}
|
||||
|
||||
fn open_system(&mut self, _: &OpenWithSystem, cx: &mut ViewContext<Self>) {
|
||||
if let Some((worktree, entry)) = self.selected_entry(cx) {
|
||||
let abs_path = worktree.abs_path().join(&entry.path);
|
||||
|
@ -3163,6 +3162,7 @@ impl Render for ProjectPanel {
|
|||
.on_action(cx.listener(Self::new_search_in_directory))
|
||||
.on_action(cx.listener(Self::unfold_directory))
|
||||
.on_action(cx.listener(Self::fold_directory))
|
||||
.on_action(cx.listener(Self::remove_from_project))
|
||||
.when(!project.is_read_only(cx), |el| {
|
||||
el.on_action(cx.listener(Self::new_file))
|
||||
.on_action(cx.listener(Self::new_directory))
|
||||
|
|
Loading…
Reference in a new issue