1use editor::EditorSettings;
2use gpui::Pixels;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use settings::{
6 DockSide, ProjectPanelEntrySpacing, Settings, SettingsContent, ShowDiagnostics,
7 ShowIndentGuides,
8};
9use ui::{
10 px,
11 scrollbars::{ScrollbarVisibility, ShowScrollbar},
12};
13
14#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
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 drag_and_drop: bool,
34}
35
36#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
37pub struct IndentGuidesSettings {
38 pub show: ShowIndentGuides,
39}
40
41#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
42pub struct ScrollbarSettings {
43 /// When to show the scrollbar in the project panel.
44 ///
45 /// Default: inherits editor scrollbar settings
46 pub show: Option<ShowScrollbar>,
47}
48
49impl ScrollbarVisibility for ProjectPanelSettings {
50 fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
51 self.scrollbar
52 .show
53 .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
54 }
55}
56
57impl Settings for ProjectPanelSettings {
58 fn from_settings(content: &settings::SettingsContent) -> Self {
59 let project_panel = content.project_panel.clone().unwrap();
60 Self {
61 button: project_panel.button.unwrap(),
62 hide_gitignore: project_panel.hide_gitignore.unwrap(),
63 default_width: px(project_panel.default_width.unwrap()),
64 dock: project_panel.dock.unwrap(),
65 entry_spacing: project_panel.entry_spacing.unwrap(),
66 file_icons: project_panel.file_icons.unwrap(),
67 folder_icons: project_panel.folder_icons.unwrap(),
68 git_status: project_panel.git_status.unwrap(),
69 indent_size: project_panel.indent_size.unwrap(),
70 indent_guides: IndentGuidesSettings {
71 show: project_panel.indent_guides.unwrap().show.unwrap(),
72 },
73 sticky_scroll: project_panel.sticky_scroll.unwrap(),
74 auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
75 auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
76 starts_open: project_panel.starts_open.unwrap(),
77 scrollbar: ScrollbarSettings {
78 show: project_panel.scrollbar.unwrap().show.map(Into::into),
79 },
80 show_diagnostics: project_panel.show_diagnostics.unwrap(),
81 hide_root: project_panel.hide_root.unwrap(),
82 drag_and_drop: project_panel.drag_and_drop.unwrap(),
83 }
84 }
85
86 fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut SettingsContent) {
87 if let Some(hide_gitignore) = vscode.read_bool("explorer.excludeGitIgnore") {
88 current.project_panel.get_or_insert_default().hide_gitignore = Some(hide_gitignore);
89 }
90 if let Some(auto_reveal) = vscode.read_bool("explorer.autoReveal") {
91 current
92 .project_panel
93 .get_or_insert_default()
94 .auto_reveal_entries = Some(auto_reveal);
95 }
96 if let Some(compact_folders) = vscode.read_bool("explorer.compactFolders") {
97 current.project_panel.get_or_insert_default().auto_fold_dirs = Some(compact_folders);
98 }
99
100 if Some(false) == vscode.read_bool("git.decorations.enabled") {
101 current.project_panel.get_or_insert_default().git_status = Some(false);
102 }
103 if Some(false) == vscode.read_bool("problems.decorations.enabled") {
104 current
105 .project_panel
106 .get_or_insert_default()
107 .show_diagnostics = Some(ShowDiagnostics::Off);
108 }
109 if let (Some(false), Some(false)) = (
110 vscode.read_bool("explorer.decorations.badges"),
111 vscode.read_bool("explorer.decorations.colors"),
112 ) {
113 current.project_panel.get_or_insert_default().git_status = Some(false);
114 current
115 .project_panel
116 .get_or_insert_default()
117 .show_diagnostics = Some(ShowDiagnostics::Off);
118 }
119 }
120}