From 56f5f3b4a7163853b4b6113410ff7b2aa616ad88 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 21 Mar 2024 23:19:09 +0800 Subject: [PATCH] enhance: use custom JsonConverter instead of converting string to FontFamily in each control --- src/SourceGit/App.axaml.cs | 5 --- src/SourceGit/Converters/StringConverters.cs | 24 -------------- src/SourceGit/Resources/Styles.axaml | 4 +-- src/SourceGit/ViewModels/Preference.cs | 35 +++++++++++++++++--- src/SourceGit/Views/Blame.axaml | 2 +- src/SourceGit/Views/CommitBaseInfo.axaml | 4 +-- src/SourceGit/Views/Preference.axaml | 4 +-- src/SourceGit/Views/Preference.axaml.cs | 12 ++++--- src/SourceGit/Views/RevisionFiles.axaml | 2 +- src/SourceGit/Views/TextDiffView.axaml | 6 ++-- 10 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/SourceGit/App.axaml.cs b/src/SourceGit/App.axaml.cs index 749e40b7..f0e2dac7 100644 --- a/src/SourceGit/App.axaml.cs +++ b/src/SourceGit/App.axaml.cs @@ -179,11 +179,6 @@ namespace SourceGit SetLocale(pref.Locale); SetTheme(pref.Theme); - - if (string.IsNullOrEmpty(pref.DefaultFont)) - { - pref.DefaultFont = FontManager.Current.DefaultFontFamily.ToString(); - } } public override void OnFrameworkInitializationCompleted() diff --git a/src/SourceGit/Converters/StringConverters.cs b/src/SourceGit/Converters/StringConverters.cs index 7bd68037..4301a983 100644 --- a/src/SourceGit/Converters/StringConverters.cs +++ b/src/SourceGit/Converters/StringConverters.cs @@ -70,29 +70,5 @@ namespace SourceGit.Converters public static FuncValueConverter ToShortSHA = new FuncValueConverter(v => v.Length > 10 ? v.Substring(0, 10) : v); - - public class ToFontFamilyConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - var name = value as string; - if (string.IsNullOrEmpty(name)) - { - return FontManager.Current.DefaultFontFamily; - } - else - { - return new FontFamily(name); - } - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - var fontFamily = value as FontFamily; - return fontFamily == null ? string.Empty : fontFamily.ToString(); - } - } - - public static ToFontFamilyConverter ToFontFamily = new ToFontFamilyConverter(); } } \ No newline at end of file diff --git a/src/SourceGit/Resources/Styles.axaml b/src/SourceGit/Resources/Styles.axaml index 333fc136..3be7e26f 100644 --- a/src/SourceGit/Resources/Styles.axaml +++ b/src/SourceGit/Resources/Styles.axaml @@ -16,7 +16,7 @@