Co-Authored-By: Ben K <ben@zed.dev> Co-Authored-By: Anthony <anthony@zed.dev> Co-Authored-By: Mikayla <mikayla@zed.dev> Release Notes: - settings: Major internal changes to settings. The primary user-facing effect is that some settings which did not make sense in project settings files are no-longer read from there. (For example the inline blame settings) --------- Co-authored-by: Ben Kunkle <ben@zed.dev> Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com> Co-authored-by: Anthony <anthony@zed.dev>
102 lines
3.8 KiB
Rust
102 lines
3.8 KiB
Rust
use editor::EditorSettings;
|
|
use gpui::Pixels;
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
use settings::{Settings, SettingsContent, StatusStyle};
|
|
use ui::{
|
|
px,
|
|
scrollbars::{ScrollbarVisibility, ShowScrollbar},
|
|
};
|
|
use util::MergeFrom;
|
|
use workspace::dock::DockPosition;
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
|
pub struct ScrollbarSettingsContent {
|
|
/// When to show the scrollbar in the git panel.
|
|
///
|
|
/// Default: inherits editor scrollbar settings
|
|
pub show: Option<Option<ShowScrollbar>>,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
|
pub struct ScrollbarSettings {
|
|
pub show: Option<ShowScrollbar>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct GitPanelSettings {
|
|
pub button: bool,
|
|
pub dock: DockPosition,
|
|
pub default_width: Pixels,
|
|
pub status_style: StatusStyle,
|
|
pub scrollbar: ScrollbarSettings,
|
|
pub fallback_branch_name: String,
|
|
pub sort_by_path: bool,
|
|
pub collapse_untracked_diff: bool,
|
|
}
|
|
|
|
impl ScrollbarVisibility for GitPanelSettings {
|
|
fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
|
|
// TODO: This PR should have defined Editor's `scrollbar.axis`
|
|
// as an Option<ScrollbarAxis>, not a ScrollbarAxes as it would allow you to
|
|
// `.unwrap_or(EditorSettings::get_global(cx).scrollbar.show)`.
|
|
//
|
|
// Once this is fixed we can extend the GitPanelSettings with a `scrollbar.axis`
|
|
// so we can show each axis based on the settings.
|
|
//
|
|
// We should fix this. PR: https://github.com/zed-industries/zed/pull/19495
|
|
self.scrollbar
|
|
.show
|
|
.unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
|
|
}
|
|
}
|
|
|
|
impl Settings for GitPanelSettings {
|
|
fn from_defaults(content: &settings::SettingsContent, _cx: &mut ui::App) -> Self {
|
|
let git_panel = content.git_panel.clone().unwrap();
|
|
Self {
|
|
button: git_panel.button.unwrap(),
|
|
dock: git_panel.dock.unwrap().into(),
|
|
default_width: px(git_panel.default_width.unwrap()),
|
|
status_style: git_panel.status_style.unwrap(),
|
|
scrollbar: ScrollbarSettings {
|
|
show: git_panel.scrollbar.unwrap().show.map(Into::into),
|
|
},
|
|
fallback_branch_name: git_panel.fallback_branch_name.unwrap(),
|
|
sort_by_path: git_panel.sort_by_path.unwrap(),
|
|
collapse_untracked_diff: git_panel.collapse_untracked_diff.unwrap(),
|
|
}
|
|
}
|
|
|
|
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut ui::App) {
|
|
let Some(git_panel) = &content.git_panel else {
|
|
return;
|
|
};
|
|
self.button.merge_from(&git_panel.button);
|
|
self.dock.merge_from(&git_panel.dock.map(Into::into));
|
|
self.default_width
|
|
.merge_from(&git_panel.default_width.map(px));
|
|
self.status_style.merge_from(&git_panel.status_style);
|
|
self.fallback_branch_name
|
|
.merge_from(&git_panel.fallback_branch_name);
|
|
self.sort_by_path.merge_from(&git_panel.sort_by_path);
|
|
self.collapse_untracked_diff
|
|
.merge_from(&git_panel.collapse_untracked_diff);
|
|
if let Some(show) = git_panel.scrollbar.as_ref().and_then(|s| s.show) {
|
|
self.scrollbar.show = Some(show.into())
|
|
}
|
|
}
|
|
|
|
fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut SettingsContent) {
|
|
if let Some(git_enabled) = vscode.read_bool("git.enabled") {
|
|
current.git_panel.get_or_insert_default().button = Some(git_enabled);
|
|
}
|
|
if let Some(default_branch) = vscode.read_string("git.defaultBranchName") {
|
|
current
|
|
.git_panel
|
|
.get_or_insert_default()
|
|
.fallback_branch_name = Some(default_branch.to_string());
|
|
}
|
|
}
|
|
}
|