outline_panel_settings.rs

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