mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-25 01:34:02 +00:00
Add "Close Window" command
This commit is contained in:
parent
b08cad9ef5
commit
21206800bc
4 changed files with 38 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
||||||
"shift-cmd-{": "pane::ActivatePrevItem",
|
"shift-cmd-{": "pane::ActivatePrevItem",
|
||||||
"shift-cmd-}": "pane::ActivateNextItem",
|
"shift-cmd-}": "pane::ActivateNextItem",
|
||||||
"cmd-w": "pane::CloseActiveItem",
|
"cmd-w": "pane::CloseActiveItem",
|
||||||
|
"cmd-shift-W": "workspace::CloseWindow",
|
||||||
"alt-cmd-w": "pane::CloseInactiveItems",
|
"alt-cmd-w": "pane::CloseInactiveItems",
|
||||||
"cmd-s": "workspace::Save",
|
"cmd-s": "workspace::Save",
|
||||||
"cmd-shift-S": "workspace::SaveAs",
|
"cmd-shift-S": "workspace::SaveAs",
|
||||||
|
|
|
@ -482,6 +482,14 @@ impl Pane {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn close_all_items(
|
||||||
|
workspace: &mut Workspace,
|
||||||
|
pane: ViewHandle<Pane>,
|
||||||
|
cx: &mut ViewContext<Workspace>,
|
||||||
|
) -> Task<Result<()>> {
|
||||||
|
Self::close_items(workspace, pane, cx, |_| true)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn close_items(
|
pub fn close_items(
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
pane: ViewHandle<Pane>,
|
pane: ViewHandle<Pane>,
|
||||||
|
|
|
@ -77,6 +77,7 @@ actions!(
|
||||||
Open,
|
Open,
|
||||||
NewFile,
|
NewFile,
|
||||||
NewWindow,
|
NewWindow,
|
||||||
|
CloseWindow,
|
||||||
AddFolderToProject,
|
AddFolderToProject,
|
||||||
Unfollow,
|
Unfollow,
|
||||||
Save,
|
Save,
|
||||||
|
@ -142,6 +143,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
|
|
||||||
cx.add_async_action(Workspace::toggle_follow);
|
cx.add_async_action(Workspace::toggle_follow);
|
||||||
cx.add_async_action(Workspace::follow_next_collaborator);
|
cx.add_async_action(Workspace::follow_next_collaborator);
|
||||||
|
cx.add_async_action(Workspace::close);
|
||||||
cx.add_action(Workspace::add_folder_to_project);
|
cx.add_action(Workspace::add_folder_to_project);
|
||||||
cx.add_action(
|
cx.add_action(
|
||||||
|workspace: &mut Workspace, _: &Unfollow, cx: &mut ViewContext<Workspace>| {
|
|workspace: &mut Workspace, _: &Unfollow, cx: &mut ViewContext<Workspace>| {
|
||||||
|
@ -881,6 +883,29 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn close(&mut self, _: &CloseWindow, cx: &mut ViewContext<Self>) -> Option<Task<Result<()>>> {
|
||||||
|
let mut tasks = Vec::new();
|
||||||
|
for pane in self.panes.clone() {
|
||||||
|
tasks.push(Pane::close_all_items(self, pane, cx));
|
||||||
|
}
|
||||||
|
Some(cx.spawn(|this, mut cx| async move {
|
||||||
|
for task in tasks {
|
||||||
|
task.await?;
|
||||||
|
}
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
if this
|
||||||
|
.panes
|
||||||
|
.iter()
|
||||||
|
.all(|pane| pane.read(cx).items().next().is_none())
|
||||||
|
{
|
||||||
|
let window_id = cx.window_id();
|
||||||
|
cx.remove_window(window_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn open_paths(
|
pub fn open_paths(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut abs_paths: Vec<PathBuf>,
|
mut abs_paths: Vec<PathBuf>,
|
||||||
|
|
|
@ -58,6 +58,10 @@ pub fn menus() -> Vec<Menu<'static>> {
|
||||||
name: "Close Editor",
|
name: "Close Editor",
|
||||||
action: Box::new(workspace::CloseActiveItem),
|
action: Box::new(workspace::CloseActiveItem),
|
||||||
},
|
},
|
||||||
|
MenuItem::Action {
|
||||||
|
name: "Close Window",
|
||||||
|
action: Box::new(workspace::CloseWindow),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
Menu {
|
Menu {
|
||||||
|
|
Loading…
Reference in a new issue