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,
|
CopyRelativePath,
|
||||||
Duplicate,
|
Duplicate,
|
||||||
RevealInFileManager,
|
RevealInFileManager,
|
||||||
|
RemoveFromProject,
|
||||||
OpenWithSystem,
|
OpenWithSystem,
|
||||||
Cut,
|
Cut,
|
||||||
Paste,
|
Paste,
|
||||||
|
@ -492,7 +493,6 @@ impl ProjectPanel {
|
||||||
entry_id: ProjectEntryId,
|
entry_id: ProjectEntryId,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let this = cx.view().clone();
|
|
||||||
let project = self.project.read(cx);
|
let project = self.project.read(cx);
|
||||||
|
|
||||||
let worktree_id = if let Some(id) = project.worktree_id_for_entry(entry_id, 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_dir = entry.is_dir();
|
||||||
let is_foldable = auto_fold_dirs && self.is_foldable(entry, worktree);
|
let is_foldable = auto_fold_dirs && self.is_foldable(entry, worktree);
|
||||||
let is_unfoldable = auto_fold_dirs && self.is_unfoldable(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_read_only = project.is_read_only(cx);
|
||||||
let is_remote = project.is_via_collab();
|
let is_remote = project.is_via_collab();
|
||||||
let is_local = project.is_local();
|
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| {
|
menu.context(self.focus_handle.clone()).map(|menu| {
|
||||||
if is_read_only {
|
if is_read_only {
|
||||||
menu.when(is_dir, |menu| {
|
menu.when(is_dir, |menu| {
|
||||||
|
@ -575,15 +574,7 @@ impl ProjectPanel {
|
||||||
"Add Folder to Project…",
|
"Add Folder to Project…",
|
||||||
Box::new(workspace::AddFolderToProject),
|
Box::new(workspace::AddFolderToProject),
|
||||||
)
|
)
|
||||||
.entry(
|
.action("Remove from Project", Box::new(RemoveFromProject))
|
||||||
"Remove from Project",
|
|
||||||
None,
|
|
||||||
cx.handler_for(&this, move |this, cx| {
|
|
||||||
this.project.update(cx, |project, cx| {
|
|
||||||
project.remove_worktree(worktree_id, cx)
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.when(is_root, |menu| {
|
.when(is_root, |menu| {
|
||||||
menu.separator()
|
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>) {
|
fn open_system(&mut self, _: &OpenWithSystem, cx: &mut ViewContext<Self>) {
|
||||||
if let Some((worktree, entry)) = self.selected_entry(cx) {
|
if let Some((worktree, entry)) = self.selected_entry(cx) {
|
||||||
let abs_path = worktree.abs_path().join(&entry.path);
|
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::new_search_in_directory))
|
||||||
.on_action(cx.listener(Self::unfold_directory))
|
.on_action(cx.listener(Self::unfold_directory))
|
||||||
.on_action(cx.listener(Self::fold_directory))
|
.on_action(cx.listener(Self::fold_directory))
|
||||||
|
.on_action(cx.listener(Self::remove_from_project))
|
||||||
.when(!project.is_read_only(cx), |el| {
|
.when(!project.is_read_only(cx), |el| {
|
||||||
el.on_action(cx.listener(Self::new_file))
|
el.on_action(cx.listener(Self::new_file))
|
||||||
.on_action(cx.listener(Self::new_directory))
|
.on_action(cx.listener(Self::new_directory))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue