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