diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index fb463b4d4c0..164690c90ff 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Metrics; using System.IO; using System.Linq; -using System.Xml; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -12,6 +12,7 @@ using System.Windows.Media.Effects; using System.Windows.Shell; using System.Windows.Threading; +using System.Xml; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; @@ -194,7 +195,7 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt // Remove existing font-related setters if (isTextBox) { - // First, find the setters to remove and store them in a list + // Find the setters to remove and store them in a list var settersToRemove = style.Setters .OfType() .Where(setter => @@ -204,7 +205,7 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt setter.Property == Control.FontStretchProperty) .ToList(); - // Remove each found setter one by one + // Remove each found setter one by one foreach (var setter in settersToRemove) { style.Setters.Remove(setter); @@ -216,29 +217,34 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt style.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight)); style.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); - // Set caret brush (retain existing logic) - var caretBrushPropertyValue = style.Setters.OfType().Any(x => x.Property.Name == "CaretBrush"); - var foregroundPropertyValue = style.Setters.OfType().Where(x => x.Property.Name == "Foreground") + // Set caret brush (retain existing logic) + var caretBrushPropertyExist = style.Setters.OfType().Any(x => x.Property == TextBoxBase.CaretBrushProperty); + var foregroundPropertyValue = style.Setters.OfType().Where(x => x.Property == Control.ForegroundProperty) .Select(x => x.Value).FirstOrDefault(); - if (!caretBrushPropertyValue && foregroundPropertyValue != null) + if (!caretBrushPropertyExist && foregroundPropertyValue != null) + { style.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue)); + } } else { + // Find the setters to remove and store them in a list var settersToRemove = style.Setters .OfType() .Where(setter => - setter.Property == TextBlock.FontFamilyProperty || - setter.Property == TextBlock.FontStyleProperty || - setter.Property == TextBlock.FontWeightProperty || - setter.Property == TextBlock.FontStretchProperty) + setter.Property == Control.FontFamilyProperty || + setter.Property == Control.FontStyleProperty || + setter.Property == Control.FontWeightProperty || + setter.Property == Control.FontStretchProperty) .ToList(); + // Remove each found setter one by one foreach (var setter in settersToRemove) { style.Setters.Remove(setter); } + // Add New font setter style.Setters.Add(new Setter(TextBlock.FontFamilyProperty, fontFamily)); style.Setters.Add(new Setter(TextBlock.FontStyleProperty, fontStyle)); style.Setters.Add(new Setter(TextBlock.FontWeightProperty, fontWeight)); @@ -253,7 +259,6 @@ private ResourceDictionary GetThemeResourceDictionary(string theme) { Source = new Uri(uri, UriKind.Absolute) }; - return dict; } @@ -261,67 +266,25 @@ private ResourceDictionary GetResourceDictionary(string theme) { var dict = GetThemeResourceDictionary(theme); - if (dict["QueryBoxStyle"] is Style queryBoxStyle && - dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle) - { - var fontFamily = new FontFamily(_settings.QueryBoxFont); - var fontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.QueryBoxFontStyle); - var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.QueryBoxFontWeight); - var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.QueryBoxFontStretch); - - queryBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily)); - queryBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle)); - queryBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight)); - queryBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); - - var caretBrushPropertyValue = queryBoxStyle.Setters.OfType().Any(x => x.Property.Name == "CaretBrush"); - var foregroundPropertyValue = queryBoxStyle.Setters.OfType().Where(x => x.Property.Name == "Foreground") - .Select(x => x.Value).FirstOrDefault(); - if (!caretBrushPropertyValue && foregroundPropertyValue != null) //otherwise BaseQueryBoxStyle will handle styling - queryBoxStyle.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue)); - - // Query suggestion box's font style is aligned with query box - querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily)); - querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle)); - querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight)); - querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); - } - - if (dict["ItemTitleStyle"] is Style resultItemStyle && - dict["ItemTitleSelectedStyle"] is Style resultItemSelectedStyle && - dict["ItemHotkeyStyle"] is Style resultHotkeyItemStyle && - dict["ItemHotkeySelectedStyle"] is Style resultHotkeyItemSelectedStyle) - { - var fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(_settings.ResultFont)); - var fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultFontStyle)); - var fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultFontWeight)); - var fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultFontStretch)); + /* Apply font settings */ + ApplyFontSettings(dict); - Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; - Array.ForEach( - new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o - => Array.ForEach(setters, p => o.Setters.Add(p))); - } - - if ( - dict["ItemSubTitleStyle"] is Style resultSubItemStyle && - dict["ItemSubTitleSelectedStyle"] is Style resultSubItemSelectedStyle) + /* Ignore Theme Window Width and use setting */ + if (dict.Contains("WindowStyle") && dict["WindowStyle"] is Style windowStyle) { - var fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(_settings.ResultSubFont)); - var fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultSubFontStyle)); - var fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultSubFontWeight)); - var fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultSubFontStretch)); + // Remove all width setters + var widthSetters = windowStyle.Setters + .OfType() + .Where(s => s.Property == FrameworkElement.WidthProperty) + .ToList(); + foreach (var setter in widthSetters) + { + windowStyle.Setters.Remove(setter); + } - Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; - Array.ForEach( - new[] { resultSubItemStyle, resultSubItemSelectedStyle }, o - => Array.ForEach(setters, p => o.Setters.Add(p))); + // Add width setter based on user settings + windowStyle.Setters.Add(new Setter(FrameworkElement.WidthProperty, _settings.WindowSize)); } - - /* Ignore Theme Window Width and use setting */ - var windowStyle = dict["WindowStyle"] as Style; - var width = _settings.WindowSize; - windowStyle.Setters.Add(new Setter(FrameworkElement.WidthProperty, width)); return dict; }