From 2741027fbde39128dcd9a5833d5c06151c82eed3 Mon Sep 17 00:00:00 2001 From: rampaa Date: Thu, 12 Oct 2023 17:04:13 +0300 Subject: [PATCH] Minor --- JL.Windows/ConfigManager.cs | 16 ++------------ JL.Windows/Utilities/WindowsUtils.cs | 33 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/JL.Windows/ConfigManager.cs b/JL.Windows/ConfigManager.cs index 946c904a..2b654aad 100644 --- a/JL.Windows/ConfigManager.cs +++ b/JL.Windows/ConfigManager.cs @@ -21,19 +21,6 @@ namespace JL.Windows; internal static class ConfigManager { #region General - - private static readonly ComboBoxItem[] s_japaneseFonts = - WindowsUtils.FindJapaneseFonts().OrderBy(static f => f.Foreground == Brushes.DimGray).ThenBy(static font => font.Content) - .ToArray(); - - private static readonly ComboBoxItem[] s_popupJapaneseFonts = - Array.ConvertAll(s_japaneseFonts, static f => new ComboBoxItem - { - Content = f.Content, - FontFamily = f.FontFamily, - Foreground = f.Foreground - }); - public static bool InactiveLookupMode { get; set; } = false; public static Brush HighlightColor { get; private set; } = Brushes.AliceBlue; public static bool RequireLookupKeyPress { get; private set; } = false; @@ -186,9 +173,10 @@ internal static class ConfigManager #endregion public static ExeConfigurationFileMap MappedExeConfiguration { get; set; } = new(); + private static readonly ComboBoxItem[] s_japaneseFonts = WindowsUtils.FindJapaneseFonts(); + private static readonly ComboBoxItem[] s_popupJapaneseFonts = WindowsUtils.CloneJapaneseFontComboBoxItems(s_japaneseFonts); private static SkinType s_theme = SkinType.Dark; - public static void ApplyPreferences() { Configuration config = ConfigurationManager.OpenMappedExeConfiguration(MappedExeConfiguration, ConfigurationUserLevel.None); diff --git a/JL.Windows/Utilities/WindowsUtils.cs b/JL.Windows/Utilities/WindowsUtils.cs index cf378d2f..73c8142b 100644 --- a/JL.Windows/Utilities/WindowsUtils.cs +++ b/JL.Windows/Utilities/WindowsUtils.cs @@ -47,7 +47,7 @@ internal static class WindowsUtils public static double DpiAwareFixedPopupXPosition { get; set; } = ConfigManager.FixedPopupXPosition / Dpi.DpiScaleX; public static double DpiAwareFixedPopupYPosition { get; set; } = ConfigManager.FixedPopupYPosition / Dpi.DpiScaleY; - public static List FindJapaneseFonts() + public static ComboBoxItem[] FindJapaneseFonts() { List japaneseFonts = new(); @@ -88,18 +88,43 @@ public static List FindJapaneseFonts() if (!foundGlyph) { - comboBoxItem.Foreground = Brushes.DimGray; + comboBoxItem.Foreground = Brushes.LightSlateGray; japaneseFonts.Add(comboBoxItem); } } else { - comboBoxItem.Foreground = Brushes.DimGray; + comboBoxItem.Foreground = Brushes.LightSlateGray; japaneseFonts.Add(comboBoxItem); } } - return japaneseFonts; + return japaneseFonts + .OrderBy(static f => f.Foreground == Brushes.LightSlateGray) + .ThenBy(static font => font.Content) + .ToArray(); + } + + public static ComboBoxItem[] CloneJapaneseFontComboBoxItems(ComboBoxItem[] japaneseFontsComboBoxItems) + { + ComboBoxItem[] clone = new ComboBoxItem[japaneseFontsComboBoxItems.Length]; + for (int i = 0; i < japaneseFontsComboBoxItems.Length; i++) + { + ComboBoxItem comboBoxItem = japaneseFontsComboBoxItems[i]; + + clone[i] = new ComboBoxItem() + { + Content = comboBoxItem.FontFamily.Source, + FontFamily = comboBoxItem.FontFamily + }; + + if (comboBoxItem.Foreground == Brushes.LightSlateGray) + { + clone[i].Foreground = Brushes.LightSlateGray; + } + } + + return clone; } public static void ShowAddNameWindow(string? selectedText, string reading = "")