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;
}
#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);

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

@ -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, () =>
{

@ -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();
}
/// <summary>
/// 输入翻译
/// </summary>
public void InputTranslate()
{
ClearAll();
OpenMainWin();
}
/// <summary>
/// 划词翻译
/// </summary>
public void CrossWordTranslate()
{
ClearAll();
@ -194,11 +205,29 @@ namespace STranslate.ViewModel
.Text = sentence.Trim();
_ = Translate();
}
public void ExitApp()
/// <summary>
/// 截屏翻译
/// </summary>
public void ScreenShotTranslate()
{
MessageBox.Show("aaa");
}
/// <summary>
/// 退出App
/// </summary>
public void ExitApp(int id)
{
//隐藏icon
IsVisibility = false;
Dispose();
Environment.Exit(0);
//语音合成销毁
Speech.Dispose();
if (id == 0)
{
//写入配置
WriteConfig();
}
Environment.Exit(id);
}
/// <summary>
@ -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; }

Loading…
Cancel
Save