diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 4ff55f4a1d9958bed60addea34fede7306afddfa..4aaff0529cf38f16e4f7e08263291168013ebb05 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.rs index 4b69a45d76bcb57a2616589c4068445bb6e81550..7395c31a902468b7133b1540a321b6f0d468c682 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::() 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.rs index 7cdeddab790dcc2227d4d91956a6261c5add5259..40582c8e13ff822189c9b3a1a467a9ff7f9d597a 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 { close_pinned: true, }, ), + MenuItem::action("Close Project", workspace::CloseProject), MenuItem::action("Close Window", workspace::CloseWindow), ], },