Skip to content

Commit f50bca7

Browse files
authored
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
1 parent 9c54bd1 commit f50bca7

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

crates/recent_projects/src/dev_servers.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ impl DevServerProjects {
319319
let connection_options = ssh_connection.into();
320320
workspace.update(cx, |_, cx| {
321321
cx.defer(move |workspace, cx| {
322-
workspace.toggle_modal(cx, |cx| SshConnectionModal::new(&connection_options, cx));
322+
workspace.toggle_modal(cx, |cx| {
323+
SshConnectionModal::new(&connection_options, false, cx)
324+
});
323325
let prompt = workspace
324326
.active_modal::<SshConnectionModal>(cx)
325327
.unwrap()
@@ -573,7 +575,7 @@ impl DevServerProjects {
573575
}))
574576
.child(
575577
h_flex().mt_1().pl_1().child(
576-
Button::new("new-remote_project", "Open Folder…")
578+
Button::new(("new-remote_project", ix), "Open Folder…")
577579
.size(ButtonSize::Default)
578580
.layer(ElevationIndex::ModalSurface)
579581
.icon(IconName::Plus)

crates/recent_projects/src/recent_projects.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod dev_servers;
22
pub mod disconnected_overlay;
33
mod ssh_connections;
4-
mod ssh_remotes;
54
use remote::SshConnectionOptions;
65
pub use ssh_connections::open_ssh_project;
76

crates/recent_projects/src/ssh_connections.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use auto_update::AutoUpdater;
55
use editor::Editor;
66
use futures::channel::oneshot;
77
use gpui::{
8-
percentage, px, Action, Animation, AnimationExt, AnyWindowHandle, AsyncAppContext,
9-
DismissEvent, EventEmitter, FocusableView, ParentElement as _, Render, SemanticVersion,
10-
SharedString, Task, Transformation, View,
8+
percentage, px, Animation, AnimationExt, AnyWindowHandle, AsyncAppContext, DismissEvent,
9+
EventEmitter, FocusableView, ParentElement as _, Render, SemanticVersion, SharedString, Task,
10+
Transformation, View,
1111
};
1212
use gpui::{AppContext, Model};
1313
use release_channel::{AppVersion, ReleaseChannel};
@@ -83,6 +83,7 @@ pub struct SshPrompt {
8383

8484
pub struct SshConnectionModal {
8585
pub(crate) prompt: View<SshPrompt>,
86+
is_separate_window: bool,
8687
}
8788

8889
impl SshPrompt {
@@ -207,9 +208,14 @@ impl Render for SshPrompt {
207208
}
208209

209210
impl SshConnectionModal {
210-
pub fn new(connection_options: &SshConnectionOptions, cx: &mut ViewContext<Self>) -> Self {
211+
pub fn new(
212+
connection_options: &SshConnectionOptions,
213+
is_separate_window: bool,
214+
cx: &mut ViewContext<Self>,
215+
) -> Self {
211216
Self {
212217
prompt: cx.new_view(|cx| SshPrompt::new(connection_options, cx)),
218+
is_separate_window,
213219
}
214220
}
215221

@@ -218,7 +224,10 @@ impl SshConnectionModal {
218224
}
219225

220226
fn dismiss(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
221-
cx.remove_window();
227+
cx.emit(DismissEvent);
228+
if self.is_separate_window {
229+
cx.remove_window();
230+
}
222231
}
223232
}
224233

@@ -232,6 +241,7 @@ impl Render for SshConnectionModal {
232241

233242
v_flex()
234243
.elevation_3(cx)
244+
.track_focus(&self.focus_handle(cx))
235245
.on_action(cx.listener(Self::dismiss))
236246
.on_action(cx.listener(Self::confirm))
237247
.w(px(500.))
@@ -250,7 +260,9 @@ impl Render for SshConnectionModal {
250260
div().absolute().left_0p5().top_0p5().child(
251261
IconButton::new("ssh-connection-cancel", IconName::ArrowLeft)
252262
.icon_size(IconSize::XSmall)
253-
.on_click(|_, cx| cx.dispatch_action(menu::Cancel.boxed_clone()))
263+
.on_click(cx.listener(move |this, _, cx| {
264+
this.dismiss(&Default::default(), cx);
265+
}))
254266
.tooltip(|cx| Tooltip::for_action("Back", &menu::Cancel, cx)),
255267
),
256268
)
@@ -464,11 +476,10 @@ pub async fn open_ssh_project(
464476
open_options: workspace::OpenOptions,
465477
cx: &mut AsyncAppContext,
466478
) -> Result<()> {
467-
let options = cx.update(|cx| (app_state.build_window_options)(None, cx))?;
468-
469479
let window = if let Some(window) = open_options.replace_window {
470480
window
471481
} else {
482+
let options = cx.update(|cx| (app_state.build_window_options)(None, cx))?;
472483
cx.open_window(options, |cx| {
473484
let project = project::Project::local(
474485
app_state.client.clone(),
@@ -485,7 +496,9 @@ pub async fn open_ssh_project(
485496

486497
let delegate = window.update(cx, |workspace, cx| {
487498
cx.activate_window();
488-
workspace.toggle_modal(cx, |cx| SshConnectionModal::new(&connection_options, cx));
499+
workspace.toggle_modal(cx, |cx| {
500+
SshConnectionModal::new(&connection_options, true, cx)
501+
});
489502
let ui = workspace
490503
.active_modal::<SshConnectionModal>(cx)
491504
.unwrap()
@@ -500,8 +513,11 @@ pub async fn open_ssh_project(
500513
})
501514
})?;
502515

503-
cx.update(|cx| {
504-
workspace::open_ssh_project(window, connection_options, delegate, app_state, paths, cx)
505-
})?
506-
.await
516+
let did_open_ssh_project = cx
517+
.update(|cx| {
518+
workspace::open_ssh_project(window, connection_options, delegate, app_state, paths, cx)
519+
})?
520+
.await;
521+
522+
did_open_ssh_project
507523
}

crates/recent_projects/src/ssh_remotes.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)