-
-
Notifications
You must be signed in to change notification settings - Fork 455
Handle duplicate hotkeys in HotkeyControlDialog #2667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
de8036b
Start working on handling duplicate hotkeys
Yusyuriv 737d29a
Implement checking for duplicate hotkeys and overwriting them
Yusyuriv 15d5510
Implement displaying localized warning messages for duplicate hotkeys…
Yusyuriv 2cce361
Merge branch 'refs/heads/dev' into duplicate-hotkey-handling
Yusyuriv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Flow.Launcher.Infrastructure.Hotkey; | ||
|
|
||
| /// <summary> | ||
| /// Interface that you should implement in your settings class to be able to pass it to | ||
| /// <c>Flow.Launcher.HotkeyControlDialog</c>. It allows the dialog to display the hotkeys that have already been | ||
| /// registered, and optionally provide a way to unregister them. | ||
| /// </summary> | ||
| public interface IHotkeySettings | ||
| { | ||
| /// <summary> | ||
| /// A list of hotkeys that have already been registered. The dialog will display these hotkeys and provide a way to | ||
| /// unregister them. | ||
| /// </summary> | ||
| public List<RegisteredHotkeyData> RegisteredHotkeys { get; } | ||
| } |
119 changes: 119 additions & 0 deletions
119
Flow.Launcher.Infrastructure/Hotkey/RegisteredHotkeyData.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| using System; | ||
|
|
||
| namespace Flow.Launcher.Infrastructure.Hotkey; | ||
|
|
||
| #nullable enable | ||
|
|
||
| /// <summary> | ||
| /// Represents a hotkey that has been registered. Used in <c>Flow.Launcher.HotkeyControlDialog</c> via | ||
| /// <see cref="UserSettings"/> and <see cref="IHotkeySettings"/> to display errors if user tries to register a hotkey | ||
| /// that has already been registered, and optionally provides a way to unregister the hotkey. | ||
| /// </summary> | ||
| public record RegisteredHotkeyData | ||
| { | ||
| /// <summary> | ||
| /// <see cref="HotkeyModel"/> representation of this hotkey. | ||
| /// </summary> | ||
| public HotkeyModel Hotkey { get; } | ||
|
|
||
| /// <summary> | ||
| /// String key in the localization dictionary that represents this hotkey. For example, <c>ReloadPluginHotkey</c>, | ||
| /// which represents the string "Reload Plugins Data" in <c>en.xaml</c> | ||
| /// </summary> | ||
| public string DescriptionResourceKey { get; } | ||
|
|
||
| /// <summary> | ||
| /// Array of values that will replace <c>{0}</c>, <c>{1}</c>, <c>{2}</c>, etc. in the localized string found via | ||
| /// <see cref="DescriptionResourceKey"/>. | ||
| /// </summary> | ||
| public object?[] DescriptionFormatVariables { get; } = Array.Empty<object?>(); | ||
|
|
||
| /// <summary> | ||
| /// An action that, when called, will unregister this hotkey. If it's <c>null</c>, it's assumed that | ||
| /// this hotkey can't be unregistered, and the "Overwrite" option will not appear in the hotkey dialog. | ||
| /// </summary> | ||
| public Action? RemoveHotkey { get; } | ||
|
|
||
| /// <summary> | ||
| /// Creates an instance of <c>RegisteredHotkeyData</c>. Assumes that the key specified in | ||
| /// <c>descriptionResourceKey</c> doesn't need any arguments for <c>string.Format</c>. If it does, | ||
| /// use one of the other constructors. | ||
| /// </summary> | ||
| /// <param name="hotkey"> | ||
| /// The hotkey this class will represent. | ||
| /// Example values: <c>F1</c>, <c>Ctrl+Shift+Enter</c> | ||
| /// </param> | ||
| /// <param name="descriptionResourceKey"> | ||
| /// The key in the localization dictionary that represents this hotkey. For example, <c>ReloadPluginHotkey</c>, | ||
| /// which represents the string "Reload Plugins Data" in <c>en.xaml</c> | ||
| /// </param> | ||
| /// <param name="removeHotkey"> | ||
| /// An action that, when called, will unregister this hotkey. If it's <c>null</c>, it's assumed that this hotkey | ||
| /// can't be unregistered, and the "Overwrite" option will not appear in the hotkey dialog. | ||
| /// </param> | ||
| public RegisteredHotkeyData(string hotkey, string descriptionResourceKey, Action? removeHotkey = null) | ||
| { | ||
| Hotkey = new HotkeyModel(hotkey); | ||
| DescriptionResourceKey = descriptionResourceKey; | ||
| RemoveHotkey = removeHotkey; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates an instance of <c>RegisteredHotkeyData</c>. Assumes that the key specified in | ||
| /// <c>descriptionResourceKey</c> needs exactly one argument for <c>string.Format</c>. | ||
| /// </summary> | ||
| /// <param name="hotkey"> | ||
| /// The hotkey this class will represent. | ||
| /// Example values: <c>F1</c>, <c>Ctrl+Shift+Enter</c> | ||
| /// </param> | ||
| /// <param name="descriptionResourceKey"> | ||
| /// The key in the localization dictionary that represents this hotkey. For example, <c>ReloadPluginHotkey</c>, | ||
| /// which represents the string "Reload Plugins Data" in <c>en.xaml</c> | ||
| /// </param> | ||
| /// <param name="descriptionFormatVariable"> | ||
| /// The value that will replace <c>{0}</c> in the localized string found via <c>description</c>. | ||
| /// </param> | ||
| /// <param name="removeHotkey"> | ||
| /// An action that, when called, will unregister this hotkey. If it's <c>null</c>, it's assumed that this hotkey | ||
| /// can't be unregistered, and the "Overwrite" option will not appear in the hotkey dialog. | ||
| /// </param> | ||
| public RegisteredHotkeyData( | ||
| string hotkey, string descriptionResourceKey, object? descriptionFormatVariable, Action? removeHotkey = null | ||
| ) | ||
| { | ||
| Hotkey = new HotkeyModel(hotkey); | ||
| DescriptionResourceKey = descriptionResourceKey; | ||
| DescriptionFormatVariables = new[] { descriptionFormatVariable }; | ||
| RemoveHotkey = removeHotkey; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates an instance of <c>RegisteredHotkeyData</c>. Assumes that the key specified in | ||
| /// <paramref name="descriptionResourceKey"/> needs multiple arguments for <c>string.Format</c>. | ||
| /// </summary> | ||
| /// <param name="hotkey"> | ||
| /// The hotkey this class will represent. | ||
| /// Example values: <c>F1</c>, <c>Ctrl+Shift+Enter</c> | ||
| /// </param> | ||
| /// <param name="descriptionResourceKey"> | ||
| /// The key in the localization dictionary that represents this hotkey. For example, <c>ReloadPluginHotkey</c>, | ||
| /// which represents the string "Reload Plugins Data" in <c>en.xaml</c> | ||
| /// </param> | ||
| /// <param name="descriptionFormatVariables"> | ||
| /// Array of values that will replace <c>{0}</c>, <c>{1}</c>, <c>{2}</c>, etc. | ||
| /// in the localized string found via <c>description</c>. | ||
| /// </param> | ||
| /// <param name="removeHotkey"> | ||
| /// An action that, when called, will unregister this hotkey. If it's <c>null</c>, it's assumed that this hotkey | ||
| /// can't be unregistered, and the "Overwrite" option will not appear in the hotkey dialog. | ||
| /// </param> | ||
| public RegisteredHotkeyData( | ||
| string hotkey, string descriptionResourceKey, object?[] descriptionFormatVariables, Action? removeHotkey = null | ||
| ) | ||
| { | ||
| Hotkey = new HotkeyModel(hotkey); | ||
| DescriptionResourceKey = descriptionResourceKey; | ||
| DescriptionFormatVariables = descriptionFormatVariables; | ||
| RemoveHotkey = removeHotkey; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,14 @@ | |
| using System.Drawing; | ||
| using System.Text.Json.Serialization; | ||
| using System.Windows; | ||
| using Flow.Launcher.Infrastructure.Hotkey; | ||
| using Flow.Launcher.Plugin; | ||
| using Flow.Launcher.Plugin.SharedModels; | ||
| using Flow.Launcher.ViewModel; | ||
|
|
||
| namespace Flow.Launcher.Infrastructure.UserSettings | ||
| { | ||
| public class Settings : BaseModel | ||
| public class Settings : BaseModel, IHotkeySettings | ||
| { | ||
| private string language = "en"; | ||
| private string _theme = Constant.DefaultTheme; | ||
|
|
@@ -207,17 +208,17 @@ public string QuerySearchPrecisionString | |
|
|
||
| public double WindowLeft { get; set; } | ||
| public double WindowTop { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Custom left position on selected monitor | ||
| /// </summary> | ||
| public double CustomWindowLeft { get; set; } = 0; | ||
|
|
||
| /// <summary> | ||
| /// Custom top position on selected monitor | ||
| /// </summary> | ||
| public double CustomWindowTop { get; set; } = 0; | ||
|
|
||
| public int MaxResultsToShow { get; set; } = 5; | ||
| public int ActivateTimes { get; set; } | ||
|
|
||
|
|
@@ -229,7 +230,7 @@ public string QuerySearchPrecisionString | |
| [JsonIgnore] | ||
| public ObservableCollection<BuiltinShortcutModel> BuiltinShortcuts { get; set; } = new() | ||
| { | ||
| new BuiltinShortcutModel("{clipboard}", "shortcut_clipboard_description", Clipboard.GetText), | ||
| new BuiltinShortcutModel("{clipboard}", "shortcut_clipboard_description", Clipboard.GetText), | ||
| new BuiltinShortcutModel("{active_explorer_path}", "shortcut_active_explorer_path", FileExplorerHelper.GetActiveExplorerPath) | ||
| }; | ||
|
|
||
|
|
@@ -253,7 +254,7 @@ public bool HideNotifyIcon | |
|
|
||
| [JsonConverter(typeof(JsonStringEnumConverter))] | ||
| public SearchWindowScreens SearchWindowScreen { get; set; } = SearchWindowScreens.Cursor; | ||
|
|
||
| [JsonConverter(typeof(JsonStringEnumConverter))] | ||
| public SearchWindowAligns SearchWindowAlign { get; set; } = SearchWindowAligns.Center; | ||
|
|
||
|
|
@@ -273,6 +274,82 @@ public bool HideNotifyIcon | |
|
|
||
| // This needs to be loaded last by staying at the bottom | ||
| public PluginsSettings PluginSettings { get; set; } = new PluginsSettings(); | ||
|
|
||
| [JsonIgnore] | ||
| public List<RegisteredHotkeyData> RegisteredHotkeys | ||
| { | ||
| get | ||
| { | ||
| var list = new List<RegisteredHotkeyData> | ||
| { | ||
| new("Up", "HotkeyLeftRightDesc"), | ||
| new("Down", "HotkeyLeftRightDesc"), | ||
| new("Left", "HotkeyUpDownDesc"), | ||
| new("Right", "HotkeyUpDownDesc"), | ||
| new("Escape", "HotkeyESCDesc"), | ||
| new("F5", "ReloadPluginHotkey"), | ||
| new("Alt+Home", "HotkeySelectFirstResult"), | ||
| new("Alt+End", "HotkeySelectLastResult"), | ||
| new("Ctrl+R", "HotkeyRequery"), | ||
| new("Ctrl+H", "ToggleHistoryHotkey"), | ||
| new("Ctrl+OemCloseBrackets", "QuickWidthHotkey"), | ||
| new("Ctrl+OemOpenBrackets", "QuickWidthHotkey"), | ||
| new("Ctrl+OemPlus", "QuickHeightHotkey"), | ||
| new("Ctrl+OemMinus", "QuickHeightHotkey"), | ||
| new("Ctrl+Shift+Enter", "HotkeyCtrlShiftEnterDesc"), | ||
| new("Shift+Enter", "OpenContextMenuHotkey"), | ||
| new("Enter", "HotkeyRunDesc"), | ||
| new("Ctrl+Enter", "OpenContainFolderHotkey"), | ||
| new("Alt+Enter", "HotkeyOpenResult"), | ||
| new("Ctrl+F12", "ToggleGameModeHotkey"), | ||
| new("Ctrl+Shift+C", "CopyFilePathHotkey"), | ||
|
|
||
| new($"{OpenResultModifiers}+D1", "HotkeyOpenResultN", 1), | ||
| new($"{OpenResultModifiers}+D2", "HotkeyOpenResultN", 2), | ||
| new($"{OpenResultModifiers}+D3", "HotkeyOpenResultN", 3), | ||
| new($"{OpenResultModifiers}+D4", "HotkeyOpenResultN", 4), | ||
| new($"{OpenResultModifiers}+D5", "HotkeyOpenResultN", 5), | ||
| new($"{OpenResultModifiers}+D6", "HotkeyOpenResultN", 6), | ||
| new($"{OpenResultModifiers}+D7", "HotkeyOpenResultN", 7), | ||
| new($"{OpenResultModifiers}+D8", "HotkeyOpenResultN", 8), | ||
| new($"{OpenResultModifiers}+D9", "HotkeyOpenResultN", 9), | ||
| new($"{OpenResultModifiers}+D0", "HotkeyOpenResultN", 10) | ||
| }; | ||
|
|
||
| if(!string.IsNullOrEmpty(Hotkey)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh my god this seems terrible lol. I don't know whether there are better way to handle this....
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe at least split it to another function. |
||
| list.Add(new(Hotkey, "flowlauncherHotkey", () => Hotkey = "")); | ||
| if(!string.IsNullOrEmpty(PreviewHotkey)) | ||
| list.Add(new(PreviewHotkey, "previewHotkey", () => PreviewHotkey = "")); | ||
| if(!string.IsNullOrEmpty(AutoCompleteHotkey)) | ||
| list.Add(new(AutoCompleteHotkey, "autoCompleteHotkey", () => AutoCompleteHotkey = "")); | ||
| if(!string.IsNullOrEmpty(AutoCompleteHotkey2)) | ||
| list.Add(new(AutoCompleteHotkey2, "autoCompleteHotkey", () => AutoCompleteHotkey2 = "")); | ||
| if(!string.IsNullOrEmpty(SelectNextItemHotkey)) | ||
| list.Add(new(SelectNextItemHotkey, "SelectNextItemHotkey", () => SelectNextItemHotkey = "")); | ||
| if(!string.IsNullOrEmpty(SelectNextItemHotkey2)) | ||
| list.Add(new(SelectNextItemHotkey2, "SelectNextItemHotkey", () => SelectNextItemHotkey2 = "")); | ||
| if(!string.IsNullOrEmpty(SelectPrevItemHotkey)) | ||
| list.Add(new(SelectPrevItemHotkey, "SelectPrevItemHotkey", () => SelectPrevItemHotkey = "")); | ||
| if(!string.IsNullOrEmpty(SelectPrevItemHotkey2)) | ||
| list.Add(new(SelectPrevItemHotkey2, "SelectPrevItemHotkey", () => SelectPrevItemHotkey2 = "")); | ||
| if(!string.IsNullOrEmpty(SettingWindowHotkey)) | ||
| list.Add(new(SettingWindowHotkey, "SettingWindowHotkey", () => SettingWindowHotkey = "")); | ||
| if(!string.IsNullOrEmpty(OpenContextMenuHotkey)) | ||
| list.Add(new(OpenContextMenuHotkey, "OpenContextMenuHotkey", () => OpenContextMenuHotkey = "")); | ||
| if(!string.IsNullOrEmpty(SelectNextPageHotkey)) | ||
| list.Add(new(SelectNextPageHotkey, "SelectNextPageHotkey", () => SelectNextPageHotkey = "")); | ||
| if(!string.IsNullOrEmpty(SelectPrevPageHotkey)) | ||
| list.Add(new(SelectPrevPageHotkey, "SelectPrevPageHotkey", () => SelectPrevPageHotkey = "")); | ||
|
|
||
| foreach (var customPluginHotkey in CustomPluginHotkeys) | ||
| { | ||
| if (!string.IsNullOrEmpty(customPluginHotkey.Hotkey)) | ||
| list.Add(new(customPluginHotkey.Hotkey, "customQueryHotkey", () => customPluginHotkey.Hotkey = "")); | ||
| } | ||
|
|
||
| return list; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public enum LastQueryMode | ||
|
|
@@ -288,7 +365,7 @@ public enum ColorSchemes | |
| Light, | ||
| Dark | ||
| } | ||
|
|
||
| public enum SearchWindowScreens | ||
| { | ||
| RememberLastLaunchLocation, | ||
|
|
@@ -297,7 +374,7 @@ public enum SearchWindowScreens | |
| Primary, | ||
| Custom | ||
| } | ||
|
|
||
| public enum SearchWindowAligns | ||
| { | ||
| Center, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can use variable argument?