From f476a8bc2ac4788cb33a21d7dd1a33043856b2c4 Mon Sep 17 00:00:00 2001 From: Andrew Lygin Date: Thu, 6 Jun 2024 04:50:57 +0300 Subject: [PATCH] editor: Add ToggleTabBar action (#12499) This PR adds the `editor: toggle tab bar` action that hides / shows the tab bar and updates the `tab_bar.show` setting in `settings.json` accordingly. First mentioned in https://github.com/zed-industries/zed/pull/7356#issuecomment-2118445379. Release Notes: - Added the `editor: toggle tab bar` action. --- crates/editor/src/actions.rs | 1 + crates/editor/src/editor.rs | 15 +++++++++++++-- crates/editor/src/element.rs | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index f2835d4154..e2a2c4d04f 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -289,6 +289,7 @@ gpui::actions!( ToggleLineNumbers, ToggleIndentGuides, ToggleSoftWrap, + ToggleTabBar, Transpose, Undo, UndoSelection, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index e5bfbf5392..601d0d47a5 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -111,7 +111,7 @@ use rpc::{proto::*, ErrorExt}; use scroll::{Autoscroll, OngoingScroll, ScrollAnchor, ScrollManager, ScrollbarAutoHide}; use selections_collection::{resolve_multiple, MutableSelectionsCollection, SelectionsCollection}; use serde::{Deserialize, Serialize}; -use settings::{Settings, SettingsStore}; +use settings::{update_settings_file, Settings, SettingsStore}; use smallvec::SmallVec; use snippet::Snippet; use std::ops::Not as _; @@ -143,7 +143,7 @@ use workspace::notifications::{DetachAndPromptErr, NotificationId}; use workspace::{ searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace, WorkspaceId, }; -use workspace::{OpenInTerminal, OpenTerminal, Toast}; +use workspace::{OpenInTerminal, OpenTerminal, TabBarSettings, Toast}; use crate::hover_links::find_url; @@ -9800,6 +9800,17 @@ impl Editor { cx.notify(); } + pub fn toggle_tab_bar(&mut self, _: &ToggleTabBar, cx: &mut ViewContext) { + let Some(workspace) = self.workspace() else { + return; + }; + let fs = workspace.read(cx).app_state().fs.clone(); + let current_show = TabBarSettings::get_global(cx).show; + update_settings_file::(fs, cx, move |setting| { + setting.show = Some(!current_show); + }); + } + pub fn toggle_indent_guides(&mut self, _: &ToggleIndentGuides, cx: &mut ViewContext) { let currently_enabled = self.should_show_indent_guides().unwrap_or_else(|| { self.buffer diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 873d031393..4df0022855 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -318,6 +318,7 @@ impl EditorElement { register_action(view, cx, Editor::open_excerpts); register_action(view, cx, Editor::open_excerpts_in_split); register_action(view, cx, Editor::toggle_soft_wrap); + register_action(view, cx, Editor::toggle_tab_bar); register_action(view, cx, Editor::toggle_line_numbers); register_action(view, cx, Editor::toggle_indent_guides); register_action(view, cx, Editor::toggle_inlay_hints);