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