git_panel_settings.rs

 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
69#[derive(Deserialize, Debug, Clone, PartialEq)]
70pub struct GitPanelSettings {
71    pub button: bool,
72    pub dock: DockPosition,
73    pub default_width: Pixels,
74    pub status_style: StatusStyle,
75    pub scrollbar: ScrollbarSettings,
76    pub fallback_branch_name: String,
77}
78
79impl Settings for GitPanelSettings {
80    const KEY: Option<&'static str> = Some("git_panel");
81
82    type FileContent = GitPanelSettingsContent;
83
84    fn load(
85        sources: SettingsSources<Self::FileContent>,
86        _: &mut gpui::App,
87    ) -> anyhow::Result<Self> {
88        sources.json_merge()
89    }
90
91    fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
92        vscode.bool_setting("git.enabled", &mut current.button);
93        vscode.string_setting("git.defaultBranchName", &mut current.fallback_branch_name);
94    }
95}