From 3819a67185dc07a86a5e734a88b9236adf003294 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 25 Jan 2023 18:51:25 -0500 Subject: [PATCH] Add "Close Window" global action which does not need a focused workspace --- crates/gpui/src/app.rs | 2 +- crates/workspace/src/workspace.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 2e7378fc16..3fc11a6b58 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -875,7 +875,7 @@ impl MutableAppContext { } pub fn window_ids(&self) -> impl Iterator + '_ { - self.cx.windows.keys().cloned() + self.cx.windows.keys().copied() } pub fn activate_window(&self, window_id: usize) { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index b0abe09070..b90c62aca1 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -198,6 +198,7 @@ pub fn init(app_state: Arc, cx: &mut MutableAppContext) { cx.add_async_action(Workspace::toggle_follow); cx.add_async_action(Workspace::follow_next_collaborator); cx.add_async_action(Workspace::close); + cx.add_global_action(Workspace::close_global); cx.add_async_action(Workspace::save_all); cx.add_action(Workspace::open_shared_screen); cx.add_action(Workspace::add_folder_to_project); @@ -823,6 +824,15 @@ impl Workspace { } } + pub fn close_global(_: &CloseWindow, cx: &mut MutableAppContext) { + let id = cx.window_ids().find(|&id| cx.window_is_active(id)); + if let Some(id) = id { + //This can only get called when the window's project connection has been lost + //so we don't need to prompt the user for anything and instead just close the window + cx.remove_window(id); + } + } + pub fn close( &mut self, _: &CloseWindow, @@ -851,6 +861,7 @@ impl Workspace { .window_ids() .flat_map(|window_id| cx.root_view::(window_id)) .count(); + cx.spawn(|this, mut cx| async move { if let Some(active_call) = active_call { if !quitting @@ -866,6 +877,7 @@ impl Workspace { ) .next() .await; + if answer == Some(1) { return anyhow::Ok(false); } else {