[FancyZones] Configurable sensitivity radius (#6554)

* Add the setting for the Sensitivity Radius to JSON and the Editor
Use the setting when determining Zones to highligh

* Fix FanzyZones unit tests
Add test for Json upgrade

* Updated texts in FancyZone Editor
More Text to Resources / Use Resources

* Added constant for default of Sensitivity Radius

* When installing from scratch of when a new device is added set the sensitivity radius to the default.
Move all the constant values to a single namespace

* restore correct formatting

Co-authored-by: Remy Blok <remy.blok@prodware.nl>
This commit is contained in:
Remy Blok
2020-09-18 09:16:06 +02:00
committed by GitHub
parent 00187269de
commit 7893f387d5
15 changed files with 341 additions and 276 deletions

View File

@@ -215,20 +215,6 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel Orientation="Horizontal" Margin="10,4,0,8">
<CheckBox x:Name="spaceAroundSetting" Content="Show space around zones" Style="{StaticResource settingCheckBoxText}" IsChecked="{Binding ShowSpacing}"/>
<TextBlock Text="Space around zones" Style="{StaticResource settingText}"/>
<TextBox x:Name="paddingValue" Text="{Binding Path=Spacing,Mode=TwoWay}" Style="{StaticResource textBox}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,12,0,16">
<Button x:Name="EditTemplateButton" Padding="8" Content="Edit selected layout" Style="{StaticResource secondaryButton}" Click="EditLayout_Click"/>
<Button x:Name="ApplyTemplateButton" Padding="8" Content="Apply" Style="{StaticResource primaryButton}" Click="Apply_Click"/>
</StackPanel>
</StackPanel>
</TabItem>
@@ -267,15 +253,22 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel Orientation="Horizontal" Margin="0,10,0,16">
<Button x:Name="EditCustomButton" Content="{x:Static props:Resources.Edit_Selected_Layout}" Padding="8" Style="{StaticResource secondaryButton}" Click="EditLayout_Click"/>
<Button x:Name="ApplyCustomButton" Content="{x:Static props:Resources.Apply}" Padding="8" Style="{StaticResource primaryButton}" Click="Apply_Click"/>
</StackPanel>
</StackPanel>
</TabItem>
</TabControl>
<StackPanel Orientation="Horizontal" Margin="10,4,0,8">
<CheckBox x:Name="spaceAroundSetting" Content="{x:Static props:Resources.Show_Space_Zones}" Style="{StaticResource settingCheckBoxText}" IsChecked="{Binding ShowSpacing}"/>
<TextBlock Text="{x:Static props:Resources.Space_Around_Zones}" Style="{StaticResource settingText}" IsEnabled="{Binding ShowSpacing}" />
<TextBox x:Name="paddingValue" Text="{Binding Path=Spacing,Mode=TwoWay}" Style="{StaticResource textBox}" MinWidth="32" IsEnabled="{Binding ShowSpacing}"/>
<TextBlock Text="{x:Static props:Resources.Distance_adjacent_zones}" Style="{StaticResource settingText}"/>
<TextBox x:Name="sensitivityRadiusValue" Text="{Binding Path=SensitivityRadius,Mode=TwoWay}" Style="{StaticResource textBox}" MinWidth="40"/>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,16">
<Button x:Name="EditCustomButton" Content="{x:Static props:Resources.Edit_Selected_Layout}" Padding="8" Style="{StaticResource secondaryButton}" Click="EditLayout_Click"/>
<Button x:Name="ApplyCustomButton" Content="{x:Static props:Resources.Apply}" Padding="8" Style="{StaticResource primaryButton}" Click="Apply_Click"/>
</StackPanel>
</StackPanel>
</Controls:MetroWindow>

View File

@@ -384,6 +384,8 @@ namespace FancyZonesEditor.Models
public int EditorSpacing { get; set; }
public int EditorZoneCount { get; set; }
public int EditorSensitivityRadius { get; set; }
}
public void Apply()
@@ -424,6 +426,7 @@ namespace FancyZonesEditor.Models
EditorShowSpacing = settings.ShowSpacing,
EditorSpacing = settings.Spacing,
EditorZoneCount = settings.ZoneCount,
EditorSensitivityRadius = settings.SensitivityRadius,
};
JsonSerializerOptions options = new JsonSerializerOptions

View File

@@ -88,6 +88,7 @@ namespace FancyZonesEditor
private const string EditorShowSpacingJsonTag = "editor-show-spacing";
private const string EditorSpacingJsonTag = "editor-spacing";
private const string EditorZoneCountJsonTag = "editor-zone-count";
private const string EditorSensitivityRadiusJsonTag = "editor-sensitivity-radius";
private const string FocusJsonTag = "focus";
private const string ColumnsJsonTag = "columns";
@@ -208,7 +209,7 @@ namespace FancyZonesEditor
{
if (_spacing != value)
{
_spacing = value;
_spacing = Math.Max(0, value);
FirePropertyChanged();
}
}
@@ -236,6 +237,26 @@ namespace FancyZonesEditor
private bool _showSpacing;
// SensitivityRadius - how much space inside the zone to highlight the adjacent zone too
public int SensitivityRadius
{
get
{
return _sensitivityRadius;
}
set
{
if (_sensitivityRadius != value)
{
_sensitivityRadius = Math.Max(0, value);
FirePropertyChanged();
}
}
}
private int _sensitivityRadius;
// IsShiftKeyPressed - is the shift key currently being held down
public bool IsShiftKeyPressed
{
@@ -435,6 +456,7 @@ namespace FancyZonesEditor
_showSpacing = true;
_spacing = 16;
_zoneCount = 3;
_sensitivityRadius = 20;
}
else
{
@@ -463,6 +485,7 @@ namespace FancyZonesEditor
_showSpacing = jsonObject.GetProperty(EditorShowSpacingJsonTag).GetBoolean();
_spacing = jsonObject.GetProperty(EditorSpacingJsonTag).GetInt32();
_zoneCount = jsonObject.GetProperty(EditorZoneCountJsonTag).GetInt32();
_sensitivityRadius = jsonObject.GetProperty(EditorSensitivityRadiusJsonTag).GetInt32();
}
}
catch (Exception ex)

View File

@@ -123,6 +123,15 @@ namespace FancyZonesEditor.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Distance to highlight adjacent zones.
/// </summary>
public static string Distance_adjacent_zones {
get {
return ResourceManager.GetString("Distance_adjacent_zones", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Edit selected layout.
/// </summary>

View File

@@ -138,6 +138,9 @@
<data name="Custom_Table_Layout" xml:space="preserve">
<value>Custom table layout creator</value>
</data>
<data name="Distance_adjacent_zones" xml:space="preserve">
<value>Distance to highlight adjacent zones</value>
</data>
<data name="Edit_Selected_Layout" xml:space="preserve">
<value>Edit selected layout</value>
</data>