fixed: ️修复文档关闭后再次打开展示多个面板

This commit is contained in:
LittleBoy 2025-03-10 16:46:47 +08:00
parent a296604f2c
commit d16d6d4671
11 changed files with 113 additions and 42 deletions

View File

@ -558,6 +558,9 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\icon-manual-wps.jpg" /> <None Include="Resources\icon-manual-wps.jpg" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="favicon.ico" />
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
@ -585,6 +588,9 @@
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion> <LangVersion>7.3</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<ApplicationIcon>favicon.ico</ApplicationIcon>
</PropertyGroup>
<!-- Include the build rules for a C# project. --> <!-- Include the build rules for a C# project. -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Include additional build rules for an Office application add-in. --> <!-- Include additional build rules for an Office application add-in. -->

View File

@ -7,6 +7,7 @@ using Microsoft.Office.Tools.Word;
using Microsoft.Web.WebView2.Core; using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms; using Microsoft.Web.WebView2.WinForms;
using Newtonsoft.Json; using Newtonsoft.Json;
using NPOI.SS.Formula;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
using NPOI.XWPF.UserModel; using NPOI.XWPF.UserModel;
using Org.BouncyCastle.Asn1.Crmf; using Org.BouncyCastle.Asn1.Crmf;
@ -377,6 +378,22 @@ namespace AIProofread
return Tools.GetJSONString(data); return Tools.GetJSONString(data);
} }
public string GetDocumentInfo(int documentId)
{
Dictionary<string, object> data = new Dictionary<string, object>();
var documentInfo = documentId > 0 ? Globals.ThisAddIn.GetDocumentById(documentId) : Globals.ThisAddIn.ActiveDocument;
var doc = documentInfo.CurrentDocument;
data.Add("code", 0);
data.Add("message", "success");
data.Add("name", doc.Name);
//data.Add("documentId", Globals.ThisAddIn.ActiveDocument.Id);
data.Add("fullName", doc.FullName);
data.Add("documentId", GeIdBytDocument(doc));
data.Add("wordsCount", doc.Words.Count);
data.Add("charactersCount", doc.Characters.Count);
return Tools.GetJSONString(data);
}
/// <summary> /// <summary>
/// 根据位置获取文档区域文本 /// 根据位置获取文档区域文本
/// </summary> /// </summary>
@ -514,11 +531,21 @@ namespace AIProofread
public void ClearCurrentDocumentMarks() => Globals.ThisAddIn.ActiveDocument?.ClearAllProofreadMark(); public void ClearCurrentDocumentMarks() => Globals.ThisAddIn.ActiveDocument?.ClearAllProofreadMark();
public void removeBookmark(string markId) => DocumentUtil.RemoveBookmark(markId); public void removeBookmark(string markId) => DocumentUtil.RemoveBookmark(markId);
/// <summary>
/// 获取设备ID
/// </summary>
/// <returns></returns>
public string GetDeviceId() public string GetDeviceId()
{ {
return Config.DeviceId; return Config.DeviceId;
} }
/// <summary>
/// 设置帮助文档地址
/// </summary>
/// <param name="url"></param>
public void SetHelpUrl(string url) => Config.USER_MANUAL_URL = url;
public string getAllBookmark() public string getAllBookmark()
{ {
return ToJSON(DocumentUtil.GetAllBookmark()); return ToJSON(DocumentUtil.GetAllBookmark());
@ -715,11 +742,11 @@ namespace AIProofread
/// 导出勘误表 /// 导出勘误表
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public string ExportProofreadResult() public string ExportProofreadResult(string modelType)
{ {
try try
{ {
Globals.ThisAddIn.ActiveDocument.ExportResult(); Globals.ThisAddIn.ActiveDocument.ExportResult(modelType);
return BridgeResult.Success(); return BridgeResult.Success();
} }
catch (Exception ex) catch (Exception ex)

View File

@ -12,12 +12,12 @@ namespace AIProofread
public class Config public class Config
{ {
public static readonly string APP_NAME = "AI校对王"; public static readonly string APP_NAME = "AI校对王";
public static readonly string APP_VERSION = "2.2.0"; public static readonly string APP_VERSION = "2.2.1";
public static bool IS_WPS = false; public static bool IS_WPS = false;
public static bool UpgradeForcedNotice = false; public static bool UpgradeForcedNotice = false;
public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory; public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory;
public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.json"; public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.json";
public static readonly string USER_MANUAL_URL = "https://doc.weixin.qq.com/doc/w3_AMYAMAaTAKQFkUi5WkYT1OPSXFD17?scode=ACQARAe_AAsF7LbNrM"; public static string USER_MANUAL_URL = "https://aiprhelp.guomai.cn/";
/// <summary> /// <summary>
/// 文本背景色 /// 文本背景色
/// </summary> /// </summary>
@ -31,7 +31,7 @@ namespace AIProofread
public static bool RUN_IN_DEBUG = true; public static bool RUN_IN_DEBUG = true;
public static AppEnvironment APP_ENV = AppEnvironment.Dev; public static AppEnvironment APP_ENV = AppEnvironment.Dev;
#else #else
public static string WEB_PATH = "http://gm2-plugin.zverse.group/"; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com public static string WEB_PATH = "https://gm-plugin.gachafun.com/"; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com
public static bool RUN_IN_DEBUG = false; public static bool RUN_IN_DEBUG = false;
public static AppEnvironment APP_ENV = AppEnvironment.Prod; public static AppEnvironment APP_ENV = AppEnvironment.Prod;
#endif #endif

View File

@ -31,7 +31,8 @@ namespace AIProofread.Controls
private void FormLogin_Load(object sender, EventArgs e) private void FormLogin_Load(object sender, EventArgs e)
{ {
//this.web.Source = new Uri(Config.WebPath("#login")); //this.web.Source = new Uri(Config.WebPath("#login"));
InitWebView(web, Config.WebPath("login?action=" + this.action), "login"); var r = new FormLogin();
InitWebView(web, Config.WebPath("login?action=" + this.action + "&version=" + Config.APP_VERSION + "&t=" + DateTime.Now.Ticks), "login");
} }

View File

@ -211,6 +211,7 @@ namespace AIProofread.Model
{ {
try try
{ {
if(TaskPane.Control.IsDisposed) return;
ProofreadMainControl control = (ProofreadMainControl)TaskPane.Control; ProofreadMainControl control = (ProofreadMainControl)TaskPane.Control;
control.ResetWeb(); control.ResetWeb();
@ -903,11 +904,11 @@ namespace AIProofread.Model
} }
} }
public void ExportResult() public void ExportResult(string modelType)
{ {
TaskPane.Control.BeginInvoke(new Action(() => TaskPane.Control.BeginInvoke(new Action(() =>
{ {
DocumentUtil.ExportProofreadResult(); DocumentUtil.ExportProofreadResult(modelType);
})); }));
} }

View File

@ -1,4 +1,5 @@
using Microsoft.Office.Interop.Word; using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
@ -32,6 +33,8 @@ namespace AIProofread.Model
return sentence; return sentence;
} }
// 截取中间位置 // 截取中间位置
try
{
var middlePosition = MAX_WORD_LENGTH / 2; var middlePosition = MAX_WORD_LENGTH / 2;
var cutStart = item.content.Start - middlePosition; var cutStart = item.content.Start - middlePosition;
// 越界了 // 越界了
@ -39,14 +42,15 @@ namespace AIProofread.Model
{ {
cutStart = 0; cutStart = 0;
} }
var originText = sentence.Substring(cutStart, MAX_WORD_LENGTH); var originText = sentence.Substring(cutStart, Math.Min(sentence.Length, MAX_WORD_LENGTH));
Debug.WriteLine($"{cutStart} {originText}");
if (!isInsert) if (!isInsert)
{ {
item.content.Start = item.content.Start - cutStart; item.content.Start = item.content.Start - cutStart;
item.content.End = item.content.End - cutStart; item.content.End = item.content.End - cutStart;
return originText; return originText;
} }
}
catch (Exception ex) { }
var range = item.mark.Range; var range = item.mark.Range;
// 获取range所在句子 // 获取range所在句子

View File

@ -7,11 +7,11 @@ using System.Security;
// 控制。更改这些特性值可修改 // 控制。更改这些特性值可修改
// 与程序集关联的信息。 // 与程序集关联的信息。
[assembly: AssemblyTitle("AI校对王")] [assembly: AssemblyTitle("AI校对王")]
[assembly: AssemblyDescription("AI校对王 2.1.2")] [assembly: AssemblyDescription("AI校对王 2.2.1")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("果麦文化")] [assembly: AssemblyCompany("果麦文化传媒股份有限公司")]
[assembly: AssemblyProduct("AI校对王 2.1.2")] [assembly: AssemblyProduct("AI校对王 2.2.1")]
[assembly: AssemblyCopyright("Copyright © GuoMai 2024")] [assembly: AssemblyCopyright("Copyright © 果麦文化传媒股份有限公司 2025")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
@ -34,5 +34,5 @@ using System.Security;
// 方法是按如下所示使用“*”: : // 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0")] [assembly: AssemblyVersion("2.0")]
[assembly: AssemblyFileVersion("2.1.2.0")] [assembly: AssemblyFileVersion("2.2.1.0")]

View File

@ -172,10 +172,10 @@ namespace AIProofread
public void CheckDocumentClosed(object sender, System.Timers.ElapsedEventArgs e) public void CheckDocumentClosed(object sender, System.Timers.ElapsedEventArgs e)
{ {
var existsList = new List<string>(); var existsList = new List<string>();
//Logger.Log("检测文档是否关闭 ..."); Logger.Log("检测文档是否关闭 ...");
try try
{ {
if (documentList.Count == 0 || CurrentWordApplication.Documents.Count == documentList.Count) return; if (documentList.Count == 0) return;
existsList.Clear(); existsList.Clear();
@ -184,13 +184,33 @@ namespace AIProofread
existsList.Add(item.FullName); existsList.Add(item.FullName);
} }
// 检测文档是否关闭 // 检测文档是否关闭
foreach (var item in documentList.documentList) for (int i = documentList.documentList.Count - 1; i >= 0; i--)
{ {
var item = documentList.documentList[i];
if (!existsList.Contains(item.fileName)) if (!existsList.Contains(item.fileName))
{ {
Logger.Log("检测到文档关闭,已移除:" + item.fileName); Logger.Log("检测到文档关闭,已移除:" + item.fileName);
try
{
item.RunInMainThread(() =>
{
item.Dispose();
});
}
catch (Exception ext)
{
Logger.Log(ext);
}
try
{
documentList.Remove(item); documentList.Remove(item);
} }
catch (Exception ext)
{
Logger.Log(ext);
}
}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -320,6 +340,7 @@ namespace AIProofread
// 设置当前文档 // 设置当前文档
ActiveDocument = documentList.SetActiveDocument(CurrentWordApplication.ActiveDocument); ActiveDocument = documentList.SetActiveDocument(CurrentWordApplication.ActiveDocument);
ActiveDocument.CheckBtnStatus(); ActiveDocument.CheckBtnStatus();
CheckDocumentClosed(null,null);
Logger.Log("Application_DocumentChange -- " + ActiveDocument.fileName); Logger.Log("Application_DocumentChange -- " + ActiveDocument.fileName);
} }
@ -378,6 +399,11 @@ namespace AIProofread
/// <param name="Cancel"></param> /// <param name="Cancel"></param>
private void Application_DocumentBeforeClose(Document currentDoc, ref bool Cancel) private void Application_DocumentBeforeClose(Document currentDoc, ref bool Cancel)
{ {
var doc = documentList.Get(currentDoc);
if (doc != null)
{
doc.HidePane();
}
Logger.Log("DocumentBeforeClose", currentDoc.FullName); Logger.Log("DocumentBeforeClose", currentDoc.FullName);
//if (allMarks.ContainsKey(currentDoc)) //if (allMarks.ContainsKey(currentDoc))
//{ //{

View File

@ -113,7 +113,8 @@ namespace AIProofread
try try
{ {
// feat(20250305): 清除批注的时候,如果监测到书签位置是空格,把空格给删了吧(无缓冲记录时) // feat(20250305): 清除批注的时候,如果监测到书签位置是空格,把空格给删了吧(无缓冲记录时)
if (mark.Range.Text.Trim().Length == 0) string text = mark.Range.Text;
if (text != null && text.Trim().Length == 0)
{ {
mark.Range.Text = ""; mark.Range.Text = "";
} }
@ -576,14 +577,15 @@ namespace AIProofread
} }
public static void ExportProofreadResult() public static void ExportProofreadResult(string modelType)
{ {
string currentName = Globals.ThisAddIn.Application.ActiveDocument.Name; string currentName = Globals.ThisAddIn.Application.ActiveDocument.Name;
// 去掉文件名后缀 // 去掉文件名后缀
currentName = currentName.Substring(0, currentName.LastIndexOf(".")); currentName = currentName.Substring(0, currentName.LastIndexOf("."));
SaveFileDialog sfd = new SaveFileDialog(); SaveFileDialog sfd = new SaveFileDialog();
modelType = modelType == "full" ? "查全" : "查准";
// 设置默认文件名 // 设置默认文件名
sfd.FileName = currentName + "_勘误表.xlsx"; sfd.FileName = currentName + $"_勘误表_优先{modelType}.xlsx";
sfd.Filter = "Excel文件|*.xlsx"; sfd.Filter = "Excel文件|*.xlsx";
var result = sfd.ShowDialog(); var result = sfd.ShowDialog();
// 如果用户取消选择,则返回 // 如果用户取消选择,则返回
@ -846,6 +848,10 @@ namespace AIProofread
{ {
tag = "黑名单"; tag = "黑名单";
} }
else if(it.Type == "fallen_officers")
{
tag = "落马官员";
}
else if (it.Tag == "i") else if (it.Tag == "i")
{ {
startIndex = it.Text.Length + 1; startIndex = it.Text.Length + 1;

BIN
AIProofread/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -30,9 +30,9 @@ namespace updater
* gm-plugin.gachafun.com * gm-plugin.gachafun.com
*/ */
#if DEBUG #if DEBUG
private static string UpgradeInfoURI = "http://pre-gm-plugin.gachafun.com/"; private static string UpgradeInfoURI = "http://gm-plugin.gachafun.com/";
#else #else
private static string UpgradeInfoURI = "https://pre-gm-plugin.gachafun.com/"; private static string UpgradeInfoURI = "https://gm-plugin.gachafun.com/";
#endif #endif
private string updateSource; private string updateSource;