outline_panel_settings.rs

  1use editor::EditorSettings;
  2use gpui::{App, Pixels};
  3pub use settings::{OutlinePanelDockPosition, Settings, ShowIndentGuides};
  4use ui::scrollbars::{ScrollbarVisibility, ShowScrollbar};
  5use util::MergeFrom;
  6
  7#[derive(Debug, Clone, Copy, PartialEq)]
  8pub struct OutlinePanelSettings {
  9    pub button: bool,
 10    pub default_width: Pixels,
 11    pub dock: OutlinePanelDockPosition,
 12    pub file_icons: bool,
 13    pub folder_icons: bool,
 14    pub git_status: bool,
 15    pub indent_size: f32,
 16    pub indent_guides: IndentGuidesSettings,
 17    pub auto_reveal_entries: bool,
 18    pub auto_fold_dirs: bool,
 19    pub scrollbar: ScrollbarSettings,
 20    pub expand_outlines_with_depth: usize,
 21}
 22
 23#[derive(Copy, Clone, Debug, PartialEq, Eq)]
 24pub struct ScrollbarSettings {
 25    /// When to show the scrollbar in the project panel.
 26    ///
 27    /// Default: inherits editor scrollbar settings
 28    pub show: Option<ShowScrollbar>,
 29}
 30
 31#[derive(Copy, Clone, Debug, PartialEq, Eq)]
 32pub struct IndentGuidesSettings {
 33    pub show: ShowIndentGuides,
 34}
 35
 36#[derive(Copy, Clone, Debug, PartialEq, Eq)]
 37pub struct IndentGuidesSettingsContent {
 38    /// When to show the scrollbar in the outline panel.
 39    pub show: Option<ShowIndentGuides>,
 40}
 41
 42impl ScrollbarVisibility for OutlinePanelSettings {
 43    fn visibility(&self, cx: &App) -> ShowScrollbar {
 44        self.scrollbar
 45            .show
 46            .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
 47    }
 48}
 49
 50impl Settings for OutlinePanelSettings {
 51    fn from_defaults(content: &settings::SettingsContent, cx: &mut App) -> Self {
 52        let panel = content.outline_panel.as_ref().unwrap();
 53        Self {
 54            button: panel.button.unwrap(),
 55            default_width: panel.default_width.map(gpui::px).unwrap(),
 56            dock: panel.dock.unwrap(),
 57            file_icons: panel.file_icons.unwrap(),
 58            folder_icons: panel.folder_icons.unwrap(),
 59            git_status: panel.git_status.unwrap(),
 60            indent_size: panel.indent_size.unwrap(),
 61            indent_guides: IndentGuidesSettings {
 62                show: panel.indent_guides.unwrap().show.unwrap(),
 63            },
 64            auto_reveal_entries: panel.auto_reveal_entries.unwrap(),
 65            auto_fold_dirs: panel.auto_fold_dirs.unwrap(),
 66            scrollbar: ScrollbarSettings {
 67                show: panel.scrollbar.unwrap().show.unwrap(),
 68            },
 69            expand_outlines_with_depth: panel.expand_outlines_with_depth.unwrap(),
 70        }
 71    }
 72
 73    fn refine(&mut self, content: &settings::SettingsContent, cx: &mut App) {
 74        let Some(panel) = content.outline_panel.as_ref() else {
 75            return;
 76        };
 77
 78        self.button.merge_from(&panel.button);
 79        self.default_width
 80            .merge_from(&panel.default_width.map(Pixels::from));
 81        self.dock.merge_from(&panel.dock.map(Into::into));
 82        self.file_icons.merge_from(&panel.file_icons);
 83        self.folder_icons.merge_from(&panel.folder_icons);
 84        self.git_status.merge_from(&panel.git_status);
 85        self.indent_size.merge_from(&panel.indent_size);
 86
 87        if let Some(indent_guides) = panel.indent_guides.as_ref() {
 88            self.indent_guides.show.merge_from(&indent_guides.show);
 89        }
 90
 91        self.auto_reveal_entries
 92            .merge_from(&panel.auto_reveal_entries);
 93        self.auto_fold_dirs.merge_from(&panel.auto_fold_dirs);
 94
 95        if let Some(scrollbar) = panel.scrollbar.as_ref() {
 96            self.scrollbar.show.merge_from(&scrollbar.show);
 97        }
 98    }
 99    fn import_from_vscode(
100        vscode: &settings::VsCodeSettings,
101        current: &mut settings::SettingsContent,
102    ) {
103        if let Some(b) = vscode.read_bool("outline.icons") {
104            let outline_panel = current.outline_panel.get_or_insert_default();
105            outline_panel.file_icons = Some(b);
106            outline_panel.folder_icons = Some(b);
107        }
108
109        if let Some(b) = vscode.read_bool("git.decorations.enabled") {
110            let outline_panel = current.outline_panel.get_or_insert_default();
111            outline_panel.git_status = Some(b);
112        }
113    }
114}