From 0c7f217106466b162420bd24fa6a198e332f05a4 Mon Sep 17 00:00:00 2001 From: Jai <814683@qq.com> Date: Tue, 10 Aug 2021 16:55:01 +0800 Subject: [PATCH] feature: add custom font settings --- src/Models/InstalledFonts.cs | 42 +++++++++++ src/Models/Preference.cs | 21 ++++++ src/Resources/Locales/en_US.xaml | 2 + src/Resources/Locales/zh_CN.xaml | 2 + src/Resources/Styles/ContextMenu.xaml | 5 +- src/Resources/Styles/DataGrid.xaml | 5 +- src/Resources/Styles/TabControl.xaml | 1 - src/Resources/Styles/TextBlock.xaml | 2 - src/Resources/Styles/TextBox.xaml | 1 - src/Resources/Styles/Tree.xaml | 7 +- src/Resources/Styles/Window.xaml | 4 +- src/Views/Blame.xaml | 5 +- src/Views/Controls/Avatar.cs | 2 +- src/Views/Controls/ChangeStatusIcon.cs | 2 +- src/Views/Controls/TextEdit.cs | 2 +- src/Views/Converters/FontFamilyName.cs | 20 ++++++ src/Views/Popups/Apply.xaml | 2 +- src/Views/Popups/Init.xaml | 1 - src/Views/Popups/Merge.xaml | 2 +- src/Views/Popups/Reset.xaml | 2 +- src/Views/Preference.xaml | 94 +++++++++++++++++++------ src/Views/Widgets/CommitDetail.xaml | 3 +- src/Views/Widgets/Dashboard.xaml | 24 +++---- src/Views/Widgets/DiffViewer.xaml | 3 +- src/Views/Widgets/Exceptions.xaml | 3 - src/Views/Widgets/PopupPanel.xaml | 4 +- src/Views/Widgets/RevisionFiles.xaml.cs | 2 +- src/Views/Widgets/Stashes.xaml | 2 - src/Views/Widgets/WorkingCopy.xaml | 7 +- 29 files changed, 202 insertions(+), 70 deletions(-) create mode 100644 src/Models/InstalledFonts.cs create mode 100644 src/Views/Converters/FontFamilyName.cs diff --git a/src/Models/InstalledFonts.cs b/src/Models/InstalledFonts.cs new file mode 100644 index 00000000..7855b493 --- /dev/null +++ b/src/Models/InstalledFonts.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Windows.Markup; +using System.Windows.Media; + +namespace SourceGit.Models { + public class InstalledFont { + public string Name { get; set; } + public int FamilyIndex { get; set; } + + public static List GetFonts { + get { + var fontList = new List(); + + var fontCollection = Fonts.SystemFontFamilies; + var familyCount = fontCollection.Count; + + for (int i = 0; i < familyCount; i++) { + var fontFamily = fontCollection.ElementAt(i); + var familyNames = fontFamily.FamilyNames; + + if (!familyNames.TryGetValue(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name), out var name)) { + if (!familyNames.TryGetValue(XmlLanguage.GetLanguage("en-us"), out name)) { + name = familyNames.FirstOrDefault().Value; + } + } + + fontList.Add(new InstalledFont() { + Name = name, + FamilyIndex = i + }); + } + + fontList.Sort((p, n) => string.Compare(p.Name, n.Name, StringComparison.Ordinal)); + + return fontList; + } + } + } +} diff --git a/src/Models/Preference.cs b/src/Models/Preference.cs index 823b97a4..9799e926 100644 --- a/src/Models/Preference.cs +++ b/src/Models/Preference.cs @@ -27,6 +27,27 @@ namespace SourceGit.Models { /// public string Locale { get; set; } = "en_US"; + /// + /// 系统字体 + /// + public string FontFamilyWindowSetting { get; set; } = "Microsoft YaHei UI"; + + [JsonIgnore] + public string FontFamilyWindow { + get => FontFamilyWindowSetting + ",Microsoft YaHei UI"; + set => FontFamilyWindowSetting = value; + } + + /// + /// 用户字体(提交列表、提交日志、差异比较等) + /// + public string FontFamilyContentSetting { get; set; } = "Consolas"; + + [JsonIgnore] public string FontFamilyContent { + get => FontFamilyContentSetting + ",Microsoft YaHei UI"; + set => FontFamilyContentSetting = value; + } + /// /// 头像服务器 /// diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml index 36d4d119..ec9d920a 100644 --- a/src/Resources/Locales/en_US.xaml +++ b/src/Resources/Locales/en_US.xaml @@ -356,6 +356,8 @@ Preference GENERAL SETTING Language + Window Font + Content Font Avatar Server Check for update Fetch remotes automatically (need restart) diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml index 5cc9cca7..da37676e 100644 --- a/src/Resources/Locales/zh_CN.xaml +++ b/src/Resources/Locales/zh_CN.xaml @@ -355,6 +355,8 @@ 偏好设置 通用配置 显示语言 + 系统字体 + 文本字体 头像服务 启用检测更新 启用定时自动拉取远程更新(重启生效) diff --git a/src/Resources/Styles/ContextMenu.xaml b/src/Resources/Styles/ContextMenu.xaml index 954ae04f..2c5be7b9 100644 --- a/src/Resources/Styles/ContextMenu.xaml +++ b/src/Resources/Styles/ContextMenu.xaml @@ -1,5 +1,6 @@ + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:models="clr-namespace:SourceGit.Models"> + + + + + + + + + + + + + - + @@ -167,11 +217,11 @@ - + @@ -194,36 +244,36 @@ - + @@ -240,19 +290,19 @@ - + diff --git a/src/Views/Widgets/CommitDetail.xaml b/src/Views/Widgets/CommitDetail.xaml index 89cbb290..c3d4fb8c 100644 --- a/src/Views/Widgets/CommitDetail.xaml +++ b/src/Views/Widgets/CommitDetail.xaml @@ -7,7 +7,8 @@ xmlns:models="clr-namespace:SourceGit.Models" xmlns:widgets="clr-namespace:SourceGit.Views.Widgets" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> + d:DesignHeight="450" d:DesignWidth="800" + FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}"> diff --git a/src/Views/Widgets/Dashboard.xaml b/src/Views/Widgets/Dashboard.xaml index 784e877d..6163089d 100644 --- a/src/Views/Widgets/Dashboard.xaml +++ b/src/Views/Widgets/Dashboard.xaml @@ -27,13 +27,13 @@ @@ -42,31 +42,31 @@ @@ -75,13 +75,13 @@ @@ -123,7 +123,7 @@ - + @@ -134,7 +134,7 @@ - + @@ -146,7 +146,7 @@ - + diff --git a/src/Views/Widgets/DiffViewer.xaml b/src/Views/Widgets/DiffViewer.xaml index 1de95c03..34666476 100644 --- a/src/Views/Widgets/DiffViewer.xaml +++ b/src/Views/Widgets/DiffViewer.xaml @@ -7,7 +7,8 @@ xmlns:models="clr-namespace:SourceGit.Models" mc:Ignorable="d" Background="{DynamicResource Brush.Window}" - d:DesignHeight="450" d:DesignWidth="800"> + d:DesignHeight="450" d:DesignWidth="800" + FontFamily="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=OneWay}">