1use editor::ShowScrollbar;
2use gpui::Pixels;
3use schemars::JsonSchema;
4use serde_derive::{Deserialize, Serialize};
5use settings::{Settings, SettingsSources, SettingsUi};
6use workspace::dock::DockPosition;
7
8#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
9pub struct ScrollbarSettingsContent {
10 /// When to show the scrollbar in the git panel.
11 ///
12 /// Default: inherits editor scrollbar settings
13 pub show: Option<Option<ShowScrollbar>>,
14}
15
16#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
17pub struct ScrollbarSettings {
18 pub show: Option<ShowScrollbar>,
19}
20
21#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
22#[serde(rename_all = "snake_case")]
23// Style of the git status indicator in the panel.
24//
25// Default: icon
26pub enum StatusStyleContent {
27 Icon,
28 LabelColor,
29}
30
31#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
32#[serde(rename_all = "snake_case")]
33pub enum StatusStyle {
34 #[default]
35 Icon,
36 LabelColor,
37}
38
39#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, SettingsUi)]
40pub struct GitPanelSettingsContent {
41 /// Whether to show the panel button in the status bar.
42 ///
43 /// Default: true
44 pub button: Option<bool>,
45 /// Where to dock the panel.
46 ///
47 /// Default: left
48 pub dock: Option<DockPosition>,
49 /// Default width of the panel in pixels.
50 ///
51 /// Default: 360
52 pub default_width: Option<f32>,
53 /// How entry statuses are displayed.
54 ///
55 /// Default: icon
56 pub status_style: Option<StatusStyle>,
57 /// How and when the scrollbar should be displayed.
58 ///
59 /// Default: inherits editor scrollbar settings
60 pub scrollbar: Option<ScrollbarSettings>,
61
62 /// What the default branch name should be when
63 /// `init.defaultBranch` is not set in git
64 ///
65 /// Default: main
66 pub fallback_branch_name: Option<String>,
67
68 /// Whether to sort entries in the panel by path
69 /// or by status (the default).
70 ///
71 /// Default: false
72 pub sort_by_path: Option<bool>,
73
74 /// Whether to collapse untracked files in the diff panel.
75 ///
76 /// Default: false
77 pub collapse_untracked_diff: Option<bool>,
78}
79
80#[derive(Deserialize, Debug, Clone, PartialEq)]
81pub struct GitPanelSettings {
82 pub button: bool,
83 pub dock: DockPosition,
84 pub default_width: Pixels,
85 pub status_style: StatusStyle,
86 pub scrollbar: ScrollbarSettings,
87 pub fallback_branch_name: String,
88 pub sort_by_path: bool,
89 pub collapse_untracked_diff: bool,
90}
91
92impl Settings for GitPanelSettings {
93 const KEY: Option<&'static str> = Some("git_panel");
94
95 type FileContent = GitPanelSettingsContent;
96
97 fn load(
98 sources: SettingsSources<Self::FileContent>,
99 _: &mut gpui::App,
100 ) -> anyhow::Result<Self> {
101 sources.json_merge()
102 }
103
104 fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
105 vscode.bool_setting("git.enabled", &mut current.button);
106 vscode.string_setting("git.defaultBranchName", &mut current.fallback_branch_name);
107 }
108}