diff --git a/STranslate/MainWindow.xaml.cs b/STranslate/MainWindow.xaml.cs index c50e531..7bbaf82 100644 --- a/STranslate/MainWindow.xaml.cs +++ b/STranslate/MainWindow.xaml.cs @@ -33,15 +33,17 @@ namespace STranslate private void InitialTray() { notifyIcon.Text = "STranslate"; - notifyIcon.BalloonTipText = "STranslate 已启动"; + //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.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); @@ -278,13 +280,13 @@ namespace STranslate /// private void Exit_Click(object sender, EventArgs e) { - notifyIcon.Dispose(); Environment.Exit(0); } private void InitView() { - this.Hide(); + this.Activate(); + this.TextBoxInput.Focus(); } private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon(); private bool _IsTopmost { get; set; } diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs index c4d9689..8a50303 100644 --- a/STranslate/ViewModel/MainVM.cs +++ b/STranslate/ViewModel/MainVM.cs @@ -84,6 +84,9 @@ namespace STranslate.ViewModel text = System.Text.RegularExpressions.Regex.Replace(text, "[1234567890!\"#$%&'()*+,-./:;<=>?@\\[\\]^_`{|}~,。、《》?;‘’:“”【】、{}|·!@#¥%……&*()——+~\\\\]", string.Empty); + + System.Diagnostics.Debug.Print($"经过转换后: {text}"); + //如果输入是中文 if (System.Text.RegularExpressions.Regex.IsMatch(text, @"^[\u4e00-\u9fa5]+$")) { @@ -102,6 +105,7 @@ namespace STranslate.ViewModel { try { + var isEng = string.Empty; IdentifyLanguage = string.Empty; OutputTxt = "翻译中..."; @@ -110,6 +114,8 @@ namespace STranslate.ViewModel { var autoRet = AutomaticLanguageRecognition(InputTxt); IdentifyLanguage = autoRet.Item1; + isEng = autoRet.Item2; + return; translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]); } else @@ -127,8 +133,11 @@ namespace STranslate.ViewModel } OutputTxt = translateResp; - //如果不是英文则不进行转换 - if (AutomaticLanguageRecognition(InputTxt).Item2 != LanguageEnum.EN.GetDescription() && LanguageEnumDict[OutputComboSelected] != LanguageEnum.EN) + //如果目标语言不是英文则不进行转换 + //1. 自动判断语种:Tuple item2 不为 EN + //2. 非自动判断语种,目标语种不为 EN + if ((!string.IsNullOrEmpty(isEng) && isEng != LanguageEnum.EN.GetDescription()) + || LanguageEnumDict[OutputComboSelected] != LanguageEnum.EN) { return; }