1use editor::ShowScrollbar;
2use gpui::Pixels;
3use schemars::JsonSchema;
4use serde_derive::{Deserialize, Serialize};
5use settings::{Settings, SettingsSources};
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)]
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
75#[derive(Deserialize, Debug, Clone, PartialEq)]
76pub struct GitPanelSettings {
77 pub button: bool,
78 pub dock: DockPosition,
79 pub default_width: Pixels,
80 pub status_style: StatusStyle,
81 pub scrollbar: ScrollbarSettings,
82 pub fallback_branch_name: String,
83 pub sort_by_path: bool,
84}
85
86impl Settings for GitPanelSettings {
87 const KEY: Option<&'static str> = Some("git_panel");
88
89 type FileContent = GitPanelSettingsContent;
90
91 fn load(
92 sources: SettingsSources<Self::FileContent>,
93 _: &mut gpui::App,
94 ) -> anyhow::Result<Self> {
95 sources.json_merge()
96 }
97
98 fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
99 vscode.bool_setting("git.enabled", &mut current.button);
100 vscode.string_setting("git.defaultBranchName", &mut current.fallback_branch_name);
101 }
102}