1use editor::EditorSettings;
  2use gpui::Pixels;
  3use schemars::JsonSchema;
  4use serde::{Deserialize, Serialize};
  5use settings::{
  6    DockSide, ProjectPanelEntrySpacing, Settings, SettingsContent, ShowDiagnostics,
  7    ShowIndentGuides,
  8};
  9use ui::{
 10    px,
 11    scrollbars::{ScrollbarVisibility, ShowScrollbar},
 12};
 13
 14#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
 15pub struct ProjectPanelSettings {
 16    pub button: bool,
 17    pub hide_gitignore: bool,
 18    pub default_width: Pixels,
 19    pub dock: DockSide,
 20    pub entry_spacing: ProjectPanelEntrySpacing,
 21    pub file_icons: bool,
 22    pub folder_icons: bool,
 23    pub git_status: bool,
 24    pub indent_size: f32,
 25    pub indent_guides: IndentGuidesSettings,
 26    pub sticky_scroll: bool,
 27    pub auto_reveal_entries: bool,
 28    pub auto_fold_dirs: bool,
 29    pub starts_open: bool,
 30    pub scrollbar: ScrollbarSettings,
 31    pub show_diagnostics: ShowDiagnostics,
 32    pub hide_root: bool,
 33    pub hide_hidden: bool,
 34    pub drag_and_drop: bool,
 35}
 36
 37#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 38pub struct IndentGuidesSettings {
 39    pub show: ShowIndentGuides,
 40}
 41
 42#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 43pub struct ScrollbarSettings {
 44    /// When to show the scrollbar in the project panel.
 45    ///
 46    /// Default: inherits editor scrollbar settings
 47    pub show: Option<ShowScrollbar>,
 48}
 49
 50impl ScrollbarVisibility for ProjectPanelSettings {
 51    fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
 52        self.scrollbar
 53            .show
 54            .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
 55    }
 56}
 57
 58impl Settings for ProjectPanelSettings {
 59    fn from_settings(content: &settings::SettingsContent) -> Self {
 60        let project_panel = content.project_panel.clone().unwrap();
 61        Self {
 62            button: project_panel.button.unwrap(),
 63            hide_gitignore: project_panel.hide_gitignore.unwrap(),
 64            default_width: px(project_panel.default_width.unwrap()),
 65            dock: project_panel.dock.unwrap(),
 66            entry_spacing: project_panel.entry_spacing.unwrap(),
 67            file_icons: project_panel.file_icons.unwrap(),
 68            folder_icons: project_panel.folder_icons.unwrap(),
 69            git_status: project_panel.git_status.unwrap(),
 70            indent_size: project_panel.indent_size.unwrap(),
 71            indent_guides: IndentGuidesSettings {
 72                show: project_panel.indent_guides.unwrap().show.unwrap(),
 73            },
 74            sticky_scroll: project_panel.sticky_scroll.unwrap(),
 75            auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
 76            auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
 77            starts_open: project_panel.starts_open.unwrap(),
 78            scrollbar: ScrollbarSettings {
 79                show: project_panel.scrollbar.unwrap().show.map(Into::into),
 80            },
 81            show_diagnostics: project_panel.show_diagnostics.unwrap(),
 82            hide_root: project_panel.hide_root.unwrap(),
 83            hide_hidden: project_panel.hide_hidden.unwrap(),
 84            drag_and_drop: project_panel.drag_and_drop.unwrap(),
 85        }
 86    }
 87
 88    fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut SettingsContent) {
 89        if let Some(hide_gitignore) = vscode.read_bool("explorer.excludeGitIgnore") {
 90            current.project_panel.get_or_insert_default().hide_gitignore = Some(hide_gitignore);
 91        }
 92        if let Some(auto_reveal) = vscode.read_bool("explorer.autoReveal") {
 93            current
 94                .project_panel
 95                .get_or_insert_default()
 96                .auto_reveal_entries = Some(auto_reveal);
 97        }
 98        if let Some(compact_folders) = vscode.read_bool("explorer.compactFolders") {
 99            current.project_panel.get_or_insert_default().auto_fold_dirs = Some(compact_folders);
100        }
101
102        if Some(false) == vscode.read_bool("git.decorations.enabled") {
103            current.project_panel.get_or_insert_default().git_status = Some(false);
104        }
105        if Some(false) == vscode.read_bool("problems.decorations.enabled") {
106            current
107                .project_panel
108                .get_or_insert_default()
109                .show_diagnostics = Some(ShowDiagnostics::Off);
110        }
111        if let (Some(false), Some(false)) = (
112            vscode.read_bool("explorer.decorations.badges"),
113            vscode.read_bool("explorer.decorations.colors"),
114        ) {
115            current.project_panel.get_or_insert_default().git_status = Some(false);
116            current
117                .project_panel
118                .get_or_insert_default()
119                .show_diagnostics = Some(ShowDiagnostics::Off);
120        }
121    }
122}