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