git_panel_settings.rs

  1use editor::ShowScrollbar;
  2use gpui::Pixels;
  3use schemars::JsonSchema;
  4use serde_derive::{Deserialize, Serialize};
  5use settings::{Settings, SettingsKey, 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, SettingsKey)]
 40#[settings_key(key = "git_panel")]
 41pub struct GitPanelSettingsContent {
 42    /// Whether to show the panel button in the status bar.
 43    ///
 44    /// Default: true
 45    pub button: Option<bool>,
 46    /// Where to dock the panel.
 47    ///
 48    /// Default: left
 49    pub dock: Option<DockPosition>,
 50    /// Default width of the panel in pixels.
 51    ///
 52    /// Default: 360
 53    pub default_width: Option<f32>,
 54    /// How entry statuses are displayed.
 55    ///
 56    /// Default: icon
 57    pub status_style: Option<StatusStyle>,
 58    /// How and when the scrollbar should be displayed.
 59    ///
 60    /// Default: inherits editor scrollbar settings
 61    pub scrollbar: Option<ScrollbarSettings>,
 62
 63    /// What the default branch name should be when
 64    /// `init.defaultBranch` is not set in git
 65    ///
 66    /// Default: main
 67    pub fallback_branch_name: Option<String>,
 68
 69    /// Whether to sort entries in the panel by path
 70    /// or by status (the default).
 71    ///
 72    /// Default: false
 73    pub sort_by_path: Option<bool>,
 74
 75    /// Whether to collapse untracked files in the diff panel.
 76    ///
 77    /// Default: false
 78    pub collapse_untracked_diff: Option<bool>,
 79}
 80
 81#[derive(Deserialize, Debug, Clone, PartialEq)]
 82pub struct GitPanelSettings {
 83    pub button: bool,
 84    pub dock: DockPosition,
 85    pub default_width: Pixels,
 86    pub status_style: StatusStyle,
 87    pub scrollbar: ScrollbarSettings,
 88    pub fallback_branch_name: String,
 89    pub sort_by_path: bool,
 90    pub collapse_untracked_diff: bool,
 91}
 92
 93impl Settings for GitPanelSettings {
 94    type FileContent = GitPanelSettingsContent;
 95
 96    fn load(
 97        sources: SettingsSources<Self::FileContent>,
 98        _: &mut gpui::App,
 99    ) -> anyhow::Result<Self> {
100        sources.json_merge()
101    }
102
103    fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
104        vscode.bool_setting("git.enabled", &mut current.button);
105        vscode.string_setting("git.defaultBranchName", &mut current.fallback_branch_name);
106    }
107}