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 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
84impl ScrollbarVisibility for ProjectPanelSettings {
85 fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
86 self.scrollbar
87 .show
88 .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
89 }
90}
91
92impl Settings for ProjectPanelSettings {
93 fn from_settings(content: &settings::SettingsContent) -> Self {
94 let project_panel = content.project_panel.clone().unwrap();
95 Self {
96 button: project_panel.button.unwrap(),
97 hide_gitignore: project_panel.hide_gitignore.unwrap(),
98 default_width: px(project_panel.default_width.unwrap()),
99 dock: project_panel.dock.unwrap(),
100 entry_spacing: project_panel.entry_spacing.unwrap(),
101 file_icons: project_panel.file_icons.unwrap(),
102 folder_icons: project_panel.folder_icons.unwrap(),
103 git_status: project_panel.git_status.unwrap()
104 && content
105 .git
106 .as_ref()
107 .unwrap()
108 .enabled
109 .unwrap()
110 .is_git_status_enabled(),
111 indent_size: project_panel.indent_size.unwrap(),
112 indent_guides: IndentGuidesSettings {
113 show: project_panel.indent_guides.unwrap().show.unwrap(),
114 },
115 sticky_scroll: project_panel.sticky_scroll.unwrap(),
116 auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
117 auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
118 bold_folder_labels: project_panel.bold_folder_labels.unwrap(),
119 starts_open: project_panel.starts_open.unwrap(),
120 scrollbar: {
121 let scrollbar = project_panel.scrollbar.unwrap();
122 ScrollbarSettings {
123 show: scrollbar.show.map(Into::into),
124 horizontal_scroll: scrollbar.horizontal_scroll.unwrap(),
125 }
126 },
127 show_diagnostics: project_panel.show_diagnostics.unwrap(),
128 hide_root: project_panel.hide_root.unwrap(),
129 hide_hidden: project_panel.hide_hidden.unwrap(),
130 drag_and_drop: project_panel.drag_and_drop.unwrap(),
131 auto_open: {
132 let auto_open = project_panel.auto_open.unwrap();
133 AutoOpenSettings {
134 on_create: auto_open.on_create.unwrap(),
135 on_paste: auto_open.on_paste.unwrap(),
136 on_drop: auto_open.on_drop.unwrap(),
137 }
138 },
139 sort_mode: project_panel.sort_mode.unwrap(),
140 diagnostic_badges: project_panel.diagnostic_badges.unwrap(),
141 git_status_indicator: project_panel.git_status_indicator.unwrap(),
142 }
143 }
144}