workspace_settings.rs

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