Skip to content

Commit

Permalink
Fixed #147 (also impacting #141).
Browse files Browse the repository at this point in the history
Also improved the themes selection visual feedback, and removed useless style (corner radius) on all textboxes.
  • Loading branch information
wokhan committed Jan 3, 2023
1 parent a47229a commit 58e7d8f
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Common/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<value>True</value>
</setting>
<setting name="Theme" serializeAs="String">
<value />
<value>Automatic</value>
</setting>
</Wokhan.WindowsFirewallNotifier.Common.Config.Settings>
</userSettings>
Expand Down
2 changes: 1 addition & 1 deletion Common/Config/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Common/Config/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="Theme" Type="System.String" Scope="User">
<Value Profile="(Default)" />
<Value Profile="(Default)">Automatic</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 0 additions & 2 deletions Common/UI/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ext="clr-namespace:Wokhan.UI.Xaml.Extensibility;assembly=Wokhan.UI">

<SolidColorBrush x:Key="AccentColorBrush" Color="{DynamicResource SystemParameters.WindowGlassColor}" />

<Style TargetType="CheckBox">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Background" Value="{DynamicResource ButtonBackground}"/>
Expand Down
16 changes: 10 additions & 6 deletions Common/UI/Themes/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls.Primitives;

using Wokhan.WindowsFirewallNotifier.Common.Config;

namespace Wokhan.WindowsFirewallNotifier.Common.UI.Themes
{
public static partial class ThemeHelper
public static class ThemeHelper
{
public const string THEME_LIGHT = "Light";
public const string THEME_DARK = "Dark";
public const string THEME_SYSTEM = "System";
public const string THEME_AUTO = "Automatic";

public static string GetActiveTheme()
{
if (Settings.Default.Theme is null or "Automatic")
if (Settings.Default.Theme is null or "" or THEME_AUTO)
{
if (SystemParameters.HighContrast)
{
return "System";
return THEME_SYSTEM;
}

using (RegistryKey? key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"))
{
return (int?)key?.GetValue("AppsUseLightTheme") == 0 ? "Dark" : "Light";
return (int?)key?.GetValue("AppsUseLightTheme") == 0 ? THEME_DARK : THEME_LIGHT;
}
}
else
Expand All @@ -38,7 +42,7 @@ public static string GetURIForCurrentTheme()

public static string GetURIForTheme(string themeName)
{
if (themeName == "Automatic")
if (themeName == THEME_AUTO)
{
return GetURIForCurrentTheme();
}
Expand Down
5 changes: 1 addition & 4 deletions Console/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<BindingConverters:ObjectToBoolConverter x:Key="objectToBool" />
<BindingConverters:ValueToVisibilityConverter x:Key="valueToVisibility" />
<BindingConverters:ValueToVisibilityNegateConverter x:Key="valueToVisibilityNegate" />
<BindingConverters:ValueChecker x:Key="valueChecker" />

<system:Double x:Key="ConsoleSizeHeight">600</system:Double>
<system:Double x:Key="ConsoleSizeWidth">900</system:Double>
Expand Down Expand Up @@ -184,10 +185,6 @@
</Style.Triggers>
</Style>

<Style TargetType="TextBox">
<Setter Property="ext:CustomAdorner.CornerRadius" Value="20" />
</Style>

<Style x:Key="FilterComboStyle" TargetType="ComboBox">
<Setter Property="IsEditable" Value="False" />
<Setter Property="Template">
Expand Down
4 changes: 3 additions & 1 deletion Console/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public App() : base()
Settings.Default.PropertyChanged += SettingsChanged;
}

private string currentTheme = "Automatic";
private void SettingsChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Settings.Theme))
if (e.PropertyName == nameof(Settings.Theme) && currentTheme != Settings.Default.Theme)
{
currentTheme = Settings.Default.Theme;
Resources.MergedDictionaries[0].Source = new Uri(ThemeHelper.GetURIForCurrentTheme());
}
}
Expand Down
2 changes: 1 addition & 1 deletion Console/UI/Pages/Status.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<RadioButton GroupName="rdbOutAll" Padding="0,0,0,10" IsChecked="{Binding AllIsOutAllowed}" Content="Allow" />
<RadioButton GroupName="rdbOutAll" IsChecked="{Binding AllIsOutBlocked}" Style="{StaticResource BlockPromptContentStyle}" />
</StackPanel>
<Rectangle Height="35" Fill="LightGray" Opacity="0.6" Grid.Column="1" Grid.ColumnSpan="4" Grid.Row="7" />
<Rectangle Height="35" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Opacity="0.6" Grid.Column="1" Grid.ColumnSpan="4" Grid.Row="7" />
<CheckBox x:Name="tgStartNotifier" IsEnabled="{Binding OneIsOutBlocked}" Grid.Column="1" Grid.ColumnSpan="4" Grid.Row="7" HorizontalAlignment="Center" Content="Enable notifications (applies for all profiles)*">
<CheckBox.Style>
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
Expand Down
48 changes: 29 additions & 19 deletions Console/UI/Windows/Options.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:controls="clr-namespace:Wokhan.WindowsFirewallNotifier.Console.UI.Controls"
xmlns:ext="clr-namespace:Wokhan.UI.Xaml.Extensibility;assembly=Wokhan.UI"
xmlns:uicontrols="clr-namespace:Wokhan.UI.Xaml.Controls;assembly=Wokhan.UI"
xmlns:themes="clr-namespace:Wokhan.WindowsFirewallNotifier.Common.UI.Themes;assembly=Wokhan.WindowsFirewallNotifier.Common"
mc:Ignorable="d"
x:Name="me"
ShowInTaskbar="False"
Expand All @@ -17,21 +18,41 @@
Title="Settings" Margin="10" DataContext="{Binding Path=(settings:Settings.Default)}">
<Window.Resources>
<Style x:Key="ThemeBoxStyle" TargetType="ToggleButton">
<Setter Property="BorderBrush" Value="Gray" />
<!--<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="BorderThickness" Value="4" />
<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="Margin" Value="10" />
<Setter Property="Padding" Value="0" />
<Setter Property="Padding" Value="0" />-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border BorderBrush="Gray" BorderThickness="4" CornerRadius="5" Padding="0" Margin="10" Name="Border" Background="{TemplateBinding Background}">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="Gray" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="DarkGray" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<Grid Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" IsHitTestVisible="False" Focusable="False">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding CommandParameter,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ToggleButton}}" FontWeight="Bold" Padding="5" VerticalAlignment="Center" Background="{DynamicResource {x:Static SystemColors.ActiveCaptionBrushKey}}" />
<UniformGrid Columns="2" Margin="10" Grid.Row="1" IsHitTestVisible="False">
<UniformGrid Columns="2" Margin="10" Grid.Row="1">
<UniformGrid.LayoutTransform>
<ScaleTransform ScaleX="0.7" ScaleY="0.7" />
</UniformGrid.LayoutTransform>
Expand All @@ -50,17 +71,6 @@
</DataTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="DarkGray" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
</Trigger>
<DataTrigger Binding="{Binding Theme,Source=(settings:Settings.Default)}" Value="System">
<Setter Property="IsChecked" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<DockPanel>
Expand Down Expand Up @@ -90,10 +100,10 @@
</StackPanel>
<TextBlock Text="Theme" Style="{StaticResource SectionHeader}" />
<WrapPanel>
<ToggleButton CommandParameter="Dark" Click="SelectTheme" Style="{StaticResource ThemeBoxStyle}" Loaded="ApplyButtonTheme" />
<ToggleButton CommandParameter="Light" Click="SelectTheme" Style="{StaticResource ThemeBoxStyle}" Loaded="ApplyButtonTheme" />
<ToggleButton CommandParameter="Automatic" Click="SelectTheme" Style="{StaticResource ThemeBoxStyle}" Loaded="ApplyButtonTheme" />
<ToggleButton CommandParameter="System" Click="SelectTheme" Style="{StaticResource ThemeBoxStyle}" Loaded="ApplyButtonTheme" />
<ToggleButton CommandParameter="{x:Static themes:ThemeHelper.THEME_DARK}" Click="SelectTheme" Style="{StaticResource ThemeBoxStyle}" Loaded="ApplyButtonTheme" IsChecked="{Binding Theme,Converter={StaticResource valueChecker},ConverterParameter={x:Static themes:ThemeHelper.THEME_DARK},Mode=OneWay}" />
<ToggleButton CommandParameter="{x:Static themes:ThemeHelper.THEME_LIGHT}" Click="SelectTheme" Style="{StaticResource ThemeBoxStyle}" Loaded="ApplyButtonTheme" IsChecked="{Binding Theme,Converter={StaticResource valueChecker},ConverterParameter={x:Static themes:ThemeHelper.THEME_LIGHT},Mode=OneWay}" />
<ToggleButton CommandParameter="{x:Static themes:ThemeHelper.THEME_AUTO}" Click="SelectTheme" Style="{StaticResource ThemeBoxStyle}" Loaded="ApplyButtonTheme" IsChecked="{Binding Theme,Converter={StaticResource valueChecker},ConverterParameter={x:Static themes:ThemeHelper.THEME_AUTO},Mode=OneWay}" />
<ToggleButton CommandParameter="{x:Static themes:ThemeHelper.THEME_SYSTEM}" Click="SelectTheme" Style="{StaticResource ThemeBoxStyle}" Loaded="ApplyButtonTheme" IsChecked="{Binding Theme,Converter={StaticResource valueChecker},ConverterParameter={x:Static themes:ThemeHelper.THEME_SYSTEM},Mode=OneWay}" />
</WrapPanel>

<!--<StackPanel Margin="10">
Expand Down
5 changes: 5 additions & 0 deletions Console/UI/Windows/Options.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,10 @@ private void ApplyButtonTheme(object sender, RoutedEventArgs e)

button.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(ThemeHelper.GetURIForTheme(theme)) });
}

private void SelectTheme(object sender, System.Windows.Input.MouseButtonEventArgs e)
{

}
}
}

0 comments on commit 58e7d8f

Please sign in to comment.