From e230ea8f2bb857d1eea22880db702ab90020a65b Mon Sep 17 00:00:00 2001 From: rampaa Date: Mon, 14 Oct 2024 02:00:03 +0300 Subject: [PATCH] Minor --- JL.Windows/ConfigManager.cs | 166 ++++++++++++------------ JL.Windows/GUI/MainWindow.xaml.cs | 4 +- JL.Windows/Utilities/KeyGestureUtils.cs | 22 ++-- JL.Windows/WinApi.cs | 18 +-- 4 files changed, 104 insertions(+), 106 deletions(-) diff --git a/JL.Windows/ConfigManager.cs b/JL.Windows/ConfigManager.cs index 220c1195..a6493459 100644 --- a/JL.Windows/ConfigManager.cs +++ b/JL.Windows/ConfigManager.cs @@ -451,72 +451,72 @@ public static void ApplyPreferences() : MainWindow.Instance.OpacitySlider.Value / 100; WinApi.UnregisterAllHotKeys(MainWindow.Instance.WindowHandle); - KeyGestureUtils.KeyGestureDict.Clear(); - KeyGestureUtils.KeyGestureNameToIntDict.Clear(); - - DisableHotkeysKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(DisableHotkeysKeyGesture), DisableHotkeysKeyGesture); - MiningModeKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(MiningModeKeyGesture), MiningModeKeyGesture); - PlayAudioKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(PlayAudioKeyGesture), PlayAudioKeyGesture); - KanjiModeKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(KanjiModeKeyGesture), KanjiModeKeyGesture); - LookupKeyKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(LookupKeyKeyGesture), LookupKeyKeyGesture, false); - ClosePopupKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(ClosePopupKeyGesture), ClosePopupKeyGesture); - ShowStatsKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(ShowStatsKeyGesture), ShowStatsKeyGesture); - NextDictKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(NextDictKeyGesture), NextDictKeyGesture); - PreviousDictKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(PreviousDictKeyGesture), PreviousDictKeyGesture); - AlwaysOnTopKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(AlwaysOnTopKeyGesture), AlwaysOnTopKeyGesture); - TextBoxIsReadOnlyKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(TextBoxIsReadOnlyKeyGesture), TextBoxIsReadOnlyKeyGesture); - ToggleAlwaysShowMainTextBoxCaretKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(ToggleAlwaysShowMainTextBoxCaretKeyGesture), ToggleAlwaysShowMainTextBoxCaretKeyGesture); - MoveCaretLeftKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(MoveCaretLeftKeyGesture), MoveCaretLeftKeyGesture); - MoveCaretRightKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(MoveCaretRightKeyGesture), MoveCaretRightKeyGesture); - MoveCaretUpKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(MoveCaretUpKeyGesture), MoveCaretUpKeyGesture); - MoveCaretDownKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(MoveCaretDownKeyGesture), MoveCaretDownKeyGesture); - LookupTermAtCaretIndexKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(LookupTermAtCaretIndexKeyGesture), LookupTermAtCaretIndexKeyGesture); - LookupFirstTermKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(LookupFirstTermKeyGesture), LookupFirstTermKeyGesture); - LookupSelectedTextKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(LookupSelectedTextKeyGesture), LookupSelectedTextKeyGesture); - SelectNextLookupResultKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(SelectNextLookupResultKeyGesture), SelectNextLookupResultKeyGesture); - SelectPreviousLookupResultKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(SelectPreviousLookupResultKeyGesture), SelectPreviousLookupResultKeyGesture); - MineSelectedLookupResultKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(MineSelectedLookupResultKeyGesture), MineSelectedLookupResultKeyGesture); - CaptureTextFromClipboardKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(CaptureTextFromClipboardKeyGesture), CaptureTextFromClipboardKeyGesture); - CaptureTextFromWebSocketKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(CaptureTextFromWebSocketKeyGesture), CaptureTextFromWebSocketKeyGesture); - ReconnectToWebSocketServerKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(ReconnectToWebSocketServerKeyGesture), ReconnectToWebSocketServerKeyGesture); - DeleteCurrentLineKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(DeleteCurrentLineKeyGesture), DeleteCurrentLineKeyGesture); + KeyGestureUtils.GlobalKeyGestureDict.Clear(); + KeyGestureUtils.GlobalKeyGestureNameToIntDict.Clear(); + + DisableHotkeysKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(DisableHotkeysKeyGesture), DisableHotkeysKeyGesture); + MiningModeKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(MiningModeKeyGesture), MiningModeKeyGesture); + PlayAudioKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(PlayAudioKeyGesture), PlayAudioKeyGesture); + KanjiModeKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(KanjiModeKeyGesture), KanjiModeKeyGesture); + LookupKeyKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(LookupKeyKeyGesture), LookupKeyKeyGesture); + ClosePopupKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ClosePopupKeyGesture), ClosePopupKeyGesture); + ShowStatsKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ShowStatsKeyGesture), ShowStatsKeyGesture); + NextDictKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(NextDictKeyGesture), NextDictKeyGesture); + PreviousDictKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(PreviousDictKeyGesture), PreviousDictKeyGesture); + AlwaysOnTopKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(AlwaysOnTopKeyGesture), AlwaysOnTopKeyGesture); + TextBoxIsReadOnlyKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(TextBoxIsReadOnlyKeyGesture), TextBoxIsReadOnlyKeyGesture); + ToggleAlwaysShowMainTextBoxCaretKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ToggleAlwaysShowMainTextBoxCaretKeyGesture), ToggleAlwaysShowMainTextBoxCaretKeyGesture); + MoveCaretLeftKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(MoveCaretLeftKeyGesture), MoveCaretLeftKeyGesture); + MoveCaretRightKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(MoveCaretRightKeyGesture), MoveCaretRightKeyGesture); + MoveCaretUpKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(MoveCaretUpKeyGesture), MoveCaretUpKeyGesture); + MoveCaretDownKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(MoveCaretDownKeyGesture), MoveCaretDownKeyGesture); + LookupTermAtCaretIndexKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(LookupTermAtCaretIndexKeyGesture), LookupTermAtCaretIndexKeyGesture); + LookupFirstTermKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(LookupFirstTermKeyGesture), LookupFirstTermKeyGesture); + LookupSelectedTextKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(LookupSelectedTextKeyGesture), LookupSelectedTextKeyGesture); + SelectNextLookupResultKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(SelectNextLookupResultKeyGesture), SelectNextLookupResultKeyGesture); + SelectPreviousLookupResultKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(SelectPreviousLookupResultKeyGesture), SelectPreviousLookupResultKeyGesture); + MineSelectedLookupResultKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(MineSelectedLookupResultKeyGesture), MineSelectedLookupResultKeyGesture); + CaptureTextFromClipboardKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(CaptureTextFromClipboardKeyGesture), CaptureTextFromClipboardKeyGesture); + CaptureTextFromWebSocketKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(CaptureTextFromWebSocketKeyGesture), CaptureTextFromWebSocketKeyGesture); + ReconnectToWebSocketServerKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ReconnectToWebSocketServerKeyGesture), ReconnectToWebSocketServerKeyGesture); + DeleteCurrentLineKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(DeleteCurrentLineKeyGesture), DeleteCurrentLineKeyGesture); ShowPreferencesWindowKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(ShowPreferencesWindowKeyGesture), ShowPreferencesWindowKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ShowPreferencesWindowKeyGesture), ShowPreferencesWindowKeyGesture); ShowAddNameWindowKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(ShowAddNameWindowKeyGesture), ShowAddNameWindowKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ShowAddNameWindowKeyGesture), ShowAddNameWindowKeyGesture); ShowAddWordWindowKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(ShowAddWordWindowKeyGesture), ShowAddWordWindowKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ShowAddWordWindowKeyGesture), ShowAddWordWindowKeyGesture); SearchWithBrowserKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(SearchWithBrowserKeyGesture), SearchWithBrowserKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(SearchWithBrowserKeyGesture), SearchWithBrowserKeyGesture); MousePassThroughModeKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(MousePassThroughModeKeyGesture), MousePassThroughModeKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(MousePassThroughModeKeyGesture), MousePassThroughModeKeyGesture); SteppedBacklogBackwardsKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(SteppedBacklogBackwardsKeyGesture), SteppedBacklogBackwardsKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(SteppedBacklogBackwardsKeyGesture), SteppedBacklogBackwardsKeyGesture); SteppedBacklogForwardsKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(SteppedBacklogForwardsKeyGesture), SteppedBacklogForwardsKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(SteppedBacklogForwardsKeyGesture), SteppedBacklogForwardsKeyGesture); InactiveLookupModeKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(InactiveLookupModeKeyGesture), InactiveLookupModeKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(InactiveLookupModeKeyGesture), InactiveLookupModeKeyGesture); MotivationKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(MotivationKeyGesture), MotivationKeyGesture); + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(MotivationKeyGesture), MotivationKeyGesture); ShowManageDictionariesWindowKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(ShowManageDictionariesWindowKeyGesture), + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ShowManageDictionariesWindowKeyGesture), ShowManageDictionariesWindowKeyGesture); ShowManageFrequenciesWindowKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(ShowManageFrequenciesWindowKeyGesture), + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ShowManageFrequenciesWindowKeyGesture), ShowManageFrequenciesWindowKeyGesture); ShowManageAudioSourcesWindowKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(ShowManageAudioSourcesWindowKeyGesture), + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ShowManageAudioSourcesWindowKeyGesture), ShowManageAudioSourcesWindowKeyGesture); ToggleMinimizedStateKeyGesture = - KeyGestureUtils.SetKeyGesture(connection, nameof(ToggleMinimizedStateKeyGesture), + KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(ToggleMinimizedStateKeyGesture), ToggleMinimizedStateKeyGesture); - SelectedTextToSpeechKeyGesture = KeyGestureUtils.SetKeyGesture(connection, nameof(SelectedTextToSpeechKeyGesture), SelectedTextToSpeechKeyGesture); + SelectedTextToSpeechKeyGesture = KeyGestureUtils.GetKeyGestureFromConfig(connection, nameof(SelectedTextToSpeechKeyGesture), SelectedTextToSpeechKeyGesture); if (GlobalHotKeys && !DisableHotkeys) { @@ -927,81 +927,81 @@ public static async Task SavePreferences(PreferencesWindow preferenceWindow) SqliteConnection connection = ConfigDBManager.CreateReadWriteDBConnection(); await using (connection.ConfigureAwait(true)) { - KeyGestureUtils.SaveKeyGesture(connection, nameof(DisableHotkeysKeyGesture), preferenceWindow.DisableHotkeysKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(MiningModeKeyGesture), preferenceWindow.MiningModeKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(PlayAudioKeyGesture), preferenceWindow.PlayAudioKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(KanjiModeKeyGesture), preferenceWindow.KanjiModeKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(LookupKeyKeyGesture), preferenceWindow.LookupKeyKeyGestureTextBox.Text); + KeyGestureUtils.UpdateKeyGesture(connection, nameof(DisableHotkeysKeyGesture), preferenceWindow.DisableHotkeysKeyGestureTextBox.Text); + KeyGestureUtils.UpdateKeyGesture(connection, nameof(MiningModeKeyGesture), preferenceWindow.MiningModeKeyGestureTextBox.Text); + KeyGestureUtils.UpdateKeyGesture(connection, nameof(PlayAudioKeyGesture), preferenceWindow.PlayAudioKeyGestureTextBox.Text); + KeyGestureUtils.UpdateKeyGesture(connection, nameof(KanjiModeKeyGesture), preferenceWindow.KanjiModeKeyGestureTextBox.Text); + KeyGestureUtils.UpdateKeyGesture(connection, nameof(LookupKeyKeyGesture), preferenceWindow.LookupKeyKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ShowManageDictionariesWindowKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ShowManageDictionariesWindowKeyGesture), preferenceWindow.ShowManageDictionariesWindowKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ShowManageFrequenciesWindowKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ShowManageFrequenciesWindowKeyGesture), preferenceWindow.ShowManageFrequenciesWindowKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ShowManageAudioSourcesWindowKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ShowManageAudioSourcesWindowKeyGesture), preferenceWindow.ShowManageAudioSourcesWindowKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ShowPreferencesWindowKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ShowPreferencesWindowKeyGesture), preferenceWindow.ShowPreferencesWindowKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ShowAddNameWindowKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ShowAddNameWindowKeyGesture), preferenceWindow.ShowAddNameWindowKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ShowAddWordWindowKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ShowAddWordWindowKeyGesture), preferenceWindow.ShowAddWordWindowKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(SearchWithBrowserKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(SearchWithBrowserKeyGesture), preferenceWindow.SearchWithBrowserKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(MousePassThroughModeKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(MousePassThroughModeKeyGesture), preferenceWindow.MousePassThroughModeKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(SteppedBacklogBackwardsKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(SteppedBacklogBackwardsKeyGesture), preferenceWindow.SteppedBacklogBackwardsKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(SteppedBacklogForwardsKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(SteppedBacklogForwardsKeyGesture), preferenceWindow.SteppedBacklogForwardsKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(InactiveLookupModeKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(InactiveLookupModeKeyGesture), preferenceWindow.InactiveLookupModeKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(MotivationKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(MotivationKeyGesture), preferenceWindow.MotivationKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ClosePopupKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ClosePopupKeyGesture), preferenceWindow.ClosePopupKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ShowStatsKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ShowStatsKeyGesture), preferenceWindow.ShowStatsKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(NextDictKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(NextDictKeyGesture), preferenceWindow.NextDictKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(PreviousDictKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(PreviousDictKeyGesture), preferenceWindow.PreviousDictKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(AlwaysOnTopKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(AlwaysOnTopKeyGesture), preferenceWindow.AlwaysOnTopKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(TextBoxIsReadOnlyKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(TextBoxIsReadOnlyKeyGesture), preferenceWindow.TextBoxIsReadOnlyKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ToggleAlwaysShowMainTextBoxCaretKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ToggleAlwaysShowMainTextBoxCaretKeyGesture), preferenceWindow.ToggleAlwaysShowMainTextBoxCaretKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(MoveCaretLeftKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(MoveCaretLeftKeyGesture), preferenceWindow.MoveCaretLeftKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(MoveCaretRightKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(MoveCaretRightKeyGesture), preferenceWindow.MoveCaretRightKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(MoveCaretUpKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(MoveCaretUpKeyGesture), preferenceWindow.MoveCaretUpKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(MoveCaretDownKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(MoveCaretDownKeyGesture), preferenceWindow.MoveCaretDownKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(LookupTermAtCaretIndexKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(LookupTermAtCaretIndexKeyGesture), preferenceWindow.LookupTermAtCaretIndexKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(LookupFirstTermKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(LookupFirstTermKeyGesture), preferenceWindow.LookupFirstTermKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(LookupSelectedTextKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(LookupSelectedTextKeyGesture), preferenceWindow.LookupSelectedTextKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(SelectNextLookupResultKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(SelectNextLookupResultKeyGesture), preferenceWindow.SelectNextLookupResultKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(SelectPreviousLookupResultKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(SelectPreviousLookupResultKeyGesture), preferenceWindow.SelectPreviousLookupResultKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(MineSelectedLookupResultKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(MineSelectedLookupResultKeyGesture), preferenceWindow.MineSelectedLookupResultKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(CaptureTextFromClipboardKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(CaptureTextFromClipboardKeyGesture), preferenceWindow.CaptureTextFromClipboardKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(CaptureTextFromWebSocketKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(CaptureTextFromWebSocketKeyGesture), preferenceWindow.CaptureTextFromWebSocketKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ReconnectToWebSocketServerKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ReconnectToWebSocketServerKeyGesture), preferenceWindow.ReconnectToWebSocketServerKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(DeleteCurrentLineKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(DeleteCurrentLineKeyGesture), preferenceWindow.DeleteCurrentLineKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(ToggleMinimizedStateKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(ToggleMinimizedStateKeyGesture), preferenceWindow.ToggleMinimizedStateKeyGestureTextBox.Text); - KeyGestureUtils.SaveKeyGesture(connection, nameof(SelectedTextToSpeechKeyGesture), + KeyGestureUtils.UpdateKeyGesture(connection, nameof(SelectedTextToSpeechKeyGesture), preferenceWindow.SelectedTextToSpeechTextBox.Text); ConfigDBManager.UpdateSetting(connection, nameof(SearchUrl), preferenceWindow.SearchUrlTextBox.Text); diff --git a/JL.Windows/GUI/MainWindow.xaml.cs b/JL.Windows/GUI/MainWindow.xaml.cs index 29e9e1bd..ab00e1ae 100644 --- a/JL.Windows/GUI/MainWindow.xaml.cs +++ b/JL.Windows/GUI/MainWindow.xaml.cs @@ -472,7 +472,7 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e) { if (ConfigManager.DisableHotkeys) { - if (KeyGestureUtils.KeyGestureNameToIntDict.TryGetValue(nameof(ConfigManager.DisableHotkeys), out int id)) + if (KeyGestureUtils.GlobalKeyGestureNameToIntDict.TryGetValue(nameof(ConfigManager.DisableHotkeys), out int id)) { WinApi.UnregisterAllHotKeys(WindowHandle, id); } @@ -1616,7 +1616,7 @@ private void Window_StateChanged(object sender, EventArgs e) List keyGestureIdsToIgnore = new(KeyGestureUtils.NamesOfKeyGesturesThatCanBeUsedWhileJLIsMinimized.Length); for (int i = 0; i < KeyGestureUtils.NamesOfKeyGesturesThatCanBeUsedWhileJLIsMinimized.Length; i++) { - if (KeyGestureUtils.KeyGestureNameToIntDict.TryGetValue(KeyGestureUtils.NamesOfKeyGesturesThatCanBeUsedWhileJLIsMinimized[i], out int id)) + if (KeyGestureUtils.GlobalKeyGestureNameToIntDict.TryGetValue(KeyGestureUtils.NamesOfKeyGesturesThatCanBeUsedWhileJLIsMinimized[i], out int id)) { keyGestureIdsToIgnore.Add(id); } diff --git a/JL.Windows/Utilities/KeyGestureUtils.cs b/JL.Windows/Utilities/KeyGestureUtils.cs index 45643bf6..b3957922 100644 --- a/JL.Windows/Utilities/KeyGestureUtils.cs +++ b/JL.Windows/Utilities/KeyGestureUtils.cs @@ -10,10 +10,10 @@ namespace JL.Windows.Utilities; internal static class KeyGestureUtils { - public static readonly Dictionary KeyGestureDict = []; - public static readonly Dictionary KeyGestureNameToIntDict = []; + public static readonly Dictionary GlobalKeyGestureDict = []; + public static readonly Dictionary GlobalKeyGestureNameToIntDict = []; - public static readonly FrozenSet ValidKeys = FrozenSet.ToFrozenSet( + public static readonly FrozenSet ValidGlobalKeys = FrozenSet.ToFrozenSet( [ #pragma warning disable format @@ -165,7 +165,7 @@ or Key.LeftCtrl or Key.RightCtrl : "None"; } - public static KeyGesture SetKeyGesture(SqliteConnection connection, string keyGestureName, KeyGesture keyGesture, bool setAsGlobalHotKey = true) + public static KeyGesture GetKeyGestureFromConfig(SqliteConnection connection, string keyGestureName, KeyGesture defaultKeyGesture) { string? rawKeyGesture = ConfigDBManager.GetSettingValue(connection, keyGestureName); if (rawKeyGesture is not null) @@ -179,8 +179,7 @@ public static KeyGesture SetKeyGesture(SqliteConnection connection, string keyGe : $"Win+{rawKeyGesture}"; KeyGesture newKeyGesture = (KeyGesture)keyGestureConverter.ConvertFromInvariantString(keyGestureString)!; - - if (ConfigManager.GlobalHotKeys && setAsGlobalHotKey) + if (ConfigManager.GlobalHotKeys) { WinApi.AddHotKeyToKeyGestureDict(keyGestureName, newKeyGesture); } @@ -188,14 +187,13 @@ public static KeyGesture SetKeyGesture(SqliteConnection connection, string keyGe return newKeyGesture; } - ConfigDBManager.InsertSetting(connection, keyGestureName, keyGesture.ToFormattedString()); - - if (ConfigManager.GlobalHotKeys && setAsGlobalHotKey) + ConfigDBManager.InsertSetting(connection, keyGestureName, defaultKeyGesture.ToFormattedString()); + if (ConfigManager.GlobalHotKeys) { - WinApi.AddHotKeyToKeyGestureDict(keyGestureName, keyGesture); + WinApi.AddHotKeyToKeyGestureDict(keyGestureName, defaultKeyGesture); } - return keyGesture; + return defaultKeyGesture; } public static void SetInputGestureText(this MenuItem menuItem, KeyGesture keyGesture) @@ -207,7 +205,7 @@ public static void SetInputGestureText(this MenuItem menuItem, KeyGesture keyGes : ""; } - public static void SaveKeyGesture(SqliteConnection connection, string key, string rawKeyGesture) + public static void UpdateKeyGesture(SqliteConnection connection, string key, string rawKeyGesture) { string value = rawKeyGesture.StartsWith("Win+", StringComparison.Ordinal) ? rawKeyGesture[4..] diff --git a/JL.Windows/WinApi.cs b/JL.Windows/WinApi.cs index 3b021274..c15e7978 100644 --- a/JL.Windows/WinApi.cs +++ b/JL.Windows/WinApi.cs @@ -188,13 +188,13 @@ public static ulong GetClipboardSequenceNo() public static void AddHotKeyToKeyGestureDict(string hotkeyName, KeyGesture keyGesture) { - int id = KeyGestureUtils.KeyGestureDict.Count; + int id = KeyGestureUtils.GlobalKeyGestureDict.Count; ModifierKeys modifierKeys = keyGesture.Modifiers is ModifierKeys.Windows ? ModifierKeys.None : keyGesture.Modifiers; - if (modifierKeys is not ModifierKeys.None || KeyGestureUtils.ValidKeys.Contains(keyGesture.Key)) + if (modifierKeys is not ModifierKeys.None || KeyGestureUtils.ValidGlobalKeys.Contains(keyGesture.Key)) { KeyGesture newKeyGesture = keyGesture; @@ -203,14 +203,14 @@ public static void AddHotKeyToKeyGestureDict(string hotkeyName, KeyGesture keyGe newKeyGesture = new KeyGesture(keyGesture.Key, ModifierKeys.None); } - KeyGestureUtils.KeyGestureDict.Add(id, newKeyGesture); - KeyGestureUtils.KeyGestureNameToIntDict.Add(hotkeyName, id); + KeyGestureUtils.GlobalKeyGestureDict.Add(id, newKeyGesture); + KeyGestureUtils.GlobalKeyGestureNameToIntDict.Add(hotkeyName, id); } } public static void RegisterAllHotKeys(nint windowHandle) { - foreach (KeyValuePair keyValuePair in KeyGestureUtils.KeyGestureDict) + foreach (KeyValuePair keyValuePair in KeyGestureUtils.GlobalKeyGestureDict) { _ = RegisterHotKey(windowHandle, keyValuePair.Key, (uint)keyValuePair.Value.Modifiers | MOD_NOREPEAT, (uint)KeyInterop.VirtualKeyFromKey(keyValuePair.Value.Key)); } @@ -218,7 +218,7 @@ public static void RegisterAllHotKeys(nint windowHandle) public static void UnregisterAllHotKeys(nint windowHandle) { - foreach (int id in KeyGestureUtils.KeyGestureDict.Keys) + foreach (int id in KeyGestureUtils.GlobalKeyGestureDict.Keys) { _ = UnregisterHotKey(windowHandle, id); } @@ -226,7 +226,7 @@ public static void UnregisterAllHotKeys(nint windowHandle) public static void UnregisterAllHotKeys(nint windowHandle, int keyGestureIdToIgnore) { - foreach (int id in KeyGestureUtils.KeyGestureDict.Keys) + foreach (int id in KeyGestureUtils.GlobalKeyGestureDict.Keys) { if (keyGestureIdToIgnore == id) { @@ -239,7 +239,7 @@ public static void UnregisterAllHotKeys(nint windowHandle, int keyGestureIdToIgn public static void UnregisterAllHotKeys(nint windowHandle, List keyGestureIdsToIgnore) { - foreach (int id in KeyGestureUtils.KeyGestureDict.Keys) + foreach (int id in KeyGestureUtils.GlobalKeyGestureDict.Keys) { if (keyGestureIdsToIgnore.Contains(id)) { @@ -348,7 +348,7 @@ private nint WndProc(nint hwnd, int msg, nint wParam, nint lParam, ref bool hand else if (msg is WM_HOTKEY) { - if (KeyGestureUtils.KeyGestureDict.TryGetValue((int)wParam, out KeyGesture? keyGesture)) + if (KeyGestureUtils.GlobalKeyGestureDict.TryGetValue((int)wParam, out KeyGesture? keyGesture)) { _ = KeyGestureUtils.HandleHotKey(keyGesture).ConfigureAwait(false); handled = true;