diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index bc43ed3..1d64d07 100644 Binary files a/.vs/AIProofread/v17/.suo and b/.vs/AIProofread/v17/.suo differ diff --git a/AIProofread/AIProofread.csproj b/AIProofread/AIProofread.csproj index 5a3ba3b..bc54380 100644 --- a/AIProofread/AIProofread.csproj +++ b/AIProofread/AIProofread.csproj @@ -284,6 +284,12 @@ Form + + Form + + + FormCommonsenseDetection.cs + Form @@ -357,18 +363,21 @@ ProofreadMainControl.cs + + + @@ -382,6 +391,9 @@ + + FormCommonsenseDetection.cs + FormContact.cs @@ -524,6 +536,12 @@ + + + + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index 91cc499..eb81886 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -345,14 +345,23 @@ namespace AIProofread /// /// 根据位置获取文档区域文本 /// - /// - /// + /// 开始段落数 + /// 数据段落书 /// public string getParagraphTextByRange(int start, int end) { var list = Tools.GetTextListByParagraphRange(start, end); return Tools.GetJSONString(list); } + + public string GetDocumentAllText() + { + return Globals.ThisAddIn.ActiveDocument.GetAllText(); + } + public string GetTextByRange(int start, int end) + { + return Globals.ThisAddIn.ActiveDocument.GetRangeText(start, end); + } /// /// 获取文档所有段落文本 /// diff --git a/AIProofread/Controls/BaseWinForm.cs b/AIProofread/Controls/BaseWinForm.cs index 154a4ba..5f0c960 100644 --- a/AIProofread/Controls/BaseWinForm.cs +++ b/AIProofread/Controls/BaseWinForm.cs @@ -110,7 +110,7 @@ namespace AIProofread.Controls this.FormBorderStyle = FormBorderStyle.None; } - protected async void InitWebView(WebView2 webView,String url,string name) + protected async void InitWebView(WebView2 webView,String url,string name,Action callaback = null) { //Bridge.InitWebEnvAsync(name, webView); try @@ -124,6 +124,10 @@ namespace AIProofread.Controls var eventForwarder = new EventForwarder(this); webView.CoreWebView2.AddHostObjectToScript("event", eventForwarder); webView.CoreWebView2.AddHostObjectToScript("bridge", Bridge.bridge); + if(callaback != null) + { + callaback(); + } webView.Source = new Uri(url); }catch (Exception ex) diff --git a/AIProofread/Controls/FormCommonsenseDetection.Designer.cs b/AIProofread/Controls/FormCommonsenseDetection.Designer.cs new file mode 100644 index 0000000..b8d0217 --- /dev/null +++ b/AIProofread/Controls/FormCommonsenseDetection.Designer.cs @@ -0,0 +1,66 @@ +namespace AIProofread.Controls +{ + partial class FormCommonsenseDetection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.MainWebView = new Microsoft.Web.WebView2.WinForms.WebView2(); + ((System.ComponentModel.ISupportInitialize)(this.MainWebView)).BeginInit(); + this.SuspendLayout(); + // + // MainWebView + // + this.MainWebView.AllowExternalDrop = false; + this.MainWebView.BackColor = System.Drawing.SystemColors.ControlDark; + this.MainWebView.CreationProperties = null; + this.MainWebView.DefaultBackgroundColor = System.Drawing.Color.White; + this.MainWebView.Dock = System.Windows.Forms.DockStyle.Fill; + this.MainWebView.Location = new System.Drawing.Point(0, 0); + this.MainWebView.Name = "MainWebView"; + this.MainWebView.Size = new System.Drawing.Size(700, 600); + this.MainWebView.TabIndex = 0; + this.MainWebView.ZoomFactor = 1D; + // + // FormCommonsenseDetection + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 600); + this.Controls.Add(this.MainWebView); + this.Name = "FormCommonsenseDetection"; + this.Text = "FormCommonsenseDetection"; + this.Load += new System.EventHandler(this.FormCommonsenseDetection_Load); + ((System.ComponentModel.ISupportInitialize)(this.MainWebView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Microsoft.Web.WebView2.WinForms.WebView2 MainWebView; + } +} \ No newline at end of file diff --git a/AIProofread/Controls/FormCommonsenseDetection.cs b/AIProofread/Controls/FormCommonsenseDetection.cs new file mode 100644 index 0000000..3cfcdb9 --- /dev/null +++ b/AIProofread/Controls/FormCommonsenseDetection.cs @@ -0,0 +1,63 @@ +using AIProofread.core; +using Newtonsoft.Json; +using System; +using System.Runtime.InteropServices; +using System.Threading; +using UtilLib; + +namespace AIProofread.Controls +{ + [ClassInterface(ClassInterfaceType.AutoDual)] + [ComVisible(true)] + public partial class FormCommonsenseDetection : BaseWinForm + { + private bool initialized = false; + + private string action; + private object data; + + public FormCommonsenseDetection() + { + InitializeComponent(); + } + + private void FormCommonsenseDetection_Load(object sender, EventArgs e) + { + // 初始化 + InitWebView(MainWebView, Config.WebPath("commonsense-detection"), "commonsense-detection", () => + { + MainWebView.CoreWebView2.AddHostObjectToScript("detection", CommonSenseDetection.Instance(this)); + }); + } + + private void SendToWeb(string action, object data) + { + var json = JsonConvert.SerializeObject(new WebMessage(action, data)); + MainWebView.CoreWebView2.PostWebMessageAsJson(json); + } + + public void SendMessageToWeb(string action, object data) + { + // 判断是否已经初始化完成 + if (this.initialized) + { + SendToWeb(action, data); + return; + } + // 添加到队列 + this.action = action; + this.data = data; + } + + public void InitializationCompleted() + { + if (!this.initialized && !string.IsNullOrEmpty(this.action)) + { + SendToWeb(this.action, this.data); + this.action = null; + this.data = null; + } + this.initialized = true; + } + } +} diff --git a/AIProofread/Controls/FormCommonsenseDetection.resx b/AIProofread/Controls/FormCommonsenseDetection.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AIProofread/Controls/FormCommonsenseDetection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AIProofread/Model/CommonsenseDetectionItem.cs b/AIProofread/Model/CommonsenseDetectionItem.cs new file mode 100644 index 0000000..381ba66 --- /dev/null +++ b/AIProofread/Model/CommonsenseDetectionItem.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AIProofread.Model +{ + public enum CommonsenseDetectionType + { + All = 1, + Paragraph = 2 + } + + public class CommonsenseDetectionItem + { + [JsonProperty("id")] + public int Id { get; set; } + [JsonProperty("type")] + public CommonsenseDetectionType Type { get; set; } + [JsonProperty("summary")] + public string Summary { get; set; } + [JsonProperty("result_content")] + public string ResultContent { get; set; } + } +} diff --git a/AIProofread/Model/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs index 93c97c2..044c9b7 100644 --- a/AIProofread/Model/DocumentInfo.cs +++ b/AIProofread/Model/DocumentInfo.cs @@ -115,10 +115,11 @@ namespace AIProofread.Model FormMessage.ShowMessage(message, confirmText, confirmAction); })); } - public FormMessage ShowMessage(string message, int closeDelay,bool showCloseBtn = true) + public FormMessage ShowMessage(string message, int closeDelay, bool showCloseBtn = true) { var msgForm = FormMessage.ShowMessage(message, closeDelay); - if(closeDelay > 0){ + if (closeDelay > 0) + { if (!showCloseBtn) { @@ -317,7 +318,7 @@ namespace AIProofread.Model } // 获取当前文档文本 - public string GetText() + public string GetAllText() { return CurrentDocument.Range().Text; } @@ -328,7 +329,9 @@ namespace AIProofread.Model /// public string GetSelectedText() { - return CurrentDocument.Range().Text; + // 获取当前文档的选区 + var selection = Globals.ThisAddIn.Application.Selection; + return selection.Text; } /// @@ -341,6 +344,17 @@ namespace AIProofread.Model string text = range?.Text; return string.IsNullOrEmpty(text) ? "" : text; } + /// + /// 获取指定选区的文本 + /// + /// + /// + /// + public string GetRangeText(int start, int end) + { + if (start >= end) return null; + return GetRangeText(CurrentDocument.Range(start, end)); + } /// /// 保存校对缓存结果 diff --git a/AIProofread/Properties/Resources.Designer.cs b/AIProofread/Properties/Resources.Designer.cs index 02d9710..de65c5c 100644 --- a/AIProofread/Properties/Resources.Designer.cs +++ b/AIProofread/Properties/Resources.Designer.cs @@ -100,6 +100,26 @@ namespace AIProofread.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap icon_ai_robot { + get { + object obj = ResourceManager.GetObject("icon-ai-robot", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap icon_ai_robot_wps { + get { + object obj = ResourceManager.GetObject("icon-ai-robot-wps", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// diff --git a/AIProofread/Properties/Resources.resx b/AIProofread/Properties/Resources.resx index ae4466c..9742ea7 100644 --- a/AIProofread/Properties/Resources.resx +++ b/AIProofread/Properties/Resources.resx @@ -118,6 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\button.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\icon-setting-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -130,11 +133,8 @@ ..\Resources\icon-proofread-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\button.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-history.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\icon-phone.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -181,11 +181,8 @@ ..\Resources\icon-refresh-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\icon-history.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\button_default.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -196,11 +193,14 @@ ..\Resources\icon-refresh.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\logo_no_text.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\logo_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\icon-phone-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -208,19 +208,25 @@ ..\Resources\icon-history-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\icon-logout.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\icon_close.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\logo_no_text.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-ai-robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-ai-robot-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/AIProofread/Resources/icon-ai-robot-wps.jpg b/AIProofread/Resources/icon-ai-robot-wps.jpg new file mode 100644 index 0000000..b9230f8 Binary files /dev/null and b/AIProofread/Resources/icon-ai-robot-wps.jpg differ diff --git a/AIProofread/Resources/icon-ai-robot.png b/AIProofread/Resources/icon-ai-robot.png new file mode 100644 index 0000000..497cdfb Binary files /dev/null and b/AIProofread/Resources/icon-ai-robot.png differ diff --git a/AIProofread/Ribbon1.Designer.cs b/AIProofread/Ribbon1.Designer.cs index cbf2cfc..316c0eb 100644 --- a/AIProofread/Ribbon1.Designer.cs +++ b/AIProofread/Ribbon1.Designer.cs @@ -45,6 +45,10 @@ namespace AIProofread this.BtnExportProofreadResult = this.Factory.CreateRibbonButton(); this.btnClear = this.Factory.CreateRibbonButton(); this.btnOpenLexicon = this.Factory.CreateRibbonButton(); + this.menuSencenDect = this.Factory.CreateRibbonMenu(); + this.btnDetectionAll = this.Factory.CreateRibbonButton(); + this.btnDetectionParagraph = this.Factory.CreateRibbonButton(); + this.btnDetectionHistory = this.Factory.CreateRibbonButton(); this.btnSetting = this.Factory.CreateRibbonButton(); this.Group = this.Factory.CreateRibbonGroup(); this.ButtonSaveCache = this.Factory.CreateRibbonButton(); @@ -93,6 +97,7 @@ namespace AIProofread this.group1.Items.Add(this.BtnExportProofreadResult); this.group1.Items.Add(this.btnClear); this.group1.Items.Add(this.btnOpenLexicon); + this.group1.Items.Add(this.menuSencenDect); this.group1.Items.Add(this.btnSetting); this.group1.Name = "group1"; // @@ -132,6 +137,39 @@ namespace AIProofread this.btnOpenLexicon.ShowImage = true; this.btnOpenLexicon.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnOpenLexicon_Click); // + // menuSencenDect + // + this.menuSencenDect.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge; + this.menuSencenDect.Image = global::AIProofread.Properties.Resources.icon_ai_robot; + this.menuSencenDect.Items.Add(this.btnDetectionAll); + this.menuSencenDect.Items.Add(this.btnDetectionParagraph); + this.menuSencenDect.Items.Add(this.btnDetectionHistory); + this.menuSencenDect.Label = "校对助手\r\n"; + this.menuSencenDect.Name = "menuSencenDect"; + this.menuSencenDect.ShowImage = true; + // + // btnDetectionAll + // + this.btnDetectionAll.Label = "全文常识检测\r\n"; + this.btnDetectionAll.Name = "btnDetectionAll"; + this.btnDetectionAll.ShowImage = true; + this.btnDetectionAll.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnDetectionAll_Click); + // + // btnDetectionParagraph + // + this.btnDetectionParagraph.Enabled = false; + this.btnDetectionParagraph.Label = "段落常识检测\r\n"; + this.btnDetectionParagraph.Name = "btnDetectionParagraph"; + this.btnDetectionParagraph.ShowImage = true; + this.btnDetectionParagraph.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnDetectionParagraph_Click); + // + // btnDetectionHistory + // + this.btnDetectionHistory.Label = "历史检测记录\r\n"; + this.btnDetectionHistory.Name = "btnDetectionHistory"; + this.btnDetectionHistory.ShowImage = true; + this.btnDetectionHistory.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnDetectionHistory_Click); + // // btnSetting // this.btnSetting.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge; @@ -365,6 +403,10 @@ namespace AIProofread internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnShowVersion; internal Microsoft.Office.Tools.Ribbon.RibbonDropDown dropDown1; internal Microsoft.Office.Tools.Ribbon.RibbonGroup grpOther; + internal Microsoft.Office.Tools.Ribbon.RibbonMenu menuSencenDect; + internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionAll; + internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionParagraph; + internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionHistory; } partial class ThisRibbonCollection diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs index 14590c0..b4cbddf 100644 --- a/AIProofread/Ribbon1.cs +++ b/AIProofread/Ribbon1.cs @@ -51,6 +51,7 @@ namespace AIProofread btnLogout.Enabled = status; ButtonLoadCache.Enabled = status; ButtonSaveCache.Enabled = status; + menuSencenDect.Enabled = status; //BtnShowPanel.Enabled = status; BtnExportProofreadResult.Enabled = status; } @@ -85,6 +86,7 @@ namespace AIProofread BtnGetContact.Image = AIProofread.Properties.Resources.icon_phone_wps; BtnUpdate.Image = AIProofread.Properties.Resources.icon_update_wps; btnLogin.Image = AIProofread.Properties.Resources.icon_user_wps; + menuSencenDect.Image = AIProofread.Properties.Resources.icon_ai_robot_wps; btnLogout.Image = AIProofread.Properties.Resources.icon_logout_wps; // 缓存相关 ButtonLoadCache.Image = AIProofread.Properties.Resources.icon_refresh_wps; @@ -480,21 +482,9 @@ namespace AIProofread Logger.LoggerForm.Show(); } - private void BtnTest_Click(object sender, RibbonControlEventArgs e) + private int GetRangeParagraphNumber(Range range) { - // 获取当前系统时间戳 - //int time = (int)(DateTime.Now.Ticks / 10000000); - //BtnTest.Label = "测试按钮" + time; - //var result = MessageBox.Show("Test", "xxx"); - //Globals.ThisAddIn.Application. var app = Globals.ThisAddIn.Application; - var selection = app.Selection; - var range = selection.Range; - // 获取所在页 - var pageNumber = GetIndexPageNumber(range); - // 获取所在行 - var rowNumber = range.get_Information(WdInformation.wdFirstCharacterLineNumber); - int paragraphNumber = 0; if (range.Paragraphs.Count > 0) { @@ -517,6 +507,26 @@ namespace AIProofread } } } + return paragraphNumber; + } + + private void BtnTest_Click(object sender, RibbonControlEventArgs e) + { + // 获取当前系统时间戳 + //int time = (int)(DateTime.Now.Ticks / 10000000); + //BtnTest.Label = "测试按钮" + time; + //var result = MessageBox.Show("Test", "xxx"); + //Globals.ThisAddIn.Application. + var app = Globals.ThisAddIn.Application; + var selection = app.Selection; + var range = selection.Range; + // 获取所在页 + var pageNumber = GetIndexPageNumber(range); + // 获取所在行 + var rowNumber = range.get_Information(WdInformation.wdFirstCharacterLineNumber); + int paragraphNumber = GetRangeParagraphNumber(range); + + MessageBox.Show($"当前页:{pageNumber}, 行:{rowNumber}, 段落:{paragraphNumber}"); } @@ -552,5 +562,46 @@ namespace AIProofread { Globals.ThisAddIn.SendMessageToWeb("show-version", ""); } + + public Range currectSelectRange; + + private void btnDetectionAll_Click(object sender, RibbonControlEventArgs e) + { + Globals.ThisAddIn.ShowDetection(); + Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("detect-all", null); + } + + private void btnDetectionParagraph_Click(object sender, RibbonControlEventArgs e) + { + Globals.ThisAddIn.ShowDetection(); + // 获取当前选中的选区的首尾段落起始与结束位置 + var start = currectSelectRange.Paragraphs.First.Range.Start; + var end = currectSelectRange.Paragraphs.Last.Range.End; + var data = JSONObject.Create().AddField("start",start).AddField("end",end).ToString(); + Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("detect-range", data); + } + + private void btnDetectionHistory_Click(object sender, RibbonControlEventArgs e) + { + Globals.ThisAddIn.ShowDetection(); + Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("show-history", null); + } + + /// + /// 存储当前选区 + /// + /// + public void ParseSelectionChange(Selection s) + { + var r = s.Range; + btnDetectionParagraph.Enabled = r.Start != r.End; + this.currectSelectRange = r; + } + + public void SetDetectionBtnStatus(bool status) + { + btnDetectionAll.Enabled = status; + btnDetectionParagraph.Enabled = status; + } } } diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index 293e53c..f152a6c 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -58,6 +58,10 @@ namespace AIProofread /// 当前文档信息 /// public DocumentInfo ActiveDocument { get; set; } + /// + /// 智能常识检测对话框 = new FormCommonsenseDetection() + /// + public FormCommonsenseDetection formCommonsenseDetection; public bool IsWPS { get; set; } public List LoginFormList = new List(); @@ -71,6 +75,23 @@ namespace AIProofread // CurrentWordApplication.DocumentChange += CurrentWordApplication_DocumentChange; //} + public void ShowDetection() + { + if (formCommonsenseDetection == null) + { + formCommonsenseDetection = new FormCommonsenseDetection(); + } + + + //formCommonsenseDetection.ShowInTaskbar = true; + formCommonsenseDetection.Show(); + } + public void HideDetection() + { + formCommonsenseDetection.Close(); + formCommonsenseDetection = null; + } + private void ProcessApplicationException(object sender,UnhandledExceptionEventArgs e) { Logger.Log("UnhandledException",e.ExceptionObject as Exception); @@ -86,6 +107,9 @@ namespace AIProofread try { AppInitialize(); + //formCommonsenseDetection.ShowInTaskbar = false; + //formCommonsenseDetection.Show(); + Logger.Log("ThisAddIn_Startup IS_WPS --> " + IsWPS); // 捕获全局异常 AppDomain.CurrentDomain.UnhandledException += ProcessApplicationException; @@ -381,6 +405,8 @@ namespace AIProofread private void Application_WindowSelectionChange(Selection s) { + ribbon.ParseSelectionChange(s); + if (s.Bookmarks != null) { if (s.Range.Start == s.Range.End) // 说明是点击呀 diff --git a/AIProofread/core/CommonSenseDetection.cs b/AIProofread/core/CommonSenseDetection.cs new file mode 100644 index 0000000..72a02f3 --- /dev/null +++ b/AIProofread/core/CommonSenseDetection.cs @@ -0,0 +1,100 @@ +using AIProofread.Controls; +using AIProofread.Model; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace AIProofread.core +{ + /// + /// 常识性检测数据 + /// + [ClassInterface(ClassInterfaceType.AutoDual)] + [ComVisible(true)] + public class CommonSenseDetection + { + /// + /// 检测历史 + /// + //public static readonly Dictionary> histories = new Dictionary>(); + // 暂时改成全局 + private List history = new List(); + + // 生成单例 + private static readonly CommonSenseDetection instance = new CommonSenseDetection(); + private FormCommonsenseDetection formCommonsenseDetection; + private CommonSenseDetection() { } + + public static CommonSenseDetection Instance(FormCommonsenseDetection handler) + { + instance.formCommonsenseDetection = handler; + return instance; + } + + public void WebInitializationCompleted() + { + if (formCommonsenseDetection != null && !formCommonsenseDetection.IsDisposed) + { + formCommonsenseDetection.InitializationCompleted(); + } + } + + + // 检测状态 + public bool isChecking = false; + public string checkingSummary; + public string checkingKey; + + public string GetCheckStatus() + { + return JSONObject.Create() + .AddField("isChecking", isChecking) + .AddField("checkingKey", checkingKey) + .AddField("checkingSummary", checkingSummary) + .ToString(); + } + + public void SetCheckingData(bool isChecking, string checkingKey, string checkingSummary) + { + if (isChecking) + { + this.isChecking = isChecking; + this.checkingKey = checkingKey; + this.checkingSummary = checkingSummary; + Globals.ThisAddIn.ribbon.SetDetectionBtnStatus(false); + } + else + { + this.isChecking = false; + this.checkingKey = null; + this.checkingSummary = null; + Globals.ThisAddIn.ribbon.SetDetectionBtnStatus(true); + } + } + + public string GetHistory() + { + //int id = Globals.ThisAddIn.ActiveDocument.Id; + return JsonConvert.SerializeObject(history);// histories.ContainsKey(id) ? JsonConvert.SerializeObject(histories[id]) : "[]"; + } + public void SetHistory(string json) + { + var item = JsonConvert.DeserializeObject(json); + history.Add(item); + //int id = Globals.ThisAddIn.ActiveDocument.Id; + //if (histories.ContainsKey(id)) + //{ + // histories.Add(id, new List() { item }); + //} + //else + //{ + // histories[id].Add(item); + //} + } + + public void Close() + { + Globals.ThisAddIn.HideDetection(); + } + } +} diff --git a/AIProofread/core/JSONObject.cs b/AIProofread/core/JSONObject.cs new file mode 100644 index 0000000..7fedb05 --- /dev/null +++ b/AIProofread/core/JSONObject.cs @@ -0,0 +1,40 @@ +using Microsoft.Office.Interop.Word; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace AIProofread.core +{ + [Serializable] + public class JSONObject + { + private Dictionary m_Dict = new Dictionary(); + private JSONObject() + { + } + public static JSONObject Create() + { + JSONObject obj = new JSONObject(); + return obj; + } + + public JSONObject AddField(string key, object value) + { + m_Dict.Add(key, value); + return this; + } + + public override string ToString() + { + return ToJSONString(); + } + + public string ToJSONString() + { + return Tools.GetJSONString(m_Dict); + } + } +} diff --git a/AIProofread/obj/Debug/AIProofread.Properties.Resources.resources b/AIProofread/obj/Debug/AIProofread.Properties.Resources.resources index 52b6ecc..159e779 100644 Binary files a/AIProofread/obj/Debug/AIProofread.Properties.Resources.resources and b/AIProofread/obj/Debug/AIProofread.Properties.Resources.resources differ diff --git a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache index f02b89d..a5008fb 100644 Binary files a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache and b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache differ diff --git a/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache b/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache index b089b12..f084c56 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache +++ b/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -0ffc09f3eb798c1989429f7c2b6c0220e93f9976a035c03b8478b5bf94f1b55c +80a1b62e50022f6927ea33d64c401a80d068064724a07da1ca8562102f036978 diff --git a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt index fe5e564..702498b 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt +++ b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt @@ -215,3 +215,4 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread. C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.dll.config C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AntdUI.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AntdUI.xml +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormCommonsenseDetection.resources diff --git a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache index e492eb1..96a3a5c 100644 Binary files a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache and b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache differ diff --git a/AIProofread/obj/Debug/AIProofread.dll b/AIProofread/obj/Debug/AIProofread.dll index fe8cf5c..71a7a9c 100644 Binary files a/AIProofread/obj/Debug/AIProofread.dll and b/AIProofread/obj/Debug/AIProofread.dll differ diff --git a/AIProofread/obj/Debug/AIProofread.pdb b/AIProofread/obj/Debug/AIProofread.pdb index 1697afc..d98ac29 100644 Binary files a/AIProofread/obj/Debug/AIProofread.pdb and b/AIProofread/obj/Debug/AIProofread.pdb differ diff --git a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index bd5d4b5..bafbec3 100644 Binary files a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/AIProofread/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll b/AIProofread/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll index 277e1f8..b3ec8ce 100644 Binary files a/AIProofread/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll and b/AIProofread/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll differ