diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index 9027df1..eb585cf 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -747,6 +747,11 @@ namespace AIProofread Globals.ThisAddIn.ActiveDocument.FocusToPanel(); } + public string GetProofreadOriginData() + { + return Tools.GetJSONString(Globals.ThisAddIn.ActiveDocument.GetProofreadOriginData()); + } + public string SaveCache(int documentId, string cache, bool silent) { var document = Globals.ThisAddIn.GetDocumentById(documentId); @@ -833,12 +838,13 @@ namespace AIProofread return BridgeResult.Success(result == DialogResult.Yes ? "yes" : "no"); } - public string InitProofreadCacheList(string content) + public string InitProofreadCacheList(string content,string originData) { try { List list = JsonConvert.DeserializeObject>(content); - Globals.ThisAddIn.InitProofreadCacheList(list); + Dictionary dics = string.IsNullOrEmpty(originData) ? null : JsonConvert.DeserializeObject>(originData); + Globals.ThisAddIn.InitProofreadCacheList(list, dics); return BridgeResult.Success(); } catch (Exception ex) diff --git a/AIProofread/Config.cs b/AIProofread/Config.cs index 35f7eea..4b4cbf4 100644 --- a/AIProofread/Config.cs +++ b/AIProofread/Config.cs @@ -20,7 +20,7 @@ namespace AIProofread /// /// 文本背景色 /// - public static readonly string TextBackgroundColor = "#D6AA69"; + public static readonly string TextBackgroundColor = "#E9DABB"; // e9dabb D6AA69 public static string DeviceId = ""; #if DEBUG /// diff --git a/AIProofread/Controls/FormContact.cs b/AIProofread/Controls/FormContact.cs index cf300e0..1314f7b 100644 --- a/AIProofread/Controls/FormContact.cs +++ b/AIProofread/Controls/FormContact.cs @@ -4,12 +4,15 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace AIProofread.Controls { + [ClassInterface(ClassInterfaceType.AutoDual)] + [ComVisible(true)] public partial class FormContact : BaseWinForm { public FormContact() diff --git a/AIProofread/Model/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs index 0f314aa..663e1c6 100644 --- a/AIProofread/Model/DocumentInfo.cs +++ b/AIProofread/Model/DocumentInfo.cs @@ -745,7 +745,7 @@ namespace AIProofread.Model } - public void InitProofreadCache(List list) + public void InitProofreadCache(List list,Dictionary itemInfoDic) { marks.Clear(); @@ -757,6 +757,19 @@ namespace AIProofread.Model if (mark != null) { var pi = new ProofreadItem(item, correct.Insert, mark, Id); + // 是否存在样式信息 + if (itemInfoDic!= null && itemInfoDic.ContainsKey(item.Id)) + { + // 获取样式信息并还原 + var info = itemInfoDic[item.Id]; + try + { + pi.originColor = info.Color; + pi.originBackgroundColor = info.Background; + pi.originSize = info.Size; + } + catch (Exception ex) { } + } marks.Add(item.Id, pi); } }); @@ -971,5 +984,25 @@ namespace AIProofread.Model } })); } + + public Dictionary GetProofreadOriginData() + { + Dictionary dic = new Dictionary(); + // 变量文档所有marks 记录mark对应range的背景、大小、颜色 + foreach (var item in marks) + { + if (item.Value.mark != null) + { + // 添加到数据 + dic.Add(item.Key, new ProofreadRangeInfo() + { + Background = item.Value.originBackgroundColor, + Color = item.Value.originColor, + Size = item.Value.originSize + }); + } + } + return dic; + } } } diff --git a/AIProofread/Model/ProofreadRangeInfo.cs b/AIProofread/Model/ProofreadRangeInfo.cs new file mode 100644 index 0000000..6d23ef1 --- /dev/null +++ b/AIProofread/Model/ProofreadRangeInfo.cs @@ -0,0 +1,11 @@ +using Microsoft.Office.Interop.Word; + +namespace AIProofread.Model +{ + public class ProofreadRangeInfo + { + public float Size { get; set; } + public WdColor Background { get; set; } + public WdColor Color { get; set; } + } +} diff --git a/AIProofread/ProofreadItem.cs b/AIProofread/ProofreadItem.cs index 53b5538..2d8f52e 100644 --- a/AIProofread/ProofreadItem.cs +++ b/AIProofread/ProofreadItem.cs @@ -14,9 +14,9 @@ namespace UtilLib public Bookmark mark; public string OriginSentence { get; set; } public CorrectItem content; - private float originSize; - private WdColor originColor; - private WdColor originBackgroundColor; + public float originSize; + public WdColor originColor; + public WdColor originBackgroundColor; public string Name { get; set; } public int DocumentId { get; set; } @@ -145,7 +145,6 @@ namespace UtilLib Math.Min(range.End + 2, fullRange.End) ); var comments = checkRange.Comments; - Logger.Log("判断是否有批注"); // 判断当前书签选区内容是否有评论 if (comments != null && comments.Count > 0) { @@ -161,10 +160,6 @@ namespace UtilLib } } } - else - { - Logger.Log("没有批注"); - } } /// @@ -224,7 +219,6 @@ namespace UtilLib var paragraphEnd = mark.Paragraphs.Last.Range.End; var end = mark.End + 2 > paragraphEnd ? paragraphEnd : mark.End + 2; var rng = Globals.ThisAddIn.ActiveDocument.Range(mark.End, end); - Logger.Log($"开始处理百分号问题:位置({mark.End},{end}) => 内容:{rng.Text}"); // 判断书签范围内是否有批注 diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs index 9871436..fdb449a 100644 --- a/AIProofread/Ribbon1.cs +++ b/AIProofread/Ribbon1.cs @@ -181,7 +181,11 @@ namespace AIProofread private void BtnGetContact_Click(object sender, RibbonControlEventArgs e) { - (new FormContact()).ShowDialog(); + var frm = new FormContact(); + Globals.ThisAddIn.ActiveDocument.RunInMainThread(() => + { + frm.ShowDialog(); + }); } private void BtnUpdate_Click(object sender, RibbonControlEventArgs e) diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index 211e1af..2416803 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -563,7 +563,7 @@ namespace AIProofread public DocumentInfo GetDocumentById(int id) { - return documentList.GetById(id); + return id <= 0 ? ActiveDocument : documentList.GetById(id); } @@ -609,9 +609,9 @@ namespace AIProofread this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } - public void InitProofreadCacheList(System.Collections.Generic.List list) + public void InitProofreadCacheList(List list, Dictionary dics) { - ActiveDocument?.InitProofreadCache(list); + ActiveDocument?.InitProofreadCache(list, dics); } #endregion diff --git a/util-lib/CorrectItem.cs b/util-lib/CorrectItem.cs index c361f84..80de143 100644 --- a/util-lib/CorrectItem.cs +++ b/util-lib/CorrectItem.cs @@ -31,7 +31,7 @@ namespace UtilLib /// /// 标识类型index(字符型数字) /// - public int Index { get; set; } + public string Index { get; set; } /// /// 标识类型(校对所属分类) ///