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 />
|
||||
</PropertyGroup>
|
||||
<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>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
|
@ -452,6 +452,8 @@ namespace AIProofread
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("校对文档格式有误或内容异常", ex);
|
||||
data["code"] = 6;
|
||||
data["message"] = "文档格式有误或内容异常,请另存文档后再进行校对";
|
||||
throw ex;
|
||||
}
|
||||
//if (loadingDialog != null && !loadingDialog.IsDisposed)
|
||||
|
@ -26,6 +26,7 @@ namespace AIProofread
|
||||
{
|
||||
public static readonly string APP_NAME = "AI校对王";
|
||||
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 UpgradeForcedNotice = false;
|
||||
public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory;
|
||||
@ -42,7 +43,7 @@ namespace AIProofread
|
||||
/// <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 AppEnvironment APP_ENV = AppEnvironment.Prod;
|
||||
#else
|
||||
|
@ -96,6 +96,7 @@ namespace AIProofread.Model
|
||||
// 初始化
|
||||
public DocumentInfo(Document doc)
|
||||
{
|
||||
Logger.Debug("new DocumentInfo for " + doc.Name);
|
||||
this.CurrentDocument = doc;
|
||||
Initialize();
|
||||
}
|
||||
@ -109,7 +110,7 @@ namespace AIProofread.Model
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -125,10 +126,10 @@ namespace AIProofread.Model
|
||||
}
|
||||
|
||||
|
||||
public void RunInMainThread(Action action)
|
||||
public void RunInMainThread(Action action,bool isClose = false)
|
||||
{
|
||||
Logger.Debug($"RunInMainThread {action}");
|
||||
if (null == TaskPane)
|
||||
Logger.Debug("RunInMainThread for " + fileName);
|
||||
if (null == TaskPane && !isClose)
|
||||
{
|
||||
CreateTaskPane();
|
||||
}
|
||||
@ -338,9 +339,8 @@ namespace AIProofread.Model
|
||||
ComputeUniqueId();
|
||||
if (TaskPane == null)
|
||||
{
|
||||
Logger.Debug("init document Initialize(318) and CreateTaskPane");
|
||||
Logger.Debug("Initialize(334) and CreateTaskPane for " + CurrentDocument.Name);
|
||||
CreateTaskPane();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -103,7 +103,6 @@ namespace AIProofread.Model
|
||||
{
|
||||
return documentList.IndexOf(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置当前激活的文档
|
||||
/// </summary>
|
||||
|
@ -57,7 +57,13 @@ namespace AIProofread
|
||||
/// <summary>
|
||||
/// 当前文档信息
|
||||
/// </summary>
|
||||
public DocumentInfo ActiveDocument { get; set; }
|
||||
public DocumentInfo ActiveDocument
|
||||
{
|
||||
get
|
||||
{
|
||||
return documentList.SetActiveDocument(Application.ActiveDocument);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 智能常识检测对话框 = new FormCommonsenseDetection()
|
||||
/// </summary>
|
||||
@ -146,7 +152,7 @@ namespace AIProofread
|
||||
if (Application.Documents.Count > 0 && Application.ActiveDocument != null)
|
||||
{
|
||||
Logger.Debug("ThisAddIn_Startup 开始初始化当前文档");
|
||||
ActiveDocument = documentList.InitDocument(Application.ActiveDocument);
|
||||
documentList.InitDocument(Application.ActiveDocument);
|
||||
|
||||
// 直接初始化面板
|
||||
// info.CheckPanel();
|
||||
@ -197,7 +203,7 @@ namespace AIProofread
|
||||
|
||||
public void CheckDocumentClosed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
var existsList = new List<string>();
|
||||
var existsList = new List<Document>();
|
||||
try
|
||||
{
|
||||
var docList = CurrentWordApplication.Documents;
|
||||
@ -205,7 +211,7 @@ namespace AIProofread
|
||||
existsList.Clear();
|
||||
foreach (Document item in docList)
|
||||
{
|
||||
existsList.Add(item.FullName);
|
||||
existsList.Add(item);
|
||||
}
|
||||
|
||||
// 检测文档是否关闭
|
||||
@ -219,21 +225,21 @@ namespace AIProofread
|
||||
continue;
|
||||
}
|
||||
// 可能出现另存问题 所以需要更新文件名称
|
||||
var oldName = item.fileName;
|
||||
var currentName = item.CurrentDocument.FullName;
|
||||
if (oldName != currentName)
|
||||
//var oldName = item.fileName;
|
||||
//var currentName = item.CurrentDocument.FullName;
|
||||
//if (oldName != currentName)
|
||||
//{
|
||||
// item.fileName = currentName;
|
||||
//}
|
||||
if (!existsList.Contains(item.CurrentDocument))
|
||||
{
|
||||
item.fileName = currentName;
|
||||
}
|
||||
if (!existsList.Contains(currentName))
|
||||
{
|
||||
Logger.Debug("检测到文档关闭,已移除:" + currentName);
|
||||
Logger.Debug("检测到文档关闭,已移除:" + item.fileName);
|
||||
try
|
||||
{
|
||||
item.RunInMainThread(() =>
|
||||
{
|
||||
item.Dispose();
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
catch (Exception ex1)
|
||||
{
|
||||
@ -246,7 +252,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
Logger.Error("移除已关闭文档",ex2);
|
||||
Logger.Error("移除已关闭文档", ex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -291,8 +297,8 @@ namespace AIProofread
|
||||
return;
|
||||
}
|
||||
|
||||
if (ActiveDocument == null) return;
|
||||
// TODO 完成缓存保存
|
||||
//if (ActiveDocument == null) return;
|
||||
//// TODO 完成缓存保存
|
||||
|
||||
}
|
||||
|
||||
@ -370,26 +376,28 @@ namespace AIProofread
|
||||
|
||||
private void Application_DocumentChange()
|
||||
{
|
||||
|
||||
// 检测是否存在打开的文档
|
||||
if (CurrentWordApplication.Documents.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var document = documentList.InitDocument(CurrentWordApplication.ActiveDocument);
|
||||
if(document == null) return;
|
||||
|
||||
var currentDocument = CurrentWordApplication.ActiveDocument;
|
||||
|
||||
Logger.Debug("DocumentChange => " + currentDocument.Name);
|
||||
CheckDocumentClosed(null, null);
|
||||
if (formCommonsenseDetection != 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)
|
||||
{
|
||||
@ -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>
|
||||
@ -408,17 +434,18 @@ namespace AIProofread
|
||||
/// <param name="Wn"></param>
|
||||
private void Application_WindowActivate(Document activeDoc, Window Wn)
|
||||
{
|
||||
Logger.Debug("Application_WindowActivate -- " + activeDoc.Name);
|
||||
if (activeDoc != null)
|
||||
Logger.Debug("WindowActivate -- " + activeDoc.Name);
|
||||
if (activeDoc != null && InDocumentInList(activeDoc))
|
||||
{
|
||||
Logger.Debug("DocumentChange -- " + activeDoc.Name
|
||||
+ " 修订模式: is " + activeDoc.TrackRevisions
|
||||
+ ActiveDocument?.CurrentDocument?.Name + "==》" + activeDoc.Name);
|
||||
|
||||
var document = documentList.SetActiveDocument(activeDoc);
|
||||
// 设置当前文档
|
||||
ActiveDocument = document;
|
||||
documentList.SetActiveDocument(activeDoc);
|
||||
//// 设置当前文档
|
||||
//ActiveDocument = document;
|
||||
}
|
||||
|
||||
//// 当前文档添加书签集合
|
||||
//if (!allMarks.ContainsKey(activeDoc))
|
||||
//{
|
||||
@ -477,7 +504,7 @@ namespace AIProofread
|
||||
private void Application_DocumentOpen(Document doc)
|
||||
{
|
||||
//LogHelper.Log("DocumentOpen " + doc.Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int GetMinWidth()
|
||||
@ -566,20 +593,20 @@ namespace AIProofread
|
||||
|
||||
public void GlobalCallback(string callbackId, string result)
|
||||
{
|
||||
ActiveDocument?.GlobalCallback(callbackId, result);
|
||||
documentList.SetActiveDocument(Application.ActiveDocument)?.GlobalCallback(callbackId, result);
|
||||
}
|
||||
|
||||
// 显示面板
|
||||
public void ShowPanel()
|
||||
{
|
||||
Logger.Debug("ShowPanel");
|
||||
ActiveDocument?.ShowPane();
|
||||
documentList.SetActiveDocument(Application.ActiveDocument)?.ShowPane();
|
||||
|
||||
}
|
||||
|
||||
// 隐藏面板
|
||||
public void HidePanel()
|
||||
{
|
||||
ActiveDocument?.HidePane();
|
||||
documentList.SetActiveDocument(Application.ActiveDocument)?.HidePane();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user