Skip to content

Commit 737d29a

Browse files
committed
Implement checking for duplicate hotkeys and overwriting them
1 parent de8036b commit 737d29a

File tree

11 files changed

+201
-56
lines changed

11 files changed

+201
-56
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Collections.Generic;
2+
3+
namespace Flow.Launcher.Infrastructure.Hotkey;
4+
5+
public interface IHotkeySettings
6+
{
7+
public List<RegisteredHotkeyData> RegisteredHotkeys { get; }
8+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
namespace Flow.Launcher.Infrastructure.Hotkey;
4+
5+
#nullable enable
6+
7+
public record RegisteredHotkeyData
8+
{
9+
public HotkeyModel Hotkey { get; }
10+
public string Description { get; }
11+
public Action? RemoveHotkey { get; }
12+
13+
public RegisteredHotkeyData(string hotkey, string description, Action? removeHotkey = null)
14+
{
15+
Hotkey = new HotkeyModel(hotkey);
16+
Description = description;
17+
RemoveHotkey = removeHotkey;
18+
}
19+
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
using System.Drawing;
55
using System.Text.Json.Serialization;
66
using System.Windows;
7+
using Flow.Launcher.Infrastructure.Hotkey;
78
using Flow.Launcher.Plugin;
89
using Flow.Launcher.Plugin.SharedModels;
910
using Flow.Launcher.ViewModel;
1011

1112
namespace Flow.Launcher.Infrastructure.UserSettings
1213
{
13-
public class Settings : BaseModel
14+
public class Settings : BaseModel, IHotkeySettings
1415
{
1516
private string language = "en";
1617
private string _theme = Constant.DefaultTheme;
@@ -207,17 +208,17 @@ public string QuerySearchPrecisionString
207208

208209
public double WindowLeft { get; set; }
209210
public double WindowTop { get; set; }
210-
211+
211212
/// <summary>
212213
/// Custom left position on selected monitor
213214
/// </summary>
214215
public double CustomWindowLeft { get; set; } = 0;
215-
216+
216217
/// <summary>
217218
/// Custom top position on selected monitor
218219
/// </summary>
219220
public double CustomWindowTop { get; set; } = 0;
220-
221+
221222
public int MaxResultsToShow { get; set; } = 5;
222223
public int ActivateTimes { get; set; }
223224

@@ -229,7 +230,7 @@ public string QuerySearchPrecisionString
229230
[JsonIgnore]
230231
public ObservableCollection<BuiltinShortcutModel> BuiltinShortcuts { get; set; } = new()
231232
{
232-
new BuiltinShortcutModel("{clipboard}", "shortcut_clipboard_description", Clipboard.GetText),
233+
new BuiltinShortcutModel("{clipboard}", "shortcut_clipboard_description", Clipboard.GetText),
233234
new BuiltinShortcutModel("{active_explorer_path}", "shortcut_active_explorer_path", FileExplorerHelper.GetActiveExplorerPath)
234235
};
235236

@@ -253,7 +254,7 @@ public bool HideNotifyIcon
253254

254255
[JsonConverter(typeof(JsonStringEnumConverter))]
255256
public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.Cursor;
256-
257+
257258
[JsonConverter(typeof(JsonStringEnumConverter))]
258259
public SearchWindowAligns SearchWindowAlign { get; set; } = SearchWindowAligns.Center;
259260

@@ -273,6 +274,78 @@ public bool HideNotifyIcon
273274

274275
// This needs to be loaded last by staying at the bottom
275276
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();
277+
278+
[JsonIgnore]
279+
public List<RegisteredHotkeyData> RegisteredHotkeys
280+
{
281+
get
282+
{
283+
var list = new List<RegisteredHotkeyData>
284+
{
285+
new("Escape", "Escape"), // TODO
286+
new("F5", "ReloadPluginHotkey"), // TODO
287+
new("Alt+Home", "Select last result"), // TODO
288+
new("Alt+End", "Select last result"), // TODO
289+
new("Ctrl+R", "Requery"), // TODO
290+
new("Ctrl+H", "ToggleHistoryHotkey"), // TODO
291+
new("Ctrl+OemCloseBrackets", "QuickWidthHotkey"), // TODO
292+
new("Ctrl+OemOpenBrackets", "QuickWidthHotkey"), // TODO
293+
new("Ctrl+OemPlus", "QuickHeightHotkey"), // TODO
294+
new("Ctrl+OemMinus", "QuickHeightHotkey"), // TODO
295+
new("Ctrl+Shift+Enter", "HotkeyCtrlShiftEnterDesc"), // TODO
296+
new("Shift+Enter", "OpenContextMenuHotkey"), // TODO
297+
new("Enter", "HotkeyRunDesc"), // TODO
298+
new("Ctrl+Enter", "Open result"), // TODO
299+
new("Alt+Enter", "Open result"), // TODO
300+
new("Ctrl+F12", "ToggleGameModeHotkey"), // TODO
301+
new("Ctrl+Shift+C", "Copy alternative"), // TODO
302+
303+
new($"{OpenResultModifiers}+D1", "Open Result"), // TODO
304+
new($"{OpenResultModifiers}+D2", "Open Result"), // TODO
305+
new($"{OpenResultModifiers}+D3", "Open Result"), // TODO
306+
new($"{OpenResultModifiers}+D4", "Open Result"), // TODO
307+
new($"{OpenResultModifiers}+D5", "Open Result"), // TODO
308+
new($"{OpenResultModifiers}+D6", "Open Result"), // TODO
309+
new($"{OpenResultModifiers}+D7", "Open Result"), // TODO
310+
new($"{OpenResultModifiers}+D8", "Open Result"), // TODO
311+
new($"{OpenResultModifiers}+D9", "Open Result"), // TODO
312+
new($"{OpenResultModifiers}+D0", "Open Result"), // TODO
313+
};
314+
315+
if(!string.IsNullOrEmpty(Hotkey))
316+
list.Add(new(Hotkey, "Open main window", () => Hotkey = "")); // TODO
317+
if(!string.IsNullOrEmpty(PreviewHotkey))
318+
list.Add(new(PreviewHotkey, "Preview Hotkey", () => PreviewHotkey = "")); // TODO
319+
if(!string.IsNullOrEmpty(AutoCompleteHotkey))
320+
list.Add(new(AutoCompleteHotkey, "AutoCompleteHotkey", () => AutoCompleteHotkey = "")); // TODO
321+
if(!string.IsNullOrEmpty(AutoCompleteHotkey2))
322+
list.Add(new(AutoCompleteHotkey2, "AutoCompleteHotkey", () => AutoCompleteHotkey2 = "")); // TODO
323+
if(!string.IsNullOrEmpty(SelectNextItemHotkey))
324+
list.Add(new(SelectNextItemHotkey, "SelectNextItemHotkey", () => SelectNextItemHotkey = "")); // TODO
325+
if(!string.IsNullOrEmpty(SelectNextItemHotkey2))
326+
list.Add(new(SelectNextItemHotkey2, "SelectNextItemHotkey", () => SelectNextItemHotkey2 = "")); // TODO
327+
if(!string.IsNullOrEmpty(SelectPrevItemHotkey))
328+
list.Add(new(SelectPrevItemHotkey, "SelectPrevItemHotkey", () => SelectPrevItemHotkey = "")); // TODO
329+
if(!string.IsNullOrEmpty(SelectPrevItemHotkey2))
330+
list.Add(new(SelectPrevItemHotkey2, "SelectPrevItemHotkey", () => SelectPrevItemHotkey2 = "")); // TODO
331+
if(!string.IsNullOrEmpty(SettingWindowHotkey))
332+
list.Add(new(SettingWindowHotkey, "SettingWindowHotkey", () => SettingWindowHotkey = "")); // TODO
333+
if(!string.IsNullOrEmpty(OpenContextMenuHotkey))
334+
list.Add(new(OpenContextMenuHotkey, "OpenContextMenuHotkey", () => OpenContextMenuHotkey = "")); // TODO
335+
if(!string.IsNullOrEmpty(SelectNextPageHotkey))
336+
list.Add(new(SelectNextPageHotkey, "SelectNextPageHotkey", () => SelectNextPageHotkey = "")); // TODO
337+
if(!string.IsNullOrEmpty(SelectPrevPageHotkey))
338+
list.Add(new(SelectPrevPageHotkey, "SelectPrevPageHotkey", () => SelectPrevPageHotkey = "")); // TODO
339+
340+
foreach (var customPluginHotkey in CustomPluginHotkeys)
341+
{
342+
if (!string.IsNullOrEmpty(customPluginHotkey.Hotkey))
343+
list.Add(new(customPluginHotkey.Hotkey, "Custom plugin hotkey", () => customPluginHotkey.Hotkey = "")); // TODO
344+
}
345+
346+
return list;
347+
}
348+
}
276349
}
277350

278351
public enum LastQueryMode
@@ -288,7 +361,7 @@ public enum ColorSchemes
288361
Light,
289362
Dark
290363
}
291-
364+
292365
public enum SearchWindowScreens
293366
{
294367
RememberLastLaunchLocation,
@@ -297,7 +370,7 @@ public enum SearchWindowScreens
297370
Primary,
298371
Custom
299372
}
300-
373+
301374
public enum SearchWindowAligns
302375
{
303376
Center,

Flow.Launcher/CustomQueryHotkeySetting.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
HorizontalAlignment="Left"
107107
VerticalAlignment="Center"
108108
HorizontalContentAlignment="Left"
109+
HotkeySettings="{Binding Settings}"
109110
DefaultHotkey="" />
110111
<TextBlock
111112
Grid.Row="1"

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public partial class CustomQueryHotkeySetting : Window
1515
private SettingWindow _settingWidow;
1616
private bool update;
1717
private CustomPluginHotkey updateCustomHotkey;
18-
private Settings _settings;
18+
public Settings Settings { get; }
1919

2020
public CustomQueryHotkeySetting(SettingWindow settingWidow, Settings settings)
2121
{
2222
_settingWidow = settingWidow;
23+
Settings = settings;
2324
InitializeComponent();
24-
_settings = settings;
2525
}
2626

2727
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
@@ -33,13 +33,13 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
3333
{
3434
if (!update)
3535
{
36-
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
36+
Settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
3737

3838
var pluginHotkey = new CustomPluginHotkey
3939
{
4040
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
4141
};
42-
_settings.CustomPluginHotkeys.Add(pluginHotkey);
42+
Settings.CustomPluginHotkeys.Add(pluginHotkey);
4343

4444
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
4545
}
@@ -59,7 +59,7 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
5959

6060
public void UpdateItem(CustomPluginHotkey item)
6161
{
62-
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
62+
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
6363
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
6464
if (updateCustomHotkey == null)
6565
{

Flow.Launcher/HotkeyControl.xaml.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ namespace Flow.Launcher
1212
{
1313
public partial class HotkeyControl
1414
{
15+
public IHotkeySettings HotkeySettings {
16+
get { return (IHotkeySettings)GetValue(HotkeySettingsProperty); }
17+
set { SetValue(HotkeySettingsProperty, value); }
18+
}
19+
20+
public static readonly DependencyProperty HotkeySettingsProperty = DependencyProperty.Register(
21+
nameof(HotkeySettings),
22+
typeof(IHotkeySettings),
23+
typeof(HotkeyControl),
24+
new PropertyMetadata()
25+
);
1526
public string WindowTitle {
1627
get { return (string)GetValue(WindowTitleProperty); }
1728
set { SetValue(WindowTitleProperty, value); }
@@ -122,7 +133,7 @@ private async Task OpenHotkeyDialog()
122133
HotKeyMapper.RemoveHotkey(Hotkey);
123134
}
124135

125-
var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, WindowTitle);
136+
var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, HotkeySettings, WindowTitle);
126137
await dialog.ShowAsync();
127138
switch (dialog.ResultType)
128139
{

Flow.Launcher/HotkeyControlDialog.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
Grid.Column="1"
107107
x:Name="tbMsg"
108108
Margin="0,0,0,2"
109+
Padding="0,0,8,0"
109110
HorizontalAlignment="Left"
110111
FontSize="13"
111112
FontWeight="SemiBold"
@@ -127,6 +128,15 @@
127128
Margin="10"
128129
HorizontalAlignment="Center"
129130
Orientation="Horizontal">
131+
<Button
132+
x:Name="OverwriteBtn"
133+
Height="30"
134+
MinWidth="100"
135+
Margin="0,0,4,0"
136+
Click="Overwrite"
137+
Content="{DynamicResource commonOverwrite}"
138+
Visibility="Collapsed"
139+
Style="{StaticResource AccentButtonStyle}" />
130140
<Button
131141
x:Name="SaveBtn"
132142
Height="30"

0 commit comments

Comments
 (0)