diff --git a/crates/markdown/examples/markdown.rs b/crates/markdown/examples/markdown.rs index c019bad1d081e59077bedb05cb36673a48f294bc..b4cb2a2503dcb6e097c34e4c8aad718f89e30272 100644 --- a/crates/markdown/examples/markdown.rs +++ b/crates/markdown/examples/markdown.rs @@ -1,6 +1,6 @@ use assets::Assets; use gpui::{Application, Entity, KeyBinding, StyleRefinement, WindowOptions, prelude::*, rgb}; -use language::{LanguageRegistry, language_settings::AllLanguageSettings}; +use language::LanguageRegistry; use markdown::{Markdown, MarkdownElement, MarkdownStyle}; use node_runtime::NodeRuntime; use settings::SettingsStore; @@ -39,9 +39,6 @@ pub fn main() { let store = SettingsStore::test(cx); cx.set_global(store); language::init(cx); - SettingsStore::update(cx, |store, cx| { - store.update_user_settings::(cx, |_| {}); - }); cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]); let node_runtime = NodeRuntime::unavailable(); diff --git a/crates/markdown/examples/markdown_as_child.rs b/crates/markdown/examples/markdown_as_child.rs index 6c0960c88b3021b6012b769aef8ffb22050b1abd..784047dc3dbd4130f0464b3e13be940b6634fedc 100644 --- a/crates/markdown/examples/markdown_as_child.rs +++ b/crates/markdown/examples/markdown_as_child.rs @@ -1,6 +1,6 @@ use assets::Assets; use gpui::{Application, Entity, KeyBinding, Length, StyleRefinement, WindowOptions, rgb}; -use language::{LanguageRegistry, language_settings::AllLanguageSettings}; +use language::LanguageRegistry; use markdown::{Markdown, MarkdownElement, MarkdownStyle}; use node_runtime::NodeRuntime; use settings::SettingsStore; @@ -23,9 +23,6 @@ pub fn main() { let store = SettingsStore::test(cx); cx.set_global(store); language::init(cx); - SettingsStore::update(cx, |store, cx| { - store.update_user_settings::(cx, |_| {}); - }); cx.bind_keys([KeyBinding::new("cmd-c", markdown::Copy, None)]); let node_runtime = NodeRuntime::unavailable(); diff --git a/crates/project/src/direnv.rs b/crates/project/src/direnv.rs index 9ba0ad10e3173a1930186db28f7efb5d9a8267f7..32f4963fd19805e369c696cfd30c8ef599bd06f3 100644 --- a/crates/project/src/direnv.rs +++ b/crates/project/src/direnv.rs @@ -65,7 +65,7 @@ pub async fn load_direnv_environment( let output = String::from_utf8_lossy(&direnv_output.stdout); if output.is_empty() { // direnv outputs nothing when it has no changes to apply to environment variables - return Ok(HashMap::new()); + return Ok(HashMap::default()); } match serde_json::from_str(&output) { diff --git a/crates/settings/src/settings_content.rs b/crates/settings/src/settings_content.rs index 8f279e5e4db2bfd2d17d78d7de4d8a550dd848e2..6e128e50b52958e8e24feb699ee9541782556574 100644 --- a/crates/settings/src/settings_content.rs +++ b/crates/settings/src/settings_content.rs @@ -3,11 +3,13 @@ mod language; mod project; mod terminal; mod theme; +mod workspace; pub use agent::*; pub use language::*; pub use project::*; pub use terminal::*; pub use theme::*; +pub use workspace::*; use collections::HashMap; use gpui::{App, SharedString}; @@ -31,6 +33,13 @@ pub struct SettingsContent { #[serde(flatten)] pub extension: ExtensionSettingsContent, + #[serde(flatten)] + pub workspace: WorkspaceSettingsContent, + + pub tabs: Option, + + pub preview_tabs: Option, + pub agent: Option, pub agent_servers: Option, diff --git a/crates/settings/src/settings_content/workspace.rs b/crates/settings/src/settings_content/workspace.rs new file mode 100644 index 0000000000000000000000000000000000000000..c9ecd867c4b56907c7ee189dcfe5f79aebabcc12 --- /dev/null +++ b/crates/settings/src/settings_content/workspace.rs @@ -0,0 +1,305 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema)] +pub struct WorkspaceSettingsContent { + /// Active pane styling settings. + pub active_pane_modifiers: Option, + /// Layout mode for the bottom dock + /// + /// Default: contained + pub bottom_dock_layout: Option, + /// Direction to split horizontally. + /// + /// Default: "up" + pub pane_split_direction_horizontal: Option, + /// Direction to split vertically. + /// + /// Default: "left" + pub pane_split_direction_vertical: Option, + /// Centered layout related settings. + pub centered_layout: Option, + /// Whether or not to prompt the user to confirm before closing the application. + /// + /// Default: false + pub confirm_quit: Option, + /// Whether or not to show the call status icon in the status bar. + /// + /// Default: true + pub show_call_status_icon: Option, + /// When to automatically save edited buffers. + /// + /// Default: off + pub autosave: Option, + /// Controls previous session restoration in freshly launched Zed instance. + /// Values: none, last_workspace, last_session + /// Default: last_session + pub restore_on_startup: Option, + /// Whether to attempt to restore previous file's state when opening it again. + /// The state is stored per pane. + /// When disabled, defaults are applied instead of the state restoration. + /// + /// E.g. for editors, selections, folds and scroll positions are restored, if the same file is closed and, later, opened again in the same pane. + /// When disabled, a single selection in the very beginning of the file, zero scroll position and no folds state is used as a default. + /// + /// Default: true + pub restore_on_file_reopen: Option, + /// The size of the workspace split drop targets on the outer edges. + /// Given as a fraction that will be multiplied by the smaller dimension of the workspace. + /// + /// Default: `0.2` (20% of the smaller dimension of the workspace) + pub drop_target_size: Option, + /// Whether to close the window when using 'close active item' on a workspace with no tabs + /// + /// Default: auto ("on" on macOS, "off" otherwise) + pub when_closing_with_no_tabs: Option, + /// Whether to use the system provided dialogs for Open and Save As. + /// When set to false, Zed will use the built-in keyboard-first pickers. + /// + /// Default: true + pub use_system_path_prompts: Option, + /// Whether to use the system provided prompts. + /// When set to false, Zed will use the built-in prompts. + /// Note that this setting has no effect on Linux, where Zed will always + /// use the built-in prompts. + /// + /// Default: true + pub use_system_prompts: Option, + /// Aliases for the command palette. When you type a key in this map, + /// it will be assumed to equal the value. + /// + /// Default: true + pub command_aliases: Option>, + /// Maximum open tabs in a pane. Will not close an unsaved + /// tab. Set to `None` for unlimited tabs. + /// + /// Default: none + pub max_tabs: Option, + /// What to do when the last window is closed + /// + /// Default: auto (nothing on macOS, "app quit" otherwise) + pub on_last_window_closed: Option, + /// Whether to resize all the panels in a dock when resizing the dock. + /// + /// Default: ["left"] + pub resize_all_panels_in_dock: Option>, + /// Whether to automatically close files that have been deleted on disk. + /// + /// Default: false + pub close_on_file_delete: Option, + /// Whether to allow windows to tab together based on the user’s tabbing preference (macOS only). + /// + /// Default: false + pub use_system_window_tabs: Option, + /// Whether to show padding for zoomed panels. + /// When enabled, zoomed bottom panels will have some top padding, + /// while zoomed left/right panels will have padding to the right/left (respectively). + /// + /// Default: true + pub zoomed_padding: Option, +} + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] +pub struct ItemSettingsContent { + /// Whether to show the Git file status on a tab item. + /// + /// Default: false + pub git_status: Option, + /// Position of the close button in a tab. + /// + /// Default: right + pub close_position: Option, + /// Whether to show the file icon for a tab. + /// + /// Default: false + pub file_icons: Option, + /// What to do after closing the current tab. + /// + /// Default: history + pub activate_on_close: Option, + /// Which files containing diagnostic errors/warnings to mark in the tabs. + /// This setting can take the following three values: + /// + /// Default: off + pub show_diagnostics: Option, + /// Whether to always show the close button on tabs. + /// + /// Default: false + pub show_close_button: Option, +} + +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)] +pub struct PreviewTabsSettingsContent { + /// Whether to show opened editors as preview tabs. + /// Preview tabs do not stay open, are reused until explicitly set to be kept open opened (via double-click or editing) and show file names in italic. + /// + /// Default: true + pub enabled: Option, + /// Whether to open tabs in preview mode when selected from the file finder. + /// + /// Default: false + pub enable_preview_from_file_finder: Option, + /// Whether a preview tab gets replaced when code navigation is used to navigate away from the tab. + /// + /// Default: false + pub enable_preview_from_code_navigation: Option, +} + +#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "lowercase")] +pub enum ClosePosition { + Left, + #[default] + Right, +} + +#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "lowercase")] +pub enum ShowCloseButton { + Always, + #[default] + Hover, + Hidden, +} + +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] +#[serde(rename_all = "snake_case")] +pub enum ShowDiagnostics { + #[default] + Off, + Errors, + All, +} + +#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum ActivateOnClose { + #[default] + History, + Neighbour, + LeftNeighbour, +} + +#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct ActivePanelModifiers { + /// Size of the border surrounding the active pane. + /// When set to 0, the active pane doesn't have any border. + /// The border is drawn inset. + /// + /// Default: `0.0` + pub border_size: Option, + /// Opacity of inactive panels. + /// When set to 1.0, the inactive panes have the same opacity as the active one. + /// If set to 0, the inactive panes content will not be visible at all. + /// Values are clamped to the [0.0, 1.0] range. + /// + /// Default: `1.0` + pub inactive_opacity: Option, +} + +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum BottomDockLayout { + /// Contained between the left and right docks + #[default] + Contained, + /// Takes up the full width of the window + Full, + /// Extends under the left dock while snapping to the right dock + LeftAligned, + /// Extends under the right dock while snapping to the left dock + RightAligned, +} + +#[derive(Copy, Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum CloseWindowWhenNoItems { + /// Match platform conventions by default, so "on" on macOS and "off" everywhere else + #[default] + PlatformDefault, + /// Close the window when there are no tabs + CloseWindow, + /// Leave the window open when there are no tabs + KeepWindowOpen, +} + +impl CloseWindowWhenNoItems { + pub fn should_close(&self) -> bool { + match self { + CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"), + CloseWindowWhenNoItems::CloseWindow => true, + CloseWindowWhenNoItems::KeepWindowOpen => false, + } + } +} + +#[derive(Copy, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum RestoreOnStartupBehavior { + /// Always start with an empty editor + None, + /// Restore the workspace that was closed last. + LastWorkspace, + /// Restore all workspaces that were open when quitting Zed. + #[default] + LastSession, +} + +#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] +pub struct TabBarSettingsContent { + /// Whether or not to show the tab bar in the editor. + /// + /// Default: true + pub show: Option, + /// Whether or not to show the navigation history buttons in the tab bar. + /// + /// Default: true + pub show_nav_history_buttons: Option, + /// Whether or not to show the tab bar buttons. + /// + /// Default: true + pub show_tab_bar_buttons: Option, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum AutosaveSetting { + /// Disable autosave. + Off, + /// Save after inactivity period of `milliseconds`. + AfterDelay { milliseconds: u64 }, + /// Autosave when focus changes. + OnFocusChange, + /// Autosave when the active window changes. + OnWindowChange, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum PaneSplitDirectionHorizontal { + Up, + Down, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum PaneSplitDirectionVertical { + Left, + Right, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, SettingsUi)] +#[serde(rename_all = "snake_case")] +pub struct CenteredLayoutSettings { + /// The relative width of the left padding of the central pane from the + /// workspace when the centered layout is used. + /// + /// Default: 0.2 + pub left_padding: Option, + // The relative width of the right padding of the central pane from the + // workspace when the centered layout is used. + /// + /// Default: 0.2 + pub right_padding: Option, +} diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index 23fbec470c4d2e305bf7b51679bbe56f6dfeaa95..055859bec395445de91978397905d2162723fce2 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -15,9 +15,9 @@ use gpui::{ Focusable, Font, HighlightStyle, Pixels, Point, Render, SharedString, Task, WeakEntity, Window, }; use project::{Project, ProjectEntryId, ProjectPath}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use settings::{Settings, SettingsKey, SettingsLocation, SettingsSources, SettingsUi}; +use settings::{ + ActivateOnClose, ClosePosition, Settings, SettingsLocation, ShowCloseButton, ShowDiagnostics, +}; use smallvec::SmallVec; use std::{ any::{Any, TypeId}, @@ -30,7 +30,7 @@ use std::{ }; use theme::Theme; use ui::{Color, Icon, IntoElement, Label, LabelCommon}; -use util::ResultExt; +use util::{MergeFrom as _, ResultExt}; pub const LEADER_UPDATE_THROTTLE: Duration = Duration::from_millis(200); @@ -49,7 +49,6 @@ impl Default for SaveOptions { } } -#[derive(Deserialize)] pub struct ItemSettings { pub git_status: bool, pub close_position: ClosePosition, @@ -59,150 +58,120 @@ pub struct ItemSettings { pub show_close_button: ShowCloseButton, } -#[derive(Deserialize)] pub struct PreviewTabsSettings { pub enabled: bool, pub enable_preview_from_file_finder: bool, pub enable_preview_from_code_navigation: bool, } -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "lowercase")] -pub enum ClosePosition { - Left, - #[default] - Right, -} - -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "lowercase")] -pub enum ShowCloseButton { - Always, - #[default] - Hover, - Hidden, -} - -#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] -#[serde(rename_all = "snake_case")] -pub enum ShowDiagnostics { - #[default] - Off, - Errors, - All, -} - -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ActivateOnClose { - #[default] - History, - Neighbour, - LeftNeighbour, -} - -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, SettingsUi, SettingsKey)] -#[settings_key(key = "tabs")] -pub struct ItemSettingsContent { - /// Whether to show the Git file status on a tab item. - /// - /// Default: false - git_status: Option, - /// Position of the close button in a tab. - /// - /// Default: right - close_position: Option, - /// Whether to show the file icon for a tab. - /// - /// Default: false - file_icons: Option, - /// What to do after closing the current tab. - /// - /// Default: history - pub activate_on_close: Option, - /// Which files containing diagnostic errors/warnings to mark in the tabs. - /// This setting can take the following three values: - /// - /// Default: off - show_diagnostics: Option, - /// Whether to always show the close button on tabs. - /// - /// Default: false - show_close_button: Option, -} - -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, SettingsUi, SettingsKey)] -#[settings_key(key = "preview_tabs")] -pub struct PreviewTabsSettingsContent { - /// Whether to show opened editors as preview tabs. - /// Preview tabs do not stay open, are reused until explicitly set to be kept open opened (via double-click or editing) and show file names in italic. - /// - /// Default: true - enabled: Option, - /// Whether to open tabs in preview mode when selected from the file finder. - /// - /// Default: false - enable_preview_from_file_finder: Option, - /// Whether a preview tab gets replaced when code navigation is used to navigate away from the tab. - /// - /// Default: false - enable_preview_from_code_navigation: Option, -} - impl Settings for ItemSettings { - type FileContent = ItemSettingsContent; + fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self { + let tabs = content.tabs.as_ref().unwrap(); + Self { + git_status: tabs.git_status.unwrap(), + close_position: tabs.close_position.unwrap(), + activate_on_close: tabs.activate_on_close.unwrap(), + file_icons: tabs.file_icons.unwrap(), + show_diagnostics: tabs.show_diagnostics.unwrap(), + show_close_button: tabs.show_close_button.unwrap(), + } + } - fn load(sources: SettingsSources, _: &mut App) -> Result { - sources.json_merge() + fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) { + let Some(tabs) = content.tabs.as_ref() else { + return; + }; + self.git_status.merge_from(&tabs.git_status); + self.close_position.merge_from(&tabs.close_position); + self.activate_on_close.merge_from(&tabs.activate_on_close); + self.file_icons.merge_from(&tabs.file_icons); + self.show_diagnostics.merge_from(&tabs.show_diagnostics); + self.show_close_button.merge_from(&tabs.show_close_button); } - fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) { + fn import_from_vscode( + vscode: &settings::VsCodeSettings, + current: &mut settings::SettingsContent, + ) { if let Some(b) = vscode.read_bool("workbench.editor.tabActionCloseVisibility") { - current.show_close_button = Some(if b { + current.tabs.get_or_insert_default().show_close_button = Some(if b { ShowCloseButton::Always } else { ShowCloseButton::Hidden }) } - vscode.enum_setting( - "workbench.editor.tabActionLocation", - &mut current.close_position, - |s| match s { - "right" => Some(ClosePosition::Right), - "left" => Some(ClosePosition::Left), - _ => None, - }, - ); + if let Some(s) = vscode.read_enum_setting("workbench.editor.tabActionLocation", |s| match s + { + "right" => Some(ClosePosition::Right), + "left" => Some(ClosePosition::Left), + _ => None, + }) { + current.tabs.get_or_insert_default().close_position = Some(s) + } if let Some(b) = vscode.read_bool("workbench.editor.focusRecentEditorAfterClose") { - current.activate_on_close = Some(if b { + current.tabs.get_or_insert_default().activate_on_close = Some(if b { ActivateOnClose::History } else { ActivateOnClose::LeftNeighbour }) } - vscode.bool_setting("workbench.editor.showIcons", &mut current.file_icons); - vscode.bool_setting("git.decorations.enabled", &mut current.git_status); + if let Some(b) = vscode.read_bool("workbench.editor.showIcons") { + current.tabs.get_or_insert_default().file_icons = Some(b); + }; + if let Some(b) = vscode.read_bool("git.decorations.enabled") { + current.tabs.get_or_insert_default().git_status = Some(b); + } } } impl Settings for PreviewTabsSettings { - type FileContent = PreviewTabsSettingsContent; - - fn load(sources: SettingsSources, _: &mut App) -> Result { - sources.json_merge() - } - - fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) { - vscode.bool_setting("workbench.editor.enablePreview", &mut current.enabled); - vscode.bool_setting( - "workbench.editor.enablePreviewFromCodeNavigation", - &mut current.enable_preview_from_code_navigation, - ); - vscode.bool_setting( - "workbench.editor.enablePreviewFromQuickOpen", - &mut current.enable_preview_from_file_finder, - ); + fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self { + let preview_tabs = content.preview_tabs.as_ref().unwrap(); + Self { + enabled: preview_tabs.enabled.unwrap(), + enable_preview_from_file_finder: preview_tabs.enable_preview_from_file_finder.unwrap(), + enable_preview_from_code_navigation: preview_tabs + .enable_preview_from_code_navigation + .unwrap(), + } + } + + fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) { + let Some(preview_tabs) = content.preview_tabs.as_ref() else { + return; + }; + + self.enabled.merge_from(&preview_tabs.enabled); + self.enable_preview_from_file_finder + .merge_from(&preview_tabs.enable_preview_from_file_finder); + self.enable_preview_from_code_navigation + .merge_from(&preview_tabs.enable_preview_from_code_navigation); + } + + fn import_from_vscode( + vscode: &settings::VsCodeSettings, + current: &mut settings::SettingsContent, + ) { + if let Some(enabled) = vscode.read_bool("workbench.editor.enablePreview") { + current.preview_tabs.get_or_insert_default().enabled = Some(enabled); + } + if let Some(enable_preview_from_code_navigation) = + vscode.read_bool("workbench.editor.enablePreviewFromCodeNavigation") + { + current + .preview_tabs + .get_or_insert_default() + .enable_preview_from_code_navigation = Some(enable_preview_from_code_navigation) + } + if let Some(enable_preview_from_file_finder) = + vscode.read_bool("workbench.editor.enablePreviewFromQuickOpen") + { + current + .preview_tabs + .get_or_insert_default() + .enable_preview_from_file_finder = Some(enable_preview_from_file_finder) + } } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 23d611964c3cd1b0284521c9444b6952748a5db9..34aa0da8896fd66b00ffa7a5ce9c32ec74dd8b99 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -9889,8 +9889,8 @@ mod tests { // Enable the close_on_file_delete setting cx.update_global(|store: &mut SettingsStore, cx| { - store.update_user_settings::(cx, |settings| { - settings.close_on_file_delete = Some(true); + store.update_user_settings(cx, |settings| { + settings.tabs.get_or_insert_default().close_on_file_delete = Some(true); }); }); diff --git a/crates/workspace/src/workspace_settings.rs b/crates/workspace/src/workspace_settings.rs index 8868f3190575ac4b861e0619732890f477d83b69..4108bec78384d49ecfbff83e5cbc2f6edcc11368 100644 --- a/crates/workspace/src/workspace_settings.rs +++ b/crates/workspace/src/workspace_settings.rs @@ -52,237 +52,12 @@ impl OnLastWindowClosed { } } -#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct ActivePanelModifiers { - /// Size of the border surrounding the active pane. - /// When set to 0, the active pane doesn't have any border. - /// The border is drawn inset. - /// - /// Default: `0.0` - pub border_size: Option, - /// Opacity of inactive panels. - /// When set to 1.0, the inactive panes have the same opacity as the active one. - /// If set to 0, the inactive panes content will not be visible at all. - /// Values are clamped to the [0.0, 1.0] range. - /// - /// Default: `1.0` - pub inactive_opacity: Option, -} - -#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum BottomDockLayout { - /// Contained between the left and right docks - #[default] - Contained, - /// Takes up the full width of the window - Full, - /// Extends under the left dock while snapping to the right dock - LeftAligned, - /// Extends under the right dock while snapping to the left dock - RightAligned, -} - -#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum CloseWindowWhenNoItems { - /// Match platform conventions by default, so "on" on macOS and "off" everywhere else - #[default] - PlatformDefault, - /// Close the window when there are no tabs - CloseWindow, - /// Leave the window open when there are no tabs - KeepWindowOpen, -} - -impl CloseWindowWhenNoItems { - pub fn should_close(&self) -> bool { - match self { - CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"), - CloseWindowWhenNoItems::CloseWindow => true, - CloseWindowWhenNoItems::KeepWindowOpen => false, - } - } -} - -#[derive(Copy, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum RestoreOnStartupBehavior { - /// Always start with an empty editor - None, - /// Restore the workspace that was closed last. - LastWorkspace, - /// Restore all workspaces that were open when quitting Zed. - #[default] - LastSession, -} - -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, SettingsUi, SettingsKey)] -#[settings_key(None)] -pub struct WorkspaceSettingsContent { - /// Active pane styling settings. - pub active_pane_modifiers: Option, - /// Layout mode for the bottom dock - /// - /// Default: contained - pub bottom_dock_layout: Option, - /// Direction to split horizontally. - /// - /// Default: "up" - pub pane_split_direction_horizontal: Option, - /// Direction to split vertically. - /// - /// Default: "left" - pub pane_split_direction_vertical: Option, - /// Centered layout related settings. - pub centered_layout: Option, - /// Whether or not to prompt the user to confirm before closing the application. - /// - /// Default: false - pub confirm_quit: Option, - /// Whether or not to show the call status icon in the status bar. - /// - /// Default: true - pub show_call_status_icon: Option, - /// When to automatically save edited buffers. - /// - /// Default: off - pub autosave: Option, - /// Controls previous session restoration in freshly launched Zed instance. - /// Values: none, last_workspace, last_session - /// Default: last_session - pub restore_on_startup: Option, - /// Whether to attempt to restore previous file's state when opening it again. - /// The state is stored per pane. - /// When disabled, defaults are applied instead of the state restoration. - /// - /// E.g. for editors, selections, folds and scroll positions are restored, if the same file is closed and, later, opened again in the same pane. - /// When disabled, a single selection in the very beginning of the file, zero scroll position and no folds state is used as a default. - /// - /// Default: true - pub restore_on_file_reopen: Option, - /// The size of the workspace split drop targets on the outer edges. - /// Given as a fraction that will be multiplied by the smaller dimension of the workspace. - /// - /// Default: `0.2` (20% of the smaller dimension of the workspace) - pub drop_target_size: Option, - /// Whether to close the window when using 'close active item' on a workspace with no tabs - /// - /// Default: auto ("on" on macOS, "off" otherwise) - pub when_closing_with_no_tabs: Option, - /// Whether to use the system provided dialogs for Open and Save As. - /// When set to false, Zed will use the built-in keyboard-first pickers. - /// - /// Default: true - pub use_system_path_prompts: Option, - /// Whether to use the system provided prompts. - /// When set to false, Zed will use the built-in prompts. - /// Note that this setting has no effect on Linux, where Zed will always - /// use the built-in prompts. - /// - /// Default: true - pub use_system_prompts: Option, - /// Aliases for the command palette. When you type a key in this map, - /// it will be assumed to equal the value. - /// - /// Default: true - pub command_aliases: Option>, - /// Maximum open tabs in a pane. Will not close an unsaved - /// tab. Set to `None` for unlimited tabs. - /// - /// Default: none - pub max_tabs: Option, - /// What to do when the last window is closed - /// - /// Default: auto (nothing on macOS, "app quit" otherwise) - pub on_last_window_closed: Option, - /// Whether to resize all the panels in a dock when resizing the dock. - /// - /// Default: ["left"] - pub resize_all_panels_in_dock: Option>, - /// Whether to automatically close files that have been deleted on disk. - /// - /// Default: false - pub close_on_file_delete: Option, - /// Whether to allow windows to tab together based on the user’s tabbing preference (macOS only). - /// - /// Default: false - pub use_system_window_tabs: Option, - /// Whether to show padding for zoomed panels. - /// When enabled, zoomed bottom panels will have some top padding, - /// while zoomed left/right panels will have padding to the right/left (respectively). - /// - /// Default: true - pub zoomed_padding: Option, -} - #[derive(Deserialize)] pub struct TabBarSettings { pub show: bool, pub show_nav_history_buttons: bool, pub show_tab_bar_buttons: bool, } - -#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, SettingsUi, SettingsKey)] -#[settings_key(key = "tab_bar")] -pub struct TabBarSettingsContent { - /// Whether or not to show the tab bar in the editor. - /// - /// Default: true - pub show: Option, - /// Whether or not to show the navigation history buttons in the tab bar. - /// - /// Default: true - pub show_nav_history_buttons: Option, - /// Whether or not to show the tab bar buttons. - /// - /// Default: true - pub show_tab_bar_buttons: Option, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum AutosaveSetting { - /// Disable autosave. - Off, - /// Save after inactivity period of `milliseconds`. - AfterDelay { milliseconds: u64 }, - /// Autosave when focus changes. - OnFocusChange, - /// Autosave when the active window changes. - OnWindowChange, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum PaneSplitDirectionHorizontal { - Up, - Down, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum PaneSplitDirectionVertical { - Left, - Right, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, SettingsUi)] -#[serde(rename_all = "snake_case")] -pub struct CenteredLayoutSettings { - /// The relative width of the left padding of the central pane from the - /// workspace when the centered layout is used. - /// - /// Default: 0.2 - pub left_padding: Option, - // The relative width of the right padding of the central pane from the - // workspace when the centered layout is used. - /// - /// Default: 0.2 - pub right_padding: Option, -} - impl Settings for WorkspaceSettings { type FileContent = WorkspaceSettingsContent;