Skip to content

Commit ad894b6

Browse files
committed
Improve hotkey error dialog and logic
Localizes hotkey error dialog and highlights the hotkey control
1 parent 558710f commit ad894b6

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎AuraClick/Pages/MainPage.xaml.cs‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ private async Task ShowHotkeyRegistrationFailedAsync()
8383
// XamlRoot must be set in the case of a ContentDialog running in a Desktop app
8484
XamlRoot = XamlRoot,
8585
Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style,
86-
Title = "Invalid hotkey",
87-
Content = "Failed to register hotkey. Change the hotkey to another key.",
88-
CloseButtonText = "Close",
86+
Title = "ContentDialogHotkeyFailedTitle".GetLocalized(),
87+
Content = "ContentDialogHotkeyFailedContent".GetLocalized(),
88+
CloseButtonText = "ContentDialogHotkeyFailedCloseButtonText".GetLocalized(),
8989
DefaultButton = ContentDialogButton.Close
9090
};
9191

@@ -94,14 +94,32 @@ private async Task ShowHotkeyRegistrationFailedAsync()
9494

9595
private async Task ApplyHotkeySelectionAsync()
9696
{
97-
if (HotkeyManager.RegisterHotkey(ToggleHotkeyId, ToggleShortcut.Keys))
97+
bool registered = HotkeyManager.RegisterHotkey(ToggleHotkeyId, ToggleShortcut.Keys);
98+
SetShortcutError(!registered);
99+
100+
if (registered)
98101
{
99102
return;
100103
}
101104

102105
await ShowHotkeyRegistrationFailedAsync();
103106
}
104107

108+
/// <summary>
109+
/// Shows or clears the error state on the hotkey's key visuals.
110+
/// </summary>
111+
private void SetShortcutError(bool isError)
112+
{
113+
// Shortcut doesn't expose an error state, and its key visuals are regenerated whenever its keys change.
114+
ToggleShortcut.UpdateLayout();
115+
foreach (KeyVisual keyVisual in ToggleShortcut.FindDescendants().OfType<KeyVisual>())
116+
{
117+
keyVisual.IsError = isError;
118+
}
119+
120+
ToolTipService.SetToolTip(ToggleShortcut, isError ? "ContentDialogHotkeyFailedContent".GetLocalized() : null);
121+
}
122+
105123
/// <summary>
106124
/// Determines whether a control should be enabled based on a checkbox state and a running-state toggle.
107125
/// </summary>

‎AuraClick/Strings/en-US/Resources.resw‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)