chore: add screen shot hot key and update exit codes

dev_ocr_translate
DESKTOP-3BO4HSG\ksat 2 years ago
parent c8f71ad499
commit 7a4aa1deb6

@ -24,7 +24,7 @@ namespace STranslate.Helper
public static bool Conflict = false; public static bool Conflict = false;
} }
#if false #if true
public static class ScreenShotTranslate public static class ScreenShotTranslate
{ {
public static byte Modifiers = (byte)KeyModifiers.MOD_ALT; public static byte Modifiers = (byte)KeyModifiers.MOD_ALT;
@ -52,7 +52,7 @@ namespace STranslate.Helper
public static int CrosswordTranslateId = 855; public static int CrosswordTranslateId = 855;
public static byte CrosswordTranslateModifiers; public static byte CrosswordTranslateModifiers;
public static int CrosswordTranslateKey; public static int CrosswordTranslateKey;
#if false #if true
public static int ScreenShotTranslateId = 856; public static int ScreenShotTranslateId = 856;
public static byte ScreenShotTranslateModifiers; public static byte ScreenShotTranslateModifiers;
public static int ScreenShotTranslateKey; public static int ScreenShotTranslateKey;
@ -112,7 +112,7 @@ namespace STranslate.Helper
CrosswordTranslateModifiers = Hotkeys.CrosswordTranslate.Modifiers; CrosswordTranslateModifiers = Hotkeys.CrosswordTranslate.Modifiers;
CrosswordTranslateKey = Hotkeys.CrosswordTranslate.Key; CrosswordTranslateKey = Hotkeys.CrosswordTranslate.Key;
#if false #if true
ScreenShotTranslateModifiers = Hotkeys.ScreenShotTranslate.Modifiers; ScreenShotTranslateModifiers = Hotkeys.ScreenShotTranslate.Modifiers;
ScreenShotTranslateKey = Hotkeys.ScreenShotTranslate.Key; ScreenShotTranslateKey = Hotkeys.ScreenShotTranslate.Key;
if (Hotkeys.ScreenShotTranslate.Key != 0) if (Hotkeys.ScreenShotTranslate.Key != 0)
@ -142,7 +142,7 @@ namespace STranslate.Helper
{ {
UnregisterHotKey(mainFormHandle, InputTranslateId); UnregisterHotKey(mainFormHandle, InputTranslateId);
UnregisterHotKey(mainFormHandle, CrosswordTranslateId); UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
#if false #if true
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
#endif #endif
UnregisterHotKey(mainFormHandle, OpenMainWindowId); UnregisterHotKey(mainFormHandle, OpenMainWindowId);
@ -181,7 +181,7 @@ namespace STranslate.Helper
CrosswordTranslateModifiers = Hotkeys.CrosswordTranslate.Modifiers; CrosswordTranslateModifiers = Hotkeys.CrosswordTranslate.Modifiers;
CrosswordTranslateKey = Hotkeys.CrosswordTranslate.Key; CrosswordTranslateKey = Hotkeys.CrosswordTranslate.Key;
#if false #if true
if (Hotkeys.ScreenShotTranslate.Key == 0) if (Hotkeys.ScreenShotTranslate.Key == 0)
{ {
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);

@ -27,6 +27,8 @@
<ContextMenu x:Key="TrayMenu"> <ContextMenu x:Key="TrayMenu">
<MenuItem Header="输入翻译" <MenuItem Header="输入翻译"
Command="{Binding InputTranslateCmd}"/> Command="{Binding InputTranslateCmd}"/>
<MenuItem Header="截图翻译"
Command="{Binding ScreenShotTranslateCmd}"/>
<Separator /> <Separator />
<MenuItem Header="显示主界面" <MenuItem Header="显示主界面"
Command="{Binding ShowMainWinCmd}"/> Command="{Binding ShowMainWinCmd}"/>

@ -44,10 +44,10 @@ namespace STranslate.View
vm.CrossWordTranslate(); vm.CrossWordTranslate();
}); });
//HotkeysHelper.Register(HotkeysHelper.ScreenShotTranslateId, () => HotkeysHelper.Register(HotkeysHelper.ScreenShotTranslateId, () =>
//{ {
// ScreenshotTranslateMenuItem_Click(null, null); vm.ScreenShotTranslate();
//}); });
HotkeysHelper.Register(HotkeysHelper.OpenMainWindowId, () => HotkeysHelper.Register(HotkeysHelper.OpenMainWindowId, () =>
{ {

@ -12,7 +12,7 @@ using STranslate.Helper;
namespace STranslate.ViewModel namespace STranslate.ViewModel
{ {
public class MainVM : BaseVM, IDisposable public class MainVM : BaseVM
{ {
public MainVM(Window win) public MainVM(Window win)
@ -22,8 +22,7 @@ namespace STranslate.ViewModel
if (!ReadConfig()) if (!ReadConfig())
{ {
IsVisibility = false; ExitApp(-1);
Environment.Exit(-1);
} }
InputCombo = LanguageEnumDict.Keys.ToList(); InputCombo = LanguageEnumDict.Keys.ToList();
@ -39,6 +38,12 @@ namespace STranslate.ViewModel
InputTranslate(); InputTranslate();
}); });
//截图翻译
ScreenShotTranslateCmd = new RelayCommand((_) => true, (_) =>
{
ScreenShotTranslate();
});
//显示主界面 //显示主界面
ShowMainWinCmd = new RelayCommand((_) => true, (_) => ShowMainWinCmd = new RelayCommand((_) => true, (_) =>
{ {
@ -56,7 +61,7 @@ namespace STranslate.ViewModel
//退出App //退出App
ExitCmd = new RelayCommand((_) => true, (_) => ExitCmd = new RelayCommand((_) => true, (_) =>
{ {
ExitApp(); ExitApp(0);
}); });
//置顶 //置顶
@ -180,11 +185,17 @@ namespace STranslate.ViewModel
_Mainwin.Activate(); _Mainwin.Activate();
(_Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox).Focus(); (_Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox).Focus();
} }
/// <summary>
/// 输入翻译
/// </summary>
public void InputTranslate() public void InputTranslate()
{ {
ClearAll(); ClearAll();
OpenMainWin(); OpenMainWin();
} }
/// <summary>
/// 划词翻译
/// </summary>
public void CrossWordTranslate() public void CrossWordTranslate()
{ {
ClearAll(); ClearAll();
@ -194,11 +205,29 @@ namespace STranslate.ViewModel
.Text = sentence.Trim(); .Text = sentence.Trim();
_ = Translate(); _ = Translate();
} }
public void ExitApp() /// <summary>
/// 截屏翻译
/// </summary>
public void ScreenShotTranslate()
{ {
MessageBox.Show("aaa");
}
/// <summary>
/// 退出App
/// </summary>
public void ExitApp(int id)
{
//隐藏icon
IsVisibility = false; IsVisibility = false;
Dispose(); //语音合成销毁
Environment.Exit(0); Speech.Dispose();
if (id == 0)
{
//写入配置
WriteConfig();
}
Environment.Exit(id);
} }
/// <summary> /// <summary>
@ -356,12 +385,6 @@ namespace STranslate.ViewModel
OutputTxt = ex.Message; OutputTxt = ex.Message;
} }
} }
public void Dispose()
{
Speech.Dispose();
WriteConfig();
}
#endregion handle #endregion handle
#region Params #region Params
@ -377,6 +400,7 @@ namespace STranslate.ViewModel
public ICommand ThemeConvertCmd { get; private set; } public ICommand ThemeConvertCmd { get; private set; }
//托盘程序 //托盘程序
public ICommand InputTranslateCmd { get; private set; } public ICommand InputTranslateCmd { get; private set; }
public ICommand ScreenShotTranslateCmd { get; private set; }
public ICommand ShowMainWinCmd { get; private set; } public ICommand ShowMainWinCmd { get; private set; }
public ICommand StartupCmd { get; private set; } public ICommand StartupCmd { get; private set; }
public ICommand ExitCmd { get; private set; } public ICommand ExitCmd { get; private set; }

Loading…
Cancel
Save