1use editor::EditorSettings;
 2use gpui::Pixels;
 3use schemars::JsonSchema;
 4use serde::{Deserialize, Serialize};
 5use settings::{Settings, SettingsContent, 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)]
18pub struct GitPanelSettings {
19    pub button: bool,
20    pub dock: DockPosition,
21    pub default_width: Pixels,
22    pub status_style: StatusStyle,
23    pub scrollbar: ScrollbarSettings,
24    pub fallback_branch_name: String,
25    pub sort_by_path: bool,
26    pub collapse_untracked_diff: bool,
27}
28
29impl ScrollbarVisibility for GitPanelSettings {
30    fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
31        // TODO: This PR should have defined Editor's `scrollbar.axis`
32        // as an Option<ScrollbarAxis>, not a ScrollbarAxes as it would allow you to
33        // `.unwrap_or(EditorSettings::get_global(cx).scrollbar.show)`.
34        //
35        // Once this is fixed we can extend the GitPanelSettings with a `scrollbar.axis`
36        // so we can show each axis based on the settings.
37        //
38        // We should fix this. PR: https://github.com/zed-industries/zed/pull/19495
39        self.scrollbar
40            .show
41            .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
42    }
43}
44
45impl Settings for GitPanelSettings {
46    fn from_settings(content: &settings::SettingsContent) -> Self {
47        let git_panel = content.git_panel.clone().unwrap();
48        Self {
49            button: git_panel.button.unwrap(),
50            dock: git_panel.dock.unwrap().into(),
51            default_width: px(git_panel.default_width.unwrap()),
52            status_style: git_panel.status_style.unwrap(),
53            scrollbar: ScrollbarSettings {
54                show: git_panel.scrollbar.unwrap().show.map(Into::into),
55            },
56            fallback_branch_name: git_panel.fallback_branch_name.unwrap(),
57            sort_by_path: git_panel.sort_by_path.unwrap(),
58            collapse_untracked_diff: git_panel.collapse_untracked_diff.unwrap(),
59        }
60    }
61
62    fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut SettingsContent) {
63        if let Some(git_enabled) = vscode.read_bool("git.enabled") {
64            current.git_panel.get_or_insert_default().button = Some(git_enabled);
65        }
66        if let Some(default_branch) = vscode.read_string("git.defaultBranchName") {
67            current
68                .git_panel
69                .get_or_insert_default()
70                .fallback_branch_name = Some(default_branch.to_string());
71        }
72    }
73}