workspace_settings.rs

  1use anyhow::Result;
  2use collections::HashMap;
  3use gpui::AppContext;
  4use schemars::JsonSchema;
  5use serde::{Deserialize, Serialize};
  6use settings::{Settings, SettingsSources};
  7
  8#[derive(Deserialize)]
  9pub struct WorkspaceSettings {
 10    pub active_pane_magnification: f32,
 11    pub pane_split_direction_horizontal: PaneSplitDirectionHorizontal,
 12    pub pane_split_direction_vertical: PaneSplitDirectionVertical,
 13    pub centered_layout: CenteredLayoutSettings,
 14    pub confirm_quit: bool,
 15    pub show_call_status_icon: bool,
 16    pub autosave: AutosaveSetting,
 17    pub restore_on_startup: RestoreOnStartupBehavior,
 18    pub drop_target_size: f32,
 19    pub when_closing_with_no_tabs: CloseWindowWhenNoItems,
 20    pub use_system_path_prompts: bool,
 21    pub command_aliases: HashMap<String, String>,
 22}
 23
 24#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
 25#[serde(rename_all = "snake_case")]
 26pub enum CloseWindowWhenNoItems {
 27    /// Match platform conventions by default, so "on" on macOS and "off" everywhere else
 28    #[default]
 29    PlatformDefault,
 30    /// Close the window when there are no tabs
 31    CloseWindow,
 32    /// Leave the window open when there are no tabs
 33    KeepWindowOpen,
 34}
 35
 36impl CloseWindowWhenNoItems {
 37    pub fn should_close(&self) -> bool {
 38        match self {
 39            CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
 40            CloseWindowWhenNoItems::CloseWindow => true,
 41            CloseWindowWhenNoItems::KeepWindowOpen => false,
 42        }
 43    }
 44}
 45
 46#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
 47#[serde(rename_all = "snake_case")]
 48pub enum RestoreOnStartupBehavior {
 49    /// Always start with an empty editor
 50    None,
 51    /// Restore the workspace that was closed last.
 52    LastWorkspace,
 53    /// Restore all workspaces that were open when quitting Zed.
 54    #[default]
 55    LastSession,
 56}
 57
 58#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
 59pub struct WorkspaceSettingsContent {
 60    /// Scale by which to zoom the active pane.
 61    /// When set to 1.0, the active pane has the same size as others,
 62    /// but when set to a larger value, the active pane takes up more space.
 63    ///
 64    /// Default: `1.0`
 65    pub active_pane_magnification: Option<f32>,
 66    // Direction to split horizontally.
 67    //
 68    // Default: "up"
 69    pub pane_split_direction_horizontal: Option<PaneSplitDirectionHorizontal>,
 70    // Direction to split vertically.
 71    //
 72    // Default: "left"
 73    pub pane_split_direction_vertical: Option<PaneSplitDirectionVertical>,
 74    // Centered layout related settings.
 75    pub centered_layout: Option<CenteredLayoutSettings>,
 76    /// Whether or not to prompt the user to confirm before closing the application.
 77    ///
 78    /// Default: false
 79    pub confirm_quit: Option<bool>,
 80    /// Whether or not to show the call status icon in the status bar.
 81    ///
 82    /// Default: true
 83    pub show_call_status_icon: Option<bool>,
 84    /// When to automatically save edited buffers.
 85    ///
 86    /// Default: off
 87    pub autosave: Option<AutosaveSetting>,
 88    /// Controls previous session restoration in freshly launched Zed instance.
 89    /// Values: none, last_workspace, last_session
 90    /// Default: last_session
 91    pub restore_on_startup: Option<RestoreOnStartupBehavior>,
 92    /// The size of the workspace split drop targets on the outer edges.
 93    /// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
 94    ///
 95    /// Default: `0.2` (20% of the smaller dimension of the workspace)
 96    pub drop_target_size: Option<f32>,
 97    /// Whether to close the window when using 'close active item' on a workspace with no tabs
 98    ///
 99    /// Default: auto ("on" on macOS, "off" otherwise)
100    pub when_closing_with_no_tabs: Option<CloseWindowWhenNoItems>,
101    /// Whether to use the system provided dialogs for Open and Save As.
102    /// When set to false, Zed will use the built-in keyboard-first pickers.
103    ///
104    /// Default: true
105    pub use_system_path_prompts: Option<bool>,
106    /// Aliases for the command palette. When you type a key in this map,
107    /// it will be assumed to equal the value.
108    ///
109    /// Default: true
110    pub command_aliases: Option<HashMap<String, String>>,
111}
112
113#[derive(Deserialize)]
114pub struct TabBarSettings {
115    pub show: bool,
116    pub show_nav_history_buttons: bool,
117}
118
119#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
120pub struct TabBarSettingsContent {
121    /// Whether or not to show the tab bar in the editor.
122    ///
123    /// Default: true
124    pub show: Option<bool>,
125    /// Whether or not to show the navigation history buttons in the tab bar.
126    ///
127    /// Default: true
128    pub show_nav_history_buttons: Option<bool>,
129}
130
131#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
132#[serde(rename_all = "snake_case")]
133pub enum AutosaveSetting {
134    /// Disable autosave.
135    Off,
136    /// Save after inactivity period of `milliseconds`.
137    AfterDelay { milliseconds: u64 },
138    /// Autosave when focus changes.
139    OnFocusChange,
140    /// Autosave when the active window changes.
141    OnWindowChange,
142}
143
144#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
145#[serde(rename_all = "snake_case")]
146pub enum PaneSplitDirectionHorizontal {
147    Up,
148    Down,
149}
150
151#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
152#[serde(rename_all = "snake_case")]
153pub enum PaneSplitDirectionVertical {
154    Left,
155    Right,
156}
157
158#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
159#[serde(rename_all = "snake_case")]
160pub struct CenteredLayoutSettings {
161    /// The relative width of the left padding of the central pane from the
162    /// workspace when the centered layout is used.
163    ///
164    /// Default: 0.2
165    pub left_padding: Option<f32>,
166    // The relative width of the right padding of the central pane from the
167    // workspace when the centered layout is used.
168    ///
169    /// Default: 0.2
170    pub right_padding: Option<f32>,
171}
172
173impl Settings for WorkspaceSettings {
174    const KEY: Option<&'static str> = None;
175
176    type FileContent = WorkspaceSettingsContent;
177
178    fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
179        sources.json_merge()
180    }
181}
182
183impl Settings for TabBarSettings {
184    const KEY: Option<&'static str> = Some("tab_bar");
185
186    type FileContent = TabBarSettingsContent;
187
188    fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
189        sources.json_merge()
190    }
191}