diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index 13c10d2..b149799 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 8a75ce1..52fd79f 100644 --- a/AIProofread/AIProofread.csproj +++ b/AIProofread/AIProofread.csproj @@ -320,6 +320,12 @@ FormMain.cs + + Form + + + FormMask.cs + Form @@ -366,6 +372,7 @@ + FormContact.cs @@ -384,6 +391,9 @@ FormMain.cs + + FormMask.cs + FormMessage.cs diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index 42ac404..5193a96 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -674,9 +674,26 @@ namespace AIProofread } } + public bool DeleteCache() + { + try + { + if (File.Exists(Globals.ThisAddIn.ActiveDocument.ProofreadCachePath)) + { + File.Delete(Globals.ThisAddIn.ActiveDocument.ProofreadCachePath); + } + } + catch (Exception) + { + return false; + } + return true; + } + public string ShowConfirm(string message, string caption, string yesButtonText, string noButtonText) { var result = FormDialog.Show(message, caption, yesButtonText, noButtonText); + return BridgeResult.Success(result == DialogResult.Yes ? "yes" : "no"); } diff --git a/AIProofread/Controls/FormDialog.Designer.cs b/AIProofread/Controls/FormDialog.Designer.cs index 3138c20..6ea4066 100644 --- a/AIProofread/Controls/FormDialog.Designer.cs +++ b/AIProofread/Controls/FormDialog.Designer.cs @@ -96,6 +96,8 @@ this.ShowIcon = false; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Deactivate += new System.EventHandler(this.FormDialog_Deactivate); + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormDialog_FormClosed); this.ResumeLayout(false); } diff --git a/AIProofread/Controls/FormDialog.cs b/AIProofread/Controls/FormDialog.cs index ae5a092..af54b12 100644 --- a/AIProofread/Controls/FormDialog.cs +++ b/AIProofread/Controls/FormDialog.cs @@ -1,4 +1,6 @@ -using System; +using AIProofread.Util; +using System; +using System.Runtime.InteropServices; using System.Windows.Forms; namespace AIProofread.Controls @@ -9,7 +11,7 @@ namespace AIProofread.Controls { InitializeComponent(); } - + private static FormMask mask; private void SetMessage(string message) { @@ -24,10 +26,16 @@ namespace AIProofread.Controls public static DialogResult Show(string message, string caption, string yesButtonText, string noButtonText) { FormDialog formMessage = new FormDialog(); + mask = new FormMask(formMessage); + mask.ShowOverWord(); formMessage.SetMessage(message); formMessage.Text = caption; formMessage.SetButtonText(yesButtonText, noButtonText); - return formMessage.ShowDialog(); + formMessage.TopMost = true; + IntPtr wordHandle = new IntPtr(Globals.ThisAddIn.Application.ActiveWindow.Hwnd); // 获取Word窗口句柄 + User32Util.SetParent(formMessage.Handle,wordHandle); + formMessage.Show(); + return DialogResult.Yes; } public static DialogResult Show(string message) { @@ -37,6 +45,7 @@ namespace AIProofread.Controls private void BtnClose_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.No; + this.TopMost = false; this.Close(); } @@ -45,5 +54,17 @@ namespace AIProofread.Controls this.DialogResult = DialogResult.Yes; this.Close(); } + + private void FormDialog_Deactivate(object sender, EventArgs e) + { + // SetForegroundWindow(this.Handle); + // this.Activate(); + } + + private void FormDialog_FormClosed(object sender, FormClosedEventArgs e) + { + mask.Close(); + mask = null; + } } } diff --git a/AIProofread/Controls/FormMask.Designer.cs b/AIProofread/Controls/FormMask.Designer.cs new file mode 100644 index 0000000..6a078ef --- /dev/null +++ b/AIProofread/Controls/FormMask.Designer.cs @@ -0,0 +1,48 @@ +namespace AIProofread.Controls +{ + partial class FormMask + { + /// + /// 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.SuspendLayout(); + // + // FormMask + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.White; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Name = "FormMask"; + this.Opacity = 0.1D; + this.Text = "FormMask"; + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/AIProofread/Controls/FormMask.cs b/AIProofread/Controls/FormMask.cs new file mode 100644 index 0000000..88e4164 --- /dev/null +++ b/AIProofread/Controls/FormMask.cs @@ -0,0 +1,46 @@ +using AIProofread.Util; +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace AIProofread.Controls +{ + public partial class FormMask : Form + { + public Form myParent; + public FormMask(Form myParent) + { + //InitializeComponent(); + this.myParent = myParent; + this.FormBorderStyle = FormBorderStyle.None; + this.BackColor = Color.Black; + this.Opacity = 0.5; // 设置遮罩透明度 + this.ShowInTaskbar = false; + + this.StartPosition = FormStartPosition.Manual; + this.WindowState = FormWindowState.Maximized; + this.Click += FormMask_Click; + //this.TopMost = true; + } + + private void FormMask_Click(object sender, EventArgs e) + { + User32Util.SetForegroundWindow(myParent.Handle); + myParent.Focus(); + } + + public void ShowOverWord() + { + IntPtr wordHandle = new IntPtr(Globals.ThisAddIn.Application.ActiveWindow.Hwnd); // 获取Word窗口句柄 + // User32Util.SetParent(this.Handle, wordHandle); + var wordRect = new User32Util.RECT(); + User32Util.GetWindowRect(wordHandle, ref wordRect); + + // 设置遮罩窗体的位置和大小 + this.Bounds = new Rectangle(wordRect.Left, wordRect.Top, + wordRect.Right - wordRect.Left, + wordRect.Bottom - wordRect.Top); + this.Show(); + } + } +} diff --git a/AIProofread/Controls/FormMask.resx b/AIProofread/Controls/FormMask.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AIProofread/Controls/FormMask.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/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs index 92598d8..7355c0a 100644 --- a/AIProofread/Model/DocumentInfo.cs +++ b/AIProofread/Model/DocumentInfo.cs @@ -465,7 +465,7 @@ namespace AIProofread.Model { if (proofreadId == selectProofreadId) return; // 取消上一个标签移除 - if (proofreadId != -1 && marks.ContainsKey(selectProofreadId)) + if (selectProofreadId != -1 && marks.ContainsKey(selectProofreadId)) { var m = marks[selectProofreadId]; if (m != null && CurrentDocument.Bookmarks.Exists(m.Name)) @@ -486,7 +486,7 @@ namespace AIProofread.Model // 已经不存在该标签了 if (mark != null && !CurrentDocument.Bookmarks.Exists(mark.Name)) { - marks.Remove(selectProofreadId); + marks.Remove(proofreadId); return; } //object lineNum = (int)mark.Range.Information[WdInformation.wdFirstCharacterLineNumber] - 1; @@ -622,8 +622,11 @@ namespace AIProofread.Model correct.CorrectItems.ForEach(item => { var mark = DocumentUtil.FindBookMarkByCorrect(item); - var pi = new ProofreadItem(item,correct.Insert, mark, Id); - marks.Add(item.Id, pi); + if (mark != null) + { + var pi = new ProofreadItem(item, correct.Insert, mark, Id); + marks.Add(item.Id, pi); + } }); //marks.Add(item.Id, new ProofreadItem(item.CorrectItems[0], null, Id)); } diff --git a/AIProofread/ProofreadItem.cs b/AIProofread/ProofreadItem.cs index 481f44a..abbf4a5 100644 --- a/AIProofread/ProofreadItem.cs +++ b/AIProofread/ProofreadItem.cs @@ -83,7 +83,7 @@ namespace UtilLib { if (mark == null) return; mark.Range.Font.Size = originSize + 2; // 将选中标签文本放大字体 - mark.Select(); + //mark.Select(); } public void UnSelect() diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index 6812fd6..df63b8d 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -353,10 +353,6 @@ namespace AIProofread this.documentList.HideAllPane(); } - [DllImport("user32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool SetForegroundWindow(IntPtr hWnd); - /// /// 显示登录窗口 /// diff --git a/AIProofread/Util/User32Util.cs b/AIProofread/Util/User32Util.cs new file mode 100644 index 0000000..44309d3 --- /dev/null +++ b/AIProofread/Util/User32Util.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace AIProofread.Util +{ + public class User32Util + { + [DllImport("user32.dll")] + public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect); + + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + public int Left; + public int Top; + public int Right; + public int Bottom; + } + + // 引入 User32.dll 中的 SetParent 方法 + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetForegroundWindow(IntPtr hWnd); + } +} diff --git a/AIProofread/core/DocumentUtil.cs b/AIProofread/core/DocumentUtil.cs index 9299125..cbf9a77 100644 --- a/AIProofread/core/DocumentUtil.cs +++ b/AIProofread/core/DocumentUtil.cs @@ -297,19 +297,28 @@ namespace AIProofread public static Bookmark FindBookMarkByCorrect(CorrectItem correct) { - var document = Globals.ThisAddIn.ActiveDocument.CurrentDocument; - var marks = document.Bookmarks; - var markName = Config.BuildBookmarkName(correct.Id); + try + { + var document = Globals.ThisAddIn.ActiveDocument.CurrentDocument; + var marks = document.Bookmarks; + var markName = Config.BuildBookmarkName(correct.Id); - if (!document.Bookmarks.Exists(markName)) return null; + if (!document.Bookmarks.Exists(markName)) return null; - ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls; - controls.Remove(markName); - //return controls[markName] as Bookmark; - var bookmark = marks[markName]; - var start = bookmark.Range.Start; - var end = bookmark.Range.End; - return controls.AddBookmark(document.Range(start, end), markName); + ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls; + // 删除原有书签 + controls.Remove(markName); + //return controls[markName] as Bookmark; + var bookmark = marks[markName]; + var start = bookmark.Range.Start; + var end = bookmark.Range.End; + return controls.AddBookmark(document.Range(start, end), markName); + } + catch (Exception ex) + { + Logger.Log(ex); + } + return null; //if(bookmark == null) //{ diff --git a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache index ded8f79..ca38fe7 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 76f943d..13f35a6 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache +++ b/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -e41eeef295075b0004214c8cd1d281efa264dd90d94486af5e0e1e63e30e1f99 +73697d8cfbb569cc987afc71aa3dff1fa36374eacaf0a7c7b55871ef5023996c diff --git a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt index 6960bd4..8098782 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt +++ b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt @@ -210,3 +210,4 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread. C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormMessage.resources C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormDialog.resources C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormWebView.resources +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormMask.resources diff --git a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache index cb8a110..3c51526 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 c518509..10c00b1 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 a662256..3447d34 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 532afea..61b88b2 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 6024533..ef47819 100644 Binary files a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ