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