Align project panel and git panel deletion behavior (#27525)

This change makes the git panel and project panel behave the same, on
Linux and macOS, and adds prompts.

Release Notes:

- Changed the git panel to prompt before restoring a file.
This commit is contained in:
Mikayla Maki 2025-03-26 14:15:24 -07:00 committed by GitHub
parent 999ad77a59
commit 9e02fee98d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 93 additions and 10 deletions

View file

@ -935,14 +935,49 @@ impl GitPanel {
fn revert_selected(
&mut self,
_: &git::RestoreFile,
action: &git::RestoreFile,
window: &mut Window,
cx: &mut Context<Self>,
) {
maybe!({
let skip_prompt = action.skip_prompt;
let list_entry = self.entries.get(self.selected_entry?)?.clone();
let entry = list_entry.status_entry()?;
self.revert_entry(&entry, window, cx);
let entry = list_entry.status_entry()?.to_owned();
let prompt = if skip_prompt {
Task::ready(Ok(0))
} else {
let prompt = window.prompt(
PromptLevel::Warning,
&format!(
"Are you sure you want to restore {}?",
entry
.worktree_path
.file_name()
.unwrap_or(entry.worktree_path.as_os_str())
.to_string_lossy()
),
None,
&["Restore", "Cancel"],
cx,
);
cx.background_spawn(prompt)
};
let this = cx.weak_entity();
window
.spawn(cx, async move |cx| {
if prompt.await? != 0 {
return anyhow::Ok(());
}
this.update_in(cx, |this, window, cx| {
this.revert_entry(&entry, window, cx);
})?;
Ok(())
})
.detach();
Some(())
});
}
@ -3460,7 +3495,7 @@ impl GitPanel {
context_menu
.context(self.focus_handle.clone())
.action(stage_title, ToggleStaged.boxed_clone())
.action(restore_title, git::RestoreFile.boxed_clone())
.action(restore_title, git::RestoreFile::default().boxed_clone())
.separator()
.action("Open Diff", Confirm.boxed_clone())
.action("Open File", SecondaryConfirm.boxed_clone())