[FancyZones] Zone Number Settings (#14910)

This commit is contained in:
Davide Giacometti
2021-12-20 17:50:51 +01:00
committed by GitHub
parent 3805348afd
commit 288e0487a0
17 changed files with 208 additions and 73 deletions

View File

@@ -10,6 +10,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public static readonly string DefaultFancyZonesZoneHighlightColor = "#0078D7";
public static readonly string DefaultFancyZonesInActiveColor = "#F5FCFF";
public static readonly string DefaultFancyzonesBorderColor = "#FFFFFF";
public static readonly string DefaultFancyzonesNumberColor = "#000000";
// Fancy Zones Default Flags.
public static readonly bool DefaultFancyzonesShiftDrag = true;

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -46,7 +46,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
FancyzonesExcludedApps = new StringProperty();
FancyzonesInActiveColor = new StringProperty(ConfigDefaults.DefaultFancyZonesInActiveColor);
FancyzonesBorderColor = new StringProperty(ConfigDefaults.DefaultFancyzonesBorderColor);
FancyzonesNumberColor = new StringProperty(ConfigDefaults.DefaultFancyzonesNumberColor);
FancyzonesSystemTheme = new BoolProperty(true);
FancyzonesShowZoneNumber = new BoolProperty(true);
}
[JsonPropertyName("fancyzones_shiftDrag")]
@@ -127,9 +129,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("fancyzones_zoneColor")]
public StringProperty FancyzonesInActiveColor { get; set; }
[JsonPropertyName("fancyzones_zoneNumberColor")]
public StringProperty FancyzonesNumberColor { get; set; }
[JsonPropertyName("fancyzones_systemTheme")]
public BoolProperty FancyzonesSystemTheme { get; set; }
[JsonPropertyName("fancyzones_showZoneNumber")]
public BoolProperty FancyzonesShowZoneNumber { get; set; }
// converts the current to a json string.
public string ToJsonString()
{

View File

@@ -3,8 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing;
using System.Globalization;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
@@ -89,6 +87,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
_highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value;
_excludedApps = Settings.Properties.FancyzonesExcludedApps.Value;
_systemTheme = Settings.Properties.FancyzonesSystemTheme.Value;
_showZoneNumber = Settings.Properties.FancyzonesShowZoneNumber.Value;
EditorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value;
_windowSwitching = Settings.Properties.FancyzonesWindowSwitching.Value;
NextTabHotkey = Settings.Properties.FancyzonesNextTabHotkey.Value;
@@ -98,13 +97,16 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
SendConfigMSG = ipcMSGCallBackFunc;
string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;
_zoneInActiveColor = !string.IsNullOrEmpty(inactiveColor) ? inactiveColor : "#F5FCFF";
_zoneInActiveColor = !string.IsNullOrEmpty(inactiveColor) ? inactiveColor : ConfigDefaults.DefaultFancyZonesInActiveColor;
string borderColor = Settings.Properties.FancyzonesBorderColor.Value;
_zoneBorderColor = !string.IsNullOrEmpty(borderColor) ? borderColor : "#FFFFFF";
_zoneBorderColor = !string.IsNullOrEmpty(borderColor) ? borderColor : ConfigDefaults.DefaultFancyzonesBorderColor;
string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;
_zoneHighlightColor = !string.IsNullOrEmpty(highlightColor) ? highlightColor : "#0078D7";
_zoneHighlightColor = !string.IsNullOrEmpty(highlightColor) ? highlightColor : ConfigDefaults.DefaultFancyZonesZoneHighlightColor;
string numberColor = Settings.Properties.FancyzonesNumberColor.Value;
_zoneNumberColor = !string.IsNullOrEmpty(numberColor) ? numberColor : ConfigDefaults.DefaultFancyzonesNumberColor;
_isEnabled = GeneralSettingsConfig.Enabled.FancyZones;
}
@@ -128,6 +130,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private bool _showOnAllMonitors;
private bool _makeDraggedWindowTransparent;
private bool _systemTheme;
private bool _showZoneNumber;
private int _highlightOpacity;
private string _excludedApps;
@@ -138,6 +141,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private string _zoneInActiveColor;
private string _zoneBorderColor;
private string _zoneHighlightColor;
private string _zoneNumberColor;
public bool IsEnabled
{
@@ -540,6 +544,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public bool ShowZoneNumber
{
get
{
return _showZoneNumber;
}
set
{
if (value != _showZoneNumber)
{
_showZoneNumber = value;
Settings.Properties.FancyzonesShowZoneNumber.Value = value;
NotifyPropertyChanged();
}
}
}
// For the following setters we use OrdinalIgnoreCase string comparison since
// we expect value to be a hex code.
public string ZoneHighlightColor
@@ -608,6 +630,28 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public string ZoneNumberColor
{
get
{
return _zoneNumberColor;
}
set
{
// The fallback value is based on ToRGBHex's behavior, which returns
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
// This extra handling is added here to deal with FxCop warnings.
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FFFFFF";
if (!value.Equals(_zoneNumberColor, StringComparison.OrdinalIgnoreCase))
{
_zoneNumberColor = value;
Settings.Properties.FancyzonesNumberColor.Value = value;
NotifyPropertyChanged();
}
}
}
public int HighlightOpacity
{
get

View File

@@ -15,16 +15,20 @@
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="SolidBackgroundBrush" Color="Black" />
<SolidColorBrush x:Key="SolidZoneNumberBrush" Color="White" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="SolidBackgroundBrush" Color="White" />
<SolidColorBrush x:Key="SolidZoneNumberBrush" Color="Black" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<SolidColorBrush x:Key="SolidBackgroundBrush" Color="Black" />
<SolidColorBrush x:Key="SolidZoneNumberBrush" Color="White" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<SolidColorBrush x:Key="DefaultAccentBrush" Color="{ThemeResource SystemAccentColor}"/>
<SolidColorBrush x:Key="DefaultBorderBrush" Color="{ThemeResource SystemAccentColor}"/>
<converters:BoolToObjectConverter x:Key="BoolToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed"/>
</ResourceDictionary>
</UserControl.Resources>
@@ -43,8 +47,14 @@
</Border>
<Grid Background="{ThemeResource SystemControlAcrylicElementBrush}" Grid.Row="2" Grid.ColumnSpan="2"/>
<Border x:Name="Zone1" Margin="4,4,2,4" CornerRadius="2" Grid.RowSpan="2" BorderThickness="1"/>
<Border x:Name="Zone2" Margin="2,4,4,2" CornerRadius="2" Grid.Column="1" BorderThickness="1"/>
<Border x:Name="Zone3" Margin="2,2,4,4" CornerRadius="2" Grid.Row="1" Grid.Column="1" BorderThickness="1"/>
<Border x:Name="Zone1" Margin="4,4,2,4" CornerRadius="2" Grid.RowSpan="2" BorderThickness="1">
<TextBlock x:Name="Zone1Number" Text="1" FontWeight="SemiBold" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{x:Bind ShowZoneNumber, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"/>
</Border>
<Border x:Name="Zone2" Margin="2,4,4,2" CornerRadius="2" Grid.Column="1" BorderThickness="1">
<TextBlock x:Name="Zone2Number" Text="2" FontWeight="SemiBold" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{x:Bind ShowZoneNumber, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"/>
</Border>
<Border x:Name="Zone3" Margin="2,2,4,4" CornerRadius="2" Grid.Row="1" Grid.Column="1" BorderThickness="1">
<TextBlock x:Name="Zone3Number" Text="3" FontWeight="SemiBold" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{x:Bind ShowZoneNumber, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"/>
</Border>
</Grid>
</UserControl>

View File

@@ -40,14 +40,14 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
set { SetValue(IsSystemThemeProperty, value); }
}
public static readonly DependencyProperty IsSystemThemeProperty = DependencyProperty.Register("IsSystemTheme", typeof(bool), typeof(FancyZonesPreviewControl), new PropertyMetadata(default(bool), OnPropertyChanged));
public string WallpaperPath
{
get { return (string)GetValue(WallpaperPathProperty); }
set { SetValue(WallpaperPathProperty, value); }
}
public static readonly DependencyProperty IsSystemThemeProperty = DependencyProperty.Register("IsSystemTheme", typeof(bool), typeof(FancyZonesPreviewControl), new PropertyMetadata(default(bool), OnPropertyChanged));
public static readonly DependencyProperty WallpaperPathProperty = DependencyProperty.Register("WallpaperPath", typeof(string), typeof(FancyZonesPreviewControl), new PropertyMetadata("ms-appx:///Assets/wallpaper_placeholder.png"));
public Color CustomBorderColor
@@ -74,6 +74,22 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
public static readonly DependencyProperty CustomHighlightColorProperty = DependencyProperty.Register("CustomHighlightColor", typeof(Color), typeof(FancyZonesPreviewControl), new PropertyMetadata(null, OnPropertyChanged));
public Color CustomNumberColor
{
get { return (Color)GetValue(CustomNumberColorProperty); }
set { SetValue(CustomNumberColorProperty, value); }
}
public static readonly DependencyProperty CustomNumberColorProperty = DependencyProperty.Register("CustomNumberColor", typeof(Color), typeof(FancyZonesPreviewControl), new PropertyMetadata(null, OnPropertyChanged));
public bool ShowZoneNumber
{
get { return (bool)GetValue(ShowZoneNumberProperty); }
set { SetValue(ShowZoneNumberProperty, value); }
}
public static readonly DependencyProperty ShowZoneNumberProperty = DependencyProperty.Register("ShowZoneNumber", typeof(bool), typeof(FancyZonesPreviewControl), new PropertyMetadata(default(bool), OnPropertyChanged));
public double HighlightOpacity
{
get { return (double)GetValue(HighlightOpacityProperty); }
@@ -90,6 +106,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
private SolidColorBrush highlightBrush;
private SolidColorBrush inActiveBrush;
private SolidColorBrush borderBrush;
private SolidColorBrush numberBrush;
private void Update()
{
@@ -98,12 +115,14 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
highlightBrush = new SolidColorBrush(CustomHighlightColor);
inActiveBrush = new SolidColorBrush(CustomInActiveColor);
borderBrush = new SolidColorBrush(CustomBorderColor);
numberBrush = new SolidColorBrush(CustomNumberColor);
}
else
{
highlightBrush = (SolidColorBrush)this.Resources["DefaultAccentBrush"];
inActiveBrush = (SolidColorBrush)this.Resources["SolidBackgroundBrush"];
borderBrush = (SolidColorBrush)this.Resources["DefaultBorderBrush"];
numberBrush = (SolidColorBrush)this.Resources["SolidZoneNumberBrush"];
}
highlightBrush.Opacity = HighlightOpacity / 100;
@@ -115,6 +134,10 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
Zone1.BorderBrush = borderBrush;
Zone2.BorderBrush = borderBrush;
Zone3.BorderBrush = borderBrush;
Zone1Number.Foreground = numberBrush;
Zone2Number.Foreground = numberBrush;
Zone3Number.Foreground = numberBrush;
}
}
}

View File

@@ -1550,7 +1550,7 @@ From there, simply click on a Markdown file, PDF file or SVG icon in the File Ex
<data name="EditButton.AutomationProperties.Name" xml:space="preserve">
<value>Edit</value>
</data>
<data name="ImageResizer_EditSize.AutomationProperties.Name" xml:space="preserve">
<data name="ImageResizer_EditSize.AutomationProperties.Name" xml:space="preserve">
<value>Edit size</value>
</data>
<data name="No" xml:space="preserve">
@@ -1848,6 +1848,12 @@ From there, simply click on a Markdown file, PDF file or SVG icon in the File Ex
<value>Enable G-code (.gcode) preview</value>
<comment>Do you want this feature on / off</comment>
</data>
<data name="FancyZones_NumberColor.Header" xml:space="preserve">
<value>Number color</value>
</data>
<data name="FancyZones_ShowZoneNumberCheckBoxControl.Content" xml:space="preserve">
<value>Show zone number</value>
</data>
<data name="ToggleSwitch.OffContent" xml:space="preserve">
<value>Off</value>
<comment>The state of a ToggleSwitch when it's off</comment>

View File

@@ -113,11 +113,17 @@
CustomHighlightColor="{x:Bind Path=ViewModel.ZoneHighlightColor, Mode=OneWay}"
CustomBorderColor="{x:Bind Path=ViewModel.ZoneBorderColor, Mode=OneWay}"
CustomInActiveColor="{x:Bind Path=ViewModel.ZoneInActiveColor, Mode=OneWay}"
CustomNumberColor="{x:Bind Path=ViewModel.ZoneNumberColor, Mode=OneWay}"
ShowZoneNumber="{x:Bind Path=ViewModel.ShowZoneNumber, Mode=OneWay}"
Margin="{StaticResource ExpanderSettingMargin}"
HorizontalAlignment="Left"
Width="170"
Grid.Column="1"
Height="86"/>
<Rectangle Style="{StaticResource ExpanderSeparatorStyle}" />
<CheckBox x:Uid="FancyZones_ShowZoneNumberCheckBoxControl" IsChecked="{x:Bind Mode=TwoWay, Path=ViewModel.ShowZoneNumber}" Margin="{StaticResource ExpanderSettingMargin}"/>
<controls:Setting x:Uid="FancyZones_HighlightOpacity" Style="{StaticResource ExpanderContentSettingStyle}">
<controls:Setting.ActionContent>
<Slider Minimum="0"
@@ -127,7 +133,7 @@
HorizontalAlignment="Right"/>
</controls:Setting.ActionContent>
</controls:Setting>
<StackPanel Visibility="{x:Bind Mode=OneWay, Path=ViewModel.SystemTheme, Converter={StaticResource FalseToVisibleConverter}}" >
<controls:Setting x:Uid="FancyZones_ZoneHighlightColor" Style="{StaticResource ExpanderContentSettingStyle}">
<controls:Setting.ActionContent>
@@ -146,6 +152,12 @@
<controls:ColorPickerButton SelectedColor="{x:Bind Path=ViewModel.ZoneBorderColor, Mode=TwoWay}" />
</controls:Setting.ActionContent>
</controls:Setting>
<controls:Setting x:Uid="FancyZones_NumberColor" Style="{StaticResource ExpanderContentSettingStyle}">
<controls:Setting.ActionContent>
<controls:ColorPickerButton SelectedColor="{x:Bind Path=ViewModel.ZoneNumberColor, Mode=TwoWay}" />
</controls:Setting.ActionContent>
</controls:Setting>
</StackPanel>
</StackPanel>
</controls:SettingExpander.Content>