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}
 17
 18#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
 19#[serde(rename_all = "snake_case")]
 20pub enum RestoreOnStartupBehaviour {
 21    /// Always start with an empty editor
 22    None,
 23    /// Restore the workspace that was closed last.
 24    #[default]
 25    LastWorkspace,
 26}
 27
 28#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
 29pub struct WorkspaceSettingsContent {
 30    /// Scale by which to zoom the active pane.
 31    /// When set to 1.0, the active pane has the same size as others,
 32    /// but when set to a larger value, the active pane takes up more space.
 33    ///
 34    /// Default: `1.0`
 35    pub active_pane_magnification: Option<f32>,
 36    // Centered layout related settings.
 37    pub centered_layout: Option<CenteredLayoutSettings>,
 38    /// Whether or not to prompt the user to confirm before closing the application.
 39    ///
 40    /// Default: false
 41    pub confirm_quit: Option<bool>,
 42    /// Whether or not to show the call status icon in the status bar.
 43    ///
 44    /// Default: true
 45    pub show_call_status_icon: Option<bool>,
 46    /// When to automatically save edited buffers.
 47    ///
 48    /// Default: off
 49    pub autosave: Option<AutosaveSetting>,
 50    /// Controls previous session restoration in freshly launched Zed instance.
 51    /// Values: none, last_workspace
 52    /// Default: last_workspace
 53    pub restore_on_startup: Option<RestoreOnStartupBehaviour>,
 54    /// The size of the workspace split drop targets on the outer edges.
 55    /// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
 56    ///
 57    /// Default: `0.2` (20% of the smaller dimension of the workspace)
 58    pub drop_target_size: Option<f32>,
 59}
 60
 61#[derive(Deserialize)]
 62pub struct TabBarSettings {
 63    pub show: bool,
 64    pub show_nav_history_buttons: bool,
 65}
 66
 67#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
 68pub struct TabBarSettingsContent {
 69    /// Whether or not to show the tab bar in the editor.
 70    ///
 71    /// Default: top
 72    pub show: Option<bool>,
 73    /// Whether or not to show the navigation history buttons in the tab bar.
 74    ///
 75    /// Default: true
 76    pub show_nav_history_buttons: Option<bool>,
 77}
 78
 79#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 80#[serde(rename_all = "snake_case")]
 81pub enum AutosaveSetting {
 82    /// Disable autosave.
 83    Off,
 84    /// Save after inactivity period of `milliseconds`.
 85    AfterDelay { milliseconds: u64 },
 86    /// Autosave when focus changes.
 87    OnFocusChange,
 88    /// Autosave when the active window changes.
 89    OnWindowChange,
 90}
 91
 92#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
 93#[serde(rename_all = "snake_case")]
 94pub struct CenteredLayoutSettings {
 95    /// The relative width of the left padding of the central pane from the
 96    /// workspace when the centered layout is used.
 97    ///
 98    /// Default: 0.2
 99    pub left_padding: Option<f32>,
100    // The relative width of the right padding of the central pane from the
101    // workspace when the centered layout is used.
102    ///
103    /// Default: 0.2
104    pub right_padding: Option<f32>,
105}
106
107impl Settings for WorkspaceSettings {
108    const KEY: Option<&'static str> = None;
109
110    type FileContent = WorkspaceSettingsContent;
111
112    fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
113        sources.json_merge()
114    }
115}
116
117impl Settings for TabBarSettings {
118    const KEY: Option<&'static str> = Some("tab_bar");
119
120    type FileContent = TabBarSettingsContent;
121
122    fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
123        sources.json_merge()
124    }
125}