diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo
index f756310..c4a9cee 100644
Binary files a/.vs/AIProofread/v17/.suo and b/.vs/AIProofread/v17/.suo differ
diff --git a/AIProofread/AIProofread.csproj.user b/AIProofread/AIProofread.csproj.user
index f4331b6..61eb47a 100644
--- a/AIProofread/AIProofread.csproj.user
+++ b/AIProofread/AIProofread.csproj.user
@@ -7,7 +7,7 @@
- Program
+ Project
C:\Soft\Kingsoft\WPS Office\12.1.0.20784\office6\wps.exe
diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs
index c171648..e930657 100644
--- a/AIProofread/Bridge.cs
+++ b/AIProofread/Bridge.cs
@@ -452,6 +452,8 @@ namespace AIProofread
catch (Exception ex)
{
Logger.Error("校对文档格式有误或内容异常", ex);
+ data["code"] = 6;
+ data["message"] = "文档格式有误或内容异常,请另存文档后再进行校对";
throw ex;
}
//if (loadingDialog != null && !loadingDialog.IsDisposed)
diff --git a/AIProofread/Config.cs b/AIProofread/Config.cs
index 3324faf..25254ee 100644
--- a/AIProofread/Config.cs
+++ b/AIProofread/Config.cs
@@ -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
///
/// 网页访问地址
///
- 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
diff --git a/AIProofread/Model/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs
index 1d8181d..7e4c2b6 100644
--- a/AIProofread/Model/DocumentInfo.cs
+++ b/AIProofread/Model/DocumentInfo.cs
@@ -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();
-
}
}
diff --git a/AIProofread/Model/DocumentList.cs b/AIProofread/Model/DocumentList.cs
index c51ba39..ced540b 100644
--- a/AIProofread/Model/DocumentList.cs
+++ b/AIProofread/Model/DocumentList.cs
@@ -103,7 +103,6 @@ namespace AIProofread.Model
{
return documentList.IndexOf(item);
}
-
///
/// 设置当前激活的文档
///
diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs
index 9420661..b1abba3 100644
--- a/AIProofread/ThisAddIn.cs
+++ b/AIProofread/ThisAddIn.cs
@@ -57,7 +57,13 @@ namespace AIProofread
///
/// 当前文档信息
///
- public DocumentInfo ActiveDocument { get; set; }
+ public DocumentInfo ActiveDocument
+ {
+ get
+ {
+ return documentList.SetActiveDocument(Application.ActiveDocument);
+ }
+ }
///
/// 智能常识检测对话框 = new FormCommonsenseDetection()
///
@@ -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();
+ var existsList = new List();
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
//}
}
+
+ ///
+ /// 判断当前文档是否在列表中
+ ///
+ ///
+ ///
+ private bool InDocumentInList(Document doc)
+ {
+ if (doc == null) return false;
+ foreach (Document item in Application.Documents)
+ {
+ if (item == doc)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
///
/// 激活文档
///
@@ -408,17 +434,18 @@ namespace AIProofread
///
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();
}
///