diff --git a/crates/recent_projects/src/dev_servers.rs b/crates/recent_projects/src/dev_servers.rs index 6171489872cd4..b80a011ca35e2 100644 --- a/crates/recent_projects/src/dev_servers.rs +++ b/crates/recent_projects/src/dev_servers.rs @@ -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::(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) diff --git a/crates/recent_projects/src/recent_projects.rs b/crates/recent_projects/src/recent_projects.rs index 2285ed6287895..d763d24234342 100644 --- a/crates/recent_projects/src/recent_projects.rs +++ b/crates/recent_projects/src/recent_projects.rs @@ -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; diff --git a/crates/recent_projects/src/ssh_connections.rs b/crates/recent_projects/src/ssh_connections.rs index ebac54385d296..af65133339809 100644 --- a/crates/recent_projects/src/ssh_connections.rs +++ b/crates/recent_projects/src/ssh_connections.rs @@ -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, + 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 { + pub fn new( + connection_options: &SshConnectionOptions, + is_separate_window: bool, + cx: &mut ViewContext, + ) -> 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) { - 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::(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 } diff --git a/crates/recent_projects/src/ssh_remotes.rs b/crates/recent_projects/src/ssh_remotes.rs deleted file mode 100644 index 8b137891791fe..0000000000000 --- a/crates/recent_projects/src/ssh_remotes.rs +++ /dev/null @@ -1 +0,0 @@ -