Skip to content

Commit

Permalink
ssh: Improve dismissal behaviour (zed-industries#18900)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
osiewicz authored Oct 9, 2024
1 parent 9c54bd1 commit f50bca7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
6 changes: 4 additions & 2 deletions crates/recent_projects/src/dev_servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion crates/recent_projects/src/recent_projects.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
42 changes: 29 additions & 13 deletions crates/recent_projects/src/ssh_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -83,6 +83,7 @@ pub struct SshPrompt {

pub struct SshConnectionModal {
pub(crate) prompt: View<SshPrompt>,
is_separate_window: bool,
}

impl SshPrompt {
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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();
}
}
}

Expand All @@ -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.))
Expand All @@ -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)),
),
)
Expand Down Expand Up @@ -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(),
Expand All @@ -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()
Expand All @@ -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
}
1 change: 0 additions & 1 deletion crates/recent_projects/src/ssh_remotes.rs

This file was deleted.

0 comments on commit f50bca7

Please sign in to comment.