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