From 1bded42b2af4b2393db1fe412b32b6580df806f8 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:57:50 +0200 Subject: [PATCH] ssh: Dismiss file picker when new window is opened (#19600) Closes #ISSUE Release Notes: - N/A --- crates/recent_projects/src/remote_servers.rs | 157 ++++++++++--------- 1 file changed, 79 insertions(+), 78 deletions(-) diff --git a/crates/recent_projects/src/remote_servers.rs b/crates/recent_projects/src/remote_servers.rs index 30c5f27dfe..407f3eb292 100644 --- a/crates/recent_projects/src/remote_servers.rs +++ b/crates/recent_projects/src/remote_servers.rs @@ -215,93 +215,94 @@ impl ProjectPicker { connection.port, &connection.username, ); - cx.new_view(|cx| { - let _path_task = cx - .spawn({ - let workspace = workspace.clone(); - move |_, mut cx| async move { - let Ok(Some(paths)) = rx.await else { - workspace - .update(&mut cx, |workspace, cx| { - let weak = cx.view().downgrade(); - workspace - .toggle_modal(cx, |cx| RemoteServerProjects::new(cx, weak)); - }) - .log_err()?; - return None; - }; - - let app_state = workspace - .update(&mut cx, |workspace, _| workspace.app_state().clone()) - .ok()?; - let options = cx - .update(|cx| (app_state.build_window_options)(None, cx)) + let _path_task = cx + .spawn({ + let workspace = workspace.clone(); + move |this, mut cx| async move { + let Ok(Some(paths)) = rx.await else { + workspace + .update(&mut cx, |workspace, cx| { + let weak = cx.view().downgrade(); + workspace + .toggle_modal(cx, |cx| RemoteServerProjects::new(cx, weak)); + }) .log_err()?; + return None; + }; - cx.open_window(options, |cx| { - cx.activate_window(); + let app_state = workspace + .update(&mut cx, |workspace, _| workspace.app_state().clone()) + .ok()?; + let options = cx + .update(|cx| (app_state.build_window_options)(None, cx)) + .log_err()?; - let fs = app_state.fs.clone(); - update_settings_file::(fs, cx, { - let paths = paths - .iter() - .map(|path| path.to_string_lossy().to_string()) - .collect(); - move |setting, _| { - if let Some(server) = setting - .ssh_connections - .as_mut() - .and_then(|connections| connections.get_mut(ix)) - { - server.projects.push(SshProject { paths }) - } + cx.open_window(options, |cx| { + cx.activate_window(); + + let fs = app_state.fs.clone(); + update_settings_file::(fs, cx, { + let paths = paths + .iter() + .map(|path| path.to_string_lossy().to_string()) + .collect(); + move |setting, _| { + if let Some(server) = setting + .ssh_connections + .as_mut() + .and_then(|connections| connections.get_mut(ix)) + { + server.projects.push(SshProject { paths }) } - }); + } + }); - let tasks = paths - .into_iter() - .map(|path| { - project.update(cx, |project, cx| { - project.find_or_create_worktree(&path, true, cx) - }) + let tasks = paths + .into_iter() + .map(|path| { + project.update(cx, |project, cx| { + project.find_or_create_worktree(&path, true, cx) }) - .collect::>(); - cx.spawn(|_| async move { - for task in tasks { - task.await?; - } - Ok(()) - }) - .detach_and_prompt_err( - "Failed to open path", - cx, - |_, _| None, - ); - - cx.new_view(|cx| { - let workspace = - Workspace::new(None, project.clone(), app_state.clone(), cx); - - workspace - .client() - .telemetry() - .report_app_event("create ssh project".to_string()); - - workspace }) + .collect::>(); + cx.spawn(|_| async move { + for task in tasks { + task.await?; + } + Ok(()) }) - .log_err(); - Some(()) - } - }) - .shared(); + .detach_and_prompt_err( + "Failed to open path", + cx, + |_, _| None, + ); - Self { - _path_task, - picker, - connection_string, - nickname, - } + cx.new_view(|cx| { + let workspace = + Workspace::new(None, project.clone(), app_state.clone(), cx); + + workspace + .client() + .telemetry() + .report_app_event("create ssh project".to_string()); + + workspace + }) + }) + .log_err(); + this.update(&mut cx, |_, cx| { + cx.emit(DismissEvent); + }) + .ok(); + Some(()) + } + }) + .shared(); + cx.new_view(|_| Self { + _path_task, + picker, + connection_string, + nickname, }) } }