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 bold_folder_labels: bool,
 30    pub starts_open: bool,
 31    pub scrollbar: ScrollbarSettings,
 32    pub show_diagnostics: ShowDiagnostics,
 33    pub hide_root: bool,
 34    pub hide_hidden: bool,
 35    pub drag_and_drop: bool,
 36    pub auto_open: AutoOpenSettings,
 37    pub sort_mode: ProjectPanelSortMode,
 38    pub diagnostic_badges: bool,
 39}
 40
 41#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 42pub struct IndentGuidesSettings {
 43    pub show: ShowIndentGuides,
 44}
 45
 46#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 47pub struct ScrollbarSettings {
 48    /// When to show the scrollbar in the project panel.
 49    ///
 50    /// Default: inherits editor scrollbar settings
 51    pub show: Option<ShowScrollbar>,
 52    /// Whether to allow horizontal scrolling in the project panel.
 53    /// When false, the view is locked to the leftmost position and long file names are clipped.
 54    ///
 55    /// Default: true
 56    pub horizontal_scroll: bool,
 57}
 58
 59#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 60pub struct AutoOpenSettings {
 61    pub on_create: bool,
 62    pub on_paste: bool,
 63    pub on_drop: bool,
 64}
 65
 66impl AutoOpenSettings {
 67    #[inline]
 68    pub fn should_open_on_create(self) -> bool {
 69        self.on_create
 70    }
 71
 72    #[inline]
 73    pub fn should_open_on_paste(self) -> bool {
 74        self.on_paste
 75    }
 76
 77    #[inline]
 78    pub fn should_open_on_drop(self) -> bool {
 79        self.on_drop
 80    }
 81}
 82
 83impl ScrollbarVisibility for ProjectPanelSettings {
 84    fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
 85        self.scrollbar
 86            .show
 87            .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
 88    }
 89}
 90
 91impl Settings for ProjectPanelSettings {
 92    fn from_settings(content: &settings::SettingsContent) -> Self {
 93        let project_panel = content.project_panel.clone().unwrap();
 94        Self {
 95            button: project_panel.button.unwrap(),
 96            hide_gitignore: project_panel.hide_gitignore.unwrap(),
 97            default_width: px(project_panel.default_width.unwrap()),
 98            dock: project_panel.dock.unwrap(),
 99            entry_spacing: project_panel.entry_spacing.unwrap(),
100            file_icons: project_panel.file_icons.unwrap(),
101            folder_icons: project_panel.folder_icons.unwrap(),
102            git_status: project_panel.git_status.unwrap()
103                && content
104                    .git
105                    .as_ref()
106                    .unwrap()
107                    .enabled
108                    .unwrap()
109                    .is_git_status_enabled(),
110            indent_size: project_panel.indent_size.unwrap(),
111            indent_guides: IndentGuidesSettings {
112                show: project_panel.indent_guides.unwrap().show.unwrap(),
113            },
114            sticky_scroll: project_panel.sticky_scroll.unwrap(),
115            auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
116            auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
117            bold_folder_labels: project_panel.bold_folder_labels.unwrap(),
118            starts_open: project_panel.starts_open.unwrap(),
119            scrollbar: {
120                let scrollbar = project_panel.scrollbar.unwrap();
121                ScrollbarSettings {
122                    show: scrollbar.show.map(Into::into),
123                    horizontal_scroll: scrollbar.horizontal_scroll.unwrap(),
124                }
125            },
126            show_diagnostics: project_panel.show_diagnostics.unwrap(),
127            hide_root: project_panel.hide_root.unwrap(),
128            hide_hidden: project_panel.hide_hidden.unwrap(),
129            drag_and_drop: project_panel.drag_and_drop.unwrap(),
130            auto_open: {
131                let auto_open = project_panel.auto_open.unwrap();
132                AutoOpenSettings {
133                    on_create: auto_open.on_create.unwrap(),
134                    on_paste: auto_open.on_paste.unwrap(),
135                    on_drop: auto_open.on_drop.unwrap(),
136                }
137            },
138            sort_mode: project_panel.sort_mode.unwrap(),
139            diagnostic_badges: project_panel.diagnostic_badges.unwrap(),
140        }
141    }
142}