1use editor::EditorSettings;
2use gpui::Pixels;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use settings::{
6 DockSide, ProjectPanelEntrySpacing, RegisterSetting, Settings, ShowDiagnostics,
7 ShowIndentGuides,
8};
9use ui::{
10 px,
11 scrollbars::{ScrollbarVisibility, ShowScrollbar},
12};
13
14#[derive(Deserialize, Debug, Clone, Copy, PartialEq, RegisterSetting)]
15pub struct ProjectPanelSettings {
16 pub button: bool,
17 pub hide_gitignore: bool,
18 pub default_width: Pixels,
19 pub dock: DockSide,
20 pub entry_spacing: ProjectPanelEntrySpacing,
21 pub file_icons: bool,
22 pub folder_icons: bool,
23 pub git_status: bool,
24 pub indent_size: f32,
25 pub indent_guides: IndentGuidesSettings,
26 pub sticky_scroll: bool,
27 pub auto_reveal_entries: bool,
28 pub auto_fold_dirs: bool,
29 pub starts_open: bool,
30 pub scrollbar: ScrollbarSettings,
31 pub show_diagnostics: ShowDiagnostics,
32 pub hide_root: bool,
33 pub hide_hidden: bool,
34 pub drag_and_drop: bool,
35 pub auto_open: AutoOpenSettings,
36}
37
38#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
39pub struct IndentGuidesSettings {
40 pub show: ShowIndentGuides,
41}
42
43#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
44pub struct ScrollbarSettings {
45 /// When to show the scrollbar in the project panel.
46 ///
47 /// Default: inherits editor scrollbar settings
48 pub show: Option<ShowScrollbar>,
49}
50
51#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
52pub struct AutoOpenSettings {
53 pub on_create: bool,
54 pub on_paste: bool,
55 pub on_drop: bool,
56}
57
58impl AutoOpenSettings {
59 #[inline]
60 pub fn should_open_on_create(self) -> bool {
61 self.on_create
62 }
63
64 #[inline]
65 pub fn should_open_on_paste(self) -> bool {
66 self.on_paste
67 }
68
69 #[inline]
70 pub fn should_open_on_drop(self) -> bool {
71 self.on_drop
72 }
73}
74
75impl ScrollbarVisibility for ProjectPanelSettings {
76 fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
77 self.scrollbar
78 .show
79 .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
80 }
81}
82
83impl Settings for ProjectPanelSettings {
84 fn from_settings(content: &settings::SettingsContent) -> Self {
85 let project_panel = content.project_panel.clone().unwrap();
86 Self {
87 button: project_panel.button.unwrap(),
88 hide_gitignore: project_panel.hide_gitignore.unwrap(),
89 default_width: px(project_panel.default_width.unwrap()),
90 dock: project_panel.dock.unwrap(),
91 entry_spacing: project_panel.entry_spacing.unwrap(),
92 file_icons: project_panel.file_icons.unwrap(),
93 folder_icons: project_panel.folder_icons.unwrap(),
94 git_status: project_panel.git_status.unwrap(),
95 indent_size: project_panel.indent_size.unwrap(),
96 indent_guides: IndentGuidesSettings {
97 show: project_panel.indent_guides.unwrap().show.unwrap(),
98 },
99 sticky_scroll: project_panel.sticky_scroll.unwrap(),
100 auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
101 auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
102 starts_open: project_panel.starts_open.unwrap(),
103 scrollbar: ScrollbarSettings {
104 show: project_panel.scrollbar.unwrap().show.map(Into::into),
105 },
106 show_diagnostics: project_panel.show_diagnostics.unwrap(),
107 hide_root: project_panel.hide_root.unwrap(),
108 hide_hidden: project_panel.hide_hidden.unwrap(),
109 drag_and_drop: project_panel.drag_and_drop.unwrap(),
110 auto_open: {
111 let auto_open = project_panel.auto_open.unwrap();
112 AutoOpenSettings {
113 on_create: auto_open.on_create.unwrap(),
114 on_paste: auto_open.on_paste.unwrap(),
115 on_drop: auto_open.on_drop.unwrap(),
116 }
117 },
118 }
119 }
120}