Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Jun 13, 2023
1 parent 131631f commit d72c5c2
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions JL.Windows/GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)
{
if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.DisableHotkeysKeyGesture))
{
if (e is not null)
{
e.Handled = true;
}

ConfigManager.DisableHotkeys = !ConfigManager.DisableHotkeys;

if (ConfigManager.GlobalHotKeys)
Expand All @@ -498,28 +503,33 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)
return;
}

if (e is not null)
{
e.Handled = true;
}
bool handled = false;

if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.SteppedBacklogBackwardsKeyGesture))
{
handled = true;

ShowPreviousBacklogItem();
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.SteppedBacklogForwardsKeyGesture))
{
handled = true;

ShowNextBacklogItem();
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ShowPreferencesWindowKeyGesture))
{
handled = true;

WindowsUtils.ShowPreferencesWindow();
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.MousePassThroughModeKeyGesture))
{
handled = true;

if (Background.Opacity is not 0)
{
Background.Opacity = 0;
Expand All @@ -543,6 +553,8 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.KanjiModeKeyGesture))
{
handled = true;

CoreConfig.KanjiMode = !CoreConfig.KanjiMode;
FirstPopupWindow.LastText = "";
Utils.Frontend.InvalidateDisplayCache();
Expand All @@ -551,6 +563,8 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ShowAddNameWindowKeyGesture))
{
handled = true;

if (DictUtils.DictsReady)
{
WindowsUtils.ShowAddNameWindow(MainTextBox.SelectedText);
Expand All @@ -559,6 +573,8 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ShowAddWordWindowKeyGesture))
{
handled = true;

if (DictUtils.DictsReady)
{
WindowsUtils.ShowAddWordWindow(MainTextBox.SelectedText);
Expand All @@ -567,6 +583,8 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ShowManageDictionariesWindowKeyGesture))
{
handled = true;

if (DictUtils.DictsReady
&& !DictUtils.UpdatingJmdict
&& !DictUtils.UpdatingJmnedict
Expand All @@ -578,6 +596,8 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ShowManageFrequenciesWindowKeyGesture))
{
handled = true;

if (FreqUtils.FreqsReady)
{
WindowsUtils.ShowManageFrequenciesWindow();
Expand All @@ -586,44 +606,60 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.SearchWithBrowserKeyGesture))
{
handled = true;

WindowsUtils.SearchWithBrowser(MainTextBox.SelectedText);
WindowsUtils.UpdateMainWindowVisibility();
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.InactiveLookupModeKeyGesture))
{
handled = true;

ConfigManager.InactiveLookupMode = !ConfigManager.InactiveLookupMode;
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.MotivationKeyGesture))
{
handled = true;

await WindowsUtils.Motivate().ConfigureAwait(false);
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ClosePopupKeyGesture))
{
handled = true;

FirstPopupWindow.HidePopup();
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ShowStatsKeyGesture))
{
handled = true;

await WindowsUtils.ShowStatsWindow().ConfigureAwait(false);
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ShowManageAudioSourcesWindowKeyGesture))
{
handled = true;

WindowsUtils.ShowManageAudioSourcesWindow();
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.AlwaysOnTopKeyGesture))
{
handled = true;

ConfigManager.AlwaysOnTop = !ConfigManager.AlwaysOnTop;

Topmost = ConfigManager.AlwaysOnTop;
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.TextOnlyVisibleOnHoverKeyGesture))
{
handled = true;

ConfigManager.TextOnlyVisibleOnHover = !ConfigManager.TextOnlyVisibleOnHover;

if (ConfigManager.TextOnlyVisibleOnHover && Background.Opacity is not 0)
Expand All @@ -639,6 +675,8 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.CaptureTextFromClipboardKeyGesture))
{
handled = true;

ConfigManager.CaptureTextFromClipboard = !ConfigManager.CaptureTextFromClipboard;
if (!CoreConfig.CaptureTextFromWebSocket && !ConfigManager.CaptureTextFromClipboard)
{
Expand All @@ -654,6 +692,8 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.CaptureTextFromWebSocketKeyGesture))
{
handled = true;

CoreConfig.CaptureTextFromWebSocket = !CoreConfig.CaptureTextFromWebSocket;
WebSocketUtils.HandleWebSocket();

Expand All @@ -671,24 +711,32 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ReconnectToWebSocketServerKeyGesture))
{
handled = true;

CoreConfig.CaptureTextFromWebSocket = true;
WebSocketUtils.HandleWebSocket();
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.TextBoxIsReadOnlyKeyGesture))
{
handled = true;

ConfigManager.TextBoxIsReadOnly = !ConfigManager.TextBoxIsReadOnly;
MainTextBox.IsReadOnly = ConfigManager.TextBoxIsReadOnly;
MainTextBox.IsUndoEnabled = !ConfigManager.TextBoxIsReadOnly;
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.DeleteCurrentLineKeyGesture))
{
handled = true;

await DeleteCurrentLine().ConfigureAwait(false);
}

else if (KeyGestureUtils.CompareKeyGestures(keyGesture, ConfigManager.ToggleMinimizedStateKeyGesture))
{
handled = true;

if (!FirstPopupWindow.IsVisible)
{
if (ConfigManager.Focusable)
Expand Down Expand Up @@ -716,6 +764,11 @@ public async Task HandleHotKey(KeyGesture keyGesture, KeyEventArgs? e)
}
}
}

if (handled && e is not null)
{
e.Handled = true;
}
}

private void ShowTitleBarButtons()
Expand Down

0 comments on commit d72c5c2

Please sign in to comment.