perf: update

dev_deconstruction
SONGE9B3\song_pd_win11 2 years ago
parent c22055fd88
commit f4c48f6418

@ -33,15 +33,17 @@ namespace STranslate
private void InitialTray() private void InitialTray()
{ {
notifyIcon.Text = "STranslate"; 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.Icon = new System.Drawing.Icon(Application.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative)).Stream);
notifyIcon.Visible = true; notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip(1000); //notifyIcon.ShowBalloonTip(1000);
notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick; notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
System.Windows.Forms.MenuItem CrossWordTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("划词翻译"); System.Windows.Forms.MenuItem CrossWordTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("划词翻译");
CrossWordTranslateMenuItemBTN.Click += new EventHandler(CrossWordTranslateMenuItem_Click); CrossWordTranslateMenuItemBTN.Click += new EventHandler(CrossWordTranslateMenuItem_Click);
//当失去焦点后无法从托盘处获取选中文本
CrossWordTranslateMenuItemBTN.Visible = false;
System.Windows.Forms.MenuItem ScreenshotTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("截图翻译"); System.Windows.Forms.MenuItem ScreenshotTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("截图翻译");
ScreenshotTranslateMenuItemBTN.Click += new EventHandler(ScreenshotTranslateMenuItem_Click); ScreenshotTranslateMenuItemBTN.Click += new EventHandler(ScreenshotTranslateMenuItem_Click);
@ -278,13 +280,13 @@ namespace STranslate
/// <param name="e"></param> /// <param name="e"></param>
private void Exit_Click(object sender, EventArgs e) private void Exit_Click(object sender, EventArgs e)
{ {
notifyIcon.Dispose(); notifyIcon.Dispose();
Environment.Exit(0); Environment.Exit(0);
} }
private void InitView() private void InitView()
{ {
this.Hide(); this.Activate();
this.TextBoxInput.Focus();
} }
private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon(); private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
private bool _IsTopmost { get; set; } private bool _IsTopmost { get; set; }

@ -84,6 +84,9 @@ namespace STranslate.ViewModel
text = System.Text.RegularExpressions.Regex.Replace(text, text = System.Text.RegularExpressions.Regex.Replace(text,
"[1234567890!\"#$%&'()*+,-./:;<=>?@\\[\\]^_`{|}~,。、《》?;‘’:“”【】、{}|·!@#¥%……&*()——+~\\\\]", "[1234567890!\"#$%&'()*+,-./:;<=>?@\\[\\]^_`{|}~,。、《》?;‘’:“”【】、{}|·!@#¥%……&*()——+~\\\\]",
string.Empty); string.Empty);
System.Diagnostics.Debug.Print($"经过转换后: {text}");
//如果输入是中文 //如果输入是中文
if (System.Text.RegularExpressions.Regex.IsMatch(text, @"^[\u4e00-\u9fa5]+$")) if (System.Text.RegularExpressions.Regex.IsMatch(text, @"^[\u4e00-\u9fa5]+$"))
{ {
@ -102,6 +105,7 @@ namespace STranslate.ViewModel
{ {
try try
{ {
var isEng = string.Empty;
IdentifyLanguage = string.Empty; IdentifyLanguage = string.Empty;
OutputTxt = "翻译中..."; OutputTxt = "翻译中...";
@ -110,6 +114,8 @@ namespace STranslate.ViewModel
{ {
var autoRet = AutomaticLanguageRecognition(InputTxt); var autoRet = AutomaticLanguageRecognition(InputTxt);
IdentifyLanguage = autoRet.Item1; IdentifyLanguage = autoRet.Item1;
isEng = autoRet.Item2;
return;
translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]); translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]);
} }
else else
@ -127,8 +133,11 @@ namespace STranslate.ViewModel
} }
OutputTxt = translateResp; 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; return;
} }

Loading…
Cancel
Save