diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 8ae7b6efff..4a208a400a 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -1497,6 +1497,7 @@ psz ptb ptc PTCHAR +ptcontrols ptd PTOKEN PToy diff --git a/PowerToys.slnx b/PowerToys.slnx index 4382ca5934..fabd54f0f0 100644 --- a/PowerToys.slnx +++ b/PowerToys.slnx @@ -13,6 +13,10 @@ + + + + diff --git a/src/common/Common.UI.Controls/Common.UI.Controls.csproj b/src/common/Common.UI.Controls/Common.UI.Controls.csproj new file mode 100644 index 0000000000..9f2f1b490c --- /dev/null +++ b/src/common/Common.UI.Controls/Common.UI.Controls.csproj @@ -0,0 +1,30 @@ + + + + + + Library + net9.0-windows10.0.26100.0 + Microsoft.PowerToys.Common.UI.Controls + PowerToys.Common.UI.Controls + true + true + true + PowerToys.Common.UI.Controls.pri + enable + x64;ARM64 + + + + + + + + + + + + + + + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/CheckBoxWithDescriptionControl.cs b/src/common/Common.UI.Controls/Controls/CheckBoxWithDescriptionControl/CheckBoxWithDescriptionControl.cs similarity index 89% rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/CheckBoxWithDescriptionControl.cs rename to src/common/Common.UI.Controls/Controls/CheckBoxWithDescriptionControl/CheckBoxWithDescriptionControl.cs index 854bf8cd72..3157515b0a 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/CheckBoxWithDescriptionControl.cs +++ b/src/common/Common.UI.Controls/Controls/CheckBoxWithDescriptionControl/CheckBoxWithDescriptionControl.cs @@ -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. @@ -8,7 +8,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Controls; -namespace Microsoft.PowerToys.Settings.UI.Controls +namespace Microsoft.PowerToys.Common.UI.Controls { public partial class CheckBoxWithDescriptionControl : CheckBox { @@ -39,7 +39,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls // Add text box only if the description is not empty. Required for additional plugin options. if (!string.IsNullOrWhiteSpace(Description)) { - panel.Children.Add(new IsEnabledTextBlock() { Style = (Style)App.Current.Resources["SecondaryIsEnabledTextBlockStyle"], Text = Description }); + panel.Children.Add(new IsEnabledTextBlock() { Style = (Style)Application.Current.Resources["SecondaryIsEnabledTextBlockStyle"], Text = Description }); } this.Content = panel; diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml b/src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml similarity index 92% rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml rename to src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml index a1f446917b..2ecd30ee4b 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml +++ b/src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml @@ -1,7 +1,7 @@ - + xmlns:controls="using:Microsoft.PowerToys.Common.UI.Controls"> + + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml.cs b/src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml.cs similarity index 92% rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml.cs rename to src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml.cs index e7f8a52f25..7c1d64f0f9 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml.cs +++ b/src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml.cs @@ -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. @@ -7,7 +7,7 @@ using System.ComponentModel; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -namespace Microsoft.PowerToys.Settings.UI.Controls +namespace Microsoft.PowerToys.Common.UI.Controls { [TemplateVisualState(Name = "Normal", GroupName = "CommonStates")] [TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")] @@ -15,7 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls { public IsEnabledTextBlock() { - this.DefaultStyleKey = typeof(KeyVisual); + this.DefaultStyleKey = typeof(IsEnabledTextBlock); } protected override void OnApplyTemplate() diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml similarity index 99% rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml rename to src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml index a28874b4ee..a162a67110 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml +++ b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml @@ -2,7 +2,7 @@ - \ No newline at end of file + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml.cs b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml.cs similarity index 97% rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml.cs rename to src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml.cs index 87dc9a4c21..1439a6e1d9 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml.cs +++ b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml.cs @@ -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. @@ -6,7 +6,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Windows.System; -namespace Microsoft.PowerToys.Settings.UI.Controls +namespace Microsoft.PowerToys.Common.UI.Controls { [TemplatePart(Name = KeyPresenter, Type = typeof(KeyCharPresenter))] [TemplateVisualState(Name = NormalState, GroupName = "CommonStates")] @@ -20,7 +20,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls private const string DisabledState = "Disabled"; private const string InvalidState = "Invalid"; private const string WarningState = "Warning"; - private KeyCharPresenter _keyPresenter; + private KeyCharPresenter _keyPresenter = null!; public object Content { diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml b/src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml similarity index 98% rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml rename to src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml index 719091a787..c846010509 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml +++ b/src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml @@ -2,7 +2,7 @@ diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs b/src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml.cs similarity index 98% rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs rename to src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml.cs index 7e4d31c28b..1a2913d254 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs +++ b/src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml.cs @@ -7,7 +7,7 @@ using CommunityToolkit.WinUI.Controls; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -namespace Microsoft.PowerToys.Settings.UI.Controls +namespace Microsoft.PowerToys.Common.UI.Controls { public sealed partial class ShortcutWithTextLabelControl : Control { diff --git a/src/settings-ui/Settings.UI/Converters/BoolToKeyVisualStateConverter.cs b/src/common/Common.UI.Controls/Converters/BoolToKeyVisualStateConverter.cs similarity index 81% rename from src/settings-ui/Settings.UI/Converters/BoolToKeyVisualStateConverter.cs rename to src/common/Common.UI.Controls/Converters/BoolToKeyVisualStateConverter.cs index 04a62b02c7..47c9305cb3 100644 --- a/src/settings-ui/Settings.UI/Converters/BoolToKeyVisualStateConverter.cs +++ b/src/common/Common.UI.Controls/Converters/BoolToKeyVisualStateConverter.cs @@ -1,16 +1,11 @@ -// 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. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.PowerToys.Settings.UI.Controls; using Microsoft.UI.Xaml.Data; -namespace Microsoft.PowerToys.Settings.UI.Converters +namespace Microsoft.PowerToys.Common.UI.Controls { public partial class BoolToKeyVisualStateConverter : IValueConverter { diff --git a/src/common/Common.UI.Controls/Themes/Generic.xaml b/src/common/Common.UI.Controls/Themes/Generic.xaml new file mode 100644 index 0000000000..201150458c --- /dev/null +++ b/src/common/Common.UI.Controls/Themes/Generic.xaml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/modules/cmdpal/CommandPalette.slnf b/src/modules/cmdpal/CommandPalette.slnf index c6ccbb7338..decc56060f 100644 --- a/src/modules/cmdpal/CommandPalette.slnf +++ b/src/modules/cmdpal/CommandPalette.slnf @@ -3,6 +3,7 @@ "path": "..\\..\\..\\PowerToys.slnx", "projects": [ "src\\common\\CalculatorEngineCommon\\CalculatorEngineCommon.vcxproj", + "src\\common\\Common.UI.Controls\\Common.UI.Controls.csproj", "src\\common\\ManagedCommon\\ManagedCommon.csproj", "src\\common\\ManagedCsWin32\\ManagedCsWin32.csproj", "src\\common\\ManagedTelemetry\\Telemetry\\ManagedTelemetry.csproj", diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml index d8d4655291..efddeddb84 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml @@ -5,6 +5,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:Microsoft.CmdPal.UI.Controls" xmlns:local="using:Microsoft.CmdPal.UI" + xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls" xmlns:services="using:Microsoft.CmdPal.UI.Services"> @@ -16,8 +17,10 @@ - - + + + + @@ -25,7 +28,7 @@ 240 - - - \ No newline at end of file diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml.cs deleted file mode 100644 index ffe65bc9f9..0000000000 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml.cs +++ /dev/null @@ -1,51 +0,0 @@ -// 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.ComponentModel; - -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; - -namespace Microsoft.CmdPal.UI.Controls; - -[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")] -[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")] -public partial class IsEnabledTextBlock : Control -{ - public IsEnabledTextBlock() - { - this.Style = (Style)App.Current.Resources["DefaultIsEnabledTextBlockStyle"]; - } - - protected override void OnApplyTemplate() - { - IsEnabledChanged -= IsEnabledTextBlock_IsEnabledChanged; - SetEnabledState(); - IsEnabledChanged += IsEnabledTextBlock_IsEnabledChanged; - base.OnApplyTemplate(); - } - - public static readonly DependencyProperty TextProperty = DependencyProperty.Register( - "Text", - typeof(string), - typeof(IsEnabledTextBlock), - null); - - [Localizable(true)] - public string Text - { - get => (string)GetValue(TextProperty); - set => SetValue(TextProperty, value); - } - - private void IsEnabledTextBlock_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) - { - SetEnabledState(); - } - - private void SetEnabledState() - { - VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true); - } -} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.cs deleted file mode 100644 index ed7022fce9..0000000000 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.cs +++ /dev/null @@ -1,178 +0,0 @@ -// 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 Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Markup; -using Windows.System; - -namespace Microsoft.CmdPal.UI.Controls; - -[TemplatePart(Name = KeyPresenter, Type = typeof(ContentPresenter))] -[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")] -[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")] -[TemplateVisualState(Name = "Default", GroupName = "StateStates")] -[TemplateVisualState(Name = "Error", GroupName = "StateStates")] -public sealed partial class KeyVisual : Control -{ - private const string KeyPresenter = "KeyPresenter"; - private KeyVisual? _keyVisual; - private ContentPresenter _keyPresenter = new(); - - public object Content - { - get => GetValue(ContentProperty); - set => SetValue(ContentProperty, value); - } - - public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(object), typeof(KeyVisual), new PropertyMetadata(default(string), OnContentChanged)); - - public VisualType VisualType - { - get => (VisualType)GetValue(VisualTypeProperty); - set => SetValue(VisualTypeProperty, value); - } - - public static readonly DependencyProperty VisualTypeProperty = DependencyProperty.Register("VisualType", typeof(VisualType), typeof(KeyVisual), new PropertyMetadata(default(VisualType), OnSizeChanged)); - - public bool IsError - { - get => (bool)GetValue(IsErrorProperty); - set => SetValue(IsErrorProperty, value); - } - - public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register("IsError", typeof(bool), typeof(KeyVisual), new PropertyMetadata(false, OnIsErrorChanged)); - - public KeyVisual() - { - this.DefaultStyleKey = typeof(KeyVisual); - this.Style = GetStyleSize("TextKeyVisualStyle"); - } - - protected override void OnApplyTemplate() - { - IsEnabledChanged -= KeyVisual_IsEnabledChanged; - _keyVisual = this; - _keyPresenter = (ContentPresenter)_keyVisual.GetTemplateChild(KeyPresenter); - Update(); - SetEnabledState(); - SetErrorState(); - IsEnabledChanged += KeyVisual_IsEnabledChanged; - base.OnApplyTemplate(); - } - - private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - ((KeyVisual)d).Update(); - } - - private static void OnSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - ((KeyVisual)d).Update(); - } - - private static void OnIsErrorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - ((KeyVisual)d).SetErrorState(); - } - - private void Update() - { - if (_keyVisual is null) - { - return; - } - - if (_keyVisual.Content is not null) - { - if (_keyVisual.Content.GetType() == typeof(string)) - { - _keyVisual.Style = GetStyleSize("TextKeyVisualStyle"); - _keyVisual._keyPresenter.Content = _keyVisual.Content; - } - else - { - _keyVisual.Style = GetStyleSize("IconKeyVisualStyle"); - - switch ((int)_keyVisual.Content) - { - /* We can enable other glyphs in the future - case 13: // The Enter key or button. - _keyVisual._keyPresenter.Content = "\uE751"; break; - - case 8: // The Back key or button. - _keyVisual._keyPresenter.Content = "\uE750"; break; - - case 16: // The right Shift key or button. - case 160: // The left Shift key or button. - case 161: // The Shift key or button. - _keyVisual._keyPresenter.Content = "\uE752"; break; */ - - case 38: _keyVisual._keyPresenter.Content = "\uE0E4"; break; // The Up Arrow key or button. - case 40: _keyVisual._keyPresenter.Content = "\uE0E5"; break; // The Down Arrow key or button. - case 37: _keyVisual._keyPresenter.Content = "\uE0E2"; break; // The Left Arrow key or button. - case 39: _keyVisual._keyPresenter.Content = "\uE0E3"; break; // The Right Arrow key or button. - - case 91: // The left Windows key - case 92: // The right Windows key - var winIcon = XamlReader.Load(@"") as PathIcon; - var winIconContainer = new Viewbox - { - Child = winIcon, - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - }; - - var iconDimensions = GetIconSize(); - winIconContainer.Height = iconDimensions; - winIconContainer.Width = iconDimensions; - _keyVisual._keyPresenter.Content = winIconContainer; - break; - default: _keyVisual._keyPresenter.Content = ((VirtualKey)_keyVisual.Content).ToString(); break; - } - } - } - } - - public Style GetStyleSize(string styleName) - { - return VisualType == VisualType.Small - ? (Style)App.Current.Resources["Small" + styleName] - : VisualType == VisualType.SmallOutline - ? (Style)App.Current.Resources["SmallOutline" + styleName] - : VisualType == VisualType.TextOnly - ? (Style)App.Current.Resources["Only" + styleName] - : (Style)App.Current.Resources["Default" + styleName]; - } - - public double GetIconSize() - { - return VisualType == VisualType.Small || VisualType == VisualType.SmallOutline - ? (double)App.Current.Resources["SmallIconSize"] - : (double)App.Current.Resources["DefaultIconSize"]; - } - - private void KeyVisual_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) - { - SetEnabledState(); - } - - private void SetErrorState() - { - VisualStateManager.GoToState(this, IsError ? "Error" : "Default", true); - } - - private void SetEnabledState() - { - VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true); - } -} - -public enum VisualType -{ - Small, - SmallOutline, - TextOnly, - Large, -} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.xaml deleted file mode 100644 index 7364ea8eec..0000000000 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.xaml +++ /dev/null @@ -1,174 +0,0 @@ - - - 16 - 12 - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml index f470c54791..be70b0ca08 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml @@ -5,49 +5,90 @@ xmlns:controls="using:Microsoft.CmdPal.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls" x:Name="LayoutRoot" d:DesignHeight="300" d:DesignWidth="400" mc:Ignorable="d"> - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs index e7fa721277..b8aad6c323 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs @@ -11,6 +11,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; +using Microsoft.Windows.ApplicationModel.Resources; using Windows.System; namespace Microsoft.CmdPal.UI.Controls; @@ -36,6 +37,8 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie public static readonly DependencyProperty AllowDisableProperty = DependencyProperty.Register("AllowDisable", typeof(bool), typeof(ShortcutControl), new PropertyMetadata(false, OnAllowDisableChanged)); + private static ResourceLoader resourceLoader = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance.ResourceLoader; + private static void OnAllowDisableChanged(DependencyObject d, DependencyPropertyChangedEventArgs? e) { var me = d as ShortcutControl; @@ -96,8 +99,7 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie { hotkeySettings = value; SetValue(HotkeySettingsProperty, value); - PreviewKeysControl.ItemsSource = HotkeySettings?.GetKeysList() ?? new List(); - AutomationProperties.SetHelpText(EditButton, HotkeySettings?.ToString() ?? string.Empty); + SetKeys(); c.Keys = HotkeySettings?.GetKeysList() ?? new List(); } } @@ -108,8 +110,6 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie InitializeComponent(); internalSettings = new HotkeySettings(); - var resourceLoader = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance.ResourceLoader; - // We create the Dialog in C# because doing it in XAML is giving WinUI/XAML Island bugs when using dark theme. shortcutDialog = new ContentDialog { @@ -421,11 +421,9 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie hotkeySettings = null; SetValue(HotkeySettingsProperty, hotkeySettings); - PreviewKeysControl.ItemsSource = HotkeySettings?.GetKeysList() ?? new List(); + SetKeys(); lastValidSettings = hotkeySettings; - - AutomationProperties.SetHelpText(EditButton, HotkeySettings?.ToString() ?? string.Empty); shortcutDialog.Hide(); } @@ -436,8 +434,7 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie HotkeySettings = lastValidSettings with { }; } - PreviewKeysControl.ItemsSource = hotkeySettings?.GetKeysList() ?? new List(); - AutomationProperties.SetHelpText(EditButton, HotkeySettings?.ToString() ?? string.Empty); + SetKeys(); shortcutDialog.Hide(); } @@ -450,9 +447,7 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie var empty = new HotkeySettings(); HotkeySettings = empty; - - PreviewKeysControl.ItemsSource = HotkeySettings.GetKeysList(); - AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString()); + SetKeys(); shortcutDialog.Hide(); } @@ -508,4 +503,23 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie Dispose(disposing: true); GC.SuppressFinalize(this); } + + private void SetKeys() + { + var keys = HotkeySettings?.GetKeysList(); + + if (keys != null && keys.Count > 0) + { + VisualStateManager.GoToState(this, "Configured", true); + PreviewKeysControl.ItemsSource = keys; +#pragma warning disable CS8602 // Dereference of a possibly null reference. + AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString()); +#pragma warning restore CS8602 // Dereference of a possibly null reference. + } + else + { + VisualStateManager.GoToState(this, "Normal", true); + AutomationProperties.SetHelpText(EditButton, resourceLoader.GetString("ConfigureShortcut")); + } + } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml index 0000685ac3..d2a5b7203f 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml @@ -2,12 +2,16 @@ x:Class="Microsoft.CmdPal.UI.Controls.ShortcutDialogContentControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:controls="using:Microsoft.CmdPal.UI.Controls" + xmlns:converters="using:Microsoft.PowerToys.Common.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls" xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls" x:Name="ShortcutContentControl" mc:Ignorable="d"> + + + @@ -33,13 +37,16 @@ - + State="{Binding ElementName=ShortcutContentControl, Path=IsError, Mode=OneWay, Converter={StaticResource BoolToKeyVisualStateConverter}, ConverterParameter=Error}" + Style="{StaticResource AccentKeyVisualStyle}" /> diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml deleted file mode 100644 index c6f2a9fe2a..0000000000 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs deleted file mode 100644 index 5605d5b195..0000000000 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 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.Collections.Generic; - -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; - -namespace Microsoft.CmdPal.UI.Controls -{ - public sealed partial class ShortcutWithTextLabelControl : UserControl - { - public string Text - { - get { return (string)GetValue(TextProperty); } - set { SetValue(TextProperty, value); } - } - - public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(ShortcutWithTextLabelControl), new PropertyMetadata(default(string))); - - public List Keys - { - get { return (List)GetValue(KeysProperty); } - set { SetValue(KeysProperty, value); } - } - - public static readonly DependencyProperty KeysProperty = DependencyProperty.Register("Keys", typeof(List), typeof(ShortcutWithTextLabelControl), new PropertyMetadata(default(string))); - - public ShortcutWithTextLabelControl() - { - this.InitializeComponent(); - } - } -} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj index a80b174cec..292c5a4e3d 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj @@ -72,10 +72,8 @@ - - @@ -128,6 +126,7 @@ + @@ -255,17 +254,6 @@ - - - MSBuild:Compile - - - - - - MSBuild:Compile - - MSBuild:Compile diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/ExtensionPage.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/ExtensionPage.xaml index df60c83362..72cf1f2f94 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/ExtensionPage.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/ExtensionPage.xaml @@ -11,6 +11,7 @@ xmlns:helpers="using:Microsoft.CmdPal.UI.Helpers" xmlns:local="using:Microsoft.CmdPal.UI.Settings" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls" xmlns:ui="using:CommunityToolkit.WinUI" xmlns:viewModels="using:Microsoft.CmdPal.UI.ViewModels" mc:Ignorable="d"> @@ -174,7 +175,7 @@ - diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml index 53994b345f..bd80615556 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml @@ -1,4 +1,4 @@ - + @@ -44,10 +45,10 @@ - + - + diff --git a/src/settings-ui/Settings.UI/PowerToys.Settings.csproj b/src/settings-ui/Settings.UI/PowerToys.Settings.csproj index c1f15281c7..f44fe8315f 100644 --- a/src/settings-ui/Settings.UI/PowerToys.Settings.csproj +++ b/src/settings-ui/Settings.UI/PowerToys.Settings.csproj @@ -31,7 +31,6 @@ - @@ -113,6 +112,7 @@ + @@ -174,15 +174,9 @@ Always - - MSBuild:Compile - MSBuild:Compile - - MSBuild:Compile - MSBuild:Compile diff --git a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml index 57cc0fb1ec..d99fb6d7b3 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml @@ -1,17 +1,19 @@ - - - + + + @@ -19,7 +21,7 @@ - + @@ -74,7 +76,7 @@ - - - - - - - @@ -109,7 +110,7 @@ - + - + - - diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/MouseWithoutBordersPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/MouseWithoutBordersPage.xaml index 901c5634c4..91fa7631cb 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/MouseWithoutBordersPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/MouseWithoutBordersPage.xaml @@ -6,6 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:Microsoft.PowerToys.Settings.UI.Helpers" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls" xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls" xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters" xmlns:ui="using:CommunityToolkit.WinUI" @@ -77,7 +78,7 @@ - - + - + - + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PeekPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/PeekPage.xaml index 49da343744..998a4559cb 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PeekPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PeekPage.xaml @@ -6,6 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:Microsoft.PowerToys.Settings.UI.Helpers" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls" xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls" xmlns:ui="using:CommunityToolkit.WinUI" AutomationProperties.LandmarkType="Main" @@ -70,7 +71,7 @@ - diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml index 5bcdf7195c..23da2b2449 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerLauncherPage.xaml @@ -9,6 +9,7 @@ xmlns:ic="using:Microsoft.Xaml.Interactions.Core" xmlns:local="using:Microsoft.PowerToys.Settings.UI.Helpers" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls" xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls" xmlns:ui="using:CommunityToolkit.WinUI" xmlns:viewModels="using:Microsoft.PowerToys.Settings.UI.ViewModels" @@ -45,7 +46,7 @@ BorderThickness="0,0,0,0" ContentAlignment="Left" CornerRadius="0"> - - - - - - + @@ -459,7 +460,7 @@ Value="{x:Bind ViewModel.SearchClickedItemWeight, Mode=TwoWay}" /> - + @@ -548,7 +549,7 @@ x:Uid="PowerLauncher_TitleFontSize" HeaderIcon="{ui:FontIcon Glyph=}"> - - - diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerPreviewPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerPreviewPage.xaml index a6b44dfdf7..895dbd0782 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerPreviewPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerPreviewPage.xaml @@ -6,6 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:Microsoft.PowerToys.Settings.UI.Helpers" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls" xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls" xmlns:ui="using:CommunityToolkit.WinUI" AutomationProperties.LandmarkType="Main" @@ -89,7 +90,7 @@ -