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