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