Skip to content

Commit

Permalink
Merge pull request #2893 from sausagemountain/master
Browse files Browse the repository at this point in the history
restore theme compatibility
  • Loading branch information
bao-qian authored Apr 29, 2020
2 parents a2e328f + 65f3267 commit 59b476b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
37 changes: 35 additions & 2 deletions Wox.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,26 @@ public ResourceDictionary GetResourceDictionary()
};

Style queryBoxStyle = dict["QueryBoxStyle"] as Style;

if (queryBoxStyle != null)
{
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(Settings.QueryBoxFont)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch)));

var caretBrushPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Any(x => x.Property == TextBox.CaretBrushProperty);
var foregroundPropertyValue = queryBoxStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == TextBox.ForegroundProperty)?.Value;
if (!caretBrushPropertyValue && foregroundPropertyValue != null)
queryBoxStyle.Setters.Add(new Setter(TextBox.CaretBrushProperty, foregroundPropertyValue));
}

Style queryTextSuggestionBoxStyle = dict["QueryTextSuggestionBoxStyle"] as Style;
var queryTextSuggestionBoxStyle = new Style(typeof(TextBox), queryBoxStyle);
bool hasSuggestion = false;
if (dict.Contains("QueryTextSuggestionBoxStyle")) {
queryTextSuggestionBoxStyle = dict["QueryTextSuggestionBoxStyle"] as Style;
hasSuggestion = true;
}
dict["QueryTextSuggestionBoxStyle"] = queryTextSuggestionBoxStyle;
if (queryTextSuggestionBoxStyle != null)
{
queryTextSuggestionBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(Settings.QueryBoxFont)));
Expand All @@ -137,6 +147,29 @@ public ResourceDictionary GetResourceDictionary()
queryTextSuggestionBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch)));
}

var queryBoxStyleSetters = queryBoxStyle.Setters.OfType<Setter>().ToList();
var queryTextSuggestionBoxStyleSetters = queryTextSuggestionBoxStyle.Setters.OfType<Setter>().ToList();
foreach (Setter setter in queryBoxStyleSetters) {
if (setter.Property == TextBox.BackgroundProperty)
continue;
if (setter.Property == TextBox.ForegroundProperty)
continue;
if (queryTextSuggestionBoxStyleSetters.All(x => x.Property != setter.Property))
queryTextSuggestionBoxStyle.Setters.Add(setter);
}

if (!hasSuggestion) {
var backgroundBrush = queryBoxStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == TextBox.BackgroundProperty)?.Value ??
(dict["BaseQuerySuggestionBoxStyle"] as Style).Setters.OfType<Setter>().FirstOrDefault(x => x.Property == TextBox.BackgroundProperty).Value;
queryBoxStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == TextBox.BackgroundProperty).Value = Brushes.Transparent;
if (queryTextSuggestionBoxStyle.Setters.OfType<Setter>().Any(x => x.Property == TextBox.BackgroundProperty)) {
queryTextSuggestionBoxStyle.Setters.OfType<Setter>().First(x => x.Property == TextBox.BackgroundProperty).Value = backgroundBrush;
}
else {
queryTextSuggestionBoxStyle.Setters.Add(new Setter(TextBox.BackgroundProperty, backgroundBrush));
}
}

Style resultItemStyle = dict["ItemTitleStyle"] as Style;
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
Expand Down
2 changes: 1 addition & 1 deletion Wox/Themes/ThemeBuilder/Template.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Style x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="{%searchFieldTextColor%}" />
</Style>
<Style x:Key="QueryTextSuggestionBoxStyle" BasedOn="{StaticResource BaseQueryTextSuggestionBoxStyle}" TargetType="{x:Type TextBox}">
<Style x:Key="QueryTextSuggestionBoxStyle" BasedOn="{StaticResource BaseQueryTextSuggestionBoxStyle}" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="{%searchFieldBackgroundColor%}"/>
</Style>
<Style x:Key="WindowBorderStyle" BasedOn="{StaticResource BaseWindowBorderStyle}" TargetType="{x:Type Border}">
Expand Down

0 comments on commit 59b476b

Please sign in to comment.