1use editor::{EditorSettings, ui_scrollbar_settings_from_raw};
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 pub diagnostic_badges: bool,
39 pub git_status_indicator: bool,
40}
41
42#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
43pub struct IndentGuidesSettings {
44 pub show: ShowIndentGuides,
45}
46
47#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
48pub struct ScrollbarSettings {
49 /// When to show the scrollbar in the project panel.
50 ///
51 /// Default: inherits editor scrollbar settings
52 pub show: Option<ShowScrollbar>,
53 /// Whether to allow horizontal scrolling in the project panel.
54 /// When false, the view is locked to the leftmost position and long file names are clipped.
55 ///
56 /// Default: true
57 pub horizontal_scroll: bool,
58}
59
60#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
61pub struct AutoOpenSettings {
62 pub on_create: bool,
63 pub on_paste: bool,
64 pub on_drop: bool,
65}
66
67impl AutoOpenSettings {
68 #[inline]
69 pub fn should_open_on_create(self) -> bool {
70 self.on_create
71 }
72
73 #[inline]
74 pub fn should_open_on_paste(self) -> bool {
75 self.on_paste
76 }
77
78 #[inline]
79 pub fn should_open_on_drop(self) -> bool {
80 self.on_drop
81 }
82}
83
84#[derive(Default)]
85pub(crate) struct ProjectPanelScrollbarProxy;
86
87impl ScrollbarVisibility for ProjectPanelScrollbarProxy {
88 fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
89 ProjectPanelSettings::get_global(cx)
90 .scrollbar
91 .show
92 .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
93 }
94}
95
96impl Settings for ProjectPanelSettings {
97 fn from_settings(content: &settings::SettingsContent) -> Self {
98 let project_panel = content.project_panel.clone().unwrap();
99 Self {
100 button: project_panel.button.unwrap(),
101 hide_gitignore: project_panel.hide_gitignore.unwrap(),
102 default_width: px(project_panel.default_width.unwrap()),
103 dock: project_panel.dock.unwrap(),
104 entry_spacing: project_panel.entry_spacing.unwrap(),
105 file_icons: project_panel.file_icons.unwrap(),
106 folder_icons: project_panel.folder_icons.unwrap(),
107 git_status: project_panel.git_status.unwrap()
108 && content
109 .git
110 .as_ref()
111 .unwrap()
112 .enabled
113 .unwrap()
114 .is_git_status_enabled(),
115 indent_size: project_panel.indent_size.unwrap(),
116 indent_guides: IndentGuidesSettings {
117 show: project_panel.indent_guides.unwrap().show.unwrap(),
118 },
119 sticky_scroll: project_panel.sticky_scroll.unwrap(),
120 auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
121 auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
122 bold_folder_labels: project_panel.bold_folder_labels.unwrap(),
123 starts_open: project_panel.starts_open.unwrap(),
124 scrollbar: {
125 let scrollbar = project_panel.scrollbar.unwrap();
126 ScrollbarSettings {
127 show: scrollbar.show.map(ui_scrollbar_settings_from_raw),
128 horizontal_scroll: scrollbar.horizontal_scroll.unwrap(),
129 }
130 },
131 show_diagnostics: project_panel.show_diagnostics.unwrap(),
132 hide_root: project_panel.hide_root.unwrap(),
133 hide_hidden: project_panel.hide_hidden.unwrap(),
134 drag_and_drop: project_panel.drag_and_drop.unwrap(),
135 auto_open: {
136 let auto_open = project_panel.auto_open.unwrap();
137 AutoOpenSettings {
138 on_create: auto_open.on_create.unwrap(),
139 on_paste: auto_open.on_paste.unwrap(),
140 on_drop: auto_open.on_drop.unwrap(),
141 }
142 },
143 sort_mode: project_panel.sort_mode.unwrap(),
144 diagnostic_badges: project_panel.diagnostic_badges.unwrap(),
145 git_status_indicator: project_panel.git_status_indicator.unwrap(),
146 }
147 }
148}