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