fasdfsa commited on
Commit
8a96ad7
·
1 Parent(s): b355108

添加翻译右键菜单

Browse files
src/WpfEditor/DictMenuHandler.cs CHANGED
@@ -1,6 +1,8 @@
1
  using CefSharp;
 
2
  using System;
3
  using System.Windows;
 
4
 
5
  namespace Echodict
6
  {
@@ -9,6 +11,7 @@ namespace Echodict
9
  private const CefMenuCommand QueryCommandId = (CefMenuCommand)26501;
10
  private const CefMenuCommand JishoCommandId = (CefMenuCommand)26502;
11
  private const CefMenuCommand NaverjaCommandId = (CefMenuCommand)26503;
 
12
 
13
  public void OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
14
  {
@@ -19,9 +22,10 @@ namespace Echodict
19
  if (!string.IsNullOrEmpty(parameters.SelectionText))
20
  {
21
  model.AddItem(CefMenuCommand.Copy, "Copy");
22
- model.AddItem(QueryCommandId, "查询"); // Query
23
- model.AddItem(JishoCommandId, "Jisho"); // Jisho
24
- model.AddItem(NaverjaCommandId, "Naverja"); // Naverja
 
25
  }
26
  }
27
 
@@ -68,6 +72,25 @@ namespace Echodict
68
  });
69
  }
70
  return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
  return false;
73
  }
 
1
  using CefSharp;
2
+ using Newtonsoft.Json.Linq;
3
  using System;
4
  using System.Windows;
5
+ using WpfEditor;
6
 
7
  namespace Echodict
8
  {
 
11
  private const CefMenuCommand QueryCommandId = (CefMenuCommand)26501;
12
  private const CefMenuCommand JishoCommandId = (CefMenuCommand)26502;
13
  private const CefMenuCommand NaverjaCommandId = (CefMenuCommand)26503;
14
+ private const CefMenuCommand TranslateCommandId = (CefMenuCommand)26504;
15
 
16
  public void OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
17
  {
 
22
  if (!string.IsNullOrEmpty(parameters.SelectionText))
23
  {
24
  model.AddItem(CefMenuCommand.Copy, "Copy");
25
+ model.AddItem(QueryCommandId, "查询"); // Query
26
+ model.AddItem(JishoCommandId, "Jisho"); // Jisho
27
+ model.AddItem(NaverjaCommandId, "Naverja"); // Naverja
28
+ model.AddItem(TranslateCommandId, "Translate"); // Translate
29
  }
30
  }
31
 
 
72
  });
73
  }
74
  return true;
75
+ } else if (commandId == TranslateCommandId) {
76
+ string text = parameters.SelectionText;
77
+ if (!string.IsNullOrEmpty(text))
78
+ {
79
+ Application.Current.Dispatcher.Invoke(async () =>
80
+ {
81
+ string res = await DeepSeek.translate(text);
82
+ if (res != "")
83
+ {
84
+ JObject jsn = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(res);
85
+ string zh = jsn["choices"][0]["message"]["content"].Value<string>();
86
+ var win = new TranslationResultWindow(zh);
87
+ win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
88
+ win.Topmost = true;
89
+ win.Show();
90
+ }
91
+ });
92
+ }
93
+ return true;
94
  }
95
  return false;
96
  }
src/WpfEditor/TextEditorControl.cs CHANGED
@@ -428,7 +428,7 @@ namespace WpfEditor
428
  }
429
  }
430
 
431
- // "翻译"菜单项点击事件处理
432
  private async void OnQueryMenuItemClick(object sender, RoutedEventArgs e)
433
  {
434
  if (HasSelection())
 
428
  }
429
  }
430
 
431
+ // "查询"菜单项点击事件处理
432
  private async void OnQueryMenuItemClick(object sender, RoutedEventArgs e)
433
  {
434
  if (HasSelection())