diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index 8db018f..7b027b3 100644 Binary files a/.vs/AIProofread/v17/.suo and b/.vs/AIProofread/v17/.suo differ diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index a68ab9e..7a196f3 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -103,7 +103,7 @@ namespace AIProofread start = currectSelectRange.Paragraphs.First.Range.Start; end = currectSelectRange.Paragraphs.Last.Range.End; } - var data = JSONObject.Create().AddField("start", start).AddField("end", end).ToString(); + var data = JSONObject.Create().Put("start", start).Put("end", end).ToString(); Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("detect-range", data); } public void SendNoticeToShowCheckHistory() @@ -384,7 +384,27 @@ namespace AIProofread } public string GetTextByRange(int start, int end) { - return Globals.ThisAddIn.ActiveDocument.GetRangeText(start, end); + var range = Globals.ThisAddIn.ActiveDocument.Range(start, end); + if (range == null) + { + return JSONObject.Create() + .Put("text", null) + .Put("page", -1) + .Put("line", -1) + .ToString(); + } + var text = Globals.ThisAddIn.ActiveDocument.GetRangeText(range); + + // 获取书签在文档的页码数 + var pageNumber = range.get_Information(WdInformation.wdActiveEndPageNumber); + // 获取书签在当前页面的行数 + var lineNumber = range.get_Information(WdInformation.wdFirstCharacterLineNumber); + + return JSONObject.Create() + .Put("text",text) + .Put("page", pageNumber) + .Put("line", lineNumber) + .ToString(); } /// /// 获取文档所有段落文本 diff --git a/AIProofread/Controls/FormCommonsenseDetection.Designer.cs b/AIProofread/Controls/FormCommonsenseDetection.Designer.cs index b8d0217..e698db4 100644 --- a/AIProofread/Controls/FormCommonsenseDetection.Designer.cs +++ b/AIProofread/Controls/FormCommonsenseDetection.Designer.cs @@ -41,7 +41,7 @@ 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.Size = new System.Drawing.Size(800, 600); this.MainWebView.TabIndex = 0; this.MainWebView.ZoomFactor = 1D; // @@ -49,9 +49,10 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(700, 600); + this.ClientSize = new System.Drawing.Size(800, 600); this.Controls.Add(this.MainWebView); this.Name = "FormCommonsenseDetection"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "FormCommonsenseDetection"; this.Load += new System.EventHandler(this.FormCommonsenseDetection_Load); ((System.ComponentModel.ISupportInitialize)(this.MainWebView)).EndInit(); diff --git a/AIProofread/Model/CommonsenseDetectionItem.cs b/AIProofread/Model/CommonsenseDetectionItem.cs index 381ba66..47d9efa 100644 --- a/AIProofread/Model/CommonsenseDetectionItem.cs +++ b/AIProofread/Model/CommonsenseDetectionItem.cs @@ -21,6 +21,10 @@ namespace AIProofread.Model public CommonsenseDetectionType Type { get; set; } [JsonProperty("summary")] public string Summary { get; set; } + + [JsonProperty("location")] + public string Location { get; set; } + [JsonProperty("result_content")] public string ResultContent { get; set; } } diff --git a/AIProofread/Model/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs index 7d395b3..8f2ee3d 100644 --- a/AIProofread/Model/DocumentInfo.cs +++ b/AIProofread/Model/DocumentInfo.cs @@ -356,6 +356,12 @@ namespace AIProofread.Model return GetRangeText(CurrentDocument.Range(start, end)); } + public Range Range(int start, int end) + { + if (start >= end) return null; + return CurrentDocument.Range(start, end); + } + /// /// 保存校对缓存结果 /// diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs index 86e79b8..0fc9ee5 100644 --- a/AIProofread/Ribbon1.cs +++ b/AIProofread/Ribbon1.cs @@ -575,7 +575,7 @@ namespace AIProofread // 获取当前选中的选区的首尾段落起始与结束位置 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(); + var data = JSONObject.Create().Put("start", start).Put("end", end).ToString(); Globals.ThisAddIn.SendMessageToWeb("show-check-range", data); } @@ -592,8 +592,13 @@ namespace AIProofread public void ParseSelectionChange(Selection s) { var r = s.Range; - btnDetectionParagraph.Enabled = r.Start != r.End; this.currectSelectRange = r; + if (CommonSenseDetection.instance.isChecking) + { + return; + } + btnDetectionParagraph.Enabled = r.Start != r.End; + btnDetectionAll.Enabled = r.Start == r.End; } public void SetDetectionBtnStatus(bool status) diff --git a/AIProofread/core/CommonSenseDetection.cs b/AIProofread/core/CommonSenseDetection.cs index 72a02f3..4dffb6a 100644 --- a/AIProofread/core/CommonSenseDetection.cs +++ b/AIProofread/core/CommonSenseDetection.cs @@ -21,7 +21,7 @@ namespace AIProofread.core private List history = new List(); // 生成单例 - private static readonly CommonSenseDetection instance = new CommonSenseDetection(); + public static readonly CommonSenseDetection instance = new CommonSenseDetection(); private FormCommonsenseDetection formCommonsenseDetection; private CommonSenseDetection() { } @@ -48,9 +48,9 @@ namespace AIProofread.core public string GetCheckStatus() { return JSONObject.Create() - .AddField("isChecking", isChecking) - .AddField("checkingKey", checkingKey) - .AddField("checkingSummary", checkingSummary) + .Put("isChecking", isChecking) + .Put("checkingKey", checkingKey) + .Put("checkingSummary", checkingSummary) .ToString(); } diff --git a/AIProofread/core/JSONObject.cs b/AIProofread/core/JSONObject.cs index 7fedb05..d25dede 100644 --- a/AIProofread/core/JSONObject.cs +++ b/AIProofread/core/JSONObject.cs @@ -21,7 +21,7 @@ namespace AIProofread.core return obj; } - public JSONObject AddField(string key, object value) + public JSONObject Put(string key, object value) { m_Dict.Add(key, value); return this;