1use editor::EditorSettings;
2use gpui::{App, Pixels};
3pub use settings::{DockSide, Settings, ShowIndentGuides};
4use ui::scrollbars::{ScrollbarVisibility, ShowScrollbar};
5use util::MergeFrom;
6
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub struct OutlinePanelSettings {
9 pub button: bool,
10 pub default_width: Pixels,
11 pub dock: DockSide,
12 pub file_icons: bool,
13 pub folder_icons: bool,
14 pub git_status: bool,
15 pub indent_size: f32,
16 pub indent_guides: IndentGuidesSettings,
17 pub auto_reveal_entries: bool,
18 pub auto_fold_dirs: bool,
19 pub scrollbar: ScrollbarSettings,
20 pub expand_outlines_with_depth: usize,
21}
22
23#[derive(Copy, Clone, Debug, PartialEq, Eq)]
24pub struct ScrollbarSettings {
25 /// When to show the scrollbar in the project panel.
26 ///
27 /// Default: inherits editor scrollbar settings
28 pub show: Option<ShowScrollbar>,
29}
30
31#[derive(Copy, Clone, Debug, PartialEq, Eq)]
32pub struct IndentGuidesSettings {
33 pub show: ShowIndentGuides,
34}
35
36impl ScrollbarVisibility for OutlinePanelSettings {
37 fn visibility(&self, cx: &App) -> ShowScrollbar {
38 self.scrollbar
39 .show
40 .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
41 }
42}
43
44impl Settings for OutlinePanelSettings {
45 fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
46 let panel = content.outline_panel.as_ref().unwrap();
47 Self {
48 button: panel.button.unwrap(),
49 default_width: panel.default_width.map(gpui::px).unwrap(),
50 dock: panel.dock.unwrap(),
51 file_icons: panel.file_icons.unwrap(),
52 folder_icons: panel.folder_icons.unwrap(),
53 git_status: panel.git_status.unwrap(),
54 indent_size: panel.indent_size.unwrap(),
55 indent_guides: IndentGuidesSettings {
56 show: panel.indent_guides.unwrap().show.unwrap(),
57 },
58 auto_reveal_entries: panel.auto_reveal_entries.unwrap(),
59 auto_fold_dirs: panel.auto_fold_dirs.unwrap(),
60 scrollbar: ScrollbarSettings {
61 show: panel.scrollbar.unwrap().show.flatten().map(Into::into),
62 },
63 expand_outlines_with_depth: panel.expand_outlines_with_depth.unwrap(),
64 }
65 }
66
67 fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
68 let Some(panel) = content.outline_panel.as_ref() else {
69 return;
70 };
71
72 self.button.merge_from(&panel.button);
73 self.default_width
74 .merge_from(&panel.default_width.map(Pixels::from));
75 self.dock.merge_from(&panel.dock);
76 self.file_icons.merge_from(&panel.file_icons);
77 self.folder_icons.merge_from(&panel.folder_icons);
78 self.git_status.merge_from(&panel.git_status);
79 self.indent_size.merge_from(&panel.indent_size);
80
81 if let Some(indent_guides) = panel.indent_guides.as_ref() {
82 self.indent_guides.show.merge_from(&indent_guides.show);
83 }
84
85 self.auto_reveal_entries
86 .merge_from(&panel.auto_reveal_entries);
87 self.auto_fold_dirs.merge_from(&panel.auto_fold_dirs);
88
89 if let Some(scrollbar) = panel.scrollbar.as_ref()
90 && let Some(show) = scrollbar.show.flatten()
91 {
92 self.scrollbar.show = Some(show.into())
93 }
94 }
95 fn import_from_vscode(
96 vscode: &settings::VsCodeSettings,
97 current: &mut settings::SettingsContent,
98 ) {
99 if let Some(b) = vscode.read_bool("outline.icons") {
100 let outline_panel = current.outline_panel.get_or_insert_default();
101 outline_panel.file_icons = Some(b);
102 outline_panel.folder_icons = Some(b);
103 }
104
105 if let Some(b) = vscode.read_bool("git.decorations.enabled") {
106 let outline_panel = current.outline_panel.get_or_insert_default();
107 outline_panel.git_status = Some(b);
108 }
109 }
110}