git_panel_settings.rs

 1use editor::EditorSettings;
 2use gpui::Pixels;
 3use schemars::JsonSchema;
 4use serde::{Deserialize, Serialize};
 5use settings::{RegisterSetting, Settings, StatusStyle};
 6use ui::{
 7    px,
 8    scrollbars::{ScrollbarVisibility, ShowScrollbar},
 9};
10use workspace::dock::DockPosition;
11
12#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
13pub struct ScrollbarSettings {
14    pub show: Option<ShowScrollbar>,
15}
16
17#[derive(Debug, Clone, PartialEq, RegisterSetting)]
18pub struct GitPanelSettings {
19    pub button: bool,
20    pub dock: DockPosition,
21    pub default_width: Pixels,
22    pub status_style: StatusStyle,
23    pub file_icons: bool,
24    pub folder_icons: bool,
25    pub scrollbar: ScrollbarSettings,
26    pub fallback_branch_name: String,
27    pub sort_by_path: bool,
28    pub collapse_untracked_diff: bool,
29    pub tree_view: bool,
30    pub diff_stats: bool,
31    pub show_count_badge: bool,
32}
33
34impl ScrollbarVisibility for GitPanelSettings {
35    fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
36        // TODO: This PR should have defined Editor's `scrollbar.axis`
37        // as an Option<ScrollbarAxis>, not a ScrollbarAxes as it would allow you to
38        // `.unwrap_or(EditorSettings::get_global(cx).scrollbar.show)`.
39        //
40        // Once this is fixed we can extend the GitPanelSettings with a `scrollbar.axis`
41        // so we can show each axis based on the settings.
42        //
43        // We should fix this. PR: https://github.com/zed-industries/zed/pull/19495
44        self.scrollbar
45            .show
46            .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
47    }
48}
49
50impl Settings for GitPanelSettings {
51    fn from_settings(content: &settings::SettingsContent) -> Self {
52        let git_panel = content.git_panel.clone().unwrap();
53        Self {
54            button: git_panel.button.unwrap(),
55            dock: git_panel.dock.unwrap().into(),
56            default_width: px(git_panel.default_width.unwrap()),
57            status_style: git_panel.status_style.unwrap(),
58            file_icons: git_panel.file_icons.unwrap(),
59            folder_icons: git_panel.folder_icons.unwrap(),
60            scrollbar: ScrollbarSettings {
61                show: git_panel.scrollbar.unwrap().show.map(Into::into),
62            },
63            fallback_branch_name: git_panel.fallback_branch_name.unwrap(),
64            sort_by_path: git_panel.sort_by_path.unwrap(),
65            collapse_untracked_diff: git_panel.collapse_untracked_diff.unwrap(),
66            tree_view: git_panel.tree_view.unwrap(),
67            diff_stats: git_panel.diff_stats.unwrap(),
68            show_count_badge: git_panel.show_count_badge.unwrap(),
69        }
70    }
71}