settings: Use a derive macro for refine (#38451)
When we refactored settings to not pass JSON blobs around, we ended up needing to write *a lot* of code that just merged things (like json merge used to do). Use a derive macro to prevent typos in this logic. Release Notes: - N/A
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
pub use settings::TitleBarVisibility;
|
||||
use settings::{Settings, SettingsContent};
|
||||
use ui::App;
|
||||
use util::MergeFrom;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct TitleBarSettings {
|
||||
@@ -16,7 +15,7 @@ pub struct TitleBarSettings {
|
||||
}
|
||||
|
||||
impl Settings for TitleBarSettings {
|
||||
fn from_defaults(s: &SettingsContent, _: &mut App) -> Self {
|
||||
fn from_settings(s: &SettingsContent, _: &mut App) -> Self {
|
||||
let content = s.title_bar.clone().unwrap();
|
||||
TitleBarSettings {
|
||||
show: content.show.unwrap(),
|
||||
@@ -29,24 +28,4 @@ impl Settings for TitleBarSettings {
|
||||
show_menus: content.show_menus.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
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) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user