From d98fcc4402ca030194181c35e41eb80d433b954f Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 21 Jul 2023 02:44:44 -0400 Subject: [PATCH] Add key binding to close all docks --- assets/keymaps/default.json | 1 + crates/workspace/src/workspace.rs | 18 ++++++++++++++++++ crates/zed/src/menus.rs | 1 + 3 files changed, 20 insertions(+) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 883b0c1872..7f420e6d93 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -406,6 +406,7 @@ "cmd-b": "workspace::ToggleLeftDock", "cmd-r": "workspace::ToggleRightDock", "cmd-j": "workspace::ToggleBottomDock", + "alt-cmd-y": "workspace::CloseAllDocks", "cmd-shift-f": "workspace::NewSearch", "cmd-k cmd-t": "theme_selector::Toggle", "cmd-k cmd-s": "zed::OpenKeymap", diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 0ebd01e1f7..c64b5189e1 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -141,6 +141,7 @@ actions!( ToggleLeftDock, ToggleRightDock, ToggleBottomDock, + CloseAllDocks, ] ); @@ -281,6 +282,9 @@ pub fn init(app_state: Arc, cx: &mut AppContext) { cx.add_action(|workspace: &mut Workspace, _: &ToggleBottomDock, 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: &mut Workspace, _: &ReopenClosedItem, cx| { workspace.reopen_closed_item(cx).detach(); @@ -1670,6 +1674,20 @@ impl Workspace { self.serialize_workspace(cx); } + pub fn close_all_docks(&mut self, cx: &mut ViewContext) { + 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. pub fn focus_panel(&mut self, cx: &mut ViewContext) -> Option> { self.focus_or_unfocus_panel::(cx, |_, _| true)? diff --git a/crates/zed/src/menus.rs b/crates/zed/src/menus.rs index 9112cd207b..22a260b588 100644 --- a/crates/zed/src/menus.rs +++ b/crates/zed/src/menus.rs @@ -93,6 +93,7 @@ pub fn menus() -> Vec> { MenuItem::action("Toggle Left Dock", workspace::ToggleLeftDock), MenuItem::action("Toggle Right Dock", workspace::ToggleRightDock), MenuItem::action("Toggle Bottom Dock", workspace::ToggleBottomDock), + MenuItem::action("Close All Docks", workspace::CloseAllDocks), MenuItem::submenu(Menu { name: "Editor Layout", items: vec![