diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index e05b1bd..a12a94e 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 f3aa980..48956f4 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -8,18 +8,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; -using System.Linq; -using System.Reflection; using System.Runtime.InteropServices; -using System.Runtime.InteropServices.ComTypes; -using System.Runtime.Remoting.Contexts; -using System.Text; using System.Text.RegularExpressions; -using System.Windows.Forms; -using System.Xml.Linq; using UtilLib; -using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header; -using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; using Document = Microsoft.Office.Interop.Word.Document; namespace AIProofread @@ -84,6 +75,20 @@ namespace AIProofread } } + public void SetCurrentDocumentId(int id) + { + var doc = Globals.ThisAddIn.Application.ActiveDocument; + Globals.ThisAddIn.documentIdDics[doc] = id; + } + + + public int GetCurrentDocumentId() + { + var doc = Globals.ThisAddIn.Application.ActiveDocument; + var dics = Globals.ThisAddIn.documentIdDics; + return dics.ContainsKey(doc) ? dics[doc] : 0; + } + // 打开网页 public void OpenUrlWithOsBrowser(string url) { @@ -149,8 +154,11 @@ namespace AIProofread { Dictionary data = new Dictionary(); var name = Globals.ThisAddIn.Application.ActiveDocument.Name; + var doc = Globals.ThisAddIn.Application.ActiveDocument; data.Add("name", name); - data.Add("fullName", Globals.ThisAddIn.Application.ActiveDocument.FullName); + data.Add("fullName", doc.FullName); + data.Add("wordsCount", doc.Words.Count); + data.Add("charactersCount", doc.Characters.Count); data.Add("content", Tools.GetAllText()); return Tools.GetJSONString(data); } @@ -243,7 +251,8 @@ namespace AIProofread { // 清空marks marks.Clear(); - }catch (Exception) { } + } + catch (Exception) { } } public void removeBookmark(string markId) @@ -376,6 +385,7 @@ namespace AIProofread public void SelectMarkById(int proofreadId) { + // 设置当前文档数据 Globals.ThisAddIn.ActiveCurrentDocumentMarks(); @@ -435,50 +445,56 @@ namespace AIProofread public void InitContent(string content) { - List list = JsonConvert.DeserializeObject>(content); - // 先清除所有数据 - clearAllProofreadMark(); - - //var app = Globals.ThisAddIn.Application; - //var cur = app.Selection; - // - foreach (var correct in list) + try { - //cur.TypeText(correct.Insert); - //var rng = cur.Range; - if (correct.Diffs != null && correct.Diffs.Count > 0) + List list = JsonConvert.DeserializeObject>(content); + // 先清除所有数据 + clearAllProofreadMark(); + + //var app = Globals.ThisAddIn.Application; + //var cur = app.Selection; + // + foreach (var correct in list) { - //var diffs = correct.Diffs.OrderBy(it => - //{ - // if (it.tag != "i") return it.start; - // return it.start + correct.Insert_len; - //}).ToList(); - int index = 0; - foreach (var item in correct.Diffs) + //cur.TypeText(correct.Insert); + //var rng = cur.Range; + if (correct.Diffs != null && correct.Diffs.Count > 0) { - var mark = AddBookmark(item, index, correct.Sentence_offset, correct.Insert_len, correct.Paragraph_offset); - if (item.tag != "i") index++; - if (mark != null) + //var diffs = correct.Diffs.OrderBy(it => + //{ + // if (it.tag != "i") return it.start; + // return it.start + correct.Insert_len; + //}).ToList(); + int index = 0; + foreach (var item in correct.Diffs) { - marks.Add(item.id, new ProofreadItem(item, mark)); + var mark = AddBookmark(item, index, correct.Sentence_offset, correct.Insert_len, correct.Paragraph_offset); + if (item.tag != "i") index++; + if (mark != null) + { + marks.Add(item.id, new ProofreadItem(item, mark)); + } } } } - } - foreach (var item in marks) - { - if (item.Value.mark != null) + foreach (var item in marks) { - if (item.Value.content.tag == "i") + if (item.Value.mark != null) { - item.Value.mark.Text = ToolUtil.GetBlankText(item.Value.content.text.Length); - } - if (item.Value.content.color != null) - { - // 给选区添加背景颜色 - item.Value.mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.Value.content.color)); + if (item.Value.content.tag == "i") + { + item.Value.mark.Text = ToolUtil.GetBlankText(item.Value.content.text.Length); + } + if (item.Value.content.color != null) + { + // 给选区添加背景颜色 + item.Value.mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.Value.content.color)); + } } } + }catch (Exception ex) + { + Logger.Log("Initial Content error:" + ex.Message + "\n" + ex.StackTrace + "\n\n"); } } @@ -520,7 +536,8 @@ namespace AIProofread try { controls.Remove(markName); - }catch (Exception) { } + } + catch (Exception) { } } Range findRange = null; if (paragraphIndex > document.Paragraphs.Count) return null; @@ -602,7 +619,7 @@ namespace AIProofread return bookmark; } - private void FindRange(ref Range range,ref object whatToFind) + private void FindRange(ref Range range, ref object whatToFind) { object matchCase = false; // 是否区分大小写 object matchWholeWord = false; // 是否匹配整个单词 diff --git a/AIProofread/Config.cs b/AIProofread/Config.cs index 15f78b0..de34f5d 100644 --- a/AIProofread/Config.cs +++ b/AIProofread/Config.cs @@ -6,7 +6,7 @@ namespace AIProofread public class Config { public static readonly string APP_NAME = "AI校对王"; - public static readonly string APP_VERSION = "1.0.4"; + public static readonly string APP_VERSION = "1.0.7"; public static bool IS_WPS = false; public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.json"; diff --git a/AIProofread/Controls/FormContact.Designer.cs b/AIProofread/Controls/FormContact.Designer.cs index e3585ed..dce3fc0 100644 --- a/AIProofread/Controls/FormContact.Designer.cs +++ b/AIProofread/Controls/FormContact.Designer.cs @@ -51,8 +51,9 @@ this.ClientSize = new System.Drawing.Size(400, 310); this.Controls.Add(this.WebViewContact); this.Name = "FormContact"; + this.ShowIcon = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FormContact"; + this.Text = "联系客服"; this.Load += new System.EventHandler(this.FormContact_Load); ((System.ComponentModel.ISupportInitialize)(this.WebViewContact)).EndInit(); this.ResumeLayout(false); diff --git a/AIProofread/Controls/FormLogin.Designer.cs b/AIProofread/Controls/FormLogin.Designer.cs index a61cbb9..06f9273 100644 --- a/AIProofread/Controls/FormLogin.Designer.cs +++ b/AIProofread/Controls/FormLogin.Designer.cs @@ -53,6 +53,7 @@ this.Controls.Add(this.web); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "FormLogin"; + this.ShowIcon = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "登录"; this.Load += new System.EventHandler(this.FormLogin_Load); diff --git a/AIProofread/Controls/FormSetting.Designer.cs b/AIProofread/Controls/FormSetting.Designer.cs index 4b1a9d3..5982bf9 100644 --- a/AIProofread/Controls/FormSetting.Designer.cs +++ b/AIProofread/Controls/FormSetting.Designer.cs @@ -55,7 +55,7 @@ this.MinimizeBox = false; this.Name = "FormSetting"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "FormSetting"; + this.Text = "插件设置"; this.Load += new System.EventHandler(this.FormSetting_Load); ((System.ComponentModel.ISupportInitialize)(this.WebViewSetting)).EndInit(); this.ResumeLayout(false); diff --git a/AIProofread/Controls/ProofreadMainControl.cs b/AIProofread/Controls/ProofreadMainControl.cs index 59bf542..3b5ad92 100644 --- a/AIProofread/Controls/ProofreadMainControl.cs +++ b/AIProofread/Controls/ProofreadMainControl.cs @@ -9,12 +9,17 @@ namespace AIProofread.Controls { private Document doc; private int minWidth; + + public ProofreadMainControl(Document doc,int minWidth) { InitializeComponent(); this.doc = doc; this.minWidth = minWidth; Bridge.InitWebEnvAsync("main", web); + + //this.minWidth = 420 * LabelWidth() / 42; + //this.MinimumSize = new System.Drawing.Size(this.minWidth, 0); } diff --git a/AIProofread/ProofreadItem.cs b/AIProofread/ProofreadItem.cs index 5ca837c..f15bdb0 100644 --- a/AIProofread/ProofreadItem.cs +++ b/AIProofread/ProofreadItem.cs @@ -13,6 +13,8 @@ namespace UtilLib public Bookmark mark; public CorrectedContent content; private float originSize; + private WdColor originColor; + private WdColor originBackgroundColor; public string Name { get; set; } public ProofreadItem(CorrectedContent content) { @@ -34,6 +36,8 @@ namespace UtilLib this.mark = bookmark; // 记录目前字体 originSize = bookmark.Range.Font.Size; + originBackgroundColor = bookmark.Shading.BackgroundPatternColor; + originColor = bookmark.Shading.ForegroundPatternColor; mark.Selected += OnMarkSelected; } SetMarkName(); @@ -49,11 +53,8 @@ namespace UtilLib { // 记录目前字体 originSize = mark.Range.Font.Size; - // 设置下划线 - mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick; // 设置名称 mark.Name = Config.BuildBookmarkName(content.id); - //mark.SelectionChange += OnMarkSelectionChange; } } @@ -81,6 +82,7 @@ namespace UtilLib { if (mark == null) return; mark.Range.Font.Size = originSize; // 还原 + mark.Shading.ForegroundPatternColor = originColor; } private void SetMarkStyle() @@ -98,7 +100,9 @@ namespace UtilLib { mark.Range.Font.Size = originSize; // 还原 //mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone; - mark.Range.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic; + //originBackgroundColor = bookmark.Shading.BackgroundPatternColor; + mark.Shading.ForegroundPatternColor = originColor; + mark.Range.Shading.BackgroundPatternColor = originColor;// Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic; } catch (Exception) { } } diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index 9f9906c..1dae595 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -45,6 +45,7 @@ namespace AIProofread public Dictionary taskPanels = new Dictionary(); public Dictionary panelsVisibleStatus = new Dictionary(); + public Dictionary documentIdDics = new Dictionary(); public CustomTaskPane currentDocumentTaskPane; private static readonly Dictionary> allMarks = new Dictionary>(); @@ -181,21 +182,16 @@ namespace AIProofread this.currentDocumentTaskPane = panel; taskPanels.Add(doc, panel); panel.Visible = false; - panel.VisibleChanged += Panel_VisibleChanged; + // 设置宽度 control.Width = MinWidth; panel.Width = MinWidth; // 监听尺寸变化 防止最小尺寸小于设置值 control.SizeChanged += Control_SizeChanged; + //new CustomTaskPaneHandler(control, MinWidth); return panel; } - private void Panel_VisibleChanged(object sender, EventArgs e) - { - if (currentDocumentTaskPane == sender) - { - } - } /// /// word创建面板 @@ -205,12 +201,20 @@ namespace AIProofread return ShowPanel(doc, !IsWPS); } + + /// + /// 添加变量控制重复调用 + /// + private bool isResizing = false; private void Control_SizeChanged(object sender, EventArgs e) { - if (currentDocumentTaskPane != null && currentDocumentTaskPane.Width < MinWidth) + if (isResizing) return; + if (currentDocumentTaskPane != null && currentDocumentTaskPane.Visible && currentDocumentTaskPane.Width < MinWidth) { + isResizing = true; SendKeys.Send("{ESC}"); currentDocumentTaskPane.Width = MinWidth; + isResizing = false; } } @@ -251,13 +255,14 @@ namespace AIProofread if (config.AppRunInDebug) { Config.RUN_IN_DEBUG = config.AppRunInDebug; - if(this.ribbon != null) + if (this.ribbon != null) { this.ribbon.ShowDebug(); } } } - }catch (Exception) { } + } + catch (Exception) { } } private void ThisAddIn_Startup(object sender, System.EventArgs e) diff --git a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache index 94f9107..b10d71f 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.CopyComplete b/AIProofread/obj/Debug/AIProofread.csproj.CopyComplete deleted file mode 100644 index e69de29..0000000 diff --git a/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache b/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache index fc4923b..b2e24ce 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache +++ b/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -c42860264b8acb7028e263a703e52b2dc93d902c0171fb7e18b49cb7e7de737a +45c1006d89b86a8263132b8f944b694a4253831b72578a761854fd2065ca7135 diff --git a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt index e2278c7..44c3fb0 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt +++ b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt @@ -49,6 +49,6 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread. C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Ribbon1.resources C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.GenerateResource.cache C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.CoreCompileInputs.cache -C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.CopyComplete 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 diff --git a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache index a9b3970..f66dc9d 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 d4a85fc..47b7595 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 dd80fb8..ddb861d 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 dbd6ae7..eaa0037 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 90f79c7..df29434 100644 Binary files a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ