缓存加载时初始化数据无法定位操作状态

This commit is contained in:
LittleBoy 2024-11-09 20:14:19 +08:00
parent 7ec0f49aa5
commit e58390f7ef
21 changed files with 329 additions and 24 deletions

Binary file not shown.

View File

@ -320,6 +320,12 @@
<Compile Include="Controls\FormMain.Designer.cs"> <Compile Include="Controls\FormMain.Designer.cs">
<DependentUpon>FormMain.cs</DependentUpon> <DependentUpon>FormMain.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\FormMask.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Controls\FormMask.Designer.cs">
<DependentUpon>FormMask.cs</DependentUpon>
</Compile>
<Compile Include="Controls\FormMessage.cs"> <Compile Include="Controls\FormMessage.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -366,6 +372,7 @@
<Compile Include="Transform.cs" /> <Compile Include="Transform.cs" />
<Compile Include="Util\HostHelper.cs" /> <Compile Include="Util\HostHelper.cs" />
<Compile Include="Util\HttpUtil.cs" /> <Compile Include="Util\HttpUtil.cs" />
<Compile Include="Util\User32Util.cs" />
<EmbeddedResource Include="Controls\FormContact.resx"> <EmbeddedResource Include="Controls\FormContact.resx">
<DependentUpon>FormContact.cs</DependentUpon> <DependentUpon>FormContact.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
@ -384,6 +391,9 @@
<EmbeddedResource Include="Controls\FormMain.resx"> <EmbeddedResource Include="Controls\FormMain.resx">
<DependentUpon>FormMain.cs</DependentUpon> <DependentUpon>FormMain.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Controls\FormMask.resx">
<DependentUpon>FormMask.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\FormMessage.resx"> <EmbeddedResource Include="Controls\FormMessage.resx">
<DependentUpon>FormMessage.cs</DependentUpon> <DependentUpon>FormMessage.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

View File

@ -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) public string ShowConfirm(string message, string caption, string yesButtonText, string noButtonText)
{ {
var result = FormDialog.Show(message, caption, yesButtonText, noButtonText); var result = FormDialog.Show(message, caption, yesButtonText, noButtonText);
return BridgeResult.Success(result == DialogResult.Yes ? "yes" : "no"); return BridgeResult.Success(result == DialogResult.Yes ? "yes" : "no");
} }

View File

@ -96,6 +96,8 @@
this.ShowIcon = false; this.ShowIcon = false;
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 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); this.ResumeLayout(false);
} }

View File

@ -1,4 +1,6 @@
using System; using AIProofread.Util;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
namespace AIProofread.Controls namespace AIProofread.Controls
@ -9,7 +11,7 @@ namespace AIProofread.Controls
{ {
InitializeComponent(); InitializeComponent();
} }
private static FormMask mask;
private void SetMessage(string message) private void SetMessage(string message)
{ {
@ -24,10 +26,16 @@ namespace AIProofread.Controls
public static DialogResult Show(string message, string caption, string yesButtonText, string noButtonText) public static DialogResult Show(string message, string caption, string yesButtonText, string noButtonText)
{ {
FormDialog formMessage = new FormDialog(); FormDialog formMessage = new FormDialog();
mask = new FormMask(formMessage);
mask.ShowOverWord();
formMessage.SetMessage(message); formMessage.SetMessage(message);
formMessage.Text = caption; formMessage.Text = caption;
formMessage.SetButtonText(yesButtonText, noButtonText); 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) public static DialogResult Show(string message)
{ {
@ -37,6 +45,7 @@ namespace AIProofread.Controls
private void BtnClose_Click(object sender, EventArgs e) private void BtnClose_Click(object sender, EventArgs e)
{ {
this.DialogResult = DialogResult.No; this.DialogResult = DialogResult.No;
this.TopMost = false;
this.Close(); this.Close();
} }
@ -45,5 +54,17 @@ namespace AIProofread.Controls
this.DialogResult = DialogResult.Yes; this.DialogResult = DialogResult.Yes;
this.Close(); 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;
}
} }
} }

View File

@ -0,0 +1,48 @@
namespace AIProofread.Controls
{
partial class FormMask
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -465,7 +465,7 @@ namespace AIProofread.Model
{ {
if (proofreadId == selectProofreadId) return; if (proofreadId == selectProofreadId) return;
// 取消上一个标签移除 // 取消上一个标签移除
if (proofreadId != -1 && marks.ContainsKey(selectProofreadId)) if (selectProofreadId != -1 && marks.ContainsKey(selectProofreadId))
{ {
var m = marks[selectProofreadId]; var m = marks[selectProofreadId];
if (m != null && CurrentDocument.Bookmarks.Exists(m.Name)) if (m != null && CurrentDocument.Bookmarks.Exists(m.Name))
@ -486,7 +486,7 @@ namespace AIProofread.Model
// 已经不存在该标签了 // 已经不存在该标签了
if (mark != null && !CurrentDocument.Bookmarks.Exists(mark.Name)) if (mark != null && !CurrentDocument.Bookmarks.Exists(mark.Name))
{ {
marks.Remove(selectProofreadId); marks.Remove(proofreadId);
return; return;
} }
//object lineNum = (int)mark.Range.Information[WdInformation.wdFirstCharacterLineNumber] - 1; //object lineNum = (int)mark.Range.Information[WdInformation.wdFirstCharacterLineNumber] - 1;
@ -622,8 +622,11 @@ namespace AIProofread.Model
correct.CorrectItems.ForEach(item => correct.CorrectItems.ForEach(item =>
{ {
var mark = DocumentUtil.FindBookMarkByCorrect(item); var mark = DocumentUtil.FindBookMarkByCorrect(item);
var pi = new ProofreadItem(item,correct.Insert, mark, Id); if (mark != null)
marks.Add(item.Id, pi); {
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)); //marks.Add(item.Id, new ProofreadItem(item.CorrectItems[0], null, Id));
} }

View File

@ -83,7 +83,7 @@ namespace UtilLib
{ {
if (mark == null) return; if (mark == null) return;
mark.Range.Font.Size = originSize + 2; // 将选中标签文本放大字体 mark.Range.Font.Size = originSize + 2; // 将选中标签文本放大字体
mark.Select(); //mark.Select();
} }
public void UnSelect() public void UnSelect()

View File

@ -353,10 +353,6 @@ namespace AIProofread
this.documentList.HideAllPane(); this.documentList.HideAllPane();
} }
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary> /// <summary>
/// 显示登录窗口 /// 显示登录窗口
/// </summary> /// </summary>

View File

@ -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);
}
}

View File

@ -297,19 +297,28 @@ namespace AIProofread
public static Bookmark FindBookMarkByCorrect(CorrectItem correct) public static Bookmark FindBookMarkByCorrect(CorrectItem correct)
{ {
var document = Globals.ThisAddIn.ActiveDocument.CurrentDocument; try
var marks = document.Bookmarks; {
var markName = Config.BuildBookmarkName(correct.Id); 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; ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls;
controls.Remove(markName); // 删除原有书签
//return controls[markName] as Bookmark; controls.Remove(markName);
var bookmark = marks[markName]; //return controls[markName] as Bookmark;
var start = bookmark.Range.Start; var bookmark = marks[markName];
var end = bookmark.Range.End; var start = bookmark.Range.Start;
return controls.AddBookmark(document.Range(start, end), markName); var end = bookmark.Range.End;
return controls.AddBookmark(document.Range(start, end), markName);
}
catch (Exception ex)
{
Logger.Log(ex);
}
return null;
//if(bookmark == null) //if(bookmark == null)
//{ //{

View File

@ -1 +1 @@
e41eeef295075b0004214c8cd1d281efa264dd90d94486af5e0e1e63e30e1f99 73697d8cfbb569cc987afc71aa3dff1fa36374eacaf0a7c7b55871ef5023996c

View File

@ -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.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.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.FormWebView.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormMask.resources