ssh: Use system prompt for the server removal action (#19332)
This PR replaces a toast for the system prompt to confirm the action of removing a server from the remote list. The alert dialog component is the right choice here as we want to have a modal action that forces choice. This should make it easier to convert to a nativa alert dialog in the future, as well as for other platforms. <img width="800" alt="Screenshot 2024-10-17 at 3 01 41 AM" src="https://github.com/user-attachments/assets/7bb1210a-54bf-40da-a85a-f269484825a1"> Release Notes: - N/A
This commit is contained in:
parent
c888101e4b
commit
9a3d8733ce
1 changed files with 27 additions and 36 deletions
|
@ -20,7 +20,7 @@ use gpui::Task;
|
||||||
use gpui::WeakView;
|
use gpui::WeakView;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Animation, AnimationExt, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
|
Animation, AnimationExt, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
|
||||||
FocusableView, FontWeight, Model, ScrollHandle, View, ViewContext,
|
FocusableView, FontWeight, Model, PromptLevel, ScrollHandle, View, ViewContext,
|
||||||
};
|
};
|
||||||
use picker::Picker;
|
use picker::Picker;
|
||||||
use project::terminals::wrap_for_ssh;
|
use project::terminals::wrap_for_ssh;
|
||||||
|
@ -986,46 +986,38 @@ impl DevServerProjects {
|
||||||
.child({
|
.child({
|
||||||
fn remove_ssh_server(
|
fn remove_ssh_server(
|
||||||
dev_servers: View<DevServerProjects>,
|
dev_servers: View<DevServerProjects>,
|
||||||
workspace: WeakView<Workspace>,
|
|
||||||
index: usize,
|
index: usize,
|
||||||
connection_string: SharedString,
|
connection_string: SharedString,
|
||||||
cx: &mut WindowContext<'_>,
|
cx: &mut WindowContext<'_>,
|
||||||
) {
|
) {
|
||||||
workspace
|
let prompt_message = format!("Remove server `{}`?", connection_string);
|
||||||
.update(cx, |this, cx| {
|
|
||||||
struct SshServerRemoval;
|
let confirmation = cx.prompt(
|
||||||
let notification = format!(
|
PromptLevel::Warning,
|
||||||
"Do you really want to remove server `{}`?",
|
&prompt_message,
|
||||||
connection_string
|
None,
|
||||||
|
&["Yes, remove it", "No, keep it"],
|
||||||
);
|
);
|
||||||
this.show_toast(
|
|
||||||
Toast::new(
|
cx.spawn(|mut cx| async move {
|
||||||
NotificationId::composite::<SshServerRemoval>(
|
if confirmation.await.ok() == Some(0) {
|
||||||
connection_string.clone(),
|
dev_servers
|
||||||
),
|
.update(&mut cx, |this, cx| {
|
||||||
notification,
|
|
||||||
)
|
|
||||||
.on_click(
|
|
||||||
"Yes, delete it",
|
|
||||||
move |cx| {
|
|
||||||
dev_servers.update(cx, |this, cx| {
|
|
||||||
this.delete_ssh_server(index, cx);
|
this.delete_ssh_server(index, cx);
|
||||||
this.mode = Mode::default_mode();
|
this.mode = Mode::default_mode();
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})
|
||||||
},
|
|
||||||
),
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
anyhow::Ok(())
|
||||||
|
})
|
||||||
|
.detach_and_log_err(cx);
|
||||||
|
}
|
||||||
self.selectable_items.add_item(Box::new({
|
self.selectable_items.add_item(Box::new({
|
||||||
let connection_string = connection_string.clone();
|
let connection_string = connection_string.clone();
|
||||||
move |this, cx| {
|
move |_, cx| {
|
||||||
remove_ssh_server(
|
remove_ssh_server(
|
||||||
cx.view().clone(),
|
cx.view().clone(),
|
||||||
this.workspace.clone(),
|
|
||||||
index,
|
index,
|
||||||
connection_string.clone(),
|
connection_string.clone(),
|
||||||
cx,
|
cx,
|
||||||
|
@ -1033,16 +1025,15 @@ impl DevServerProjects {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
let is_selected = self.selectable_items.is_selected();
|
let is_selected = self.selectable_items.is_selected();
|
||||||
ListItem::new("delete-server")
|
ListItem::new("remove-server")
|
||||||
.selected(is_selected)
|
.selected(is_selected)
|
||||||
.inset(true)
|
.inset(true)
|
||||||
.spacing(ui::ListItemSpacing::Sparse)
|
.spacing(ui::ListItemSpacing::Sparse)
|
||||||
.start_slot(Icon::new(IconName::Trash).color(Color::Error))
|
.start_slot(Icon::new(IconName::Trash).color(Color::Error))
|
||||||
.child(Label::new("Delete Server").color(Color::Error))
|
.child(Label::new("Remove Server").color(Color::Error))
|
||||||
.on_click(cx.listener(move |this, _, cx| {
|
.on_click(cx.listener(move |_, _, cx| {
|
||||||
remove_ssh_server(
|
remove_ssh_server(
|
||||||
cx.view().clone(),
|
cx.view().clone(),
|
||||||
this.workspace.clone(),
|
|
||||||
index,
|
index,
|
||||||
connection_string.clone(),
|
connection_string.clone(),
|
||||||
cx,
|
cx,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue