project_panel_settings.rs

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