project_panel_settings.rs

  1use editor::EditorSettings;
  2use gpui::Pixels;
  3use schemars::JsonSchema;
  4use serde::{Deserialize, Serialize};
  5use settings::{
  6    DockSide, ProjectPanelEntrySpacing, ProjectPanelSortMode, RegisterSetting, Settings,
  7    ShowDiagnostics, ShowIndentGuides,
  8};
  9use ui::{
 10    px,
 11    scrollbars::{ScrollbarVisibility, ShowScrollbar},
 12};
 13
 14#[derive(Deserialize, Debug, Clone, Copy, PartialEq, RegisterSetting)]
 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 auto_open: AutoOpenSettings,
 36    pub sort_mode: ProjectPanelSortMode,
 37}
 38
 39#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 40pub struct IndentGuidesSettings {
 41    pub show: ShowIndentGuides,
 42}
 43
 44#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 45pub struct ScrollbarSettings {
 46    /// When to show the scrollbar in the project panel.
 47    ///
 48    /// Default: inherits editor scrollbar settings
 49    pub show: Option<ShowScrollbar>,
 50}
 51
 52#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 53pub struct AutoOpenSettings {
 54    pub on_create: bool,
 55    pub on_paste: bool,
 56    pub on_drop: bool,
 57}
 58
 59impl AutoOpenSettings {
 60    #[inline]
 61    pub fn should_open_on_create(self) -> bool {
 62        self.on_create
 63    }
 64
 65    #[inline]
 66    pub fn should_open_on_paste(self) -> bool {
 67        self.on_paste
 68    }
 69
 70    #[inline]
 71    pub fn should_open_on_drop(self) -> bool {
 72        self.on_drop
 73    }
 74}
 75
 76impl ScrollbarVisibility for ProjectPanelSettings {
 77    fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
 78        self.scrollbar
 79            .show
 80            .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
 81    }
 82}
 83
 84impl Settings for ProjectPanelSettings {
 85    fn from_settings(content: &settings::SettingsContent) -> Self {
 86        let project_panel = content.project_panel.clone().unwrap();
 87        Self {
 88            button: project_panel.button.unwrap(),
 89            hide_gitignore: project_panel.hide_gitignore.unwrap(),
 90            default_width: px(project_panel.default_width.unwrap()),
 91            dock: project_panel.dock.unwrap(),
 92            entry_spacing: project_panel.entry_spacing.unwrap(),
 93            file_icons: project_panel.file_icons.unwrap(),
 94            folder_icons: project_panel.folder_icons.unwrap(),
 95            git_status: project_panel.git_status.unwrap(),
 96            indent_size: project_panel.indent_size.unwrap(),
 97            indent_guides: IndentGuidesSettings {
 98                show: project_panel.indent_guides.unwrap().show.unwrap(),
 99            },
100            sticky_scroll: project_panel.sticky_scroll.unwrap(),
101            auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
102            auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
103            starts_open: project_panel.starts_open.unwrap(),
104            scrollbar: ScrollbarSettings {
105                show: project_panel.scrollbar.unwrap().show.map(Into::into),
106            },
107            show_diagnostics: project_panel.show_diagnostics.unwrap(),
108            hide_root: project_panel.hide_root.unwrap(),
109            hide_hidden: project_panel.hide_hidden.unwrap(),
110            drag_and_drop: project_panel.drag_and_drop.unwrap(),
111            auto_open: {
112                let auto_open = project_panel.auto_open.unwrap();
113                AutoOpenSettings {
114                    on_create: auto_open.on_create.unwrap(),
115                    on_paste: auto_open.on_paste.unwrap(),
116                    on_drop: auto_open.on_drop.unwrap(),
117                }
118            },
119            sort_mode: project_panel
120                .sort_mode
121                .unwrap_or(ProjectPanelSortMode::DirectoriesFirst),
122        }
123    }
124}