From ca9645c2bf759fa086697e97d35ec3bf76932f95 Mon Sep 17 00:00:00 2001 From: Andrew Lygin Date: Sun, 4 Feb 2024 15:39:34 +0300 Subject: [PATCH] Move tab bar placement setting to the "tabs" section --- assets/settings/default.json | 23 +++++++-------- crates/editor/src/editor.rs | 13 +++++---- crates/editor/src/editor_settings.rs | 19 +------------ crates/editor/src/items.rs | 8 +++--- crates/settings/src/settings.rs | 1 - crates/settings/src/tab_bar.rs | 16 ----------- crates/workspace/src/item.rs | 29 +++++++++++++++---- crates/workspace/src/pane.rs | 6 ++-- crates/workspace/src/workspace.rs | 4 +-- docs/src/configuring_zed.md | 42 ++++++++++++++++++++++++---- 10 files changed, 87 insertions(+), 74 deletions(-) delete mode 100644 crates/settings/src/tab_bar.rs diff --git a/assets/settings/default.json b/assets/settings/default.json index f041b362df..70a6091eaf 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -118,19 +118,6 @@ // Share your project when you are the first to join a channel "share_on_join": true }, - // The editor tab bar related settings - "tab_bar": { - // Where to show the tab bar in the editor. - // This setting can take three values: - // - // 1. Don't show the tab bar: - // "no" - // 2. Show tab bar at the top of the editor (default): - // "top" - // 3. Show tab bar at the bottom of the editor: - // "bottom" - "placement": "top" - }, // Toolbar related settings "toolbar": { // Whether to show breadcrumbs. @@ -298,6 +285,16 @@ "autosave": "off", // Settings related to the editor's tabs "tabs": { + // Where to show the tab bar in the editor. + // This setting can take three values: + // + // 1. Show tab bar at the top of the editor (default): + // "top" + // 2. Show tab bar at the bottom of the editor: + // "bottom" + // 3. Don't show the tab bar: + // "no" + "placement": "top", // Show git status colors in the editor tabs. "git_status": false, // Position of the close button on the editor tabs. diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 097d04dc5a..264f822323 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -49,7 +49,7 @@ use copilot::Copilot; use debounced_delay::DebouncedDelay; pub use display_map::DisplayPoint; use display_map::*; -pub use editor_settings::{EditorSettings, TabBar}; +pub use editor_settings::EditorSettings; use element::LineWithInvisibles; pub use element::{ CursorLayout, EditorElement, HighlightedRange, HighlightedRangeLine, PointForPosition, @@ -124,9 +124,10 @@ use ui::{ Tooltip, }; use util::{maybe, post_inc, RangeExt, ResultExt, TryFutureExt}; -use workspace::Toast; use workspace::{ - searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace, WorkspaceId, + item::{TabBarPlacement, TabsSettings}, + searchable::SearchEvent, + ItemNavHistory, Pane, SplitDirection, Toast, ViewId, Workspace, WorkspaceId, }; use crate::hover_links::find_url; @@ -387,7 +388,7 @@ pub struct Editor { hovered_cursors: HashMap>, pub show_local_selections: bool, mode: EditorMode, - tab_bar_settings: TabBar, + tab_bar_placement: TabBarPlacement, show_breadcrumbs: bool, show_gutter: bool, show_wrap_guides: Option, @@ -1529,7 +1530,7 @@ impl Editor { blink_manager: blink_manager.clone(), show_local_selections: true, mode, - tab_bar_settings: EditorSettings::get_global(cx).tab_bar, + tab_bar_placement: TabsSettings::get_global(cx).placement, show_breadcrumbs: EditorSettings::get_global(cx).toolbar.breadcrumbs, show_gutter: mode == EditorMode::Full, show_wrap_guides: None, @@ -9536,8 +9537,8 @@ impl Editor { ); let editor_settings = EditorSettings::get_global(cx); self.scroll_manager.vertical_scroll_margin = editor_settings.vertical_scroll_margin; - self.tab_bar_settings = editor_settings.tab_bar; self.show_breadcrumbs = editor_settings.toolbar.breadcrumbs; + self.tab_bar_placement = TabsSettings::get_global(cx).placement; cx.notify(); } diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 8b093e6c83..d3a122954f 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -1,6 +1,6 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use settings::{Settings, TabBarPlacement}; +use settings::Settings; #[derive(Deserialize, Clone)] pub struct EditorSettings { @@ -10,7 +10,6 @@ pub struct EditorSettings { pub show_completion_documentation: bool, pub completion_documentation_secondary_query_debounce: u64, pub use_on_type_format: bool, - pub tab_bar: TabBar, pub toolbar: Toolbar, pub scrollbar: Scrollbar, pub gutter: Gutter, @@ -47,11 +46,6 @@ pub enum DoubleClickInMultibuffer { Open, } -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] -pub struct TabBar { - pub placement: TabBarPlacement, -} - #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] pub struct Toolbar { pub breadcrumbs: bool, @@ -132,8 +126,6 @@ pub struct EditorSettingsContent { /// /// Default: true pub use_on_type_format: Option, - /// Tab bar related settings - pub tab_bar: Option, /// Toolbar related settings pub toolbar: Option, /// Scrollbar related settings @@ -170,15 +162,6 @@ pub struct EditorSettingsContent { pub double_click_in_multibuffer: Option, } -// Tab bar related settings -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] -pub struct TabBarContent { - /// Where to place tab bar in the editor. - /// - /// Default: top - pub placement: Option, -} - // Toolbar related settings #[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] pub struct ToolbarContent { diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index 3c3cd88630..7a2687f2d2 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -18,8 +18,8 @@ use language::{ use project::repository::GitFileStatus; use project::{search::SearchQuery, FormatTrigger, Item as _, Project, ProjectPath}; use rpc::proto::{self, update_view, PeerId}; -use settings::{Settings, TabBarPlacement}; -use workspace::item::ItemSettings; +use settings::Settings; +use workspace::item::{TabBarPlacement, TabsSettings}; use std::{ borrow::Cow, @@ -595,7 +595,7 @@ impl Item for Editor { } fn tab_content(&self, detail: Option, selected: bool, cx: &WindowContext) -> AnyElement { - let label_color = if ItemSettings::get_global(cx).git_status { + let label_color = if TabsSettings::get_global(cx).git_status { self.buffer() .read(cx) .as_singleton() @@ -796,7 +796,7 @@ impl Item for Editor { } fn tab_bar_placement(&self) -> TabBarPlacement { - self.tab_bar_settings.placement + self.tab_bar_placement } fn breadcrumb_location(&self) -> ToolbarItemLocation { diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 4b3561cc2c..a766a1dff5 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -1,7 +1,6 @@ mod keymap_file; mod settings_file; mod settings_store; -mod tab_bar; use rust_embed::RustEmbed; use std::{borrow::Cow, str}; diff --git a/crates/settings/src/tab_bar.rs b/crates/settings/src/tab_bar.rs deleted file mode 100644 index 9312d308fd..0000000000 --- a/crates/settings/src/tab_bar.rs +++ /dev/null @@ -1,16 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -/// The tab bar placement in a pane. -/// -/// Default: top -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] -#[serde(rename_all = "snake_case")] -pub enum TabBarPlacement { - /// Don't show tab bar. - No, - /// Place tab bar on top of the pane. - Top, - /// Place tab bar at the bottom of the pane. - Bottom, -} diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index 90459ae582..1e221c77cc 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -20,7 +20,7 @@ use gpui::{ use project::{Project, ProjectEntryId, ProjectPath}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use settings::{Settings, TabBarPlacement}; +use settings::Settings; use smallvec::SmallVec; use std::{ any::{Any, TypeId}, @@ -37,11 +37,24 @@ use ui::Element as _; pub const LEADER_UPDATE_THROTTLE: Duration = Duration::from_millis(200); #[derive(Deserialize)] -pub struct ItemSettings { +pub struct TabsSettings { + pub placement: TabBarPlacement, pub git_status: bool, pub close_position: ClosePosition, } +/// The tab bar placement in a pane. +#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] +#[serde(rename_all = "snake_case")] +pub enum TabBarPlacement { + /// Don't show tab bar. + No, + /// Place tab bar on top of the pane. + Top, + /// Place tab bar at the bottom of the pane. + Bottom, +} + #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "lowercase")] pub enum ClosePosition { @@ -60,10 +73,14 @@ impl ClosePosition { } #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] -pub struct ItemSettingsContent { +pub struct TabsSettingsContent { + /// Where to place tab bar in the editor. + /// + /// Default: top + pub placement: Option, /// Whether to show the Git file status on a tab item. /// - /// Default: true + /// Default: false git_status: Option, /// Position of the close button in a tab. /// @@ -71,10 +88,10 @@ pub struct ItemSettingsContent { close_position: Option, } -impl Settings for ItemSettings { +impl Settings for TabsSettings { const KEY: Option<&'static str> = Some("tabs"); - type FileContent = ItemSettingsContent; + type FileContent = TabsSettingsContent; fn load( default_value: &Self::FileContent, diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 4f44ec7c07..0059c61d9b 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1,5 +1,5 @@ use crate::{ - item::{ClosePosition, Item, ItemHandle, ItemSettings, WeakItemHandle}, + item::{ClosePosition, Item, ItemHandle, TabBarPlacement, TabsSettings, WeakItemHandle}, toolbar::Toolbar, workspace_settings::{AutosaveSetting, WorkspaceSettings}, NewCenterTerminal, NewFile, NewSearch, OpenVisible, SplitDirection, ToggleZoom, Workspace, @@ -17,7 +17,7 @@ use gpui::{ use parking_lot::Mutex; use project::{Project, ProjectEntryId, ProjectPath}; use serde::Deserialize; -use settings::{Settings, TabBarPlacement}; +use settings::Settings; use std::{ any::Any, cmp, fmt, mem, @@ -1305,7 +1305,7 @@ impl Pane { let is_active = ix == self.active_item_index; let label = item.tab_content(Some(detail), is_active, cx); - let close_side = &ItemSettings::get_global(cx).close_position; + let close_side = &TabsSettings::get_global(cx).close_position; let indicator = maybe!({ let indicator_color = match (item.has_conflict(cx), item.is_dirty(cx)) { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index c8d2c021b8..3f094d8bbe 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -32,7 +32,7 @@ use gpui::{ LayoutId, ManagedView, Model, ModelContext, PathPromptOptions, Point, PromptLevel, Render, Size, Subscription, Task, View, WeakView, WindowHandle, WindowOptions, }; -use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem}; +use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem, TabsSettings}; use itertools::Itertools; use language::{LanguageRegistry, Rope}; use lazy_static::lazy_static; @@ -259,7 +259,7 @@ impl Column for WorkspaceId { } pub fn init_settings(cx: &mut AppContext) { WorkspaceSettings::register(cx); - ItemSettings::register(cx); + TabsSettings::register(cx); } pub fn init(app_state: Arc, cx: &mut AppContext) { diff --git a/docs/src/configuring_zed.md b/docs/src/configuring_zed.md index ed420c47a4..652eb7b184 100644 --- a/docs/src/configuring_zed.md +++ b/docs/src/configuring_zed.md @@ -190,15 +190,17 @@ List of `string` values 2. Position the dock to the right of the workspace like a side panel: `right` 3. Position the dock full screen over the entire workspace: `expanded` -## Editor Tab Bar +## Editor Tabs -- Description: Configuration for the editor tab bar. -- Setting: `tab_bar` +- Description: Configuration for the editor tabs. +- Setting: `tabs` - Default: ```json -"tab_bar": { - "placement": "top" +"tabs": { + "placement": "top", + "close_position": "right", + "git_status": false }, ``` @@ -234,6 +236,36 @@ List of `string` values } ``` +### Close Position + +- Description: Where to display close button within a tab. +- Setting: `close_position` +- Default: `right` + +**Options** + +1. Display the close button on the right: + +```json +{ + "close_position": "right" +} +``` + +2. Display the close button on the left: + +```json +{ + "close_position": "left" +} +``` + +### Git Status + +- Description: Wheter or not to show Git file status in tab. +- Setting: `git_status` +- Default: false + ## Editor Toolbar - Description: Whether or not to show various elements in the editor toolbar.