Add key binding to close all docks

This commit is contained in:
Joseph T. Lyons 2023-07-21 02:44:44 -04:00
parent 57b6e25278
commit d98fcc4402
3 changed files with 20 additions and 0 deletions

View file

@ -406,6 +406,7 @@
"cmd-b": "workspace::ToggleLeftDock", "cmd-b": "workspace::ToggleLeftDock",
"cmd-r": "workspace::ToggleRightDock", "cmd-r": "workspace::ToggleRightDock",
"cmd-j": "workspace::ToggleBottomDock", "cmd-j": "workspace::ToggleBottomDock",
"alt-cmd-y": "workspace::CloseAllDocks",
"cmd-shift-f": "workspace::NewSearch", "cmd-shift-f": "workspace::NewSearch",
"cmd-k cmd-t": "theme_selector::Toggle", "cmd-k cmd-t": "theme_selector::Toggle",
"cmd-k cmd-s": "zed::OpenKeymap", "cmd-k cmd-s": "zed::OpenKeymap",

View file

@ -141,6 +141,7 @@ actions!(
ToggleLeftDock, ToggleLeftDock,
ToggleRightDock, ToggleRightDock,
ToggleBottomDock, ToggleBottomDock,
CloseAllDocks,
] ]
); );
@ -281,6 +282,9 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
cx.add_action(|workspace: &mut Workspace, _: &ToggleBottomDock, cx| { cx.add_action(|workspace: &mut Workspace, _: &ToggleBottomDock, cx| {
workspace.toggle_dock(DockPosition::Bottom, cx); workspace.toggle_dock(DockPosition::Bottom, cx);
}); });
cx.add_action(|workspace: &mut Workspace, _: &CloseAllDocks, cx| {
workspace.close_all_docks(cx);
});
cx.add_action(Workspace::activate_pane_at_index); cx.add_action(Workspace::activate_pane_at_index);
cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| { cx.add_action(|workspace: &mut Workspace, _: &ReopenClosedItem, cx| {
workspace.reopen_closed_item(cx).detach(); workspace.reopen_closed_item(cx).detach();
@ -1670,6 +1674,20 @@ impl Workspace {
self.serialize_workspace(cx); self.serialize_workspace(cx);
} }
pub fn close_all_docks(&mut self, cx: &mut ViewContext<Self>) {
let docks = [&self.left_dock, &self.bottom_dock, &self.right_dock];
for dock in docks {
dock.update(cx, |dock, cx| {
dock.set_open(false, cx);
});
}
cx.focus_self();
cx.notify();
self.serialize_workspace(cx);
}
/// Transfer focus to the panel of the given type. /// Transfer focus to the panel of the given type.
pub fn focus_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>) -> Option<ViewHandle<T>> { pub fn focus_panel<T: Panel>(&mut self, cx: &mut ViewContext<Self>) -> Option<ViewHandle<T>> {
self.focus_or_unfocus_panel::<T>(cx, |_, _| true)? self.focus_or_unfocus_panel::<T>(cx, |_, _| true)?

View file

@ -93,6 +93,7 @@ pub fn menus() -> Vec<Menu<'static>> {
MenuItem::action("Toggle Left Dock", workspace::ToggleLeftDock), MenuItem::action("Toggle Left Dock", workspace::ToggleLeftDock),
MenuItem::action("Toggle Right Dock", workspace::ToggleRightDock), MenuItem::action("Toggle Right Dock", workspace::ToggleRightDock),
MenuItem::action("Toggle Bottom Dock", workspace::ToggleBottomDock), MenuItem::action("Toggle Bottom Dock", workspace::ToggleBottomDock),
MenuItem::action("Close All Docks", workspace::CloseAllDocks),
MenuItem::submenu(Menu { MenuItem::submenu(Menu {
name: "Editor Layout", name: "Editor Layout",
items: vec![ items: vec![