break: ActiveDocument 改为实时获取
优化调试逻辑,增强日志记录,简化代码结构 - 修改 AIProofread.csproj.user 的 <StartAction> 配置,调试时直接启动项目。 - Bridge.cs 中增加异常处理的详细错误信息。 - DocumentInfo.cs 增加日志记录,调整 RunInMainThread 方法逻辑。 - DocumentList.cs 删除过时的 XML 注释。 - ThisAddIn.cs 优化文档管理逻辑,调整 ActiveDocument 属性为只读,改进文档列表处理,删除冗余代码。
This commit is contained in:
parent
a54765e911
commit
8284a9d552
Binary file not shown.
@ -7,7 +7,7 @@
|
|||||||
<SupportUrlHistory />
|
<SupportUrlHistory />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||||
<StartAction>Program</StartAction>
|
<StartAction>Project</StartAction>
|
||||||
<StartProgram>C:\Soft\Kingsoft\WPS Office\12.1.0.20784\office6\wps.exe</StartProgram>
|
<StartProgram>C:\Soft\Kingsoft\WPS Office\12.1.0.20784\office6\wps.exe</StartProgram>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||||
|
@ -452,6 +452,8 @@ namespace AIProofread
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Error("校对文档格式有误或内容异常", ex);
|
Logger.Error("校对文档格式有误或内容异常", ex);
|
||||||
|
data["code"] = 6;
|
||||||
|
data["message"] = "文档格式有误或内容异常,请另存文档后再进行校对";
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
//if (loadingDialog != null && !loadingDialog.IsDisposed)
|
//if (loadingDialog != null && !loadingDialog.IsDisposed)
|
||||||
|
@ -26,6 +26,7 @@ namespace AIProofread
|
|||||||
{
|
{
|
||||||
public static readonly string APP_NAME = "AI校对王";
|
public static readonly string APP_NAME = "AI校对王";
|
||||||
public static readonly string APP_VERSION = "2.2.5";
|
public static readonly string APP_VERSION = "2.2.5";
|
||||||
|
public static readonly string BuildVersion = "20250509_1656";
|
||||||
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;
|
||||||
@ -42,7 +43,7 @@ namespace AIProofread
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 网页访问地址
|
/// 网页访问地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string WEB_PATH = AppServer.PROD; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group
|
public static string WEB_PATH = AppServer.DEV; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group
|
||||||
public static bool RUN_IN_DEBUG = true;
|
public static bool RUN_IN_DEBUG = true;
|
||||||
public static AppEnvironment APP_ENV = AppEnvironment.Prod;
|
public static AppEnvironment APP_ENV = AppEnvironment.Prod;
|
||||||
#else
|
#else
|
||||||
|
@ -96,6 +96,7 @@ namespace AIProofread.Model
|
|||||||
// 初始化
|
// 初始化
|
||||||
public DocumentInfo(Document doc)
|
public DocumentInfo(Document doc)
|
||||||
{
|
{
|
||||||
|
Logger.Debug("new DocumentInfo for " + doc.Name);
|
||||||
this.CurrentDocument = doc;
|
this.CurrentDocument = doc;
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
@ -109,7 +110,7 @@ namespace AIProofread.Model
|
|||||||
{
|
{
|
||||||
CreateTaskPane();
|
CreateTaskPane();
|
||||||
}
|
}
|
||||||
Logger.Debug("TaskPane.Visible {" + TaskPane == null ? "null" : (TaskPane.Visible ? "true" : "false") + " => true");
|
Logger.Debug("TaskPane.Visible {" + TaskPane == null ? "null" : (TaskPane.Visible ? "true" : "false") + " => true " + fileName);
|
||||||
TaskPane.Visible = PaneVisible = true;
|
TaskPane.Visible = PaneVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,10 +126,10 @@ namespace AIProofread.Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void RunInMainThread(Action action)
|
public void RunInMainThread(Action action,bool isClose = false)
|
||||||
{
|
{
|
||||||
Logger.Debug($"RunInMainThread {action}");
|
Logger.Debug("RunInMainThread for " + fileName);
|
||||||
if (null == TaskPane)
|
if (null == TaskPane && !isClose)
|
||||||
{
|
{
|
||||||
CreateTaskPane();
|
CreateTaskPane();
|
||||||
}
|
}
|
||||||
@ -338,9 +339,8 @@ namespace AIProofread.Model
|
|||||||
ComputeUniqueId();
|
ComputeUniqueId();
|
||||||
if (TaskPane == null)
|
if (TaskPane == null)
|
||||||
{
|
{
|
||||||
Logger.Debug("init document Initialize(318) and CreateTaskPane");
|
Logger.Debug("Initialize(334) and CreateTaskPane for " + CurrentDocument.Name);
|
||||||
CreateTaskPane();
|
CreateTaskPane();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,6 @@ namespace AIProofread.Model
|
|||||||
{
|
{
|
||||||
return documentList.IndexOf(item);
|
return documentList.IndexOf(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置当前激活的文档
|
/// 设置当前激活的文档
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -57,7 +57,13 @@ namespace AIProofread
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前文档信息
|
/// 当前文档信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DocumentInfo ActiveDocument { get; set; }
|
public DocumentInfo ActiveDocument
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return documentList.SetActiveDocument(Application.ActiveDocument);
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 智能常识检测对话框 = new FormCommonsenseDetection()
|
/// 智能常识检测对话框 = new FormCommonsenseDetection()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -146,7 +152,7 @@ namespace AIProofread
|
|||||||
if (Application.Documents.Count > 0 && Application.ActiveDocument != null)
|
if (Application.Documents.Count > 0 && Application.ActiveDocument != null)
|
||||||
{
|
{
|
||||||
Logger.Debug("ThisAddIn_Startup 开始初始化当前文档");
|
Logger.Debug("ThisAddIn_Startup 开始初始化当前文档");
|
||||||
ActiveDocument = documentList.InitDocument(Application.ActiveDocument);
|
documentList.InitDocument(Application.ActiveDocument);
|
||||||
|
|
||||||
// 直接初始化面板
|
// 直接初始化面板
|
||||||
// info.CheckPanel();
|
// info.CheckPanel();
|
||||||
@ -197,7 +203,7 @@ 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<Document>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var docList = CurrentWordApplication.Documents;
|
var docList = CurrentWordApplication.Documents;
|
||||||
@ -205,7 +211,7 @@ namespace AIProofread
|
|||||||
existsList.Clear();
|
existsList.Clear();
|
||||||
foreach (Document item in docList)
|
foreach (Document item in docList)
|
||||||
{
|
{
|
||||||
existsList.Add(item.FullName);
|
existsList.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测文档是否关闭
|
// 检测文档是否关闭
|
||||||
@ -219,21 +225,21 @@ namespace AIProofread
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 可能出现另存问题 所以需要更新文件名称
|
// 可能出现另存问题 所以需要更新文件名称
|
||||||
var oldName = item.fileName;
|
//var oldName = item.fileName;
|
||||||
var currentName = item.CurrentDocument.FullName;
|
//var currentName = item.CurrentDocument.FullName;
|
||||||
if (oldName != currentName)
|
//if (oldName != currentName)
|
||||||
|
//{
|
||||||
|
// item.fileName = currentName;
|
||||||
|
//}
|
||||||
|
if (!existsList.Contains(item.CurrentDocument))
|
||||||
{
|
{
|
||||||
item.fileName = currentName;
|
Logger.Debug("检测到文档关闭,已移除:" + item.fileName);
|
||||||
}
|
|
||||||
if (!existsList.Contains(currentName))
|
|
||||||
{
|
|
||||||
Logger.Debug("检测到文档关闭,已移除:" + currentName);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
item.RunInMainThread(() =>
|
item.RunInMainThread(() =>
|
||||||
{
|
{
|
||||||
item.Dispose();
|
item.Dispose();
|
||||||
});
|
}, true);
|
||||||
}
|
}
|
||||||
catch (Exception ex1)
|
catch (Exception ex1)
|
||||||
{
|
{
|
||||||
@ -246,7 +252,7 @@ namespace AIProofread
|
|||||||
}
|
}
|
||||||
catch (Exception ex2)
|
catch (Exception ex2)
|
||||||
{
|
{
|
||||||
Logger.Error("移除已关闭文档",ex2);
|
Logger.Error("移除已关闭文档", ex2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,8 +297,8 @@ namespace AIProofread
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ActiveDocument == null) return;
|
//if (ActiveDocument == null) return;
|
||||||
// TODO 完成缓存保存
|
//// TODO 完成缓存保存
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,26 +376,28 @@ namespace AIProofread
|
|||||||
|
|
||||||
private void Application_DocumentChange()
|
private void Application_DocumentChange()
|
||||||
{
|
{
|
||||||
|
|
||||||
// 检测是否存在打开的文档
|
// 检测是否存在打开的文档
|
||||||
if (CurrentWordApplication.Documents.Count == 0)
|
if (CurrentWordApplication.Documents.Count == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var document = documentList.InitDocument(CurrentWordApplication.ActiveDocument);
|
var currentDocument = CurrentWordApplication.ActiveDocument;
|
||||||
if(document == null) return;
|
|
||||||
|
Logger.Debug("DocumentChange => " + currentDocument.Name);
|
||||||
CheckDocumentClosed(null, null);
|
CheckDocumentClosed(null, null);
|
||||||
if (formCommonsenseDetection != null)
|
if (formCommonsenseDetection != null)
|
||||||
{
|
{
|
||||||
formCommonsenseDetection.SendMessageToWeb("document-change", null);
|
formCommonsenseDetection.SendMessageToWeb("document-change", null);
|
||||||
}
|
}
|
||||||
|
if (InDocumentInList(currentDocument))
|
||||||
|
{
|
||||||
|
documentList.InitDocument(currentDocument);
|
||||||
|
}
|
||||||
|
//var document = documentList.InitDocument(CurrentWordApplication.ActiveDocument);
|
||||||
|
//if (document == null) return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetActiveDocument(Document doc)
|
|
||||||
{
|
|
||||||
ActiveDocument = documentList.SetActiveDocument(doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Application_WindowDeactivate(Document doc, Window Wn)
|
private void Application_WindowDeactivate(Document doc, Window Wn)
|
||||||
{
|
{
|
||||||
@ -401,6 +409,24 @@ namespace AIProofread
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断当前文档是否在列表中
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="doc"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool InDocumentInList(Document doc)
|
||||||
|
{
|
||||||
|
if (doc == null) return false;
|
||||||
|
foreach (Document item in Application.Documents)
|
||||||
|
{
|
||||||
|
if (item == doc)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 激活文档
|
/// 激活文档
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -408,17 +434,18 @@ namespace AIProofread
|
|||||||
/// <param name="Wn"></param>
|
/// <param name="Wn"></param>
|
||||||
private void Application_WindowActivate(Document activeDoc, Window Wn)
|
private void Application_WindowActivate(Document activeDoc, Window Wn)
|
||||||
{
|
{
|
||||||
Logger.Debug("Application_WindowActivate -- " + activeDoc.Name);
|
Logger.Debug("WindowActivate -- " + activeDoc.Name);
|
||||||
if (activeDoc != null)
|
if (activeDoc != null && InDocumentInList(activeDoc))
|
||||||
{
|
{
|
||||||
Logger.Debug("DocumentChange -- " + activeDoc.Name
|
Logger.Debug("DocumentChange -- " + activeDoc.Name
|
||||||
+ " 修订模式: is " + activeDoc.TrackRevisions
|
+ " 修订模式: is " + activeDoc.TrackRevisions
|
||||||
+ ActiveDocument?.CurrentDocument?.Name + "==》" + activeDoc.Name);
|
+ ActiveDocument?.CurrentDocument?.Name + "==》" + activeDoc.Name);
|
||||||
|
|
||||||
var document = documentList.SetActiveDocument(activeDoc);
|
documentList.SetActiveDocument(activeDoc);
|
||||||
// 设置当前文档
|
//// 设置当前文档
|
||||||
ActiveDocument = document;
|
//ActiveDocument = document;
|
||||||
}
|
}
|
||||||
|
|
||||||
//// 当前文档添加书签集合
|
//// 当前文档添加书签集合
|
||||||
//if (!allMarks.ContainsKey(activeDoc))
|
//if (!allMarks.ContainsKey(activeDoc))
|
||||||
//{
|
//{
|
||||||
@ -477,7 +504,7 @@ namespace AIProofread
|
|||||||
private void Application_DocumentOpen(Document doc)
|
private void Application_DocumentOpen(Document doc)
|
||||||
{
|
{
|
||||||
//LogHelper.Log("DocumentOpen " + doc.Name);
|
//LogHelper.Log("DocumentOpen " + doc.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int GetMinWidth()
|
public int GetMinWidth()
|
||||||
@ -566,20 +593,20 @@ namespace AIProofread
|
|||||||
|
|
||||||
public void GlobalCallback(string callbackId, string result)
|
public void GlobalCallback(string callbackId, string result)
|
||||||
{
|
{
|
||||||
ActiveDocument?.GlobalCallback(callbackId, result);
|
documentList.SetActiveDocument(Application.ActiveDocument)?.GlobalCallback(callbackId, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示面板
|
// 显示面板
|
||||||
public void ShowPanel()
|
public void ShowPanel()
|
||||||
{
|
{
|
||||||
Logger.Debug("ShowPanel");
|
documentList.SetActiveDocument(Application.ActiveDocument)?.ShowPane();
|
||||||
ActiveDocument?.ShowPane();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏面板
|
// 隐藏面板
|
||||||
public void HidePanel()
|
public void HidePanel()
|
||||||
{
|
{
|
||||||
ActiveDocument?.HidePane();
|
documentList.SetActiveDocument(Application.ActiveDocument)?.HidePane();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user