mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[Settings] Shortcut edit dialog: Fix bugs (#25060)
* custom error badge * fix theme bug * fix focus bug (#25051) * use Infobar control * add comments
This commit is contained in:
@@ -79,6 +79,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetDisposedState() => disposedValue;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
|
||||
@@ -89,6 +89,8 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive, FilterAccessibleKeyboardEvents);
|
||||
ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse();
|
||||
|
||||
App.GetSettingsWindow().Activated += ShortcutDialog_SettingsWindow_Activated;
|
||||
|
||||
// We create the Dialog in C# because doing it in XAML is giving WinUI/XAML Island bugs when using dark theme.
|
||||
shortcutDialog = new ContentDialog
|
||||
{
|
||||
@@ -111,6 +113,8 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
shortcutDialog.Opened -= ShortcutDialog_Opened;
|
||||
shortcutDialog.Closing -= ShortcutDialog_Closing;
|
||||
|
||||
App.GetSettingsWindow().Activated -= ShortcutDialog_SettingsWindow_Activated;
|
||||
|
||||
// Dispose the HotkeySettingsControlHook object to terminate the hook threads when the textbox is unloaded
|
||||
hook.Dispose();
|
||||
}
|
||||
@@ -336,6 +340,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
c.Keys = HotkeySettings.GetKeysList();
|
||||
|
||||
shortcutDialog.XamlRoot = this.XamlRoot;
|
||||
shortcutDialog.RequestedTheme = this.ActualTheme;
|
||||
await shortcutDialog.ShowAsync();
|
||||
}
|
||||
|
||||
@@ -363,6 +368,21 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
}
|
||||
}
|
||||
|
||||
private void ShortcutDialog_SettingsWindow_Activated(object sender, WindowActivatedEventArgs args)
|
||||
{
|
||||
args.Handled = true;
|
||||
if (args.WindowActivationState != WindowActivationState.Deactivated && hook.GetDisposedState() == true)
|
||||
{
|
||||
// If the PT settings window gets focussed/activated again, we enable the keyboard hook to catch the keyboard input.
|
||||
hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive, FilterAccessibleKeyboardEvents);
|
||||
}
|
||||
else if (args.WindowActivationState == WindowActivationState.Deactivated && hook.GetDisposedState() == false)
|
||||
{
|
||||
// If the PT settings window lost focus/activation, we disable the keyboard hook to allow keyboard input on other windows.
|
||||
hook.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShortcutDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
|
||||
{
|
||||
_isActive = false;
|
||||
|
||||
@@ -56,39 +56,14 @@
|
||||
VerticalAlignment="Top"
|
||||
Orientation="Vertical"
|
||||
Spacing="8">
|
||||
<Grid Height="36">
|
||||
<Grid Height="62">
|
||||
|
||||
<Border
|
||||
x:Name="WarningBanner"
|
||||
Margin="-2,0,0,0"
|
||||
Padding="8"
|
||||
Background="{ThemeResource InfoBarErrorSeverityBackgroundBrush}"
|
||||
BorderBrush="{ThemeResource InfoBarBorderBrush}"
|
||||
BorderThickness="{ThemeResource InfoBarBorderThickness}"
|
||||
CornerRadius="{ThemeResource ControlCornerRadius}"
|
||||
Visibility="{Binding ElementName=ShortcutContentControl, Path=IsError, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<InfoBar x:Uid="InvalidShortcut"
|
||||
IsClosable="False"
|
||||
IsOpen="{Binding ElementName=ShortcutContentControl, Path=IsError, Mode=OneWay}"
|
||||
IsTabStop="{Binding ElementName=ShortcutContentControl, Path=IsError, Mode=OneWay}"
|
||||
Severity="Error" />
|
||||
|
||||
<!--TODO(stefan) InfoBadge not available
|
||||
<InfoBadge AutomationProperties.AccessibilityView="Raw"
|
||||
Margin="2,0,12,0"
|
||||
Style="{StaticResource CriticalIconInfoBadgeStyle}" />
|
||||
-->
|
||||
|
||||
<TextBlock
|
||||
x:Name="InvalidShortcutWarningLabel"
|
||||
x:Uid="InvalidShortcut"
|
||||
Grid.Column="1"
|
||||
Margin="0,-1,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontWeight="{ThemeResource InfoBarTitleFontWeight}"
|
||||
Foreground="{ThemeResource InfoBarTitleForeground}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
<toolkitcontrols:MarkdownTextBlock
|
||||
x:Uid="InvalidShortcutWarningLabel"
|
||||
|
||||
@@ -2119,11 +2119,12 @@ From there, simply click on one of the supported files in the File Explorer and
|
||||
<data name="Activation_Shortcut_Title" xml:space="preserve">
|
||||
<value>Activation shortcut</value>
|
||||
</data>
|
||||
<data name="InvalidShortcut.Text" xml:space="preserve">
|
||||
<data name="InvalidShortcut.Title" xml:space="preserve">
|
||||
<value>Invalid shortcut</value>
|
||||
</data>
|
||||
<data name="InvalidShortcutWarningLabel.Text" xml:space="preserve">
|
||||
<value>Only shortcuts that start with **Windows key**, **Ctrl**, **Alt** or **Shift** are valid.</value>
|
||||
<comment>The ** sequences are used for text formatting of the key names. Don't remove them on translation.</comment>
|
||||
</data>
|
||||
<data name="FancyZones_SpanZonesAcrossMonitors.Description" xml:space="preserve">
|
||||
<value>All monitors must have the same DPI scaling and will be treated as one large combined rectangle which contains all monitors</value>
|
||||
@@ -3115,4 +3116,4 @@ Activate by holding the key for the character you want to add an accent to, then
|
||||
<data name="RegistryPreview_LaunchButtonControl.Header" xml:space="preserve">
|
||||
<value>Launch Registry Preview</value>
|
||||
</data>
|
||||
</root>
|
||||
</root>
|
||||
Reference in New Issue
Block a user