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_nav_history_buttons: bool,
64}
65
66#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
67pub struct TabBarSettingsContent {
68 /// Whether or not to show the navigation history buttons in the tab bar.
69 ///
70 /// Default: true
71 pub show_nav_history_buttons: Option<bool>,
72}
73
74#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
75#[serde(rename_all = "snake_case")]
76pub enum AutosaveSetting {
77 /// Disable autosave.
78 Off,
79 /// Save after inactivity period of `milliseconds`.
80 AfterDelay { milliseconds: u64 },
81 /// Autosave when focus changes.
82 OnFocusChange,
83 /// Autosave when the active window changes.
84 OnWindowChange,
85}
86
87#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
88#[serde(rename_all = "snake_case")]
89pub struct CenteredLayoutSettings {
90 /// The relative width of the left padding of the central pane from the
91 /// workspace when the centered layout is used.
92 ///
93 /// Default: 0.2
94 pub left_padding: Option<f32>,
95 // The relative width of the right padding of the central pane from the
96 // workspace when the centered layout is used.
97 ///
98 /// Default: 0.2
99 pub right_padding: Option<f32>,
100}
101
102impl Settings for WorkspaceSettings {
103 const KEY: Option<&'static str> = None;
104
105 type FileContent = WorkspaceSettingsContent;
106
107 fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
108 sources.json_merge()
109 }
110}
111
112impl Settings for TabBarSettings {
113 const KEY: Option<&'static str> = Some("tab_bar");
114
115 type FileContent = TabBarSettingsContent;
116
117 fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
118 sources.json_merge()
119 }
120}