project_panel_settings.rs

  1use editor::ShowScrollbar;
  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(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 ProjectPanelSettings {
 23    pub button: bool,
 24    pub default_width: Pixels,
 25    pub dock: ProjectPanelDockPosition,
 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 IndentGuidesSettings {
 38    pub show: ShowIndentGuides,
 39}
 40
 41#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 42pub struct IndentGuidesSettingsContent {
 43    /// When to show the scrollbar in the project panel.
 44    pub show: Option<ShowIndentGuides>,
 45}
 46
 47#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 48pub struct ScrollbarSettings {
 49    /// When to show the scrollbar in the project panel.
 50    ///
 51    /// Default: inherits editor scrollbar settings
 52    pub show: Option<ShowScrollbar>,
 53}
 54
 55#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 56pub struct ScrollbarSettingsContent {
 57    /// When to show the scrollbar in the project panel.
 58    ///
 59    /// Default: inherits editor scrollbar settings
 60    pub show: Option<Option<ShowScrollbar>>,
 61}
 62
 63#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
 64pub struct ProjectPanelSettingsContent {
 65    /// Whether to show the project panel button in the status bar.
 66    ///
 67    /// Default: true
 68    pub button: Option<bool>,
 69    /// Customize default width (in pixels) taken by project panel
 70    ///
 71    /// Default: 240
 72    pub default_width: Option<f32>,
 73    /// The position of project panel
 74    ///
 75    /// Default: left
 76    pub dock: Option<ProjectPanelDockPosition>,
 77    /// Whether to show file icons in the project panel.
 78    ///
 79    /// Default: true
 80    pub file_icons: Option<bool>,
 81    /// Whether to show folder icons or chevrons for directories in the project panel.
 82    ///
 83    /// Default: true
 84    pub folder_icons: Option<bool>,
 85    /// Whether to show the git status in the project 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 project 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: false
103    pub auto_fold_dirs: Option<bool>,
104    /// Scrollbar-related settings
105    pub scrollbar: Option<ScrollbarSettingsContent>,
106    /// Settings related to indent guides in the project panel.
107    pub indent_guides: Option<IndentGuidesSettingsContent>,
108}
109
110impl Settings for ProjectPanelSettings {
111    const KEY: Option<&'static str> = Some("project_panel");
112
113    type FileContent = ProjectPanelSettingsContent;
114
115    fn load(
116        sources: SettingsSources<Self::FileContent>,
117        _: &mut gpui::AppContext,
118    ) -> anyhow::Result<Self> {
119        sources.json_merge()
120    }
121}