ssh: Improve dismissal behaviour (#18900)

Do not always close current window in SshConnectionModal; only do so
when the window was spawned from ssh modal. Assign unique IDs to "Open
folder" buttons

Closes #ISSUE

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-10-09 12:22:53 +02:00 committed by GitHub
parent 9c54bd1bd4
commit f50bca7630
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 17 deletions

View file

@ -319,7 +319,9 @@ impl DevServerProjects {
let connection_options = ssh_connection.into();
workspace.update(cx, |_, cx| {
cx.defer(move |workspace, cx| {
workspace.toggle_modal(cx, |cx| SshConnectionModal::new(&connection_options, cx));
workspace.toggle_modal(cx, |cx| {
SshConnectionModal::new(&connection_options, false, cx)
});
let prompt = workspace
.active_modal::<SshConnectionModal>(cx)
.unwrap()
@ -573,7 +575,7 @@ impl DevServerProjects {
}))
.child(
h_flex().mt_1().pl_1().child(
Button::new("new-remote_project", "Open Folder…")
Button::new(("new-remote_project", ix), "Open Folder…")
.size(ButtonSize::Default)
.layer(ElevationIndex::ModalSurface)
.icon(IconName::Plus)

View file

@ -1,7 +1,6 @@
mod dev_servers;
pub mod disconnected_overlay;
mod ssh_connections;
mod ssh_remotes;
use remote::SshConnectionOptions;
pub use ssh_connections::open_ssh_project;

View file

@ -5,9 +5,9 @@ use auto_update::AutoUpdater;
use editor::Editor;
use futures::channel::oneshot;
use gpui::{
percentage, px, Action, Animation, AnimationExt, AnyWindowHandle, AsyncAppContext,
DismissEvent, EventEmitter, FocusableView, ParentElement as _, Render, SemanticVersion,
SharedString, Task, Transformation, View,
percentage, px, Animation, AnimationExt, AnyWindowHandle, AsyncAppContext, DismissEvent,
EventEmitter, FocusableView, ParentElement as _, Render, SemanticVersion, SharedString, Task,
Transformation, View,
};
use gpui::{AppContext, Model};
use release_channel::{AppVersion, ReleaseChannel};
@ -83,6 +83,7 @@ pub struct SshPrompt {
pub struct SshConnectionModal {
pub(crate) prompt: View<SshPrompt>,
is_separate_window: bool,
}
impl SshPrompt {
@ -207,9 +208,14 @@ impl Render for SshPrompt {
}
impl SshConnectionModal {
pub fn new(connection_options: &SshConnectionOptions, cx: &mut ViewContext<Self>) -> Self {
pub fn new(
connection_options: &SshConnectionOptions,
is_separate_window: bool,
cx: &mut ViewContext<Self>,
) -> Self {
Self {
prompt: cx.new_view(|cx| SshPrompt::new(connection_options, cx)),
is_separate_window,
}
}
@ -218,7 +224,10 @@ impl SshConnectionModal {
}
fn dismiss(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
cx.remove_window();
cx.emit(DismissEvent);
if self.is_separate_window {
cx.remove_window();
}
}
}
@ -232,6 +241,7 @@ impl Render for SshConnectionModal {
v_flex()
.elevation_3(cx)
.track_focus(&self.focus_handle(cx))
.on_action(cx.listener(Self::dismiss))
.on_action(cx.listener(Self::confirm))
.w(px(500.))
@ -250,7 +260,9 @@ impl Render for SshConnectionModal {
div().absolute().left_0p5().top_0p5().child(
IconButton::new("ssh-connection-cancel", IconName::ArrowLeft)
.icon_size(IconSize::XSmall)
.on_click(|_, cx| cx.dispatch_action(menu::Cancel.boxed_clone()))
.on_click(cx.listener(move |this, _, cx| {
this.dismiss(&Default::default(), cx);
}))
.tooltip(|cx| Tooltip::for_action("Back", &menu::Cancel, cx)),
),
)
@ -464,11 +476,10 @@ pub async fn open_ssh_project(
open_options: workspace::OpenOptions,
cx: &mut AsyncAppContext,
) -> Result<()> {
let options = cx.update(|cx| (app_state.build_window_options)(None, cx))?;
let window = if let Some(window) = open_options.replace_window {
window
} else {
let options = cx.update(|cx| (app_state.build_window_options)(None, cx))?;
cx.open_window(options, |cx| {
let project = project::Project::local(
app_state.client.clone(),
@ -485,7 +496,9 @@ pub async fn open_ssh_project(
let delegate = window.update(cx, |workspace, cx| {
cx.activate_window();
workspace.toggle_modal(cx, |cx| SshConnectionModal::new(&connection_options, cx));
workspace.toggle_modal(cx, |cx| {
SshConnectionModal::new(&connection_options, true, cx)
});
let ui = workspace
.active_modal::<SshConnectionModal>(cx)
.unwrap()
@ -500,8 +513,11 @@ pub async fn open_ssh_project(
})
})?;
cx.update(|cx| {
workspace::open_ssh_project(window, connection_options, delegate, app_state, paths, cx)
})?
.await
let did_open_ssh_project = cx
.update(|cx| {
workspace::open_ssh_project(window, connection_options, delegate, app_state, paths, cx)
})?
.await;
did_open_ssh_project
}

View file

@ -1 +0,0 @@