workspace.rs

  1use std::num::NonZeroUsize;
  2
  3use collections::HashMap;
  4use schemars::JsonSchema;
  5use serde::{Deserialize, Serialize};
  6
  7use crate::DockPosition;
  8
  9#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
 10pub struct WorkspaceSettingsContent {
 11    /// Active pane styling settings.
 12    pub active_pane_modifiers: Option<ActivePanelModifiers>,
 13    /// Layout mode for the bottom dock
 14    ///
 15    /// Default: contained
 16    pub bottom_dock_layout: Option<BottomDockLayout>,
 17    /// Direction to split horizontally.
 18    ///
 19    /// Default: "up"
 20    pub pane_split_direction_horizontal: Option<PaneSplitDirectionHorizontal>,
 21    /// Direction to split vertically.
 22    ///
 23    /// Default: "left"
 24    pub pane_split_direction_vertical: Option<PaneSplitDirectionVertical>,
 25    /// Centered layout related settings.
 26    pub centered_layout: Option<CenteredLayoutSettings>,
 27    /// Whether or not to prompt the user to confirm before closing the application.
 28    ///
 29    /// Default: false
 30    pub confirm_quit: Option<bool>,
 31    /// Whether or not to show the call status icon in the status bar.
 32    ///
 33    /// Default: true
 34    pub show_call_status_icon: Option<bool>,
 35    /// When to automatically save edited buffers.
 36    ///
 37    /// Default: off
 38    pub autosave: Option<AutosaveSetting>,
 39    /// Controls previous session restoration in freshly launched Zed instance.
 40    /// Values: none, last_workspace, last_session
 41    /// Default: last_session
 42    pub restore_on_startup: Option<RestoreOnStartupBehavior>,
 43    /// Whether to attempt to restore previous file's state when opening it again.
 44    /// The state is stored per pane.
 45    /// When disabled, defaults are applied instead of the state restoration.
 46    ///
 47    /// E.g. for editors, selections, folds and scroll positions are restored, if the same file is closed and, later, opened again in the same pane.
 48    /// When disabled, a single selection in the very beginning of the file, zero scroll position and no folds state is used as a default.
 49    ///
 50    /// Default: true
 51    pub restore_on_file_reopen: Option<bool>,
 52    /// The size of the workspace split drop targets on the outer edges.
 53    /// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
 54    ///
 55    /// Default: `0.2` (20% of the smaller dimension of the workspace)
 56    pub drop_target_size: Option<f32>,
 57    /// Whether to close the window when using 'close active item' on a workspace with no tabs
 58    ///
 59    /// Default: auto ("on" on macOS, "off" otherwise)
 60    pub when_closing_with_no_tabs: Option<CloseWindowWhenNoItems>,
 61    /// Whether to use the system provided dialogs for Open and Save As.
 62    /// When set to false, Zed will use the built-in keyboard-first pickers.
 63    ///
 64    /// Default: true
 65    pub use_system_path_prompts: Option<bool>,
 66    /// Whether to use the system provided prompts.
 67    /// When set to false, Zed will use the built-in prompts.
 68    /// Note that this setting has no effect on Linux, where Zed will always
 69    /// use the built-in prompts.
 70    ///
 71    /// Default: true
 72    pub use_system_prompts: Option<bool>,
 73    /// Aliases for the command palette. When you type a key in this map,
 74    /// it will be assumed to equal the value.
 75    ///
 76    /// Default: true
 77    #[serde(default)]
 78    pub command_aliases: HashMap<String, String>,
 79    /// Maximum open tabs in a pane. Will not close an unsaved
 80    /// tab. Set to `None` for unlimited tabs.
 81    ///
 82    /// Default: none
 83    pub max_tabs: Option<NonZeroUsize>,
 84    /// What to do when the last window is closed
 85    ///
 86    /// Default: auto (nothing on macOS, "app quit" otherwise)
 87    pub on_last_window_closed: Option<OnLastWindowClosed>,
 88    /// Whether to resize all the panels in a dock when resizing the dock.
 89    ///
 90    /// Default: ["left"]
 91    #[serde(default)]
 92    pub resize_all_panels_in_dock: Vec<DockPosition>,
 93    /// Whether to automatically close files that have been deleted on disk.
 94    ///
 95    /// Default: false
 96    pub close_on_file_delete: Option<bool>,
 97    /// Whether to allow windows to tab together based on the user’s tabbing preference (macOS only).
 98    ///
 99    /// Default: false
100    pub use_system_window_tabs: Option<bool>,
101    /// Whether to show padding for zoomed panels.
102    /// When enabled, zoomed bottom panels will have some top padding,
103    /// while zoomed left/right panels will have padding to the right/left (respectively).
104    ///
105    /// Default: true
106    pub zoomed_padding: Option<bool>,
107
108    // Settings related to the editor's tab bar.
109    pub tab_bar: Option<TabBarSettingsContent>,
110
111    pub tabs: Option<ItemSettingsContent>,
112}
113
114#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
115pub struct ItemSettingsContent {
116    /// Whether to show the Git file status on a tab item.
117    ///
118    /// Default: false
119    pub git_status: Option<bool>,
120    /// Position of the close button in a tab.
121    ///
122    /// Default: right
123    pub close_position: Option<ClosePosition>,
124    /// Whether to show the file icon for a tab.
125    ///
126    /// Default: false
127    pub file_icons: Option<bool>,
128    /// What to do after closing the current tab.
129    ///
130    /// Default: history
131    pub activate_on_close: Option<ActivateOnClose>,
132    /// Which files containing diagnostic errors/warnings to mark in the tabs.
133    /// This setting can take the following three values:
134    ///
135    /// Default: off
136    pub show_diagnostics: Option<ShowDiagnostics>,
137    /// Whether to always show the close button on tabs.
138    ///
139    /// Default: false
140    pub show_close_button: Option<ShowCloseButton>,
141}
142
143#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
144pub struct PreviewTabsSettingsContent {
145    /// Whether to show opened editors as preview tabs.
146    /// Preview tabs do not stay open, are reused until explicitly set to be kept open opened (via double-click or editing) and show file names in italic.
147    ///
148    /// Default: true
149    pub enabled: Option<bool>,
150    /// Whether to open tabs in preview mode when selected from the file finder.
151    ///
152    /// Default: false
153    pub enable_preview_from_file_finder: Option<bool>,
154    /// Whether a preview tab gets replaced when code navigation is used to navigate away from the tab.
155    ///
156    /// Default: false
157    pub enable_preview_from_code_navigation: Option<bool>,
158}
159
160#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
161#[serde(rename_all = "lowercase")]
162pub enum ClosePosition {
163    Left,
164    #[default]
165    Right,
166}
167
168#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
169#[serde(rename_all = "lowercase")]
170pub enum ShowCloseButton {
171    Always,
172    #[default]
173    Hover,
174    Hidden,
175}
176
177#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
178#[serde(rename_all = "snake_case")]
179pub enum ShowDiagnostics {
180    #[default]
181    Off,
182    Errors,
183    All,
184}
185
186#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
187#[serde(rename_all = "snake_case")]
188pub enum ActivateOnClose {
189    #[default]
190    History,
191    Neighbour,
192    LeftNeighbour,
193}
194
195#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema)]
196#[serde(rename_all = "snake_case")]
197pub struct ActivePanelModifiers {
198    /// Size of the border surrounding the active pane.
199    /// When set to 0, the active pane doesn't have any border.
200    /// The border is drawn inset.
201    ///
202    /// Default: `0.0`
203    pub border_size: Option<f32>,
204    /// Opacity of inactive panels.
205    /// When set to 1.0, the inactive panes have the same opacity as the active one.
206    /// If set to 0, the inactive panes content will not be visible at all.
207    /// Values are clamped to the [0.0, 1.0] range.
208    ///
209    /// Default: `1.0`
210    pub inactive_opacity: Option<f32>,
211}
212
213#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, JsonSchema)]
214#[serde(rename_all = "snake_case")]
215pub enum BottomDockLayout {
216    /// Contained between the left and right docks
217    #[default]
218    Contained,
219    /// Takes up the full width of the window
220    Full,
221    /// Extends under the left dock while snapping to the right dock
222    LeftAligned,
223    /// Extends under the right dock while snapping to the left dock
224    RightAligned,
225}
226
227#[derive(Copy, Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
228#[serde(rename_all = "snake_case")]
229pub enum CloseWindowWhenNoItems {
230    /// Match platform conventions by default, so "on" on macOS and "off" everywhere else
231    #[default]
232    PlatformDefault,
233    /// Close the window when there are no tabs
234    CloseWindow,
235    /// Leave the window open when there are no tabs
236    KeepWindowOpen,
237}
238
239impl CloseWindowWhenNoItems {
240    pub fn should_close(&self) -> bool {
241        match self {
242            CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
243            CloseWindowWhenNoItems::CloseWindow => true,
244            CloseWindowWhenNoItems::KeepWindowOpen => false,
245        }
246    }
247}
248
249#[derive(Copy, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, Debug)]
250#[serde(rename_all = "snake_case")]
251pub enum RestoreOnStartupBehavior {
252    /// Always start with an empty editor
253    None,
254    /// Restore the workspace that was closed last.
255    LastWorkspace,
256    /// Restore all workspaces that were open when quitting Zed.
257    #[default]
258    LastSession,
259}
260
261#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, PartialEq)]
262pub struct TabBarSettingsContent {
263    /// Whether or not to show the tab bar in the editor.
264    ///
265    /// Default: true
266    pub show: Option<bool>,
267    /// Whether or not to show the navigation history buttons in the tab bar.
268    ///
269    /// Default: true
270    pub show_nav_history_buttons: Option<bool>,
271    /// Whether or not to show the tab bar buttons.
272    ///
273    /// Default: true
274    pub show_tab_bar_buttons: Option<bool>,
275}
276
277#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
278#[serde(rename_all = "snake_case")]
279pub enum AutosaveSetting {
280    /// Disable autosave.
281    Off,
282    /// Save after inactivity period of `milliseconds`.
283    AfterDelay { milliseconds: u64 },
284    /// Autosave when focus changes.
285    OnFocusChange,
286    /// Autosave when the active window changes.
287    OnWindowChange,
288}
289
290#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
291#[serde(rename_all = "snake_case")]
292pub enum PaneSplitDirectionHorizontal {
293    Up,
294    Down,
295}
296
297#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
298#[serde(rename_all = "snake_case")]
299pub enum PaneSplitDirectionVertical {
300    Left,
301    Right,
302}
303
304#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
305#[serde(rename_all = "snake_case")]
306pub struct CenteredLayoutSettings {
307    /// The relative width of the left padding of the central pane from the
308    /// workspace when the centered layout is used.
309    ///
310    /// Default: 0.2
311    pub left_padding: Option<f32>,
312    // The relative width of the right padding of the central pane from the
313    // workspace when the centered layout is used.
314    ///
315    /// Default: 0.2
316    pub right_padding: Option<f32>,
317}
318
319#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Debug)]
320#[serde(rename_all = "snake_case")]
321pub enum OnLastWindowClosed {
322    /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
323    #[default]
324    PlatformDefault,
325    /// Quit the application the last window is closed
326    QuitApp,
327}
328
329impl OnLastWindowClosed {
330    pub fn is_quit_app(&self) -> bool {
331        match self {
332            OnLastWindowClosed::PlatformDefault => false,
333            OnLastWindowClosed::QuitApp => true,
334        }
335    }
336}