diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index a8dc586aa9..030332e450 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -2113,6 +2113,7 @@ todo toggleswitch toolbar Toolchain +toolkitcontrols toolkitconverters toolset toolstrip diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index e52b052521..164a248b19 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -878,10 +878,10 @@ - + - - + + diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/HotkeySettings.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/HotkeySettings.cs index 9fe1099a2d..6d91af440a 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/HotkeySettings.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/HotkeySettings.cs @@ -2,6 +2,7 @@ // 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 System.Text; using System.Text.Json.Serialization; using Microsoft.PowerToys.Settings.UI.Library.Utilities; @@ -100,6 +101,55 @@ namespace Microsoft.PowerToys.Settings.UI.Library return output.ToString(); } + public List GetKeysList() + { + List shortcutList = new List(); + + if (Win) + { + shortcutList.Add(92); // The Windows key or button. + } + + if (Ctrl) + { + shortcutList.Add("Ctrl"); + } + + if (Alt) + { + shortcutList.Add("Alt"); + } + + if (Shift) + { + shortcutList.Add("Shift"); + + // shortcutList.Add(16); // The Shift key or button. + } + + if (Code > 0) + { + switch (Code) + { + // https://docs.microsoft.com/en-us/uwp/api/windows.system.virtualkey?view=winrt-20348 + case 38: // The Up Arrow key or button. + case 40: // The Down Arrow key or button. + case 37: // The Left Arrow key or button. + case 39: // The Right Arrow key or button. + // case 8: // The Back key or button. + // case 13: // The Enter key or button. + shortcutList.Add(Code); + break; + default: + var localKey = Helper.GetKeyName((uint)Code); + shortcutList.Add(localKey); + break; + } + } + + return shortcutList; + } + public bool IsValid() { if (IsAccessibleShortcut()) diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/HotkeySettingsControl.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/HotkeySettingsControl.xaml deleted file mode 100644 index 67dfd91bda..0000000000 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/HotkeySettingsControl.xaml +++ /dev/null @@ -1,15 +0,0 @@ - - - \ No newline at end of file diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/KeyVisual/KeyVisual.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/KeyVisual/KeyVisual.cs index 1ef7ec2410..1dafeacdaa 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/KeyVisual/KeyVisual.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/KeyVisual/KeyVisual.cs @@ -2,29 +2,186 @@ // 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.Design; +using Windows.System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Markup; namespace Microsoft.PowerToys.Settings.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 class KeyVisual : Control { + private const string KeyPresenter = "KeyPresenter"; + private KeyVisual _keyVisual; + private ContentPresenter _keyPresenter; + public object Content { - get => (string)GetValue(ContentProperty); + get => (object)GetValue(ContentProperty); set => SetValue(ContentProperty, value); } - public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(object), typeof(KeyVisual), new PropertyMetadata(default(string))); + 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 = (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 == null) + { + return; + } + + if (_keyVisual.Content != 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 + PathIcon winIcon = XamlReader.Load(@"") as PathIcon; + Viewbox winIconContainer = new Viewbox(); + winIconContainer.Child = winIcon; + winIconContainer.HorizontalAlignment = HorizontalAlignment.Center; + winIconContainer.VerticalAlignment = VerticalAlignment.Center; + + double 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) + { + if (VisualType == VisualType.Small) + { + return (Style)App.Current.Resources["Small" + styleName]; + } + else if (VisualType == VisualType.SmallOutline) + { + return (Style)App.Current.Resources["SmallOutline" + styleName]; + } + else + { + return (Style)App.Current.Resources["Default" + styleName]; + } + } + + public double GetIconSize() + { + if (VisualType == VisualType.Small || VisualType == VisualType.SmallOutline) + { + return (double)App.Current.Resources["SmallIconSize"]; + } + else + { + return (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, + Large, } } diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/KeyVisual/KeyVisual.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/KeyVisual/KeyVisual.xaml index 16d9b0f4cf..3237b7f7c2 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/KeyVisual/KeyVisual.xaml +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/KeyVisual/KeyVisual.xaml @@ -2,56 +2,123 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Microsoft.PowerToys.Settings.UI.Controls"> - - - - #12FFFFFF - #18FFFFFF - #0FFFFFFF - - - - - #0F000000 - #29000000 - #B3FFFFFF - - - - - - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml new file mode 100644 index 0000000000..34a2a61867 --- /dev/null +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml @@ -0,0 +1,49 @@ + + + + + + + + \ No newline at end of file diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/HotkeySettingsControl.xaml.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs similarity index 65% rename from src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/HotkeySettingsControl.xaml.cs rename to src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs index c27ad5ccb6..08b8b6750c 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/HotkeySettingsControl.xaml.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs @@ -5,33 +5,39 @@ using System; using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Library; +using Windows.ApplicationModel.Resources; +using Windows.System.Diagnostics; using Windows.UI.Core; using Windows.UI.Xaml; +using Windows.UI.Xaml.Automation; using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Input; namespace Microsoft.PowerToys.Settings.UI.Controls { - public sealed partial class HotkeySettingsControl : UserControl, IDisposable + public sealed partial class ShortcutControl : UserControl, IDisposable { private readonly UIntPtr ignoreKeyEventFlag = (UIntPtr)0x5555; - private bool _shiftKeyDownOnEntering; - private bool _shiftToggled; + private bool _enabled; + private HotkeySettings hotkeySettings; + private HotkeySettings internalSettings; + private HotkeySettings lastValidSettings; + private HotkeySettingsControlHook hook; + private bool _isActive; + private bool disposedValue; public string Header { get; set; } public string Keys { get; set; } - public static readonly DependencyProperty IsActiveProperty = - DependencyProperty.Register( - "Enabled", - typeof(bool), - typeof(HotkeySettingsControl), - null); + public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register("Enabled", typeof(bool), typeof(ShortcutControl), null); + public static readonly DependencyProperty HotkeySettingsProperty = DependencyProperty.Register("HotkeySettings", typeof(HotkeySettings), typeof(ShortcutControl), null); - private bool _enabled; + private ShortcutDialogContentControl c = new ShortcutDialogContentControl(); + private ContentDialog shortcutDialog; public bool Enabled { @@ -47,35 +53,15 @@ namespace Microsoft.PowerToys.Settings.UI.Controls if (value) { - HotkeyTextBox.IsEnabled = true; - - // TitleText.IsActive = "True"; - // TitleGlyph.IsActive = "True"; + EditButton.IsEnabled = true; } else { - HotkeyTextBox.IsEnabled = false; - - // TitleText.IsActive = "False"; - // TitleGlyph.IsActive = "False"; + EditButton.IsEnabled = false; } } } - public static readonly DependencyProperty HotkeySettingsProperty = - DependencyProperty.Register( - "HotkeySettings", - typeof(HotkeySettings), - typeof(HotkeySettingsControl), - null); - - private HotkeySettings hotkeySettings; - private HotkeySettings internalSettings; - private HotkeySettings lastValidSettings; - private HotkeySettingsControlHook hook; - private bool _isActive; - private bool disposedValue; - public HotkeySettings HotkeySettings { get @@ -89,24 +75,43 @@ namespace Microsoft.PowerToys.Settings.UI.Controls { hotkeySettings = value; SetValue(HotkeySettingsProperty, value); - HotkeyTextBox.Text = HotkeySettings.ToString(); + PreviewKeysControl.ItemsSource = HotkeySettings.GetKeysList(); + AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString()); + c.Keys = HotkeySettings.GetKeysList(); } } } - public HotkeySettingsControl() + public ShortcutControl() { InitializeComponent(); internalSettings = new HotkeySettings(); - HotkeyTextBox.GettingFocus += HotkeyTextBox_GettingFocus; - HotkeyTextBox.LosingFocus += HotkeyTextBox_LosingFocus; - HotkeyTextBox.Unloaded += HotkeyTextBox_Unloaded; + this.Unloaded += ShortcutControl_Unloaded; hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive, FilterAccessibleKeyboardEvents); + ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView(); + + // We create the Dialog in C# because doing it in XAML is giving WinUI/XAML Island bugs when using dark theme. + shortcutDialog = new ContentDialog + { + XamlRoot = this.XamlRoot, + Title = resourceLoader.GetString("Activation_Shortcut_Title"), + Content = c, + PrimaryButtonText = resourceLoader.GetString("Activation_Shortcut_Save"), + CloseButtonText = resourceLoader.GetString("Activation_Shortcut_Cancel"), + DefaultButton = ContentDialogButton.Primary, + }; + shortcutDialog.PrimaryButtonClick += ShortcutDialog_PrimaryButtonClick; + shortcutDialog.Opened += ShortcutDialog_Opened; + shortcutDialog.Closing += ShortcutDialog_Closing; } - private void HotkeyTextBox_Unloaded(object sender, RoutedEventArgs e) + private void ShortcutControl_Unloaded(object sender, RoutedEventArgs e) { + shortcutDialog.PrimaryButtonClick -= ShortcutDialog_PrimaryButtonClick; + shortcutDialog.Opened -= ShortcutDialog_Opened; + shortcutDialog.Closing -= ShortcutDialog_Closing; + // Dispose the HotkeySettingsControlHook object to terminate the hook threads when the textbox is unloaded hook.Dispose(); } @@ -137,7 +142,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls break; case Windows.System.VirtualKey.Escape: internalSettings = new HotkeySettings(); - HotkeySettings = new HotkeySettings(); + shortcutDialog.IsPrimaryButtonEnabled = false; return; default: internalSettings.Code = matchValueCode; @@ -224,6 +229,12 @@ namespace Microsoft.PowerToys.Settings.UI.Controls } } + // Either the cancel or save button has keyboard focus. + if (FocusManager.GetFocusedElement(LayoutRoot.XamlRoot).GetType() == typeof(Button)) + { + return false; + } + return true; } @@ -233,15 +244,62 @@ namespace Microsoft.PowerToys.Settings.UI.Controls { KeyEventHandler(key, true, key); + c.Keys = internalSettings.GetKeysList(); + + if (internalSettings.GetKeysList().Count == 0) + { + // Empty, disable save button + shortcutDialog.IsPrimaryButtonEnabled = false; + } + else if (internalSettings.GetKeysList().Count == 1) + { + // 1 key, disable save button + shortcutDialog.IsPrimaryButtonEnabled = false; + + // Check if the one key is a hotkey + if (internalSettings.Shift || internalSettings.Win || internalSettings.Alt || internalSettings.Ctrl) + { + c.IsError = false; + } + else + { + c.IsError = true; + } + } + // Tab and Shift+Tab are accessible keys and should not be displayed in the hotkey control. if (internalSettings.Code > 0 && !internalSettings.IsAccessibleShortcut()) { - HotkeyTextBox.Text = internalSettings.ToString(); lastValidSettings = internalSettings.Clone(); + + if (!ComboIsValid(lastValidSettings)) + { + DisableKeys(); + } + else + { + EnableKeys(); + } } }); } + private void EnableKeys() + { + shortcutDialog.IsPrimaryButtonEnabled = true; + c.IsError = false; + + // WarningLabel.Style = (Style)App.Current.Resources["SecondaryTextStyle"]; + } + + private void DisableKeys() + { + shortcutDialog.IsPrimaryButtonEnabled = false; + c.IsError = true; + + // WarningLabel.Style = (Style)App.Current.Resources["SecondaryWarningTextStyle"]; + } + private async void Hotkey_KeyUp(int key) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => @@ -255,8 +313,19 @@ namespace Microsoft.PowerToys.Settings.UI.Controls return _isActive; } - private void HotkeyTextBox_GettingFocus(object sender, RoutedEventArgs e) +#pragma warning disable CA1801 // Review unused parameters + private void ShortcutDialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args) +#pragma warning restore CA1801 // Review unused parameters { + if (!ComboIsValid(hotkeySettings)) + { + DisableKeys(); + } + else + { + EnableKeys(); + } + // Reset the status on entering the hotkey each time. _shiftKeyDownOnEntering = false; _shiftToggled = false; @@ -270,30 +339,45 @@ namespace Microsoft.PowerToys.Settings.UI.Controls _isActive = true; } - private void HotkeyTextBox_LosingFocus(object sender, RoutedEventArgs e) + private async void OpenDialogButton_Click(object sender, RoutedEventArgs e) { - if (lastValidSettings != null && (lastValidSettings.IsValid() || lastValidSettings.IsEmpty())) + c.Keys = null; + c.Keys = HotkeySettings.GetKeysList(); + + shortcutDialog.XamlRoot = this.XamlRoot; + await shortcutDialog.ShowAsync(); + } + +#pragma warning disable CA1801 // Review unused parameters + private void ShortcutDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) +#pragma warning restore CA1801 // Review unused parameters + { + if (ComboIsValid(lastValidSettings)) { HotkeySettings = lastValidSettings.Clone(); } - HotkeyTextBox.Text = hotkeySettings.ToString(); - if (AutomationPeer.ListenerExists(AutomationEvents.PropertyChanged)) + PreviewKeysControl.ItemsSource = hotkeySettings.GetKeysList(); + AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString()); + shortcutDialog.Hide(); + } + + private static bool ComboIsValid(HotkeySettings settings) + { + if (settings != null && (settings.IsValid() || settings.IsEmpty())) { - TextBoxAutomationPeer peer = - FrameworkElementAutomationPeer.FromElement(HotkeyTextBox) as TextBoxAutomationPeer; - string textBoxChangeActivityId = "textBoxChangedOnLosingFocus"; - - if (peer != null) - { - peer.RaiseNotificationEvent( - AutomationNotificationKind.ActionCompleted, - AutomationNotificationProcessing.ImportantMostRecent, - HotkeyTextBox.Text, - textBoxChangeActivityId); - } + return true; } + else + { + return false; + } + } +#pragma warning disable CA1801 // Review unused parameters + private void ShortcutDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) +#pragma warning restore CA1801 // Review unused parameters + { _isActive = false; } diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml new file mode 100644 index 0000000000..9796a39d7a --- /dev/null +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml.cs new file mode 100644 index 0000000000..94991146d2 --- /dev/null +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutDialogContentControl.xaml.cs @@ -0,0 +1,48 @@ +// 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.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Microsoft.PowerToys.Settings.UI.Library; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +namespace Microsoft.PowerToys.Settings.UI.Controls +{ + public sealed partial class ShortcutDialogContentControl : UserControl + { + public ShortcutDialogContentControl() + { + this.InitializeComponent(); + } + +#pragma warning disable CA2227 // Collection properties should be read only + public List Keys +#pragma warning restore CA2227 // Collection properties should be read only + { + get { return (List)GetValue(KeysProperty); } + set { SetValue(KeysProperty, value); } + } + + public static readonly DependencyProperty KeysProperty = DependencyProperty.Register("Keys", typeof(List), typeof(SettingsPageControl), new PropertyMetadata(default(string))); + + public bool IsError + { + get => (bool)GetValue(IsErrorProperty); + set => SetValue(IsErrorProperty, value); + } + + public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register("IsError", typeof(bool), typeof(ShortcutDialogContentControl), new PropertyMetadata(false)); + } +} diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml new file mode 100644 index 0000000000..0c81b3b8c4 --- /dev/null +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs new file mode 100644 index 0000000000..d3e194abdc --- /dev/null +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs @@ -0,0 +1,47 @@ +// 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.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +namespace Microsoft.PowerToys.Settings.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))); + +#pragma warning disable CA2227 // Collection properties should be read only + public List Keys +#pragma warning restore CA2227 // Collection properties should be read only + { + 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/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutTextControl.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutTextControl.xaml deleted file mode 100644 index 307515efa1..0000000000 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutTextControl.xaml +++ /dev/null @@ -1,11 +0,0 @@ - - - diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutTextControl.xaml.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutTextControl.xaml.cs deleted file mode 100644 index 7767a73581..0000000000 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutTextControl.xaml.cs +++ /dev/null @@ -1,60 +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; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Text.RegularExpressions; -using Windows.UI.Text; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Documents; - -namespace Microsoft.PowerToys.Settings.UI.Controls -{ - public sealed partial class ShortcutTextControl : UserControl - { - public string Text - { - get => (string)GetValue(TextProperty); - set => SetValue(TextProperty, value); - } - - public ShortcutTextControl() - { - this.InitializeComponent(); - } - - public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(ShortcutVisualControl), new PropertyMetadata(default(string), (s, e) => - { - var self = (ShortcutTextControl)s; - var parts = Regex.Split(e.NewValue.ToString(), @"({[\s\S]+?})").Where(l => !string.IsNullOrEmpty(l)).ToArray(); - - foreach (var seg in parts) - { - if (!string.IsNullOrWhiteSpace(seg)) - { - if (seg.Contains("{", StringComparison.InvariantCulture)) - { - Run key = new Run() - { - Text = Regex.Replace(seg, @"[{}]", string.Empty), - FontWeight = FontWeights.SemiBold, - }; - self.ContentText.Inlines.Add(key); - } - else - { - Run description = new Run() - { - Text = seg, - FontWeight = FontWeights.Normal, - }; - self.ContentText.Inlines.Add(description); - } - } - } - })); - } -} diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutVisualControl.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutVisualControl.xaml deleted file mode 100644 index 0050ba6749..0000000000 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutVisualControl.xaml +++ /dev/null @@ -1,15 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutVisualControl.xaml.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutVisualControl.xaml.cs deleted file mode 100644 index 90559b3e7f..0000000000 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Controls/ShortcutVisualControl.xaml.cs +++ /dev/null @@ -1,62 +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; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Text.RegularExpressions; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; - -namespace Microsoft.PowerToys.Settings.UI.Controls -{ - public sealed partial class ShortcutVisualControl : UserControl - { - public ShortcutVisualControl() - { - InitializeComponent(); - } - - public string Text - { - get => (string)GetValue(TextProperty); - set => SetValue(TextProperty, value); - } - - public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(ShortcutVisualControl), new PropertyMetadata(default(string), (s, e) => - { - var self = (ShortcutVisualControl)s; - var parts = Regex.Split(e.NewValue.ToString(), @"({[\s\S]+?})").Where(l => !string.IsNullOrEmpty(l)).ToArray(); - - foreach (var seg in parts) - { - if (!string.IsNullOrWhiteSpace(seg)) - { - if (seg.Contains("{", StringComparison.InvariantCulture)) - { - KeyVisual k = new KeyVisual - { - Content = Regex.Replace(seg, @"[{}]", string.Empty), - VerticalAlignment = VerticalAlignment.Center, - }; - - self.contentPanel.Children.Add(k); - } - else - { - TextBlock t = new TextBlock - { - Text = seg, - TextWrapping = TextWrapping.Wrap, - VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(0, 6, 0, 0), - }; - - self.contentPanel.Children.Add(t); - } - } - } - })); - } -} diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj index 64c8f7edc9..dea96f5e5a 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj @@ -95,18 +95,18 @@ - - HotkeySettingsControl.xaml + + ShortcutControl.xaml - - ShortcutTextControl.xaml + + ShortcutDialogContentControl.xaml - - ShortcutVisualControl.xaml + + ShortcutWithTextLabelControl.xaml SettingsPageControl.xaml @@ -305,7 +305,7 @@ - + MSBuild:Compile Designer @@ -321,11 +321,11 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/OOBE/Views/OobeAwake.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/OOBE/Views/OobeAwake.xaml index 70e837e1e9..a40da244ed 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/OOBE/Views/OobeAwake.xaml +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/OOBE/Views/OobeAwake.xaml @@ -5,7 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"> + xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls" + xmlns:toolkitcontrols="using:Microsoft.Toolkit.Uwp.UI.Controls"> - + - +