Skip to content

Commit

Permalink
fix(hotkey): Fix screenshot hotkey bug #14
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Jan 19, 2024
1 parent 8cd06e0 commit a14f164
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
14 changes: 7 additions & 7 deletions STranslate/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ private void Register(Window view)
MessageBox_S.Show("全局热键冲突,请前往软件首选项中修改...");
}
var msg = "";
if (!HotkeyHelper.Hotkeys!.InputTranslate.Conflict)
if (!HotkeyHelper.Hotkeys.InputTranslate.Conflict && !string.IsNullOrEmpty(HotkeyHelper.Hotkeys.InputTranslate.Text))
msg += $"输入: {HotkeyHelper.Hotkeys.InputTranslate.Text}\n";
if (!HotkeyHelper.Hotkeys!.CrosswordTranslate.Conflict)
if (!HotkeyHelper.Hotkeys.CrosswordTranslate.Conflict && !string.IsNullOrEmpty(HotkeyHelper.Hotkeys.CrosswordTranslate.Text))
msg += $"划词: {HotkeyHelper.Hotkeys.CrosswordTranslate.Text}\n";
if (!HotkeyHelper.Hotkeys!.ScreenShotTranslate.Conflict)
if (!HotkeyHelper.Hotkeys.ScreenShotTranslate.Conflict && !string.IsNullOrEmpty(HotkeyHelper.Hotkeys.ScreenShotTranslate.Text))
msg += $"截图: {HotkeyHelper.Hotkeys.ScreenShotTranslate.Text}\n";
if (!HotkeyHelper.Hotkeys!.OpenMainWindow.Conflict)
if (!HotkeyHelper.Hotkeys.OpenMainWindow.Conflict && !string.IsNullOrEmpty(HotkeyHelper.Hotkeys.OpenMainWindow.Text))
msg += $"显示: {HotkeyHelper.Hotkeys.OpenMainWindow.Text}\n";
if (!HotkeyHelper.Hotkeys!.MousehookTranslate.Conflict)
if (!HotkeyHelper.Hotkeys.MousehookTranslate.Conflict && !string.IsNullOrEmpty(HotkeyHelper.Hotkeys.MousehookTranslate.Text))
msg += $"鼠标: {HotkeyHelper.Hotkeys.MousehookTranslate.Text}\n";
if (!HotkeyHelper.Hotkeys!.OCR.Conflict)
if (!HotkeyHelper.Hotkeys.OCR.Conflict && !string.IsNullOrEmpty(HotkeyHelper.Hotkeys.OCR.Text))
msg += $"识字: {HotkeyHelper.Hotkeys.OCR.Text}\n";
if (!HotkeyHelper.Hotkeys!.SilentOCR.Conflict)
if (!HotkeyHelper.Hotkeys.SilentOCR.Conflict && !string.IsNullOrEmpty(HotkeyHelper.Hotkeys.SilentOCR.Text))
msg += $"静默: {HotkeyHelper.Hotkeys.SilentOCR.Text}\n";
NotifyIconVM.UpdateToolTip(msg.TrimEnd('\n'));
}
Expand Down
2 changes: 1 addition & 1 deletion STranslate/Views/Preference/HotkeyPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
CaretBrush="Transparent"
Cursor="Hand"
InputMethod.IsInputMethodEnabled="False"
KeyUp="CrossWord_KeyUp"
KeyUp="Screenshot_KeyUp"
PreviewKeyDown="HotKeyTextBox_PreviewKeyDown" />
<Label x:Name="ScreenshotHotKeyConflictLabel"
Grid.Column="2"
Expand Down
32 changes: 17 additions & 15 deletions STranslate/Views/Preference/HotkeyPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void HotKeyTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
((TextBox)sender).Text = _hotkeysText = shortcutText.ToString();
}

private void CrossWord_KeyUp(object sender, KeyEventArgs e)
private void Input_KeyUp(object sender, KeyEventArgs e)
{
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
if (
Expand All @@ -106,15 +106,15 @@ private void CrossWord_KeyUp(object sender, KeyEventArgs e)
{
return;
}
conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Modifiers = _hotkeysModifiers;
conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Key = _hotkeysKey;
conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Text = _hotkeysText.ToString();
conf.CurrentConfig!.Hotkeys!.InputTranslate.Modifiers = _hotkeysModifiers;
conf.CurrentConfig!.Hotkeys!.InputTranslate.Key = _hotkeysKey;
conf.CurrentConfig!.Hotkeys!.InputTranslate.Text = _hotkeysText.ToString();
HotkeyHelper.ReRegisterHotKey();
HotKeyConflictCheck();
RefreshNotifyToolTip();
}

private void Input_KeyUp(object sender, KeyEventArgs e)
private void CrossWord_KeyUp(object sender, KeyEventArgs e)
{
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
if (
Expand All @@ -130,9 +130,9 @@ private void Input_KeyUp(object sender, KeyEventArgs e)
{
return;
}
conf.CurrentConfig!.Hotkeys!.InputTranslate.Modifiers = _hotkeysModifiers;
conf.CurrentConfig!.Hotkeys!.InputTranslate.Key = _hotkeysKey;
conf.CurrentConfig!.Hotkeys!.InputTranslate.Text = _hotkeysText.ToString();
conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Modifiers = _hotkeysModifiers;
conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Key = _hotkeysKey;
conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Text = _hotkeysText.ToString();
HotkeyHelper.ReRegisterHotKey();
HotKeyConflictCheck();
RefreshNotifyToolTip();
Expand Down Expand Up @@ -286,19 +286,19 @@ private void HotKeyConflictCheck()
private void RefreshNotifyToolTip()
{
var msg = "";
if (!conf.CurrentConfig!.Hotkeys!.InputTranslate.Conflict)
if (!conf.CurrentConfig!.Hotkeys!.InputTranslate.Conflict && !string.IsNullOrEmpty(conf.CurrentConfig!.Hotkeys!.InputTranslate.Text))
msg += $"输入: {conf.CurrentConfig!.Hotkeys!.InputTranslate.Text}\r\n";
if (!conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Conflict)
if (!conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Conflict && !string.IsNullOrEmpty(conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Text))
msg += $"划词: {conf.CurrentConfig!.Hotkeys!.CrosswordTranslate.Text}\r\n";
if (!conf.CurrentConfig!.Hotkeys!.ScreenShotTranslate.Conflict)
if (!conf.CurrentConfig!.Hotkeys!.ScreenShotTranslate.Conflict && !string.IsNullOrEmpty(conf.CurrentConfig!.Hotkeys!.ScreenShotTranslate.Text))
msg += $"截图: {conf.CurrentConfig!.Hotkeys!.ScreenShotTranslate.Text}\r\n";
if (!conf.CurrentConfig!.Hotkeys!.OpenMainWindow.Conflict)
if (!conf.CurrentConfig!.Hotkeys!.OpenMainWindow.Conflict && !string.IsNullOrEmpty(conf.CurrentConfig!.Hotkeys!.OpenMainWindow.Text))
msg += $"显示: {conf.CurrentConfig!.Hotkeys!.OpenMainWindow.Text}\r\n";
if (!conf.CurrentConfig!.Hotkeys!.MousehookTranslate.Conflict)
if (!conf.CurrentConfig!.Hotkeys!.MousehookTranslate.Conflict && !string.IsNullOrEmpty(conf.CurrentConfig!.Hotkeys!.MousehookTranslate.Text))
msg += $"鼠标: {conf.CurrentConfig!.Hotkeys!.MousehookTranslate.Text}\r\n";
if (!conf.CurrentConfig!.Hotkeys!.OCR.Conflict)
if (!conf.CurrentConfig!.Hotkeys!.OCR.Conflict && !string.IsNullOrEmpty(conf.CurrentConfig!.Hotkeys!.OCR.Text))
msg += $"识字: {conf.CurrentConfig!.Hotkeys!.OCR.Text}\r\n";
if (!conf.CurrentConfig!.Hotkeys!.SilentOCR.Conflict)
if (!conf.CurrentConfig!.Hotkeys!.SilentOCR.Conflict && !string.IsNullOrEmpty(conf.CurrentConfig!.Hotkeys!.SilentOCR.Text))
msg += $"静默: {conf.CurrentConfig!.Hotkeys!.SilentOCR.Text}\r\n";
Singleton<NotifyIconViewModel>.Instance.UpdateToolTip(msg.TrimEnd(['\r', '\n']));
}
Expand Down Expand Up @@ -345,6 +345,7 @@ private void ResetHoskeys(object sender, RoutedEventArgs e)

HotkeyHelper.ReRegisterHotKey();
HotKeyConflictCheck();
RefreshNotifyToolTip();

ToastHelper.Show("重置成功", WindowType.Preference);
}
Expand All @@ -359,6 +360,7 @@ private void SaveHotkeys(object sender, RoutedEventArgs e)
}
else
{
RefreshNotifyToolTip();
ToastHelper.Show("保存热键成功", WindowType.Preference);
}
}
Expand Down

0 comments on commit a14f164

Please sign in to comment.