mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[MWB]Migrate to PowerToys-style shortcuts and better defaults(#27442)
* [MWB] Migrate to PowerToys-style shortcuts and disable Ctrlx3 for multiple mode * f: analyzer fixes * f: add Win to all default shortcuts * f: remove capture screen feature * f: add ability to disable shortcut * f: restrict disabling shortcuts only for MWB for now, because we don't explicitly support this feature anywhere else * handle downgrade->upgrade scenario * f: res loader * f: fix disabled state * f: fix L hotkey handling
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using CommunityToolkit.WinUI.UI;
|
||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.UI.Xaml;
|
||||
@@ -33,9 +34,39 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
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);
|
||||
|
||||
public static readonly DependencyProperty AllowDisableProperty = DependencyProperty.Register("AllowDisable", typeof(bool), typeof(ShortcutControl), new PropertyMetadata(false, OnAllowDisableChanged));
|
||||
|
||||
private static void OnAllowDisableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var me = d as ShortcutControl;
|
||||
if (me == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var description = me.c?.FindDescendant<TextBlock>();
|
||||
if (description == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
||||
|
||||
var newValue = (bool)(e?.NewValue ?? false);
|
||||
|
||||
var text = newValue ? resourceLoader.GetString("Activation_Shortcut_With_Disable_Description") : resourceLoader.GetString("Activation_Shortcut_Description");
|
||||
description.Text = text;
|
||||
}
|
||||
|
||||
private ShortcutDialogContentControl c = new ShortcutDialogContentControl();
|
||||
private ContentDialog shortcutDialog;
|
||||
|
||||
public bool AllowDisable
|
||||
{
|
||||
get => (bool)GetValue(AllowDisableProperty);
|
||||
set => SetValue(AllowDisableProperty, value);
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
@@ -106,9 +137,12 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
};
|
||||
shortcutDialog.PrimaryButtonClick += ShortcutDialog_PrimaryButtonClick;
|
||||
shortcutDialog.SecondaryButtonClick += ShortcutDialog_Reset;
|
||||
shortcutDialog.RightTapped += ShortcutDialog_Disable;
|
||||
shortcutDialog.Opened += ShortcutDialog_Opened;
|
||||
shortcutDialog.Closing += ShortcutDialog_Closing;
|
||||
AutomationProperties.SetName(EditButton, resourceLoader.GetString("Activation_Shortcut_Title"));
|
||||
|
||||
OnAllowDisableChanged(this, null);
|
||||
}
|
||||
|
||||
private void ShortcutControl_Unloaded(object sender, RoutedEventArgs e)
|
||||
@@ -381,6 +415,21 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
shortcutDialog.Hide();
|
||||
}
|
||||
|
||||
private void ShortcutDialog_Disable(object sender, RightTappedRoutedEventArgs e)
|
||||
{
|
||||
if (!AllowDisable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var empty = new HotkeySettings();
|
||||
HotkeySettings = empty;
|
||||
|
||||
PreviewKeysControl.ItemsSource = HotkeySettings.GetKeysList();
|
||||
AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString());
|
||||
shortcutDialog.Hide();
|
||||
}
|
||||
|
||||
private static bool ComboIsValid(HotkeySettings settings)
|
||||
{
|
||||
if (settings != null && (settings.IsValid() || settings.IsEmpty()))
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock
|
||||
x:Uid="Activation_Shortcut_Description"
|
||||
Grid.Row="0" />
|
||||
|
||||
<ItemsControl
|
||||
|
||||
Reference in New Issue
Block a user