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