workspace: Add close project menu item (#47365)

cc https://github.com/zed-industries/zed/discussions/42163

Release Notes:

- Added a menu item to close the current project, going back to a clean
window state
This commit is contained in:
Lukas Wirth authored and GitHub committed 2026-01-22 12:15:24 +01:00
1 parent 000f33c116
commit aa7c61219b
3 files changed
+43 -2

No files matched your search

+3 -1
View File
@@ -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,
+39 -1
View File
@@ -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| {
+1
View File
@@ -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),
],
},