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