diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index a12a94e..20001d6 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 768b787..28355bf 100644 --- a/AIProofread/AIProofread.csproj +++ b/AIProofread/AIProofread.csproj @@ -204,6 +204,12 @@ FormContact.cs + + Form + + + FormLoading.cs + Form @@ -241,6 +247,9 @@ FormContact.cs + + FormLoading.cs + FormLogin.cs diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index 48956f4..a4b96ce 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; +using System.IO; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using UtilLib; @@ -163,6 +164,19 @@ namespace AIProofread return Tools.GetJSONString(data); } + /// + /// 读取文档原始文件并转换成base64 + /// + /// + public string getDocumentFileData() + { + var doc = Globals.ThisAddIn.Application.ActiveDocument.FullName; + FileStream fs = new FileStream(doc, FileMode.Open, FileAccess.Read, FileShare.Read); + byte[] bytes = new byte[fs.Length]; + fs.Read(bytes, 0, bytes.Length); + return Convert.ToBase64String(bytes); + } + public void ShowUpgrade(string data) { var upgradeData = JsonConvert.DeserializeObject(data); @@ -468,12 +482,18 @@ namespace AIProofread int index = 0; foreach (var item in correct.Diffs) { - var mark = AddBookmark(item, index, correct.Sentence_offset, correct.Insert_len, correct.Paragraph_offset); + var mark = AddBookmark(item, index, correct.Sentence_offset, correct.Insert_len, correct.Paragraph_num); if (item.tag != "i") index++; + var msg = new Dictionary{ + {"message",mark == null ? "没有找到标记对象":"标记对象" + mark.Name }, + { "origin",item } + }; if (mark != null) { marks.Add(item.id, new ProofreadItem(item, mark)); } + + Logger.LogToWeb(JsonConvert.SerializeObject(msg)); } } } @@ -492,7 +512,8 @@ namespace AIProofread } } } - }catch (Exception ex) + } + catch (Exception ex) { Logger.Log("Initial Content error:" + ex.Message + "\n" + ex.StackTrace + "\n\n"); } diff --git a/AIProofread/Controls/FormLoading.Designer.cs b/AIProofread/Controls/FormLoading.Designer.cs new file mode 100644 index 0000000..531da55 --- /dev/null +++ b/AIProofread/Controls/FormLoading.Designer.cs @@ -0,0 +1,88 @@ +namespace AIProofread.Controls +{ + partial class FormLoading + { + /// + /// 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.panel1 = new System.Windows.Forms.Panel(); + this.lblInfo = new System.Windows.Forms.Label(); + this.lblLoading = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.Controls.Add(this.lblInfo); + this.panel1.Controls.Add(this.lblLoading); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(390, 179); + this.panel1.TabIndex = 0; + // + // lblInfo + // + this.lblInfo.AutoEllipsis = true; + this.lblInfo.Location = new System.Drawing.Point(14, 88); + this.lblInfo.Name = "lblInfo"; + this.lblInfo.Size = new System.Drawing.Size(364, 23); + this.lblInfo.TabIndex = 1; + this.lblInfo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // lblLoading + // + this.lblLoading.Location = new System.Drawing.Point(12, 49); + this.lblLoading.Name = "lblLoading"; + this.lblLoading.Size = new System.Drawing.Size(366, 23); + this.lblLoading.TabIndex = 0; + this.lblLoading.Text = "Loading..."; + this.lblLoading.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // FormLoading + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(390, 179); + this.Controls.Add(this.panel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FormLoading"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Loading"; + this.panel1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label lblLoading; + private System.Windows.Forms.Label lblInfo; + } +} \ No newline at end of file diff --git a/AIProofread/Controls/FormLoading.cs b/AIProofread/Controls/FormLoading.cs new file mode 100644 index 0000000..937ebb1 --- /dev/null +++ b/AIProofread/Controls/FormLoading.cs @@ -0,0 +1,19 @@ + +using System.Windows.Forms; + +namespace AIProofread.Controls +{ + public partial class FormLoading : Form + { + public FormLoading() + { + InitializeComponent(); + } + public void SetLoadingText(string text) + { + lblLoading.Text = text; + } + public void SetInfoText(string text) { lblInfo.Text = text; } + } + +} diff --git a/AIProofread/Controls/FormLoading.resx b/AIProofread/Controls/FormLoading.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AIProofread/Controls/FormLoading.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/Logger.cs b/AIProofread/Logger.cs index 83be22b..4c42667 100644 --- a/AIProofread/Logger.cs +++ b/AIProofread/Logger.cs @@ -35,5 +35,13 @@ namespace AIProofread { Log(tag + "\n" + e.StackTrace); } + + public static void LogToWeb(string msg) + { + if (Config.RUN_IN_DEBUG) + { + Globals.ThisAddIn.SendMessageToWeb("DEBUG-LOG", msg); + } + } } } diff --git a/AIProofread/Ribbon1.Designer.cs b/AIProofread/Ribbon1.Designer.cs index c10708a..dd98b21 100644 --- a/AIProofread/Ribbon1.Designer.cs +++ b/AIProofread/Ribbon1.Designer.cs @@ -52,6 +52,8 @@ namespace AIProofread this.btnShowPane = this.Factory.CreateRibbonButton(); this.btnHidePane = this.Factory.CreateRibbonButton(); this.btnTestLocation = this.Factory.CreateRibbonButton(); + this.btnSelectionPosition = this.Factory.CreateRibbonButton(); + this.button1 = this.Factory.CreateRibbonButton(); this.tabAIProofread.SuspendLayout(); this.group1.SuspendLayout(); this.grpDebug.SuspendLayout(); @@ -169,6 +171,8 @@ namespace AIProofread this.grpDebug.Items.Add(this.btnShowPane); this.grpDebug.Items.Add(this.btnHidePane); this.grpDebug.Items.Add(this.btnTestLocation); + this.grpDebug.Items.Add(this.btnSelectionPosition); + this.grpDebug.Items.Add(this.button1); this.grpDebug.Label = "开发调试"; this.grpDebug.Name = "grpDebug"; this.grpDebug.Visible = false; @@ -189,8 +193,22 @@ namespace AIProofread // this.btnTestLocation.Label = "文本位置"; this.btnTestLocation.Name = "btnTestLocation"; + this.btnTestLocation.Visible = false; this.btnTestLocation.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnTestLocation_Click); // + // btnSelectionPosition + // + this.btnSelectionPosition.Label = "选中位置"; + this.btnSelectionPosition.Name = "btnSelectionPosition"; + this.btnSelectionPosition.Visible = false; + this.btnSelectionPosition.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnSelectionPosition_Click); + // + // button1 + // + this.button1.Label = "button1"; + this.button1.Name = "button1"; + this.button1.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.button1_Click); + // // Ribbon1 // this.Name = "Ribbon1"; @@ -225,6 +243,8 @@ namespace AIProofread internal Microsoft.Office.Tools.Ribbon.RibbonButton btnShowPane; internal Microsoft.Office.Tools.Ribbon.RibbonButton btnHidePane; internal Microsoft.Office.Tools.Ribbon.RibbonButton btnTestLocation; + internal Microsoft.Office.Tools.Ribbon.RibbonButton btnSelectionPosition; + internal Microsoft.Office.Tools.Ribbon.RibbonButton button1; } partial class ThisRibbonCollection diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs index 27362b6..7bbf824 100644 --- a/AIProofread/Ribbon1.cs +++ b/AIProofread/Ribbon1.cs @@ -158,5 +158,73 @@ namespace AIProofread TestStr(3, "针"); TestStr(22, "疏"); } + + private void btnSelectionPosition_Click(object sender, RibbonControlEventArgs e) + { + var doc = Globals.ThisAddIn.Application.ActiveDocument; + var sel = Globals.ThisAddIn.Application.Selection; + if (sel != null && sel.Range != null) + { + Paragraphs paragraphs = doc.Paragraphs; + Range range = sel.Range; + Paragraph paragraph = range.Paragraphs.First; + int paragraphIndex = -1; + for (int i = 1; i <= paragraphs.Count; i++) + { + + var para = paragraphs[i]; + if (para.Range.Start >= paragraph.Range.Start && para.Range.End <= paragraph.Range.End) + { + paragraphIndex = i; + break; + } + } + int startInParagraph = range.Start - paragraph.Range.Start; + int endInParagraph = range.End - paragraph.Range.Start; + + System.Windows.Forms.MessageBox.Show($"Selected text in {paragraphIndex} starts at position {startInParagraph} and ends at position {endInParagraph} in the paragraph."); + } + else + { + System.Windows.Forms.MessageBox.Show("No text selected."); + } + } + + //public bool IsParagraphInTableOfContents(Document doc, Paragraph para) + //{ + // // 检查文档和段落是否为null + // if (doc == null || para == null) + // return false; + + // // 获取文档中的目录范围 + // Range tocRange = null; + // foreach (Range range in .) + // { + // if (range.InlineShapes.Count > 0) // 假设目录包含字段代码 + // { + // tocRange = range; + // break; + // } + // } + + // // 如果没有找到目录范围,则返回false + // if (tocRange == null) + // return false; + + // // 获取段落范围 + // Word.Range paraRange = para.Range; + + // // 检查段落是否在目录范围内 + // return paraRange.StoryLength > 0 && tocRange.StoryLength > 0 && + // paraRange.Start >= tocRange.Start && paraRange.End <= tocRange.End; + //} + + private void button1_Click(object sender, RibbonControlEventArgs e) + { + var doc = Globals.ThisAddIn.Application.ActiveDocument; + var styles = doc.Styles["TOC Heading"]; + + Console.WriteLine(styles.Font.Name); + } } } diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index 1dae595..ead53a9 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -11,6 +11,7 @@ using Microsoft.Office.Interop.Word; using System.Linq; using System.Windows.Forms; using System.IO; +using System.Diagnostics; namespace AIProofread { @@ -292,6 +293,7 @@ namespace AIProofread Application.WindowActivate += Application_WindowActivate; Application.WindowDeactivate += Application_WindowDeactivate; (Application as ApplicationEvents4_Event).NewDocument += Application_NewDocument; + //Application.DocumentChange += // 选区发生变化事件 //this.Application.WindowSelectionChange += Application_WindowSelectionChange; diff --git a/AIProofread/core/DocumentText.cs b/AIProofread/core/DocumentText.cs index a431d64..350064c 100644 --- a/AIProofread/core/DocumentText.cs +++ b/AIProofread/core/DocumentText.cs @@ -6,16 +6,24 @@ namespace AIProofread { public string Hash { get; set; } public string Text { get; set; } + public int ParagraphNumber { get; set; } public DocumentText() { } - public DocumentText(string text) + public DocumentText(string text, int paragraphNumber) { this.Text = text; + this.ParagraphNumber = paragraphNumber; } public DocumentText(byte[] hash, string text) { this.Hash = BitConverter.ToString(hash).ToLower().Replace("-", ""); this.Text = text; } + public DocumentText(byte[] hash, string text, int paragraphNumber) + { + this.Hash = BitConverter.ToString(hash).ToLower().Replace("-", ""); + this.Text = text; + this.ParagraphNumber = paragraphNumber; + } } } diff --git a/AIProofread/core/Tools.cs b/AIProofread/core/Tools.cs index 39b4249..be5f589 100644 --- a/AIProofread/core/Tools.cs +++ b/AIProofread/core/Tools.cs @@ -1,10 +1,13 @@ -using Newtonsoft.Json; +using AIProofread.Controls; +using Microsoft.Office.Interop.Word; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Security.Policy; using System.Text; +using System.Windows.Forms; using static System.Net.Mime.MediaTypeNames; namespace AIProofread @@ -14,30 +17,57 @@ namespace AIProofread private static readonly string[] paragSplitor = new string[] { "\r", "\n", "\r\n" }; public static Dictionary GetAllText() { + var doc = Globals.ThisAddIn.Application.ActiveDocument; // 获取当前文档所有文本 - string allText = Globals.ThisAddIn.Application.ActiveDocument.Range().Text; + string allText = doc.Range().Text; List list = new List(); - - if (allText != null && allText.Trim().Length > 0) + // // 开始分割 + MD5 md5 = new MD5CryptoServiceProvider(); + + //if (allText != null && allText.Trim().Length > 0) + //{ + + // List lines = allText.Split(paragSplitor, StringSplitOptions.None).ToList();//StringUtil.CutTextToSentences(allText); + // foreach (string text in lines) + // { + // if(text.Trim().Length > 0) + // { + // byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text)); + // list.Add(new DocumentText(hash, text + "\n")); + // } + // else + // { + + // list.Add(new DocumentText(text + "\n")); + // } + // } + //} + + Paragraphs paragraphs = doc.Paragraphs; + int total = paragraphs.Count; + //FormLoading frm = new FormLoading(); + //frm.Show(); + for (int paragraphNumber = 1; paragraphNumber <= total; paragraphNumber++) { - // 开始分割 - MD5 md5 = new MD5CryptoServiceProvider(); - - List lines = allText.Split(paragSplitor, StringSplitOptions.None).ToList();//StringUtil.CutTextToSentences(allText); - foreach (string text in lines) + Paragraph p = paragraphs[paragraphNumber]; + Range r = p.Range; + if (r.ListFormat.ListType == WdListType.wdListPictureBullet + || r.Tables.Count > 0 + || p.Range.Text.Trim().Length == 0) { - if(text.Trim().Length > 0) - { - byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text)); - list.Add(new DocumentText(hash, text + "\n")); - } - else - { - - list.Add(new DocumentText(text + "\n")); - } + continue; } + string text = p.Range.Text; + //Logger.LogToWeb(string.Format("get paragraph {0}", paragraphNumber)); + //frm.SetLoadingText(text); + if (text.Trim().Length > 0) + { + //byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text)); + list.Add(new DocumentText(text,paragraphNumber)); + } + } + //frm.Close(); var map = new Dictionary { { "list", list }, diff --git a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache index b10d71f..7ce5048 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 b2e24ce..b737a76 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache +++ b/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -45c1006d89b86a8263132b8f944b694a4253831b72578a761854fd2065ca7135 +79ea390e4d68eda54ffacc73a1e70c811a130e7954fbba3a2df5692e3b3c6464 diff --git a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt index 44c3fb0..963d945 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt +++ b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt @@ -52,3 +52,4 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread. C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.pdb C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofr.8811D769.Up2Date +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormLoading.resources diff --git a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache index f66dc9d..6b6164f 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 47b7595..db29289 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 ddb861d..05b0cec 100644 Binary files a/AIProofread/obj/Debug/AIProofread.pdb and b/AIProofread/obj/Debug/AIProofread.pdb differ diff --git a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache index eaa0037..8f69875 100644 Binary files a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index df29434..eba936e 100644 Binary files a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/util-lib/DocumentCorrectItem.cs b/util-lib/DocumentCorrectItem.cs index 2587227..22b16ef 100644 --- a/util-lib/DocumentCorrectItem.cs +++ b/util-lib/DocumentCorrectItem.cs @@ -10,6 +10,7 @@ namespace UtilLib public int Insert_len { get; set; } public int Offset { get; set; } public int Paragraph_offset { get; set; } + public int Paragraph_num { get; set; } public int Sentence_offset { get; set; } public List Diffs { get; set; } }