project_panel_settings.rs

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