1use gpui::Pixels;
2use schemars::JsonSchema;
3use serde_derive::{Deserialize, Serialize};
4use settings::{Settings, SettingsSources};
5
6#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Copy, PartialEq)]
7#[serde(rename_all = "snake_case")]
8pub enum ProjectPanelDockPosition {
9 Left,
10 Right,
11}
12
13#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
14pub struct ProjectPanelSettings {
15 pub button: bool,
16 pub default_width: Pixels,
17 pub dock: ProjectPanelDockPosition,
18 pub file_icons: bool,
19 pub folder_icons: bool,
20 pub git_status: bool,
21 pub indent_size: f32,
22 pub auto_reveal_entries: bool,
23 pub auto_fold_dirs: bool,
24 pub scrollbar: ScrollbarSettings,
25}
26
27/// When to show the scrollbar in the project panel.
28///
29/// Default: always
30#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
31#[serde(rename_all = "snake_case")]
32pub enum ShowScrollbar {
33 #[default]
34 /// Always show the scrollbar.
35 Always,
36 /// Never show the scrollbar.
37 Never,
38}
39
40#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
41pub struct ScrollbarSettings {
42 /// When to show the scrollbar in the project panel.
43 ///
44 /// Default: always
45 pub show: ShowScrollbar,
46}
47
48#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
49pub struct ScrollbarSettingsContent {
50 /// When to show the scrollbar in the project panel.
51 ///
52 /// Default: always
53 pub show: Option<ShowScrollbar>,
54}
55
56#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
57pub struct ProjectPanelSettingsContent {
58 /// Whether to show the project panel button in the status bar.
59 ///
60 /// Default: true
61 pub button: Option<bool>,
62 /// Customize default width (in pixels) taken by project panel
63 ///
64 /// Default: 240
65 pub default_width: Option<f32>,
66 /// The position of project panel
67 ///
68 /// Default: left
69 pub dock: Option<ProjectPanelDockPosition>,
70 /// Whether to show file icons in the project panel.
71 ///
72 /// Default: true
73 pub file_icons: Option<bool>,
74 /// Whether to show folder icons or chevrons for directories in the project panel.
75 ///
76 /// Default: true
77 pub folder_icons: Option<bool>,
78 /// Whether to show the git status in the project panel.
79 ///
80 /// Default: true
81 pub git_status: Option<bool>,
82 /// Amount of indentation (in pixels) for nested items.
83 ///
84 /// Default: 20
85 pub indent_size: Option<f32>,
86 /// Whether to reveal it in the project panel automatically,
87 /// when a corresponding project entry becomes active.
88 /// Gitignored entries are never auto revealed.
89 ///
90 /// Default: true
91 pub auto_reveal_entries: Option<bool>,
92 /// Whether to fold directories automatically
93 /// when directory has only one directory inside.
94 ///
95 /// Default: false
96 pub auto_fold_dirs: Option<bool>,
97 /// Scrollbar-related settings
98 pub scrollbar: Option<ScrollbarSettingsContent>,
99}
100
101impl Settings for ProjectPanelSettings {
102 const KEY: Option<&'static str> = Some("project_panel");
103
104 type FileContent = ProjectPanelSettingsContent;
105
106 fn load(
107 sources: SettingsSources<Self::FileContent>,
108 _: &mut gpui::AppContext,
109 ) -> anyhow::Result<Self> {
110 sources.json_merge()
111 }
112}