Remove project panel trash action for remote projects (#21300)

Closes #20845

I'm uncertain about my placement for the logic to remove actions from
the command palette list. If anyone has insights or alternative
approaches, I'm open to changing the code.

Release Notes:

- Removed project panel `Trash` action for remote projects.

---------

Co-authored-by: Finn Evers <dev@bahn.sh>
This commit is contained in:
moshyfawn 2024-11-29 15:37:24 -05:00 committed by GitHub
parent 4137d1adb9
commit aea6fa0c09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions

View file

@ -15,6 +15,7 @@ doctest = false
[dependencies]
anyhow.workspace = true
collections.workspace = true
command_palette_hooks.workspace = true
db.workspace = true
editor.workspace = true
file_icons.workspace = true

View file

@ -17,6 +17,7 @@ use file_icons::FileIcons;
use anyhow::{anyhow, Context as _, Result};
use collections::{hash_map, BTreeSet, HashMap};
use command_palette_hooks::CommandPaletteFilter;
use git::repository::GitFileStatus;
use gpui::{
actions, anchored, deferred, div, impl_actions, point, px, size, uniform_list, Action,
@ -38,6 +39,7 @@ use project_panel_settings::{
};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use std::any::TypeId;
use std::{
cell::OnceCell,
cmp,
@ -311,6 +313,15 @@ impl ProjectPanel {
})
.detach();
let trash_action = [TypeId::of::<Trash>()];
let is_remote = project.read(cx).is_via_collab();
if is_remote {
CommandPaletteFilter::update_global(cx, |filter, _cx| {
filter.hide_action_types(&trash_action);
});
}
let filename_editor = cx.new_view(Editor::single_line);
cx.subscribe(
@ -655,9 +666,11 @@ impl ProjectPanel {
.action("Copy Relative Path", Box::new(CopyRelativePath))
.separator()
.action("Rename", Box::new(Rename))
.when(!is_root, |menu| {
.when(!is_root & !is_remote, |menu| {
menu.action("Trash", Box::new(Trash { skip_prompt: false }))
.action("Delete", Box::new(Delete { skip_prompt: false }))
})
.when(!is_root, |menu| {
menu.action("Delete", Box::new(Delete { skip_prompt: false }))
})
.when(!is_remote & is_root, |menu| {
menu.separator()