Move tab bar placement setting to the "tabs" section

This commit is contained in:
Andrew Lygin
2024-02-04 15:39:34 +03:00
parent b81e8971df
commit ca9645c2bf
10 changed files with 87 additions and 74 deletions

View File

@@ -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.

View File

@@ -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<HoveredCursor, Task<()>>,
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<bool>,
@@ -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();
}

View File

@@ -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<bool>,
/// Tab bar related settings
pub tab_bar: Option<TabBarContent>,
/// Toolbar related settings
pub toolbar: Option<ToolbarContent>,
/// Scrollbar related settings
@@ -170,15 +162,6 @@ pub struct EditorSettingsContent {
pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
}
// 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<TabBarPlacement>,
}
// Toolbar related settings
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct ToolbarContent {

View File

@@ -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<usize>, 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 {

View File

@@ -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};

View File

@@ -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,
}

View File

@@ -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<TabBarPlacement>,
/// Whether to show the Git file status on a tab item.
///
/// Default: true
/// Default: false
git_status: Option<bool>,
/// Position of the close button in a tab.
///
@@ -71,10 +88,10 @@ pub struct ItemSettingsContent {
close_position: Option<ClosePosition>,
}
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,

View File

@@ -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)) {

View File

@@ -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<AppState>, cx: &mut AppContext) {

View File

@@ -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.