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