Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
workspace: Add close project menu item (#47365)
Lukas Wirth21fbceb8d4c5
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex 4ff55f4a1d9..4aaff0529cf 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -227,6 +227,8 @@ actions!(ToggleAllDocks,/// Closes the current window.CloseWindow,+ /// Closes the current project.+ CloseProject,/// Opens the feedback dialog.Feedback,/// Follows the next collaborator in the session.@@ -8289,7 +8291,7 @@ pub fn open_new(let task = Workspace::new_local(Vec::new(),app_state,- None,+ open_options.replace_window,open_options.env,Some(Box::new(init)),cx,diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rsindex 4b69a45d76b..7395c31a902 100644--- a/crates/zed/src/zed.rs+++ b/crates/zed/src/zed.rs@@ -93,7 +93,8 @@ use workspace::{open_new,};use workspace::{- CloseIntent, CloseWindow, NotificationFrame, RestoreBanner, with_active_or_new_workspace,+ CloseIntent, CloseProject, CloseWindow, NotificationFrame, RestoreBanner,+ with_active_or_new_workspace,};use workspace::{Pane, notifications::DetachAndPromptErr};use zed_actions::{@@ -1135,6 +1136,43 @@ fn register_actions(}}})+ .register_action({+ let app_state = Arc::downgrade(&app_state);+ move |_, _: &CloseProject, window, cx| {+ let Some(window_handle) = window.window_handle().downcast::<Workspace>() else {+ return;+ };+ if let Some(app_state) = app_state.upgrade() {+ open_new(+ workspace::OpenOptions {+ replace_window: Some(window_handle),+ ..Default::default()+ },+ app_state,+ cx,+ |workspace, window, cx| {+ cx.activate(true);+ // Create buffer synchronously to avoid flicker+ let project = workspace.project().clone();+ let buffer = project.update(cx, |project, cx| {+ project.create_local_buffer("", None, true, cx)+ });+ let editor = cx.new(|cx| {+ Editor::for_buffer(buffer, Some(project), window, cx)+ });+ workspace.add_item_to_active_pane(+ Box::new(editor),+ None,+ true,+ window,+ cx,+ );+ },+ )+ .detach();+ }+ }+ }).register_action({let app_state = Arc::downgrade(&app_state);move |_, _: &NewFile, _, cx| {diff --git a/crates/zed/src/zed/app_menus.rs b/crates/zed/src/zed/app_menus.rsindex 7cdeddab790..40582c8e13f 100644--- a/crates/zed/src/zed/app_menus.rs+++ b/crates/zed/src/zed/app_menus.rs@@ -154,6 +154,7 @@ pub fn app_menus(cx: &mut App) -> Vec<Menu> {close_pinned: true,},),+ MenuItem::action("Close Project", workspace::CloseProject),MenuItem::action("Close Window", workspace::CloseWindow),],},