1use editor::EditorSettings;
2use gpui::{App, Pixels};
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
6use ui::scrollbars::{ScrollbarVisibility, ShowScrollbar};
7
8#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Copy, PartialEq)]
9#[serde(rename_all = "snake_case")]
10pub enum OutlinePanelDockPosition {
11 Left,
12 Right,
13}
14
15#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
16#[serde(rename_all = "snake_case")]
17pub enum ShowIndentGuides {
18 Always,
19 Never,
20}
21
22#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
23pub struct OutlinePanelSettings {
24 pub button: bool,
25 pub default_width: Pixels,
26 pub dock: OutlinePanelDockPosition,
27 pub file_icons: bool,
28 pub folder_icons: bool,
29 pub git_status: bool,
30 pub indent_size: f32,
31 pub indent_guides: IndentGuidesSettings,
32 pub auto_reveal_entries: bool,
33 pub auto_fold_dirs: bool,
34 pub scrollbar: ScrollbarSettings,
35 pub expand_outlines_with_depth: usize,
36}
37
38#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
39pub struct ScrollbarSettings {
40 /// When to show the scrollbar in the project panel.
41 ///
42 /// Default: inherits editor scrollbar settings
43 pub show: Option<ShowScrollbar>,
44}
45
46#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
47pub struct ScrollbarSettingsContent {
48 /// When to show the scrollbar in the project panel.
49 ///
50 /// Default: inherits editor scrollbar settings
51 pub show: Option<Option<ShowScrollbar>>,
52}
53
54#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
55pub struct IndentGuidesSettings {
56 pub show: ShowIndentGuides,
57}
58
59#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
60pub struct IndentGuidesSettingsContent {
61 /// When to show the scrollbar in the outline panel.
62 pub show: Option<ShowIndentGuides>,
63}
64
65#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, SettingsUi, SettingsKey)]
66#[settings_key(key = "outline_panel")]
67pub struct OutlinePanelSettingsContent {
68 /// Whether to show the outline panel button in the status bar.
69 ///
70 /// Default: true
71 pub button: Option<bool>,
72 /// Customize default width (in pixels) taken by outline panel
73 ///
74 /// Default: 240
75 pub default_width: Option<f32>,
76 /// The position of outline panel
77 ///
78 /// Default: left
79 pub dock: Option<OutlinePanelDockPosition>,
80 /// Whether to show file icons in the outline panel.
81 ///
82 /// Default: true
83 pub file_icons: Option<bool>,
84 /// Whether to show folder icons or chevrons for directories in the outline panel.
85 ///
86 /// Default: true
87 pub folder_icons: Option<bool>,
88 /// Whether to show the git status in the outline panel.
89 ///
90 /// Default: true
91 pub git_status: Option<bool>,
92 /// Amount of indentation (in pixels) for nested items.
93 ///
94 /// Default: 20
95 pub indent_size: Option<f32>,
96 /// Whether to reveal it in the outline panel automatically,
97 /// when a corresponding project entry becomes active.
98 /// Gitignored entries are never auto revealed.
99 ///
100 /// Default: true
101 pub auto_reveal_entries: Option<bool>,
102 /// Whether to fold directories automatically
103 /// when directory has only one directory inside.
104 ///
105 /// Default: true
106 pub auto_fold_dirs: Option<bool>,
107 /// Settings related to indent guides in the outline panel.
108 pub indent_guides: Option<IndentGuidesSettingsContent>,
109 /// Scrollbar-related settings
110 pub scrollbar: Option<ScrollbarSettingsContent>,
111 /// Default depth to expand outline items in the current file.
112 /// The default depth to which outline entries are expanded on reveal.
113 /// - Set to 0 to collapse all items that have children
114 /// - Set to 1 or higher to collapse items at that depth or deeper
115 ///
116 /// Default: 100
117 pub expand_outlines_with_depth: Option<usize>,
118}
119
120impl ScrollbarVisibility for OutlinePanelSettings {
121 fn visibility(&self, cx: &App) -> ShowScrollbar {
122 self.scrollbar
123 .show
124 .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
125 }
126}
127
128impl Settings for OutlinePanelSettings {
129 type FileContent = OutlinePanelSettingsContent;
130
131 fn load(
132 sources: SettingsSources<Self::FileContent>,
133 _: &mut gpui::App,
134 ) -> anyhow::Result<Self> {
135 sources.json_merge()
136 }
137
138 fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
139 if let Some(b) = vscode.read_bool("outline.icons") {
140 current.file_icons = Some(b);
141 current.folder_icons = Some(b);
142 }
143
144 vscode.bool_setting("git.decorations.enabled", &mut current.git_status);
145 }
146}