Switch from delete file by default to trash file by default (#10875)

TODO:

- [x] Don't immediately seg fault
- [x] Implement for directories 
- [x] Add cmd-delete to remove files
- [ ] ~~Add setting for trash vs. delete~~ You can just use keybindings
to change the behavior.

fixes https://github.com/zed-industries/zed/issues/7228
fixes https://github.com/zed-industries/zed/issues/5094

Release Notes:

- Added a new `project_panel::Trash` action and changed the default
behavior for `backspace` and `delete` in the project panel to send a
file to the systems trash, instead of permanently deleting it
([#7228](https://github.com/zed-industries/zed/issues/7228),
[#5094](https://github.com/zed-industries/zed/issues/5094)). The
original behavior can be restored by adding the following section to
your keybindings:

```json5
[
// ...Other keybindings...
  {
    "context": "ProjectPanel",
    "bindings": {
        "backspace": "project_panel::Delete",
        "delete": "project_panel::Delete",
    }
  }
]
This commit is contained in:
Mikayla Maki 2024-04-26 17:43:50 -07:00 committed by GitHub
parent 5dbd23f6b0
commit d2569afe66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 99 additions and 22 deletions

View file

@ -1513,6 +1513,7 @@ impl Project {
pub fn delete_entry(
&mut self,
entry_id: ProjectEntryId,
trash: bool,
cx: &mut ModelContext<Self>,
) -> Option<Task<Result<()>>> {
let worktree = self.worktree_for_entry(entry_id, cx)?;
@ -1521,7 +1522,10 @@ impl Project {
if self.is_local() {
worktree.update(cx, |worktree, cx| {
worktree.as_local_mut().unwrap().delete_entry(entry_id, cx)
worktree
.as_local_mut()
.unwrap()
.delete_entry(entry_id, trash, cx)
})
} else {
let client = self.client.clone();
@ -1531,6 +1535,7 @@ impl Project {
.request(proto::DeleteProjectEntry {
project_id,
entry_id: entry_id.to_proto(),
use_trash: trash,
})
.await?;
worktree
@ -8341,6 +8346,7 @@ impl Project {
mut cx: AsyncAppContext,
) -> Result<proto::ProjectEntryResponse> {
let entry_id = ProjectEntryId::from_proto(envelope.payload.entry_id);
let trash = envelope.payload.use_trash;
this.update(&mut cx, |_, cx| cx.emit(Event::DeletedEntry(entry_id)))?;
@ -8354,7 +8360,7 @@ impl Project {
worktree
.as_local_mut()
.unwrap()
.delete_entry(entry_id, cx)
.delete_entry(entry_id, trash, cx)
.ok_or_else(|| anyhow!("invalid entry"))
})??
.await?;