-
-
Notifications
You must be signed in to change notification settings - Fork 455
Fix flow's hotkey not working correctly after changing in settings #565
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
12 commits
Select commit
Hold shift + click to select a range
48fb0dc
move and centralise the hotkey management calls
jjw24 dd9cb2f
update display text to be more aligned with functionality
jjw24 04d959c
update method call to short-circuit logical operators
jjw24 b96a02b
add last query mode update to SetCustomPluginHotkey
jjw24 8c31039
refactor- point CustomQueryHotkey to HotkeyMapper
jjw24 86804bc
remove obsolete behaviour
jjw24 20f849d
move CheckHotkeyAvailability to HotkeyMapper
jjw24 bcb17a0
add focus for custom query hotkey preview
jjw24 689c42d
Merge branch 'dev' into fix_hotkey_change
jjw24 33b34f2
update per review
jjw24 b96cc7a
add colon to Priority text for consistency
jjw24 4ba8296
fix hotkey unavailable text
jjw24 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| using Flow.Launcher.Infrastructure.Hotkey; | ||
| using Flow.Launcher.Infrastructure.UserSettings; | ||
| using System; | ||
| using NHotkey; | ||
| using NHotkey.Wpf; | ||
| using Flow.Launcher.Core.Resource; | ||
| using System.Windows; | ||
| using Flow.Launcher.ViewModel; | ||
|
|
||
| namespace Flow.Launcher.Helper | ||
| { | ||
| internal static class HotKeyMapper | ||
| { | ||
| private static Settings settings; | ||
| private static MainViewModel mainViewModel; | ||
|
|
||
| internal static void Initialize(MainViewModel mainVM) | ||
| { | ||
| mainViewModel = mainVM; | ||
| settings = mainViewModel._settings; | ||
|
|
||
| SetHotkey(settings.Hotkey, OnHotkey); | ||
| LoadCustomPluginHotkey(); | ||
| } | ||
|
|
||
| private static void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action) | ||
| { | ||
| var hotkey = new HotkeyModel(hotkeyStr); | ||
| SetHotkey(hotkey, action); | ||
| } | ||
|
|
||
| internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs> action) | ||
| { | ||
| string hotkeyStr = hotkey.ToString(); | ||
| try | ||
| { | ||
| HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| string errorMsg = | ||
| string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), | ||
| hotkeyStr); | ||
| MessageBox.Show(errorMsg); | ||
| } | ||
| } | ||
|
|
||
| internal static void RemoveHotkey(string hotkeyStr) | ||
| { | ||
| if (!string.IsNullOrEmpty(hotkeyStr)) | ||
| { | ||
| HotkeyManager.Current.Remove(hotkeyStr); | ||
| } | ||
| } | ||
|
|
||
| internal static void OnHotkey(object sender, HotkeyEventArgs e) | ||
| { | ||
| if (!ShouldIgnoreHotkeys()) | ||
| { | ||
| UpdateLastQUeryMode(); | ||
|
|
||
| mainViewModel.ToggleFlowLauncher(); | ||
| e.Handled = true; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks if Flow Launcher should ignore any hotkeys | ||
| /// </summary> | ||
| private static bool ShouldIgnoreHotkeys() | ||
| { | ||
| return settings.IgnoreHotkeysOnFullscreen && WindowsInteropHelper.IsWindowFullscreen(); | ||
| } | ||
|
|
||
| private static void UpdateLastQUeryMode() | ||
| { | ||
| switch(settings.LastQueryMode) | ||
| { | ||
| case LastQueryMode.Empty: | ||
| mainViewModel.ChangeQueryText(string.Empty); | ||
| break; | ||
| case LastQueryMode.Preserved: | ||
| mainViewModel.LastQuerySelected = true; | ||
| break; | ||
| case LastQueryMode.Selected: | ||
| mainViewModel.LastQuerySelected = false; | ||
| break; | ||
| default: | ||
| throw new ArgumentException($"wrong LastQueryMode: <{settings.LastQueryMode}>"); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| internal static void LoadCustomPluginHotkey() | ||
| { | ||
| if (settings.CustomPluginHotkeys == null) | ||
| return; | ||
|
|
||
| foreach (CustomPluginHotkey hotkey in settings.CustomPluginHotkeys) | ||
| { | ||
| SetCustomQueryHotkey(hotkey); | ||
| } | ||
| } | ||
|
|
||
| internal static void SetCustomQueryHotkey(CustomPluginHotkey hotkey) | ||
| { | ||
| SetHotkey(hotkey.Hotkey, (s, e) => | ||
| { | ||
| if (ShouldIgnoreHotkeys()) | ||
| return; | ||
|
|
||
| mainViewModel.MainWindowVisibility = Visibility.Visible; | ||
| mainViewModel.ChangeQueryText(hotkey.ActionKeyword); | ||
| }); | ||
| } | ||
|
|
||
| internal static bool CheckAvailability(HotkeyModel currentHotkey) | ||
| { | ||
| try | ||
| { | ||
| HotkeyManager.Current.AddOrReplace("HotkeyAvailabilityTest", currentHotkey.CharKey, currentHotkey.ModifierKeys, (sender, e) => { }); | ||
|
|
||
| return true; | ||
| } | ||
| catch | ||
| { | ||
| } | ||
| finally | ||
| { | ||
| HotkeyManager.Current.Remove("HotkeyAvailabilityTest"); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
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
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.
We can remove the catch
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.
cant remove it, catch is needed to go to
return falseat the bottom, you can just use catch but you duplicate code for no benefit, so may be just leave it?