project_panel_settings.rs

 1use anyhow;
 2use gpui::Pixels;
 3use schemars::JsonSchema;
 4use serde_derive::{Deserialize, Serialize};
 5use settings::{Settings, SettingsSources};
 6
 7#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Copy, PartialEq)]
 8#[serde(rename_all = "snake_case")]
 9pub enum ProjectPanelDockPosition {
10    Left,
11    Right,
12}
13
14#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
15pub struct ProjectPanelSettings {
16    pub default_width: Pixels,
17    pub dock: ProjectPanelDockPosition,
18    pub file_icons: bool,
19    pub folder_icons: bool,
20    pub git_status: bool,
21    pub indent_size: f32,
22    pub auto_reveal_entries: bool,
23    pub auto_fold_dirs: bool,
24}
25
26#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
27pub struct ProjectPanelSettingsContent {
28    /// Customise default width (in pixels) taken by project panel
29    ///
30    /// Default: 240
31    pub default_width: Option<f32>,
32    /// The position of project panel
33    ///
34    /// Default: left
35    pub dock: Option<ProjectPanelDockPosition>,
36    /// Whether to show file icons in the project panel.
37    ///
38    /// Default: true
39    pub file_icons: Option<bool>,
40    /// Whether to show folder icons or chevrons for directories in the project panel.
41    ///
42    /// Default: true
43    pub folder_icons: Option<bool>,
44    /// Whether to show the git status in the project panel.
45    ///
46    /// Default: true
47    pub git_status: Option<bool>,
48    /// Amount of indentation (in pixels) for nested items.
49    ///
50    /// Default: 20
51    pub indent_size: Option<f32>,
52    /// Whether to reveal it in the project panel automatically,
53    /// when a corresponding project entry becomes active.
54    /// Gitignored entries are never auto revealed.
55    ///
56    /// Default: true
57    pub auto_reveal_entries: Option<bool>,
58    /// Whether to fold directories automatically
59    /// when directory has only one directory inside.
60    ///
61    /// Default: false
62    pub auto_fold_dirs: Option<bool>,
63}
64
65impl Settings for ProjectPanelSettings {
66    const KEY: Option<&'static str> = Some("project_panel");
67
68    type FileContent = ProjectPanelSettingsContent;
69
70    fn load(
71        sources: SettingsSources<Self::FileContent>,
72        _: &mut gpui::AppContext,
73    ) -> anyhow::Result<Self> {
74        sources.json_merge()
75    }
76}