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 button: bool,
 17    pub default_width: Pixels,
 18    pub dock: ProjectPanelDockPosition,
 19    pub file_icons: bool,
 20    pub folder_icons: bool,
 21    pub git_status: bool,
 22    pub indent_size: f32,
 23    pub auto_reveal_entries: bool,
 24    pub auto_fold_dirs: bool,
 25    pub scrollbar: ScrollbarSettings,
 26}
 27
 28/// When to show the scrollbar in the project panel.
 29///
 30/// Default: always
 31#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 32#[serde(rename_all = "snake_case")]
 33pub enum ShowScrollbar {
 34    #[default]
 35    /// Always show the scrollbar.
 36    Always,
 37    /// Never show the scrollbar.
 38    Never,
 39}
 40
 41#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 42pub struct ScrollbarSettings {
 43    /// When to show the scrollbar in the project panel.
 44    ///
 45    /// Default: always
 46    pub show: ShowScrollbar,
 47}
 48
 49#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 50pub struct ScrollbarSettingsContent {
 51    /// When to show the scrollbar in the project panel.
 52    ///
 53    /// Default: always
 54    pub show: Option<ShowScrollbar>,
 55}
 56
 57#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
 58pub struct ProjectPanelSettingsContent {
 59    /// Whether to show the project panel button in the status bar.
 60    ///
 61    /// Default: true
 62    pub button: Option<bool>,
 63    /// Customize default width (in pixels) taken by project panel
 64    ///
 65    /// Default: 240
 66    pub default_width: Option<f32>,
 67    /// The position of project panel
 68    ///
 69    /// Default: left
 70    pub dock: Option<ProjectPanelDockPosition>,
 71    /// Whether to show file icons in the project panel.
 72    ///
 73    /// Default: true
 74    pub file_icons: Option<bool>,
 75    /// Whether to show folder icons or chevrons for directories in the project panel.
 76    ///
 77    /// Default: true
 78    pub folder_icons: Option<bool>,
 79    /// Whether to show the git status in the project panel.
 80    ///
 81    /// Default: true
 82    pub git_status: Option<bool>,
 83    /// Amount of indentation (in pixels) for nested items.
 84    ///
 85    /// Default: 20
 86    pub indent_size: Option<f32>,
 87    /// Whether to reveal it in the project panel automatically,
 88    /// when a corresponding project entry becomes active.
 89    /// Gitignored entries are never auto revealed.
 90    ///
 91    /// Default: true
 92    pub auto_reveal_entries: Option<bool>,
 93    /// Whether to fold directories automatically
 94    /// when directory has only one directory inside.
 95    ///
 96    /// Default: false
 97    pub auto_fold_dirs: Option<bool>,
 98    /// Scrollbar-related settings
 99    pub scrollbar: Option<ScrollbarSettingsContent>,
100}
101
102impl Settings for ProjectPanelSettings {
103    const KEY: Option<&'static str> = Some("project_panel");
104
105    type FileContent = ProjectPanelSettingsContent;
106
107    fn load(
108        sources: SettingsSources<Self::FileContent>,
109        _: &mut gpui::AppContext,
110    ) -> anyhow::Result<Self> {
111        sources.json_merge()
112    }
113}