diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 9e3e59b309..69e30a6ccb 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1095,19 +1095,21 @@ impl Workspace { } pub fn close_global(_: &CloseWindow, cx: &mut AppContext) { - cx.windows().iter().find(|window| { - window - .update(cx, |_, window| { - if window.is_window_active() { - //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 - window.remove_window(); - true - } else { - false - } - }) - .unwrap_or(false) + cx.defer(|cx| { + cx.windows().iter().find(|window| { + window + .update(cx, |_, window| { + if window.is_window_active() { + //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 + window.remove_window(); + true + } else { + false + } + }) + .unwrap_or(false) + }); }); } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 21e6c8fa21..e0da81edc4 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -144,6 +144,7 @@ fn main() { cx.set_global(client.clone()); + zed::init(cx); theme::init(theme::LoadThemes::All, cx); project::Project::init(&client, cx); client::init(&client, cx); @@ -158,7 +159,6 @@ fn main() { cx, ); assistant::init(cx); - // component_test::init(cx); cx.spawn(|_| watch_languages(fs.clone(), languages.clone())) .detach(); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index bcfdb848ab..fb85b1fc01 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -64,6 +64,13 @@ actions!( ] ); +pub fn init(cx: &mut AppContext) { + cx.on_action(|_: &Hide, cx| cx.hide()); + cx.on_action(|_: &HideOthers, cx| cx.hide_other_apps()); + cx.on_action(|_: &ShowAll, cx| cx.unhide_other_apps()); + cx.on_action(quit); +} + pub fn build_window_options( bounds: Option, display_uuid: Option, @@ -130,7 +137,6 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { status_bar.add_left_item(diagnostic_summary, cx); status_bar.add_left_item(activity_indicator, cx); status_bar.add_right_item(feedback_button, cx); - // status_bar.add_right_item(copilot, cx); status_bar.add_right_item(copilot, cx); status_bar.add_right_item(active_buffer_language, cx); status_bar.add_right_item(vim_mode_indicator, cx); @@ -207,15 +213,6 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { workspace .register_action(about) - .register_action(|_, _: &Hide, cx| { - cx.hide(); - }) - .register_action(|_, _: &HideOthers, cx| { - cx.hide_other_apps(); - }) - .register_action(|_, _: &ShowAll, cx| { - cx.unhide_other_apps(); - }) .register_action(|_, _: &Minimize, cx| { cx.minimize_window(); }) @@ -225,7 +222,6 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { .register_action(|_, _: &ToggleFullScreen, cx| { cx.toggle_full_screen(); }) - .register_action(quit) .register_action(|_, action: &OpenZedURL, cx| { cx.global::>() .open_urls(&[action.url.clone()]) @@ -451,10 +447,10 @@ fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext) { .detach(); } -fn quit(_: &mut Workspace, _: &Quit, cx: &mut gpui::ViewContext) { +fn quit(_: &Quit, cx: &mut AppContext) { let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit; - cx.spawn(|_, mut cx| async move { - let mut workspace_windows = cx.update(|_, cx| { + cx.spawn(|mut cx| async move { + let mut workspace_windows = cx.update(|cx| { cx.windows() .into_iter() .filter_map(|window| window.downcast::()) @@ -463,14 +459,14 @@ fn quit(_: &mut Workspace, _: &Quit, cx: &mut gpui::ViewContext) { // If multiple windows have unsaved changes, and need a save prompt, // prompt in the active window before switching to a different window. - cx.update(|_, cx| { + cx.update(|cx| { workspace_windows.sort_by_key(|window| window.is_active(&cx) == Some(false)); }) .log_err(); - if let (true, Some(_)) = (should_confirm, workspace_windows.first().copied()) { - let answer = cx - .update(|_, cx| { + if let (true, Some(workspace)) = (should_confirm, workspace_windows.first().copied()) { + let answer = workspace + .update(&mut cx, |_, cx| { cx.prompt( PromptLevel::Info, "Are you sure you want to quit?", @@ -500,9 +496,7 @@ fn quit(_: &mut Workspace, _: &Quit, cx: &mut gpui::ViewContext) { } } } - cx.update(|_, cx| { - cx.quit(); - })?; + cx.update(|cx| cx.quit())?; anyhow::Ok(()) }) .detach_and_log_err(cx);