diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index b1e7c68cbd93fa929b82d442c45bc565ed8220cf..f5b211bf8f7099c6e29f5a5e68c49e335426b668 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -8,7 +8,6 @@ use gpui::{ use http_client::{AsyncBody, HttpClient, HttpClientWithUrl}; use paths::remote_servers_dir; use release_channel::{AppCommitSha, ReleaseChannel}; -use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use settings::{Settings, SettingsContent, SettingsStore}; use smol::{fs, io::AsyncReadExt}; diff --git a/crates/settings/src/settings_content.rs b/crates/settings/src/settings_content.rs index b5f54022c24085f68a6d4e6764a83aad86a4191f..85aba4d3e04c0378c7ddb6dc0a09dc49216bbeef 100644 --- a/crates/settings/src/settings_content.rs +++ b/crates/settings/src/settings_content.rs @@ -191,7 +191,7 @@ pub struct TitleBarSettingsContent { /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen". /// /// Default: "always" - pub show: Option, + pub show: Option, /// Whether to show the branch icon beside branch switcher in the title bar. /// /// Default: false @@ -224,7 +224,7 @@ pub struct TitleBarSettingsContent { #[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)] #[serde(rename_all = "snake_case")] -pub enum TitleBarVisibilityContent { +pub enum TitleBarVisibility { Always, Never, HideInFullScreen, diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs index 4bcb984f87bd62d7f6ab7e89d272651035cce20e..54f1c10cf720d737e16dc128724280fbebcecf04 100644 --- a/crates/settings/src/settings_store.rs +++ b/crates/settings/src/settings_store.rs @@ -1050,7 +1050,7 @@ mod tests { use std::num::NonZeroU32; use crate::{ - TitleBarSettingsContent, TitleBarVisibilityContent, VsCodeSettingsSource, default_settings, + TitleBarSettingsContent, TitleBarVisibility, VsCodeSettingsSource, default_settings, settings_content::LanguageSettingsContent, test_settings, }; @@ -1081,7 +1081,7 @@ mod tests { #[derive(Debug, PartialEq)] struct TitleBarSettings { - show: TitleBarVisibilityContent, + show: TitleBarVisibility, show_branch_name: bool, } @@ -1105,8 +1105,8 @@ mod tests { let mut show = None; vscode.enum_setting("window.titleBarStyle", &mut show, |value| match value { - "never" => Some(TitleBarVisibilityContent::Never), - "always" => Some(TitleBarVisibilityContent::Always), + "never" => Some(TitleBarVisibility::Never), + "always" => Some(TitleBarVisibility::Always), _ => None, }); if let Some(show) = show { @@ -1163,7 +1163,7 @@ mod tests { ); assert_eq!( store.get::(None).show, - TitleBarVisibilityContent::Always + TitleBarVisibility::Always ); store @@ -1184,7 +1184,7 @@ mod tests { ); assert_eq!( store.get::(None).show, - TitleBarVisibilityContent::Never + TitleBarVisibility::Never ); // todo!() @@ -1253,7 +1253,7 @@ mod tests { path: Path::new("/root2/something") })), &TitleBarSettings { - show: TitleBarVisibilityContent::Never, + show: TitleBarVisibility::Never, show_branch_name: true, } ); @@ -1274,7 +1274,7 @@ mod tests { ); assert_eq!( store.get::(None).show, - TitleBarVisibilityContent::Always, + TitleBarVisibility::Always, ); } @@ -1402,7 +1402,7 @@ mod tests { }"# .unindent(), |settings| { - settings.title_bar.as_mut().unwrap().show = Some(TitleBarVisibilityContent::Never); + settings.title_bar.as_mut().unwrap().show = Some(TitleBarVisibility::Never); }, r#"{ "title_bar": { "show": "never", "name": "Max" } @@ -1594,7 +1594,7 @@ mod tests { assert_eq!( store.get::(None), &TitleBarSettings { - show: TitleBarVisibilityContent::Never, + show: TitleBarVisibility::Never, show_branch_name: true, } ); @@ -1615,7 +1615,7 @@ mod tests { assert_eq!( store.get::(None), &TitleBarSettings { - show: TitleBarVisibilityContent::Always, + show: TitleBarVisibility::Always, show_branch_name: true, // Staff from global settings } ); diff --git a/crates/title_bar/src/title_bar_settings.rs b/crates/title_bar/src/title_bar_settings.rs index 5dce89b0cea0413a9c7096ad85c4d39e257d55ce..670d085756c5e27c45f8640e2d053a7f6929aead 100644 --- a/crates/title_bar/src/title_bar_settings.rs +++ b/crates/title_bar/src/title_bar_settings.rs @@ -1,15 +1,7 @@ -use db::anyhow; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use settings::{Settings, SettingsContent, SettingsKey, SettingsSources, SettingsUi}; - -#[derive(Copy, Clone, Serialize, Deserialize, JsonSchema, Debug, SettingsUi)] -#[serde(rename_all = "snake_case")] -pub enum TitleBarVisibility { - Always, - Never, - HideInFullScreen, -} +pub use settings::TitleBarVisibility; +use settings::{Settings, SettingsContent}; +use ui::App; +use util::MergeFrom; #[derive(Copy, Clone, Debug)] pub struct TitleBarSettings { @@ -24,35 +16,37 @@ pub struct TitleBarSettings { } impl Settings for TitleBarSettings { - fn from_defaults(s: &SettingsContent) -> Option { - let content = s.title_bar?; + fn from_defaults(s: &SettingsContent, _: &mut App) -> Self { + let content = s.title_bar.clone().unwrap(); TitleBarSettings { - show: content.show?, - show_branch_icon: content.show_branch_icon?, - show_onboarding_banner: content.show_onboarding_banner?, - show_user_picture: content.show_user_picture?, - show_branch_name: content.show_branch_name?, - show_project_items: content.show_project_items?, - show_sign_in: content.show_sign_in?, - show_menus: content.show_menus?, + 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 refine(&mut self, s: &SettingsContent, _: &mut App) { - let Some(content) = s.title_bar else { + let Some(content) = &s.title_bar else { return; }; - self.show.refine(&content.show); - self.show_branch_icon.refine(content.show_branch_icon); + self.show.merge_from(&content.show); + self.show_branch_icon.merge_from(&content.show_branch_icon); self.show_onboarding_banner - .refine(content.show_onboarding_banner); - self.show_user_picture.refine(content.show_user_picture); - self.show_branch_name.refine(content.show_branch_name); - self.show_project_items.refine(content.show_project_items); - self.show_sign_in.refine(content.show_sign_in); - self.show_menus.refine(content.show_menus); + .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 Self::FileContent) {} + fn import_from_vscode(_: &settings::VsCodeSettings, _: &mut SettingsContent) {} }