workspace_settings.rs

 1use schemars::JsonSchema;
 2use serde::{Deserialize, Serialize};
 3use settings::Settings;
 4
 5#[derive(Deserialize)]
 6pub struct WorkspaceSettings {
 7    pub active_pane_magnification: f32,
 8    pub confirm_quit: bool,
 9    pub show_call_status_icon: bool,
10    pub autosave: AutosaveSetting,
11}
12
13#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
14pub struct WorkspaceSettingsContent {
15    /// Scale by which to zoom the active pane.
16    /// When set to 1.0, the active pane has the same size as others,
17    /// but when set to a larger value, the active pane takes up more space.
18    ///
19    /// Default: `1.0`
20    pub active_pane_magnification: Option<f32>,
21    /// Whether or not to prompt the user to confirm before closing the application.
22    ///
23    /// Default: false
24    pub confirm_quit: Option<bool>,
25    /// Whether or not to show the call status icon in the status bar.
26    ///
27    /// Default: true
28    pub show_call_status_icon: Option<bool>,
29    /// When to automatically save edited buffers.
30    ///
31    /// Default: off
32    pub autosave: Option<AutosaveSetting>,
33}
34
35#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
36#[serde(rename_all = "snake_case")]
37pub enum AutosaveSetting {
38    /// Disable autosave.
39    Off,
40    /// Save after inactivity period of `milliseconds`.
41    AfterDelay { milliseconds: u64 },
42    /// Autosave when focus changes.
43    OnFocusChange,
44    /// Autosave when the active window changes.
45    OnWindowChange,
46}
47
48impl Settings for WorkspaceSettings {
49    const KEY: Option<&'static str> = None;
50
51    type FileContent = WorkspaceSettingsContent;
52
53    fn load(
54        default_value: &Self::FileContent,
55        user_values: &[&Self::FileContent],
56        _: &mut gpui::AppContext,
57    ) -> anyhow::Result<Self> {
58        Self::load_via_json_merge(default_value, user_values)
59    }
60}