From 74eb8755a582a7813ad45ab191d54ed73e3e0264 Mon Sep 17 00:00:00 2001 From: "DESKTOP-3BO4HSG\\ksat" Date: Wed, 18 Jan 2023 11:09:27 +0800 Subject: [PATCH] fix: hot keys conflict message perf: add keydown keyup --- STranslate/View/MainWindow.xaml.cs | 18 ++++++++--------- STranslate/View/SettingsWindow.xaml | 30 +++++++++++++++++------------ STranslate/ViewModel/SettingsVM.cs | 23 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/STranslate/View/MainWindow.xaml.cs b/STranslate/View/MainWindow.xaml.cs index 4c9a851..e0d1605 100644 --- a/STranslate/View/MainWindow.xaml.cs +++ b/STranslate/View/MainWindow.xaml.cs @@ -20,11 +20,6 @@ namespace STranslate.View vm.Mainwin = this; InitialTray(); - - //if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict) - //{ - // MessageBox.Show("全局快捷键有冲突..."); - //} } /// @@ -57,6 +52,11 @@ namespace STranslate.View { vm.OpenMainWin(); }); + + if (Hotkeys.InputTranslate.Conflict || Hotkeys.CrosswordTranslate.Conflict || Hotkeys.ScreenShotTranslate.Conflict || Hotkeys.OpenMainWindow.Conflict) + { + MessageBox.Show("全局快捷键有冲突,请前往软件首选项中修改..."); + } } private MainVM vm = MainVM.Instance; @@ -77,18 +77,18 @@ namespace STranslate.View NotifyIcon.ShowBalloonTip(500); NotifyIcon.MouseDoubleClick += InputTranslateMenuItem_Click; - var inputTranslateMenuItemBtn = new MenuItem("输入翻译\tAlt+A"); + var inputTranslateMenuItemBtn = new MenuItem("输入翻译"); inputTranslateMenuItemBtn.Click += InputTranslateMenuItem_Click; - var screenshotTranslateMenuItemBtn = new MenuItem("截图翻译\tAlt+S"); + var screenshotTranslateMenuItemBtn = new MenuItem("截图翻译"); screenshotTranslateMenuItemBtn.Click += ScreenshotTranslateMenuItem_Click; - var crossWordTranslateMenuItemBtn = new MenuItem("划词翻译\tAlt+D"); + var crossWordTranslateMenuItemBtn = new MenuItem("划词翻译"); //CrossWordTranslateMenuItemBTN.Click += CrossWordTranslateMenuItem_Click; //当失去焦点后无法从托盘处获取选中文本 crossWordTranslateMenuItemBtn.Enabled = false; - var openMainWinBtn = new MenuItem("显示主界面\tAlt+G"); + var openMainWinBtn = new MenuItem("显示主界面"); openMainWinBtn.Click += OpenMainWin_Click; var preferenceBtn = new MenuItem("首选项"); diff --git a/STranslate/View/SettingsWindow.xaml b/STranslate/View/SettingsWindow.xaml index f88cc95..b74e7d1 100644 --- a/STranslate/View/SettingsWindow.xaml +++ b/STranslate/View/SettingsWindow.xaml @@ -15,12 +15,12 @@ TargetType="Button"> + Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"/> @@ -113,7 +113,7 @@ - + - diff --git a/STranslate/ViewModel/SettingsVM.cs b/STranslate/ViewModel/SettingsVM.cs index ded2b15..03894a9 100644 --- a/STranslate/ViewModel/SettingsVM.cs +++ b/STranslate/ViewModel/SettingsVM.cs @@ -72,6 +72,12 @@ namespace STranslate.ViewModel (o as Window)?.Close(); }); + //重置热键 + ResetHotKeysCmd = new RelayCommand((_) => true, (_) => + { + System.Diagnostics.Debug.Print("重置快捷键"); + }); + OpenUrlCmd = new RelayCommand((_) => true, (o) => { try @@ -85,6 +91,16 @@ namespace STranslate.ViewModel MessageBox.Show($"未找到默认应用\n{ex.Message}"); } }); + + PreviewKeyDownCmd = new RelayCommand((_) => true, (o) => + { + System.Diagnostics.Debug.Print($"Press key, control: {o}"); + }); + + CrossWordKeyUpCmd = new RelayCommand((_) => true, (_) => + { + System.Diagnostics.Debug.Print($"Key up"); + }); } @@ -108,6 +124,13 @@ namespace STranslate.ViewModel public ICommand UpdateCmd { get; private set; } public ICommand StartupCmd { get; private set; } public ICommand EscCmd { get; private set; } + public ICommand ResetHotKeysCmd { get; private set; } + /// + /// 按键按下事件 + /// + public ICommand PreviewKeyDownCmd { get; private set; } + public ICommand CrossWordKeyUpCmd { get; private set; } + private static SettingsVM _instance; public static SettingsVM Instance => _instance ?? (_instance = new SettingsVM());