From 7a4aa1deb6c4f82e39e33a64dc16a3a10ba9f8b3 Mon Sep 17 00:00:00 2001 From: "DESKTOP-3BO4HSG\\ksat" Date: Mon, 9 Jan 2023 16:02:39 +0800 Subject: [PATCH] chore: add screen shot hot key and update exit codes --- STranslate/Helper/HotkeysHelper.cs | 10 +++--- STranslate/View/MainWindow.xaml | 2 ++ STranslate/View/MainWindow.xaml.cs | 8 ++--- STranslate/ViewModel/MainVM.cs | 50 ++++++++++++++++++++++-------- 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/STranslate/Helper/HotkeysHelper.cs b/STranslate/Helper/HotkeysHelper.cs index 28ac43d..9ab02f4 100644 --- a/STranslate/Helper/HotkeysHelper.cs +++ b/STranslate/Helper/HotkeysHelper.cs @@ -24,7 +24,7 @@ namespace STranslate.Helper public static bool Conflict = false; } -#if false +#if true public static class ScreenShotTranslate { public static byte Modifiers = (byte)KeyModifiers.MOD_ALT; @@ -52,7 +52,7 @@ namespace STranslate.Helper public static int CrosswordTranslateId = 855; public static byte CrosswordTranslateModifiers; public static int CrosswordTranslateKey; -#if false +#if true public static int ScreenShotTranslateId = 856; public static byte ScreenShotTranslateModifiers; public static int ScreenShotTranslateKey; @@ -112,7 +112,7 @@ namespace STranslate.Helper CrosswordTranslateModifiers = Hotkeys.CrosswordTranslate.Modifiers; CrosswordTranslateKey = Hotkeys.CrosswordTranslate.Key; -#if false +#if true ScreenShotTranslateModifiers = Hotkeys.ScreenShotTranslate.Modifiers; ScreenShotTranslateKey = Hotkeys.ScreenShotTranslate.Key; if (Hotkeys.ScreenShotTranslate.Key != 0) @@ -142,7 +142,7 @@ namespace STranslate.Helper { UnregisterHotKey(mainFormHandle, InputTranslateId); UnregisterHotKey(mainFormHandle, CrosswordTranslateId); -#if false +#if true UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); #endif UnregisterHotKey(mainFormHandle, OpenMainWindowId); @@ -181,7 +181,7 @@ namespace STranslate.Helper CrosswordTranslateModifiers = Hotkeys.CrosswordTranslate.Modifiers; CrosswordTranslateKey = Hotkeys.CrosswordTranslate.Key; -#if false +#if true if (Hotkeys.ScreenShotTranslate.Key == 0) { UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); diff --git a/STranslate/View/MainWindow.xaml b/STranslate/View/MainWindow.xaml index 03566b0..9a62b02 100644 --- a/STranslate/View/MainWindow.xaml +++ b/STranslate/View/MainWindow.xaml @@ -27,6 +27,8 @@ + diff --git a/STranslate/View/MainWindow.xaml.cs b/STranslate/View/MainWindow.xaml.cs index 82b02b0..1f6f4df 100644 --- a/STranslate/View/MainWindow.xaml.cs +++ b/STranslate/View/MainWindow.xaml.cs @@ -44,10 +44,10 @@ namespace STranslate.View vm.CrossWordTranslate(); }); - //HotkeysHelper.Register(HotkeysHelper.ScreenShotTranslateId, () => - //{ - // ScreenshotTranslateMenuItem_Click(null, null); - //}); + HotkeysHelper.Register(HotkeysHelper.ScreenShotTranslateId, () => + { + vm.ScreenShotTranslate(); + }); HotkeysHelper.Register(HotkeysHelper.OpenMainWindowId, () => { diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs index 35b71e5..9441fd8 100644 --- a/STranslate/ViewModel/MainVM.cs +++ b/STranslate/ViewModel/MainVM.cs @@ -12,7 +12,7 @@ using STranslate.Helper; namespace STranslate.ViewModel { - public class MainVM : BaseVM, IDisposable + public class MainVM : BaseVM { public MainVM(Window win) @@ -22,8 +22,7 @@ namespace STranslate.ViewModel if (!ReadConfig()) { - IsVisibility = false; - Environment.Exit(-1); + ExitApp(-1); } InputCombo = LanguageEnumDict.Keys.ToList(); @@ -39,6 +38,12 @@ namespace STranslate.ViewModel InputTranslate(); }); + //截图翻译 + ScreenShotTranslateCmd = new RelayCommand((_) => true, (_) => + { + ScreenShotTranslate(); + }); + //显示主界面 ShowMainWinCmd = new RelayCommand((_) => true, (_) => { @@ -56,7 +61,7 @@ namespace STranslate.ViewModel //退出App ExitCmd = new RelayCommand((_) => true, (_) => { - ExitApp(); + ExitApp(0); }); //置顶 @@ -180,11 +185,17 @@ namespace STranslate.ViewModel _Mainwin.Activate(); (_Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox).Focus(); } + /// + /// 输入翻译 + /// public void InputTranslate() { ClearAll(); OpenMainWin(); } + /// + /// 划词翻译 + /// public void CrossWordTranslate() { ClearAll(); @@ -194,11 +205,29 @@ namespace STranslate.ViewModel .Text = sentence.Trim(); _ = Translate(); } - public void ExitApp() + /// + /// 截屏翻译 + /// + public void ScreenShotTranslate() { + MessageBox.Show("aaa"); + } + + /// + /// 退出App + /// + public void ExitApp(int id) + { + //隐藏icon IsVisibility = false; - Dispose(); - Environment.Exit(0); + //语音合成销毁 + Speech.Dispose(); + if (id == 0) + { + //写入配置 + WriteConfig(); + } + Environment.Exit(id); } /// @@ -356,12 +385,6 @@ namespace STranslate.ViewModel OutputTxt = ex.Message; } } - - public void Dispose() - { - Speech.Dispose(); - WriteConfig(); - } #endregion handle #region Params @@ -377,6 +400,7 @@ namespace STranslate.ViewModel public ICommand ThemeConvertCmd { get; private set; } //托盘程序 public ICommand InputTranslateCmd { get; private set; } + public ICommand ScreenShotTranslateCmd { get; private set; } public ICommand ShowMainWinCmd { get; private set; } public ICommand StartupCmd { get; private set; } public ICommand ExitCmd { get; private set; }