Start working on handling duplicate hotkeys

This commit is contained in:
Yusyuriv 2024-04-24 20:23:11 +06:00
parent 4ce591fa20
commit de8036bdba
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
3 changed files with 67 additions and 20 deletions

View file

@ -82,7 +82,8 @@
<Border
x:Name="Alert"
Width="420"
Height="50"
Padding="0, 10"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Background="{DynamicResource InfoBarWarningBG}"
BorderBrush="{DynamicResource InfoBarBD}"
@ -90,21 +91,26 @@
CornerRadius="5"
Visibility="Collapsed">
<Grid VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<ui:FontIcon
Margin="20,0,14,0"
VerticalAlignment="Center"
FontSize="15"
Foreground="{DynamicResource InfoBarWarningIcon}"
Glyph="&#xf167;" />
<TextBlock
x:Name="tbMsg"
Margin="0,0,0,2"
HorizontalAlignment="Left"
FontSize="13"
FontWeight="SemiBold"
Foreground="{DynamicResource Color05B}" />
</StackPanel>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:FontIcon
Grid.Column="0"
Margin="20,0,14,0"
VerticalAlignment="Center"
FontSize="15"
Foreground="{DynamicResource InfoBarWarningIcon}"
Glyph="&#xf167;" />
<TextBlock
Grid.Column="1"
x:Name="tbMsg"
Margin="0,0,0,2"
HorizontalAlignment="Left"
FontSize="13"
FontWeight="SemiBold"
TextWrapping="Wrap"
Foreground="{DynamicResource Color05B}" />
</Grid>
</Border>

View file

@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
using Flow.Launcher.Core.Resource;
@ -16,6 +17,28 @@ public partial class HotkeyControlDialog : ContentDialog
public HotkeyModel CurrentHotkey { get; private set; }
public ObservableCollection<string> KeysToDisplay { get; } = new();
private readonly Dictionary<HotkeyModel, string> StaticHotkeys = new()
{
[new HotkeyModel("Escape")] = "", // TODO
[new HotkeyModel("F5")] = "ReloadPluginHotkey",
[new HotkeyModel("Alt+Home")] = "Select first result", // TODO
[new HotkeyModel("Alt+End")] = "Select last result", // TODO
[new HotkeyModel("Ctrl+R")] = "Requery", // TODO
[new HotkeyModel("Ctrl+H")] = "ToggleHistoryHotkey",
[new HotkeyModel("Ctrl+OemCloseBrackets")] = "QuickWidthHotkey",
[new HotkeyModel("Ctrl+OemOpenBrackets")] = "QuickWidthHotkey",
[new HotkeyModel("Ctrl+OemPlus")] = "QuickHeightHotkey",
[new HotkeyModel("Ctrl+OemMinus")] = "QuickHeightHotkey",
[new HotkeyModel("Ctrl+Shift+Enter")] = "HotkeyCtrlShiftEnterDesc",
[new HotkeyModel("Shift+Enter")] = "OpenContextMenuHotkey",
[new HotkeyModel("Enter")] = "HotkeyRunDesc",
[new HotkeyModel("Ctrl+Enter")] = "Open result", // TODO
[new HotkeyModel("Alt+Enter")] = "Open result", // TODO
// TODO D0-D9 But not here since they're not completely static, they can be Ctrl+D0-D9, Alt+D0-D9, or Ctrl+Alt+D0-D9
[new HotkeyModel("Ctrl+F12")] = "ToggleGameModeHotkey",
[new HotkeyModel("Ctrl+Shift+C")] = "Copy alternative", // TODO
};
public enum EResultType
{
Cancel,
@ -109,11 +132,20 @@ public partial class HotkeyControlDialog : ContentDialog
if (tbMsg == null)
return;
if (StaticHotkeys.TryGetValue((HotkeyModel)hotkey, out var staticHotkey))
{
ShowWarningAndDisableSaveButton(
string.Format(
InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableInUseStatic"),
InternationalizationManager.Instance.GetTranslation(staticHotkey)
)
);
return;
}
if (!CheckHotkeyAvailability(hotkey.Value, true))
{
tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable");
Alert.Visibility = Visibility.Visible;
SaveBtn.IsEnabled = false;
ShowWarningAndDisableSaveButton(InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable"));
}
else
{
@ -122,6 +154,13 @@ public partial class HotkeyControlDialog : ContentDialog
}
}
private void ShowWarningAndDisableSaveButton(string message)
{
tbMsg.Text = message;
Alert.Visibility = Visibility.Visible;
SaveBtn.IsEnabled = false;
}
private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) =>
hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey);
}

View file

@ -311,6 +311,8 @@
<system:String x:Key="update">Update</system:String>
<system:String x:Key="hotkeyRegTitle">Binding Hotkey</system:String>
<system:String x:Key="hotkeyUnavailable">Current hotkey is unavailable.</system:String>
<system:String x:Key="hotkeyUnavailableInUseStatic">This hotkey is unavailable because it is reserved for Flow Launcher's functionality: {0}.</system:String>
<system:String x:Key="hotkeyUnavailableInUse">This hotkey is unavailable because it is already used for {0}.</system:String>
<system:String x:Key="hotkeyRegGuide">Press the keys you want to use for this function.</system:String>
<!-- Custom Query Shortcut Dialog -->