Allow deleting entries from the project panel
This commit is contained in:
parent
509ede0e80
commit
4b1c46fa45
9 changed files with 198 additions and 8 deletions
|
@ -263,6 +263,7 @@ impl Project {
|
|||
client.add_model_message_handler(Self::handle_update_worktree);
|
||||
client.add_model_request_handler(Self::handle_create_project_entry);
|
||||
client.add_model_request_handler(Self::handle_rename_project_entry);
|
||||
client.add_model_request_handler(Self::handle_delete_project_entry);
|
||||
client.add_model_request_handler(Self::handle_apply_additional_edits_for_completion);
|
||||
client.add_model_request_handler(Self::handle_apply_code_action);
|
||||
client.add_model_request_handler(Self::handle_reload_buffers);
|
||||
|
@ -768,6 +769,35 @@ impl Project {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn delete_entry(
|
||||
&mut self,
|
||||
entry_id: ProjectEntryId,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
let worktree = self.worktree_for_entry(entry_id, cx)?;
|
||||
if self.is_local() {
|
||||
worktree.update(cx, |worktree, cx| {
|
||||
worktree.as_local_mut().unwrap().delete_entry(entry_id, cx)
|
||||
})
|
||||
} else {
|
||||
let client = self.client.clone();
|
||||
let project_id = self.remote_id().unwrap();
|
||||
Some(cx.spawn_weak(|_, mut cx| async move {
|
||||
client
|
||||
.request(proto::DeleteProjectEntry {
|
||||
project_id,
|
||||
entry_id: entry_id.to_proto(),
|
||||
})
|
||||
.await?;
|
||||
worktree
|
||||
.update(&mut cx, move |worktree, cx| {
|
||||
worktree.as_remote().unwrap().delete_entry(entry_id, cx)
|
||||
})
|
||||
.await
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_share(&self, cx: &AppContext) -> bool {
|
||||
self.is_local() && self.visible_worktrees(cx).next().is_some()
|
||||
}
|
||||
|
@ -3858,6 +3888,21 @@ impl Project {
|
|||
})
|
||||
}
|
||||
|
||||
async fn handle_delete_project_entry(
|
||||
this: ModelHandle<Self>,
|
||||
envelope: TypedEnvelope<proto::DeleteProjectEntry>,
|
||||
_: Arc<Client>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::Ack> {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let entry_id = ProjectEntryId::from_proto(envelope.payload.entry_id);
|
||||
this.delete_entry(entry_id, cx)
|
||||
.ok_or_else(|| anyhow!("invalid entry"))
|
||||
})?
|
||||
.await?;
|
||||
Ok(proto::Ack {})
|
||||
}
|
||||
|
||||
async fn handle_update_diagnostic_summary(
|
||||
this: ModelHandle<Self>,
|
||||
envelope: TypedEnvelope<proto::UpdateDiagnosticSummary>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue