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