Settings refactor (#38367)

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>
This commit is contained in:
Conrad Irwin
2025-09-18 16:47:23 +00:00
committed by GitHub
co-authored by Ben Kunkle Mikayla Maki Anthony
parent 0a9023bce0
commit fcdab160f9
219 changed files with 11697 additions and 11894 deletions
+36 -61
View File
@@ -1,17 +1,9 @@
use db::anyhow;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
pub use settings::TitleBarVisibility;
use settings::{Settings, SettingsContent};
use ui::App;
use util::MergeFrom;
#[derive(Copy, Clone, Serialize, Deserialize, JsonSchema, Debug, SettingsUi)]
#[serde(rename_all = "snake_case")]
pub enum TitleBarVisibility {
Always,
Never,
HideInFullScreen,
}
#[derive(Copy, Clone, Deserialize, Debug)]
#[derive(Copy, Clone, Debug)]
pub struct TitleBarSettings {
pub show: TitleBarVisibility,
pub show_branch_icon: bool,
@@ -23,55 +15,38 @@ pub struct TitleBarSettings {
pub show_menus: bool,
}
#[derive(
Copy, Clone, Default, Serialize, Deserialize, JsonSchema, Debug, SettingsUi, SettingsKey,
)]
#[settings_ui(group = "Title Bar")]
#[settings_key(key = "title_bar")]
pub struct TitleBarSettingsContent {
/// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
///
/// Default: "always"
pub show: Option<TitleBarVisibility>,
/// Whether to show the branch icon beside branch switcher in the title bar.
///
/// Default: false
pub show_branch_icon: Option<bool>,
/// Whether to show onboarding banners in the title bar.
///
/// Default: true
pub show_onboarding_banner: Option<bool>,
/// Whether to show user avatar in the title bar.
///
/// Default: true
pub show_user_picture: Option<bool>,
/// Whether to show the branch name button in the titlebar.
///
/// Default: true
pub show_branch_name: Option<bool>,
/// Whether to show the project host and name in the titlebar.
///
/// Default: true
pub show_project_items: Option<bool>,
/// Whether to show the sign in button in the title bar.
///
/// Default: true
pub show_sign_in: Option<bool>,
/// Whether to show the menus in the title bar.
///
/// Default: false
pub show_menus: Option<bool>,
}
impl Settings for TitleBarSettings {
type FileContent = TitleBarSettingsContent;
fn load(sources: SettingsSources<Self::FileContent>, _: &mut gpui::App) -> anyhow::Result<Self>
where
Self: Sized,
{
sources.json_merge()
fn from_defaults(s: &SettingsContent, _: &mut App) -> Self {
let content = s.title_bar.clone().unwrap();
TitleBarSettings {
show: content.show.unwrap(),
show_branch_icon: content.show_branch_icon.unwrap(),
show_onboarding_banner: content.show_onboarding_banner.unwrap(),
show_user_picture: content.show_user_picture.unwrap(),
show_branch_name: content.show_branch_name.unwrap(),
show_project_items: content.show_project_items.unwrap(),
show_sign_in: content.show_sign_in.unwrap(),
show_menus: content.show_menus.unwrap(),
}
}
fn import_from_vscode(_: &settings::VsCodeSettings, _: &mut Self::FileContent) {}
fn refine(&mut self, s: &SettingsContent, _: &mut App) {
let Some(content) = &s.title_bar else {
return;
};
self.show.merge_from(&content.show);
self.show_branch_icon.merge_from(&content.show_branch_icon);
self.show_onboarding_banner
.merge_from(&content.show_onboarding_banner);
self.show_user_picture
.merge_from(&content.show_user_picture);
self.show_branch_name.merge_from(&content.show_branch_name);
self.show_project_items
.merge_from(&content.show_project_items);
self.show_sign_in.merge_from(&content.show_sign_in);
self.show_menus.merge_from(&content.show_menus);
}
fn import_from_vscode(_: &settings::VsCodeSettings, _: &mut SettingsContent) {}
}