Skip to content

Commit de8036b

Browse files
committed
Start working on handling duplicate hotkeys
1 parent 4ce591f commit de8036b

File tree

3 files changed

+67
-20
lines changed

3 files changed

+67
-20
lines changed

Flow.Launcher/HotkeyControlDialog.xaml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,35 @@
8282
<Border
8383
x:Name="Alert"
8484
Width="420"
85-
Height="50"
85+
Padding="0, 10"
86+
VerticalAlignment="Center"
8687
HorizontalAlignment="Center"
8788
Background="{DynamicResource InfoBarWarningBG}"
8889
BorderBrush="{DynamicResource InfoBarBD}"
8990
BorderThickness="1"
9091
CornerRadius="5"
9192
Visibility="Collapsed">
9293
<Grid VerticalAlignment="Center">
93-
<StackPanel Orientation="Horizontal">
94-
<ui:FontIcon
95-
Margin="20,0,14,0"
96-
VerticalAlignment="Center"
97-
FontSize="15"
98-
Foreground="{DynamicResource InfoBarWarningIcon}"
99-
Glyph="&#xf167;" />
100-
<TextBlock
101-
x:Name="tbMsg"
102-
Margin="0,0,0,2"
103-
HorizontalAlignment="Left"
104-
FontSize="13"
105-
FontWeight="SemiBold"
106-
Foreground="{DynamicResource Color05B}" />
107-
</StackPanel>
94+
<Grid.ColumnDefinitions>
95+
<ColumnDefinition Width="Auto" />
96+
<ColumnDefinition Width="*" />
97+
</Grid.ColumnDefinitions>
98+
<ui:FontIcon
99+
Grid.Column="0"
100+
Margin="20,0,14,0"
101+
VerticalAlignment="Center"
102+
FontSize="15"
103+
Foreground="{DynamicResource InfoBarWarningIcon}"
104+
Glyph="&#xf167;" />
105+
<TextBlock
106+
Grid.Column="1"
107+
x:Name="tbMsg"
108+
Margin="0,0,0,2"
109+
HorizontalAlignment="Left"
110+
FontSize="13"
111+
FontWeight="SemiBold"
112+
TextWrapping="Wrap"
113+
Foreground="{DynamicResource Color05B}" />
108114
</Grid>
109115
</Border>
110116

Flow.Launcher/HotkeyControlDialog.xaml.cs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
23
using System.Windows;
34
using System.Windows.Input;
45
using Flow.Launcher.Core.Resource;
@@ -16,6 +17,28 @@ public partial class HotkeyControlDialog : ContentDialog
1617
public HotkeyModel CurrentHotkey { get; private set; }
1718
public ObservableCollection<string> KeysToDisplay { get; } = new();
1819

20+
private readonly Dictionary<HotkeyModel, string> StaticHotkeys = new()
21+
{
22+
[new HotkeyModel("Escape")] = "", // TODO
23+
[new HotkeyModel("F5")] = "ReloadPluginHotkey",
24+
[new HotkeyModel("Alt+Home")] = "Select first result", // TODO
25+
[new HotkeyModel("Alt+End")] = "Select last result", // TODO
26+
[new HotkeyModel("Ctrl+R")] = "Requery", // TODO
27+
[new HotkeyModel("Ctrl+H")] = "ToggleHistoryHotkey",
28+
[new HotkeyModel("Ctrl+OemCloseBrackets")] = "QuickWidthHotkey",
29+
[new HotkeyModel("Ctrl+OemOpenBrackets")] = "QuickWidthHotkey",
30+
[new HotkeyModel("Ctrl+OemPlus")] = "QuickHeightHotkey",
31+
[new HotkeyModel("Ctrl+OemMinus")] = "QuickHeightHotkey",
32+
[new HotkeyModel("Ctrl+Shift+Enter")] = "HotkeyCtrlShiftEnterDesc",
33+
[new HotkeyModel("Shift+Enter")] = "OpenContextMenuHotkey",
34+
[new HotkeyModel("Enter")] = "HotkeyRunDesc",
35+
[new HotkeyModel("Ctrl+Enter")] = "Open result", // TODO
36+
[new HotkeyModel("Alt+Enter")] = "Open result", // TODO
37+
// 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
38+
[new HotkeyModel("Ctrl+F12")] = "ToggleGameModeHotkey",
39+
[new HotkeyModel("Ctrl+Shift+C")] = "Copy alternative", // TODO
40+
};
41+
1942
public enum EResultType
2043
{
2144
Cancel,
@@ -109,11 +132,20 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
109132
if (tbMsg == null)
110133
return;
111134

135+
136+
if (StaticHotkeys.TryGetValue((HotkeyModel)hotkey, out var staticHotkey))
137+
{
138+
ShowWarningAndDisableSaveButton(
139+
string.Format(
140+
InternationalizationManager.Instance.GetTranslation("hotkeyUnavailableInUseStatic"),
141+
InternationalizationManager.Instance.GetTranslation(staticHotkey)
142+
)
143+
);
144+
return;
145+
}
112146
if (!CheckHotkeyAvailability(hotkey.Value, true))
113147
{
114-
tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable");
115-
Alert.Visibility = Visibility.Visible;
116-
SaveBtn.IsEnabled = false;
148+
ShowWarningAndDisableSaveButton(InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable"));
117149
}
118150
else
119151
{
@@ -122,6 +154,13 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
122154
}
123155
}
124156

157+
private void ShowWarningAndDisableSaveButton(string message)
158+
{
159+
tbMsg.Text = message;
160+
Alert.Visibility = Visibility.Visible;
161+
SaveBtn.IsEnabled = false;
162+
}
163+
125164
private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) =>
126165
hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey);
127166
}

Flow.Launcher/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@
311311
<system:String x:Key="update">Update</system:String>
312312
<system:String x:Key="hotkeyRegTitle">Binding Hotkey</system:String>
313313
<system:String x:Key="hotkeyUnavailable">Current hotkey is unavailable.</system:String>
314+
<system:String x:Key="hotkeyUnavailableInUseStatic">This hotkey is unavailable because it is reserved for Flow Launcher's functionality: {0}.</system:String>
315+
<system:String x:Key="hotkeyUnavailableInUse">This hotkey is unavailable because it is already used for {0}.</system:String>
314316
<system:String x:Key="hotkeyRegGuide">Press the keys you want to use for this function.</system:String>
315317

316318
<!-- Custom Query Shortcut Dialog -->

0 commit comments

Comments
 (0)