[MeasureTool]Add setting to specify the default measure style (#25645)

* MeasureTool: Add possibility to specify the default measure style

* MeasureTool: Improve description of user setting

* MeasureTool: Use enum value instead of magic number
This commit is contained in:
Sebastian Zanoni
2023-04-27 16:38:24 +02:00
committed by GitHub
parent 4af9f0172d
commit 78d705890a
9 changed files with 130 additions and 1 deletions

View File

@@ -255,8 +255,10 @@
<StackPanel
HorizontalAlignment="Center"
Orientation="Horizontal"
Spacing="8">
Spacing="8"
Loaded="StackPanel_Loaded">
<ToggleButton
Name="btnBounds"
AutomationProperties.Name="{x:Bind p:Resources.Bounds}"
Click="BoundsTool_Click"
Content="&#xEF20;"
@@ -268,6 +270,7 @@
</ToggleButton.KeyboardAccelerators>
</ToggleButton>
<ToggleButton
Name="btnSpacing"
AutomationProperties.Name="{x:Bind p:Resources.Spacing}"
Click="MeasureTool_Click"
Style="{StaticResource ToggleButtonRadioButtonStyle}"
@@ -279,6 +282,7 @@
</ToggleButton>
<ToggleButton
Name="btnHorizontalSpacing"
AutomationProperties.Name="{x:Bind p:Resources.HorizontalSpacing}"
Click="HorizontalMeasureTool_Click"
Style="{StaticResource ToggleButtonRadioButtonStyle}"
@@ -289,6 +293,7 @@
</ToggleButton.KeyboardAccelerators>
</ToggleButton>
<ToggleButton
Name="btnVerticalSpacing"
AutomationProperties.Name="{x:Bind p:Resources.VerticalSpacing}"
Click="VerticalMeasureTool_Click"
Style="{StaticResource ToggleButtonRadioButtonStyle}"

View File

@@ -11,6 +11,7 @@ using Microsoft.UI.Xaml.Automation.Provider;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Settings.UI.Library.Enumerations;
using Windows.Graphics;
using WinUIEx;
using static NativeMethods;
@@ -25,6 +26,8 @@ namespace MeasureToolUI
private const int WindowWidth = 216;
private const int WindowHeight = 50;
private readonly Settings settings = new();
private PowerToys.MeasureToolCore.Core _coreLogic;
private AppWindow _appWindow;
@@ -69,6 +72,11 @@ namespace MeasureToolUI
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
private void StackPanel_Loaded(object sender, RoutedEventArgs e)
{
SelectDefaultMeasureStyle();
}
private void MainWindow_Closed(object sender, WindowEventArgs args)
{
_coreLogic?.Dispose();
@@ -148,6 +156,25 @@ namespace MeasureToolUI
this.Close();
}
private void SelectDefaultMeasureStyle()
{
ToggleButton responsibleBtn = settings.DefaultMeasureStyle switch
{
MeasureToolMeasureStyle.None => null,
MeasureToolMeasureStyle.Bounds => btnBounds,
MeasureToolMeasureStyle.Spacing => btnSpacing,
MeasureToolMeasureStyle.HorizontalSpacing => btnHorizontalSpacing,
MeasureToolMeasureStyle.VerticalSpacing => btnVerticalSpacing,
_ => null,
};
if (responsibleBtn is not null)
{
var peer = FrameworkElementAutomationPeer.FromElement(responsibleBtn) as ToggleButtonAutomationPeer;
peer.Toggle();
}
}
public void Dispose()
{
_coreLogic?.Dispose();

View File

@@ -89,6 +89,7 @@
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
<ProjectReference Include="..\MeasureToolCore\PowerToys.MeasureToolCore.vcxproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,30 @@
// 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.
using System.IO;
using Microsoft.PowerToys.Settings.UI.Library;
using Settings.UI.Library.Enumerations;
namespace MeasureToolUI
{
public sealed class Settings
{
private static readonly SettingsUtils ModuleSettings = new();
public MeasureToolMeasureStyle DefaultMeasureStyle
{
get
{
try
{
return (MeasureToolMeasureStyle)ModuleSettings.GetSettings<MeasureToolSettings>(MeasureToolSettings.ModuleName).Properties.DefaultMeasureStyle.Value;
}
catch (FileNotFoundException)
{
return MeasureToolMeasureStyle.None;
}
}
}
}
}

View File

@@ -0,0 +1,15 @@
// 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.
namespace Settings.UI.Library.Enumerations
{
public enum MeasureToolMeasureStyle
{
None,
Bounds,
Spacing,
HorizontalSpacing,
VerticalSpacing,
}
}

View File

@@ -4,6 +4,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Settings.UI.Library.Enumerations;
namespace Microsoft.PowerToys.Settings.UI.Library
{
@@ -18,6 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
DrawFeetOnCross = true;
PerColorChannelEdgeDetection = false;
MeasureCrossColor = new StringProperty("#FF4500");
DefaultMeasureStyle = new IntProperty((int)MeasureToolMeasureStyle.None);
}
public HotkeySettings ActivationShortcut { get; set; }
@@ -37,6 +39,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public StringProperty MeasureCrossColor { get; set; }
public IntProperty DefaultMeasureStyle { get; set; }
public override string ToString() => JsonSerializer.Serialize(this);
}
}

View File

@@ -155,6 +155,27 @@
<value>Customize the shortcut to bring up the command bar</value>
<comment>"Screen Ruler" is the name of the utility</comment>
</data>
<data name="MeasureTool_DefaultMeasureStyle.Header" xml:space="preserve">
<value>Default measure style</value>
</data>
<data name="MeasureTool_DefaultMeasureStyle.Description" xml:space="preserve">
<value>The utility will start having the selected style activated</value>
</data>
<data name="MeasureTool_DefaultMeasureStyle_None.Content" xml:space="preserve">
<value>None</value>
</data>
<data name="MeasureTool_DefaultMeasureStyle_Bounds.Content" xml:space="preserve">
<value>Bounds</value>
</data>
<data name="MeasureTool_DefaultMeasureStyle_Spacing.Content" xml:space="preserve">
<value>Spacing</value>
</data>
<data name="MeasureTool_DefaultMeasureStyle_Horizontal_Spacing.Content" xml:space="preserve">
<value>Horizontal spacing</value>
</data>
<data name="MeasureTool_DefaultMeasureStyle_Vertical_Spacing.Content" xml:space="preserve">
<value>Vertical spacing</value>
</data>
<data name="MeasureTool_UnitsOfMeasure.Header" xml:space="preserve">
<value>Units of measurement</value>
</data>

View File

@@ -223,6 +223,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public int DefaultMeasureStyle
{
get
{
return Settings.Properties.DefaultMeasureStyle.Value;
}
set
{
if (Settings.Properties.DefaultMeasureStyle.Value != value)
{
Settings.Properties.DefaultMeasureStyle.Value = value;
NotifyPropertyChanged();
}
}
}
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);

View File

@@ -39,6 +39,15 @@
MinWidth="{StaticResource SettingActionControlMinWidth}"
HotkeySettings="{x:Bind Path=ViewModel.ActivationShortcut, Mode=TwoWay}" />
</labs:SettingsCard>
<labs:SettingsCard x:Uid="MeasureTool_DefaultMeasureStyle">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.DefaultMeasureStyle, Mode=TwoWay}">
<ComboBoxItem x:Uid="MeasureTool_DefaultMeasureStyle_None"/>
<ComboBoxItem x:Uid="MeasureTool_DefaultMeasureStyle_Bounds" />
<ComboBoxItem x:Uid="MeasureTool_DefaultMeasureStyle_Spacing" />
<ComboBoxItem x:Uid="MeasureTool_DefaultMeasureStyle_Horizontal_Spacing" />
<ComboBoxItem x:Uid="MeasureTool_DefaultMeasureStyle_Vertical_Spacing" />
</ComboBox>
</labs:SettingsCard>
</controls:SettingsGroup>