dev_split_view_vm
DESKTOP-3BO4HSG\ksat 2 years ago
parent 60cc864fa8
commit 7c8363b531

@ -51,7 +51,7 @@
Visibility="{Binding IsVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"
ToolTipText="STranslate"
ContextMenu="{StaticResource TrayMenu}"
LeftClickCommand="{Binding ShowMainWinCmd}"
DoubleClickCommand="{Binding InputTranslateCmd}"
IconSource="/Images/translate.ico">
</tb:TaskbarIcon>

@ -21,70 +21,12 @@ namespace STranslate
DataContext = new MainVM(this);
vm = (MainVM)DataContext;
InitView();
//InitialTray();
//if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict)
//{
// MessageBox.Show("全局快捷键有冲突,请您到设置中重新设置");
//}
}
private void InitialTray()
{
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
notifyIcon.Text = $"STranslate_{version}\n" +
$"划词翻译快捷键: ALT + D\n" +
$"输入翻译快捷键: ALT + A\n";
//notifyIcon.BalloonTipText = "STranslate 已启动";
notifyIcon.Icon = new System.Drawing.Icon(Application.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative)).Stream);
notifyIcon.Visible = true;
//notifyIcon.ShowBalloonTip(1000);
notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
System.Windows.Forms.MenuItem CrossWordTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("划词翻译");
CrossWordTranslateMenuItemBTN.Click += new EventHandler(CrossWordTranslateMenuItem_Click);
//当失去焦点后无法从托盘处获取选中文本
CrossWordTranslateMenuItemBTN.Visible = false;
System.Windows.Forms.MenuItem ScreenshotTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("截图翻译");
ScreenshotTranslateMenuItemBTN.Click += new EventHandler(ScreenshotTranslateMenuItem_Click);
ScreenshotTranslateMenuItemBTN.Enabled = false;
System.Windows.Forms.MenuItem InputTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("输入翻译");
InputTranslateMenuItemBTN.Click += new EventHandler(InputTranslateMenuItem_Click);
System.Windows.Forms.MenuItem OpenMainWinBTN = new System.Windows.Forms.MenuItem("显示主界面");
OpenMainWinBTN.Click += new EventHandler(OpenMainWin_Click);
System.Windows.Forms.MenuItem AutoStartBTN = new System.Windows.Forms.MenuItem("开机自启");
AutoStartBTN.Click += new EventHandler(AutoStart_Click);
AutoStartBTN.Checked = StartupHelper.IsStartup();
System.Windows.Forms.MenuItem ExitBTN = new System.Windows.Forms.MenuItem("退出");
ExitBTN.Click += new EventHandler(Exit_Click);
System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] {
CrossWordTranslateMenuItemBTN,
ScreenshotTranslateMenuItemBTN,
InputTranslateMenuItemBTN,
OpenMainWinBTN,
AutoStartBTN,
ExitBTN,
};
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
}
private void AutoStart_Click(object sender, EventArgs e)
{
if (StartupHelper.IsStartup()) StartupHelper.UnSetStartup();
else StartupHelper.SetStartup();
(sender as System.Windows.Forms.MenuItem).Checked = StartupHelper.IsStartup();
}
/// <summary>
/// 移动
@ -127,7 +69,7 @@ namespace STranslate
&& e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Shift)
&& e.Key == Key.Q)
{
Exit_Click(null, null);
vm.ExitApp();
}
}
@ -147,7 +89,7 @@ namespace STranslate
HotkeysHelper.Register(HotkeysHelper.CrosswordTranslateId, () =>
{
CrossWordTranslateMenuItem_Click(null, null);
vm.CrossWordTranslate();
});
//HotkeysHelper.Register(HotkeysHelper.ScreenShotTranslateId, () =>
@ -157,7 +99,7 @@ namespace STranslate
HotkeysHelper.Register(HotkeysHelper.OpenMainWindowId, () =>
{
OpenMainWin_Click(null, null);
vm.OpenMainWin();
});
}
@ -175,78 +117,6 @@ namespace STranslate
}
}
/// <summary>
/// 清空输入输出框
/// </summary>
private void ClearTextBox()
{
vm.InputTxt = string.Empty;
vm.OutputTxt = string.Empty;
vm.SnakeRet = string.Empty;
vm.SmallHumpRet = string.Empty;
vm.LargeHumpRet = string.Empty;
vm.IdentifyLanguage = string.Empty;
}
/// <summary>
/// 显示主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenMainWin_Click(object sender, EventArgs e)
{
this.Show();
this.Activate();
}
/// <summary>
/// 左键双击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NotifyIcon_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
InputTranslateMenuItem_Click(null, null);
}
/// <summary>
/// 输入翻译
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InputTranslateMenuItem_Click(object sender, EventArgs e)
{
ClearTextBox();
OpenMainWin_Click(null, null);
TextBoxInput.Focus();
}
/// <summary>
/// 划词翻译
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CrossWordTranslateMenuItem_Click(object sender, EventArgs e)
{
ClearTextBox();
var sentence = GetWordsHelper.Get();
this.Show();
this.Activate();
this.TextBoxInput.Text = sentence.Trim();
_ = vm.Translate();
}
/// <summary>
/// 截图翻译
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScreenshotTranslateMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("开发中");
}
/// <summary>
/// 是否置顶(不好拆)
/// </summary>
@ -264,23 +134,6 @@ namespace STranslate
}
_IsTopmost = !_IsTopmost;
}
/// <summary>
/// 退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Exit_Click(object sender, EventArgs e)
{
vm.Dispose();
notifyIcon.Dispose();
Environment.Exit(0);
}
private void InitView()
{
this.Activate();
this.TextBoxInput.Focus();
}
private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
private bool _IsTopmost { get; set; }
private readonly string _TopmostTemplateName = "ButtonTemplateTopmost";
private readonly string _UnTopmostTemplateName = "ButtonTemplateUnTopmost";

@ -35,6 +35,7 @@ namespace STranslate.ViewModel
#region 托盘程序
//运行前检查是否开机自启
IsStartup = StartupHelper.IsStartup();
//输入翻译
InputTranslateCmd = new RelayCommand((_) => true, (_) =>
{
@ -46,6 +47,7 @@ namespace STranslate.ViewModel
{
OpenMainWin();
});
//开机自启
StartupCmd = new RelayCommand((_) => true, (_) =>
{
@ -57,9 +59,7 @@ namespace STranslate.ViewModel
//退出App
ExitCmd = new RelayCommand((_) => true, (_) =>
{
IsVisibility = false;
Dispose();
Environment.Exit(0);
ExitApp();
});
#endregion
@ -150,7 +150,18 @@ namespace STranslate.ViewModel
}
public void CrossWordTranslate()
{
ClearAll();
var sentence = GetWordsHelper.Get();
OpenMainWin();
//TODO: add textbox focus
//this.TextBoxInput.Text = sentence.Trim();
_ = Translate();
}
public void ExitApp()
{
IsVisibility = false;
Dispose();
Environment.Exit(0);
}
/// <summary>

Loading…
Cancel
Save