diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index 6d3ee23..6ec16fe 100644 Binary files a/.vs/AIProofread/v17/.suo and b/.vs/AIProofread/v17/.suo differ diff --git a/AIProofread/AIProofread.csproj b/AIProofread/AIProofread.csproj index 9ceba33..87f58d3 100644 --- a/AIProofread/AIProofread.csproj +++ b/AIProofread/AIProofread.csproj @@ -582,6 +582,8 @@ + + 10.0 diff --git a/AIProofread/AIProofread.csproj.user b/AIProofread/AIProofread.csproj.user index 78e7ff7..f4331b6 100644 --- a/AIProofread/AIProofread.csproj.user +++ b/AIProofread/AIProofread.csproj.user @@ -7,8 +7,8 @@ - Project - C:\Soft\Kingsoft\WPS Office\12.1.0.18608\office6\wps.exe + Program + C:\Soft\Kingsoft\WPS Office\12.1.0.20784\office6\wps.exe Project diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index d762260..c171648 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -109,6 +109,10 @@ namespace AIProofread Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("show-history", null); } + public void HasNewVersion() + { + Globals.ThisAddIn.ribbon.ShowNewVersionIcon(); + } /// /// 检查插件更新信息 /// @@ -315,6 +319,19 @@ namespace AIProofread { return Tools.GetAllText(Globals.ThisAddIn.Application.ActiveDocument); } + public bool SaveDocument(int documentId) + { + var document = documentId > 0 ? Globals.ThisAddIn.GetDocumentById(documentId) : Globals.ThisAddIn.ActiveDocument; + try + { + document.Save(); + return true; + }catch (Exception ex) + { + Logger.Error("保存文档失败", ex); + } + return false; + } public bool Saved(int documentId) { @@ -576,18 +593,15 @@ namespace AIProofread webViewDict.Add(name, webView); } - Logger.Error("初始化Main Pane Web环境 开始"); + Logger.Debug("初始化Main Pane Web环境 开始"); // 禁用web安全,允许跨域 否则需要web编译为umd加载模式 var ops = new CoreWebView2EnvironmentOptions("--disable-web-security"); var env = await CoreWebView2Environment.CreateAsync(null, Config.WEB_DATA_PATH, ops); await webView.EnsureCoreWebView2Async(env); - //webView.CoreWebView2.Settings.AreDevToolsEnabled = false; - //webView.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false; - //webView.CoreWebView2.Settings.AreHostObjectsAllowed = true; // 添加 js与客户端代理 webView.CoreWebView2.AddHostObjectToScript("bridge", bridge); - Logger.Error("初始化Main Pane Web环境 结束"); + Logger.Debug("初始化Main Pane Web环境 结束"); } catch (Exception ex) { @@ -864,6 +878,7 @@ namespace AIProofread } catch (Exception ex) { + Logger.Error("读取文件失败:" + ex.Message, ex); return BridgeResult.Error(-1, ex.Message); } } @@ -901,7 +916,7 @@ namespace AIProofread } try { - Logger.Info("SaveCache " + document.fileName + " used " + document.ProofreadCachePath); + Logger.Debug("SaveCache " + document.fileName + " used " + document.ProofreadCachePath); if (File.Exists(document.ProofreadCachePath)) { @@ -914,6 +929,7 @@ namespace AIProofread } catch (Exception ex) { + Logger.Error("保存缓存失败:" + ex.Message, ex); return BridgeResult.Error(-1, ex.Message); } } @@ -938,6 +954,7 @@ namespace AIProofread } catch (Exception ex) { + Logger.Error("加载缓存失败:" + ex.Message, ex); return BridgeResult.Error(ex.Message); } } @@ -951,8 +968,9 @@ namespace AIProofread File.Delete(Globals.ThisAddIn.ActiveDocument.ProofreadCachePath); } } - catch (Exception) + catch (Exception ex) { + Logger.Error("删除缓存失败:" + ex.Message, ex); return false; } return true; @@ -976,6 +994,7 @@ namespace AIProofread } catch (Exception ex) { + Logger.Error("初始化缓存失败:" + ex.Message, ex); return BridgeResult.Error(ex); } } diff --git a/AIProofread/Config.cs b/AIProofread/Config.cs index 88524f1..3324faf 100644 --- a/AIProofread/Config.cs +++ b/AIProofread/Config.cs @@ -19,19 +19,8 @@ namespace AIProofread /// /// 测试环境 /// - public const string TEST = "http://gm2-plugin.zverse.group/"; - /// - /// 果麦预发布-灰度 - /// - public const string PRE = "https://pre-gm-plugin.gachafun.com/"; - /// - /// 果麦生产 - /// - public const string PROD = "https://gm-plugin.gachafun.com/"; - /// - /// 果麦金融 - /// - public const string GM_FN = "https://gm-plugin-fn.gachafun.com/"; + public const string PROD = "http://aijdw1.goldmye.com/"; + public const string TEST = "http://tt-plugin.zverse.group/"; } public class Config { @@ -48,18 +37,19 @@ namespace AIProofread public static readonly string TextBackgroundColor = "#E9DABB"; // e9dabb D6AA69 public static string DeviceId = ""; -#if DEBUG + + #if DEBUG /// /// 网页访问地址 /// - public static string WEB_PATH = AppServer.DEV; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group + public static string WEB_PATH = AppServer.PROD; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group public static bool RUN_IN_DEBUG = true; - public static AppEnvironment APP_ENV = AppEnvironment.Dev; -#else - public static string WEB_PATH = AppServer.DEV; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com - public static bool RUN_IN_DEBUG = true; - public static AppEnvironment APP_ENV = AppEnvironment.Dev; -#endif + public static AppEnvironment APP_ENV = AppEnvironment.Prod; + #else + public static string WEB_PATH = AppServer.PROD; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com + public static bool RUN_IN_DEBUG = false; + public static AppEnvironment APP_ENV = AppEnvironment.Prod; + #endif public static readonly string APP_DATA_PATH = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ai_proofread"; public static readonly string APP_LOG_PATH = APP_DATA_PATH + "\\logs\\"; diff --git a/AIProofread/Controls/ProofreadMainControl.cs b/AIProofread/Controls/ProofreadMainControl.cs index 7ed3bf9..c64e8bc 100644 --- a/AIProofread/Controls/ProofreadMainControl.cs +++ b/AIProofread/Controls/ProofreadMainControl.cs @@ -39,9 +39,9 @@ namespace AIProofread.Controls -

页面加载失败

-

请检查您的网络连接或稍后再试。

- 重新加载 +

加载组件失败

+

请检查您的网络连接并重启软件。

+ 重新加载 "; (sender as WebView2).CoreWebView2.NavigateToString(errorPageHtml); @@ -57,7 +57,7 @@ namespace AIProofread.Controls if (ex.TryGetWebMessageAsString() == "reload") { isShowingErrorPage = false; - //web.Source = new Uri(Config.WebPath("correct")); + web.Source = new Uri(Config.WebPath("correct")); } }; this.web.Source = new Uri(Config.WebPath("correct" )); diff --git a/AIProofread/LogHelper.cs b/AIProofread/LogHelper.cs index 22be393..0fdae97 100644 --- a/AIProofread/LogHelper.cs +++ b/AIProofread/LogHelper.cs @@ -37,7 +37,7 @@ namespace AIProofread roller.Layout = layout; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); - hierarchy.Root.Level = log4net.Core.Level.Debug; + hierarchy.Root.Level = log4net.Core.Level.Info; hierarchy.Configured = true; } diff --git a/AIProofread/Model/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs index bd2fc76..302a4dd 100644 --- a/AIProofread/Model/DocumentInfo.cs +++ b/AIProofread/Model/DocumentInfo.cs @@ -8,6 +8,7 @@ using System.Windows.Forms; using AIProofread.Controls; using AIProofread.core; using AIProofread.Util; +using DocumentFormat.OpenXml.Office2013.WebExtentionPane; using log4net; using Microsoft.Office.Interop.Word; using Newtonsoft.Json; @@ -104,11 +105,11 @@ namespace AIProofread.Model /// public void ShowPane() { - if(null == TaskPane) + if (null == TaskPane) { 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"); TaskPane.Visible = PaneVisible = true; } @@ -117,12 +118,13 @@ namespace AIProofread.Model /// public void HidePane() { - if (!PaneVisible) return; + //if (!PaneVisible) return; ShowDocumentStatus("HidePane"); Logger.Debug($"TaskPane.Visible {TaskPane.Visible} => false"); TaskPane.Visible = PaneVisible = false; } + public void RunInMainThread(Action action) { Logger.Debug($"RunInMainThread {action}"); @@ -184,54 +186,59 @@ namespace AIProofread.Model /// public void Active() { - ShowDocumentStatus("Active"); - IsActive = true; - if (Config.IS_WPS && null != TaskPane && PaneVisible) + try { - TaskPane.Visible = true; + Logger.Debug("激活 for " + CurrentDocument.FullName + " 没有 visible is " + PaneVisible); + ShowDocumentStatus("Active"); + IsActive = true; + if (Config.IS_WPS && null != TaskPane) + { + TaskPane.Visible = PaneVisible; + } + } + catch (Exception e) + { + Logger.Error("Active Error", e); } } public void Deactive() { - ShowDocumentStatus("Deactive"); - IsActive = false; - if (Config.IS_WPS) + try { - if (PaneVisible) - { - // 异步等待一段时间 重新设置为true,防止面板关闭时,触发事件 - ThreadPool.QueueUserWorkItem(state => - { - Thread.Sleep(500); - PaneVisible = true; - }); - } - if (null != TaskPane && PaneVisible) + ShowDocumentStatus("Deactive"); + IsActive = false; + if (Config.IS_WPS && null != TaskPane) { + PaneVisible = TaskPane.Visible; TaskPane.Visible = false; + Logger.Debug("取消 for " + CurrentDocument.FullName + " current visible " + PaneVisible); } + }catch (Exception e) + { + Logger.Error("Deactive Error", e); } - - } public void Dispose() { try { + // 判断TaskPane是否已经释放 + if (null == TaskPane) return; + if (TaskPane.Control.IsDisposed) return; + + ProofreadMainControl control = (ProofreadMainControl)TaskPane.Control; + control.ResetWeb(); + + HidePane(); + TaskPane?.Dispose(); // 释放com try { Marshal.ReleaseComObject(CurrentDocument); } catch (Exception) { } - if(TaskPane.Control.IsDisposed) return; - ProofreadMainControl control = (ProofreadMainControl)TaskPane.Control; - control.ResetWeb(); - - HidePane(); - TaskPane?.Dispose(); } catch (Exception e) { @@ -277,7 +284,7 @@ namespace AIProofread.Model MinWidth = MIN_WIDTH * control.LabelWidth() / 42; } // 创建pane - TaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(control, " "); + TaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(control, Config.RUN_IN_DEBUG ? CurrentDocument.Name : " "); // 默认隐藏 TaskPane.Visible = false; // 设置宽度 @@ -289,7 +296,9 @@ namespace AIProofread.Model TaskPane.VisibleChanged += TaskPane_VisibleChanged; } - + /// + /// 检查按钮状态 + /// public void CheckBtnStatus() { // @@ -302,8 +311,15 @@ namespace AIProofread.Model private void TaskPane_VisibleChanged(object sender, EventArgs e) { - // 如果已经隐藏 则记录隐藏用于(WPS)多面板的切换的处理 - PaneVisible = TaskPane.Visible; + if (Config.IS_WPS) + { + if(CurrentDocument == Globals.ThisAddIn.ActiveDocument) + { + Logger.Debug($"VisibleChanged ${CurrentDocument.Name} is {TaskPane.Visible}"); + // 如果已经隐藏 则记录隐藏用于(WPS)多面板的切换的处理 + PaneVisible = TaskPane.Visible; + } + } CheckBtnStatus(); //Globals.ThisAddIn.ribbon.BtnShowPanel.Enabled = !TaskPane.Visible && Proofread; } @@ -648,7 +664,7 @@ namespace AIProofread.Model // 选中 targetRange.Select(); Globals.ThisAddIn.Application.ActiveWindow.ScrollIntoView(targetRange);//.Selection.GoTo(ref bookmark, ref missing, ref missing, ref bookmarkName); - + // //mark.DisableCharacterSpaceGrid = false; // 先滚动到可视区域 @@ -672,7 +688,7 @@ namespace AIProofread.Model List insertMarks = new List(); foreach (var correct in list) { - if(LogHelper.LoggerForm != null) + if (LogHelper.LoggerForm != null) { LogHelper.Log(string.Format("correct content:{0}", correct.Insert)); } @@ -688,7 +704,7 @@ namespace AIProofread.Model int _prev = prevOffset; bool isDisabled = false; // 判断查找内容是否在原始数据中,否则直跳过 - if(item.Tag != "i" && item.Origin.Trim().Length > 0) + if (item.Tag != "i" && item.Origin.Trim().Length > 0) { isDisabled = correct.Insert.IndexOf(item.Origin) == -1; } @@ -787,7 +803,7 @@ namespace AIProofread.Model } - public void InitProofreadCache(List list,Dictionary itemInfoDic) + public void InitProofreadCache(List list, Dictionary itemInfoDic) { marks.Clear(); @@ -800,7 +816,7 @@ namespace AIProofread.Model { var pi = new ProofreadItem(item, correct.Insert, mark, Id); // 是否存在样式信息 - if (itemInfoDic!= null && itemInfoDic.ContainsKey(item.Id)) + if (itemInfoDic != null && itemInfoDic.ContainsKey(item.Id)) { // 获取样式信息并还原 var info = itemInfoDic[item.Id]; @@ -890,6 +906,10 @@ namespace AIProofread.Model // 采纳 marks[proofreadId].Process(status); } + else + { + Logger.Debug("不存在此校对项"); + } } internal bool Saved() @@ -914,7 +934,8 @@ namespace AIProofread.Model try { CurrentDocument.Save(); - }catch (Exception ex) + } + catch (Exception ex) { LogHelper.Log(ex); } @@ -1031,7 +1052,7 @@ namespace AIProofread.Model public Dictionary GetProofreadOriginData() { - Dictionary dic = new Dictionary(); + Dictionary dic = new Dictionary(); // 变量文档所有marks 记录mark对应range的背景、大小、颜色 foreach (var item in marks) { diff --git a/AIProofread/Model/DocumentList.cs b/AIProofread/Model/DocumentList.cs index 3418a07..c51ba39 100644 --- a/AIProofread/Model/DocumentList.cs +++ b/AIProofread/Model/DocumentList.cs @@ -24,7 +24,7 @@ namespace AIProofread.Model public void Clear() { - documentList.ForEach(doc =>{ doc.Dispose(); }); + documentList.ForEach(doc => { doc.Dispose(); }); documentList.Clear(); } @@ -118,9 +118,8 @@ namespace AIProofread.Model Logger.Error("Document not exists SetActiveDocument"); return null; } - if (ActiveDocument == document) return document; - - if (Globals.ThisAddIn.IsWPS) + + if (ActiveDocument != null && ActiveDocument.CurrentDocument != originDocument) { // WPS 只有一个窗口 所以需要先关闭之前文档的面板 ActiveDocument?.Deactive(); @@ -129,6 +128,7 @@ namespace AIProofread.Model ActiveDocument = document; //document.IsActive = true; document.Active(); + document.CheckBtnStatus(); return document; } @@ -141,12 +141,18 @@ namespace AIProofread.Model { var document = Get(originDocument); - // 如果不存在,则添加 - if (document == null) + try { - Logger.Debug("Document not exists,InitDocument: " + originDocument.Name); - document = new DocumentInfo(originDocument); - Add(document); + // 如果不存在,则添加 + if (document == null) + { + Logger.Debug("Document not exists,InitDocument: " + originDocument.Name); + document = new DocumentInfo(originDocument); + Add(document); + } + }catch(Exception ex) + { + Logger.Error("InitDocument error: " + ex.Message,ex); } return document; } diff --git a/AIProofread/Properties/AssemblyInfo.cs b/AIProofread/Properties/AssemblyInfo.cs index 78e4918..5f3f4d9 100644 --- a/AIProofread/Properties/AssemblyInfo.cs +++ b/AIProofread/Properties/AssemblyInfo.cs @@ -7,10 +7,10 @@ using System.Security; // 控制。更改这些特性值可修改 // 与程序集关联的信息。 [assembly: AssemblyTitle("AI校对王")] -[assembly: AssemblyDescription("AI校对王 2.2.4")] +[assembly: AssemblyDescription("AI校对王 2.2.5")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("果麦文化传媒股份有限公司")] -[assembly: AssemblyProduct("AI校对王 2.2.4")] +[assembly: AssemblyProduct("AI校对王 2.2.5")] [assembly: AssemblyCopyright("Copyright © 果麦文化传媒股份有限公司 2025")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/AIProofread/Properties/Resources.Designer.cs b/AIProofread/Properties/Resources.Designer.cs index aad8863..6579ec8 100644 --- a/AIProofread/Properties/Resources.Designer.cs +++ b/AIProofread/Properties/Resources.Designer.cs @@ -380,6 +380,26 @@ namespace AIProofread.Properties { } } + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap icon_update_new { + get { + object obj = ResourceManager.GetObject("icon-update-new", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap icon_update_new_wps { + get { + object obj = ResourceManager.GetObject("icon-update-new-wps", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// diff --git a/AIProofread/Properties/Resources.resx b/AIProofread/Properties/Resources.resx index b8833c2..5ca8f90 100644 --- a/AIProofread/Properties/Resources.resx +++ b/AIProofread/Properties/Resources.resx @@ -136,9 +136,6 @@ ..\Resources\icon-history.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\icon-phone.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -160,6 +157,9 @@ ..\Resources\icon-update-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-manual.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\icon-setting.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -187,8 +187,11 @@ ..\Resources\icon-refresh-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\icon-manual-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\button_default.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -202,14 +205,14 @@ ..\Resources\logo_no_text.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-ai-robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\logo_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\icon-phone-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -217,8 +220,11 @@ ..\Resources\icon-history-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\icon-ai-robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\icon-logout.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -226,13 +232,13 @@ ..\Resources\icon_close.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-manual.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-update-new.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\icon-manual-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icon-update-new-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/AIProofread/Resources/icon-update-new-wps.jpg b/AIProofread/Resources/icon-update-new-wps.jpg new file mode 100644 index 0000000..769232b Binary files /dev/null and b/AIProofread/Resources/icon-update-new-wps.jpg differ diff --git a/AIProofread/Resources/icon-update-new.png b/AIProofread/Resources/icon-update-new.png new file mode 100644 index 0000000..72617e9 Binary files /dev/null and b/AIProofread/Resources/icon-update-new.png differ diff --git a/AIProofread/Ribbon1.Designer.cs b/AIProofread/Ribbon1.Designer.cs index 44c4699..28810f1 100644 --- a/AIProofread/Ribbon1.Designer.cs +++ b/AIProofread/Ribbon1.Designer.cs @@ -255,7 +255,9 @@ namespace AIProofread this.btnLogin.Image = global::AIProofread.Properties.Resources.icon_user; this.btnLogin.Label = "用户登录\r\n"; this.btnLogin.Name = "btnLogin"; + this.btnLogin.ScreenTip = "用户登录\r\n"; this.btnLogin.ShowImage = true; + this.btnLogin.SuperTip = "通过手机验证码或者密码登录账号"; this.btnLogin.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnLogin_Click); // // btnLogout diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs index 904db45..eba7bdf 100644 --- a/AIProofread/Ribbon1.cs +++ b/AIProofread/Ribbon1.cs @@ -178,6 +178,11 @@ namespace AIProofread //Globals.ThisAddIn.SendMessageToWeb("confirm-logout", null); } + public void ShowNewVersionIcon() + { + BtnUpdate.Image = Globals.ThisAddIn.IsWPS? Resources.icon_update_new_wps : Resources.icon_update_new; + } + private void btnOpenLexicon_Click(object sender, RibbonControlEventArgs e) { diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index b6b2df7..9420661 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -62,6 +62,9 @@ namespace AIProofread /// 智能常识检测对话框 = new FormCommonsenseDetection() /// public FormCommonsenseDetection formCommonsenseDetection; + /// + /// 是否为wps + /// public bool IsWPS { get; set; } public List LoginFormList = new List(); @@ -161,6 +164,11 @@ namespace AIProofread } } + private void Application_DocumentBeforePrint(Document Doc, ref bool Cancel) + { + throw new NotImplementedException(); + } + // 异步获取设备唯一标识 public void InitDeviceId() { @@ -176,7 +184,7 @@ namespace AIProofread if (!string.IsNullOrEmpty(deviceId)) { Config.DeviceId = deviceId; - Logger.Debug("设备唯一标识:" + deviceId); + Logger.Info("设备唯一标识:" + deviceId); } } catch (Exception ex) @@ -227,25 +235,25 @@ namespace AIProofread item.Dispose(); }); } - catch (Exception ext) + catch (Exception ex1) { - Logger.Debug(ext); + Logger.Error("移除已关闭文档->释放面板", ex1); } try { documentList.Remove(item); } - catch (Exception ext) + catch (Exception ex2) { - Logger.Debug(ext); + Logger.Error("移除已关闭文档",ex2); } } } } catch (Exception ex) { - Logger.Debug(ex.Message, ex); + Logger.Error("检测已关闭文档", ex); } //await System.Threading.Tasks.Task.Run(() => // { @@ -306,7 +314,6 @@ namespace AIProofread { Config.IS_WPS = true; IsWPS = true; - try { Globals.Ribbons.Ribbon1.InitWPS(); @@ -316,15 +323,16 @@ namespace AIProofread Logger.Error("Init WPS Error ", ex); } } - string verTextFile = Config.APP_BASE_DIR + Path.GetFileName("app_version.txt"); - try - { - File.WriteAllText(verTextFile, Config.APP_VERSION); - } - catch (Exception ex) - { - Logger.Error("Write App Version Error ", ex); - } + //string verTextFile = Config.APP_BASE_DIR + Path.GetFileName("app_version.txt"); + //try + //{ + // File.WriteAllText(verTextFile, Config.APP_VERSION); + //} + //catch (Exception ex) + //{ + // Logger.Error("Write App Version Error ", ex); + //} + Logger.Info("init " + (Config.IS_WPS ? "WPS" : "WORD") + " end"); } private void InitAppByConfig() @@ -368,21 +376,14 @@ namespace AIProofread { return; } - var document = CurrentWordApplication.ActiveDocument; - Logger.Debug("Application_DocumentChange -- " + document.Name + " 修订模式: is " + document.TrackRevisions); - // 设置当前文档 - ActiveDocument = documentList.SetActiveDocument(document); - if (ActiveDocument == null) - { - return; - } - ActiveDocument.CheckBtnStatus(); + var document = documentList.InitDocument(CurrentWordApplication.ActiveDocument); + if(document == null) return; + CheckDocumentClosed(null, null); if (formCommonsenseDetection != null) { formCommonsenseDetection.SendMessageToWeb("document-change", null); } - // } public void SetActiveDocument(Document doc) @@ -408,9 +409,15 @@ namespace AIProofread private void Application_WindowActivate(Document activeDoc, Window Wn) { Logger.Debug("Application_WindowActivate -- " + activeDoc.Name); - if (activeDoc != null && (ActiveDocument == null || activeDoc != ActiveDocument.CurrentDocument)) + if (activeDoc != null) { - documentList.SetActiveDocument(activeDoc); + Logger.Debug("DocumentChange -- " + activeDoc.Name + + " 修订模式: is " + activeDoc.TrackRevisions + + ActiveDocument?.CurrentDocument?.Name + "==》" + activeDoc.Name); + + var document = documentList.SetActiveDocument(activeDoc); + // 设置当前文档 + ActiveDocument = document; } //// 当前文档添加书签集合 //if (!allMarks.ContainsKey(activeDoc)) @@ -443,18 +450,12 @@ namespace AIProofread /// private void Application_DocumentBeforeClose(Document currentDoc, ref bool Cancel) { + Logger.Debug("will close " + currentDoc.Name); var doc = documentList.Get(currentDoc); - if (doc != null) + if (Config.IS_WPS && doc != null) { doc.HidePane(); } - //LogHelper.Log("DocumentBeforeClose", currentDoc.FullName); - //if (allMarks.ContainsKey(currentDoc)) - //{ - // allMarks.Remove(currentDoc); - //} - - //DisposePanel(currentDoc); } //public void ActiveCurrentDocumentMarks(Document document) @@ -476,7 +477,7 @@ namespace AIProofread private void Application_DocumentOpen(Document doc) { //LogHelper.Log("DocumentOpen " + doc.Name); - } + } public int GetMinWidth() @@ -491,34 +492,69 @@ namespace AIProofread private void Application_WindowSelectionChange(Selection s) { + // 处理当前文档选区,用于判断是否显示常识性检测 ribbon.ParseSelectionChange(s); + if (ActiveDocument == null || !s.Active) return; + // 当前选区是否存在书签 + if (s.Range.Start != s.Range.End || s.Bookmarks.Count == 0) return; + var bookmarks = s.Bookmarks; + // 获取当前选区书签的起始位置 + var currentPosition = s.Range.Start; - if (s.Bookmarks != null) + // Logger.Info("当前选区书签数量: " + s.Bookmarks.Count); + // 遍历书签 找到所需的书签 + foreach (Bookmark item in s.Bookmarks) { - if (s.Range.Start == s.Range.End) // 说明是点击呀 + // 判断书签的选区不包含当前选中区域 + if (currentPosition < item.Range.Start || currentPosition > item.Range.End) { - //var count = s.Bookmarks.Count; - if (s.Bookmarks.Count >= 1) // 只有这一个 - { - foreach (Bookmark item in s.Bookmarks) - { - int proofreadId = Config.GetBookmarkIdByName(item.Name); - if (proofreadId > 0) - { - // 只选择第一个书签 - // TODO: 优化 - //Bridge.bridge.SelectMarkById(proofreadId, 0); - ActiveDocument?.SelectMarkById(proofreadId, true); - return; - } - } - } + ReleaseComObject(item); + continue; } + + Logger.Debug("当前选区书签名称: " + item.Name + "范围:" + item.Range.Start + "," + item.Range.End); + //Logger.Debug("当前选区书签内容: " + item.Range.Text); + // 获取书签id + int proofreadId = Config.GetBookmarkIdByName(item.Name); + // 释放com对象 + ReleaseComObject(item); + Logger.Debug("当前选区proofreadId: " + proofreadId); + if (proofreadId > 0) + { + //var targetRange = item.Range; + //// 选中 + //targetRange.Select(); + //Globals.ThisAddIn.Application.ActiveWindow.ScrollIntoView(targetRange); + // 只选择第一个书签 + ActiveDocument?.SelectMarkById(proofreadId, true); + ReleaseComObject(bookmarks); + return; + } + // } + + ReleaseComObject(bookmarks); //Bridge.bridge.SelectMarkById(-1, 0); } - - public int MyProperty { get; set; } + // 释放COM对象 + private void ReleaseComObject(object obj) + { + if (obj != null) + { + try + { + System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); + } + catch (Exception ex) + { + Logger.Error("ReleaseComObject Error", ex); + } + finally + { + obj = null; + } + } + } public void SendMessageToWeb(string msg, object data) { diff --git a/AIProofread/core/AppModule.cs b/AIProofread/core/AppModule.cs index 072ecd2..5da88c1 100644 --- a/AIProofread/core/AppModule.cs +++ b/AIProofread/core/AppModule.cs @@ -13,7 +13,7 @@ /// /// 是否启用常识性检测 /// - public const bool ENABLE_COMMONSENSE_CHECK = true; + public const bool ENABLE_COMMONSENSE_CHECK = false; /// /// 设置功能 /// @@ -34,9 +34,9 @@ public const bool ENABLE_SAVE_CACHE = true; public const bool ENABLE_LOAD_CACHE = true; - public const bool ENABLE_CUSTOMER_SERVICE = true; - public const bool ENABLE_UPGRADE = true; - public const bool ENABLE_HELP = true; + public const bool ENABLE_CUSTOMER_SERVICE = false; + public const bool ENABLE_UPGRADE = false; + public const bool ENABLE_HELP = false; } } diff --git a/AIProofread/core/CorrectResultExportor.cs b/AIProofread/core/CorrectResultExportor.cs index 0416dd4..8a4cf01 100644 --- a/AIProofread/core/CorrectResultExportor.cs +++ b/AIProofread/core/CorrectResultExportor.cs @@ -343,7 +343,7 @@ namespace AIProofread.core }; var beforeText = it.Start == 0 ? null : originSentence.Substring(0, it.Start); - var richTextLength = it.Origin.Length; // it.Tag == "i" ? 1 : it.Text.Length + var richTextLength = it.Tag == "i" ? it.Text.Length:it.Origin.Length; // it.Tag == "i" ? 1 : it.Text.Length var richText = originSentence.Substring(it.Start, richTextLength); var afterText = it.Start >= originSentence.Length ? null : originSentence.Substring(it.Start + richTextLength); diff --git a/AIProofread/core/DocumentUtil.cs b/AIProofread/core/DocumentUtil.cs index 6daa028..fbdea9a 100644 --- a/AIProofread/core/DocumentUtil.cs +++ b/AIProofread/core/DocumentUtil.cs @@ -17,12 +17,14 @@ using AIProofread.Model; using NPOI.SS.Util; using NPOI.HSSF.Util; using AIProofread.core; +using log4net; namespace AIProofread { public class DocumentUtil { static int markId = 0; + public static readonly ILog Logger = LogHelper.GetLogger(typeof(DocumentUtil)); /// /// 添加一个书签 @@ -117,7 +119,7 @@ namespace AIProofread } catch (Exception e) { - LogHelper.Log("remove mark", e); + Logger.Error("remove mark" + e.Message, e); } } } @@ -142,23 +144,6 @@ namespace AIProofread mark.Delete(); } } - //foreach (var mark in document.Bookmarks) - //{ - // if (markId != null) - // { - // if (mark.Name == markId) - // { - // // 删除 - // mark.Delete(); - // mark.Range.Shading.BackgroundPatternColor = (WdColor)WdColorIndex.wdAuto; - // return; - // } - // } - // else - // { - // mark.Delete(); - // } - //} } public static System.Collections.Generic.List GetSectionText() @@ -254,52 +239,11 @@ namespace AIProofread { "search_end",range.End }, { "search_text",range.Text } }; - LogHelper.Log(JsonConvert.SerializeObject(msg1)); - //while (range.Find.Found) - //{ - // var obj4 = range.Document; - // MatchControl = range.Start; - // MatchAlefHamza = range.End; - // var range2 = obj4.Range(ref MatchControl, ref MatchAlefHamza); - // num3 = range2.End; - // if (range2.Text == findText) - // { - // return range2; - // } - // break; - // //if (findIndex == num) - // //{ - - // //} - // //num++; - // //range.Find.MatchByte = true; - // //Find find2 = range.Find; - // //MatchAlefHamza = missword; - // //MatchControl = true; - // //MatchDiacritics = Type.Missing; - // //MatchKashida = Type.Missing; - // //Replace = Type.Missing; - // //ReplaceWith = Type.Missing; - // //Format = Type.Missing; - // //Wrap = Type.Missing; - // //Forward = Type.Missing; - // //MatchAllWordForms = Type.Missing; - // //MatchSoundsLike = Type.Missing; - // //MatchWildcards = Type.Missing; - // //MatchWholeWord = Type.Missing; - // //Start = Type.Missing; - // //End = Type.Missing; - // //// 再次重复查找 - // //find2.Execute(ref MatchAlefHamza, ref MatchControl, ref MatchDiacritics, ref MatchKashida, ref Replace, ref ReplaceWith, ref Format, ref Wrap, ref Forward, ref MatchAllWordForms, ref MatchSoundsLike, ref MatchWildcards, ref MatchWholeWord, ref Start, ref End); - //} - //if (num3 == 0) - //{ - // return null; - //} + Logger.Debug(JsonConvert.SerializeObject(msg1)); } catch (Exception ex) { - LogHelper.Log(ex); + Logger.Error(ex); } return null; } @@ -327,24 +271,9 @@ namespace AIProofread } catch (Exception ex) { - LogHelper.Log(ex); + Logger.Error(ex); } return null; - - //if(bookmark == null) - //{ - // foreach (var m in marks) - // { - // var mark = m as Bookmark; - // var name = mark.Name; - // var tag = mark.Tag?.ToString(); - // if(tag == markName || name == markName) - // { - // return mark; - // } - // } - //} - //return bookmark as Bookmark; } public static Bookmark FindRangeAndCreateBookmark(CorrectItem correct, CorrectContext sentense, Microsoft.Office.Interop.Word.Document document, ref int prevOffset) @@ -381,7 +310,7 @@ namespace AIProofread } catch (Exception ex) { - LogHelper.Log("create mark error:" + ex.Message + "\n" + ex.StackTrace + "\n\n"); + Logger.Error("create mark error:" + ex.Message + "\n" + ex.StackTrace + "\n\n"); } return bookmark; } @@ -404,6 +333,7 @@ namespace AIProofread } //int count = 0; var range = document.Range(offset + item.Start, offset + item.End + 1); + #region 删除批注 //while (true && count++ < 10) //{ // // @@ -428,6 +358,7 @@ namespace AIProofread // Logger.Log(dce); // } //} + #endregion // 比对原始内容与校对原文是否一致 if (range.Text == item.Origin) { @@ -446,11 +377,13 @@ namespace AIProofread { return range1; } + return null; // 执行查找 - return FindTextInRange(sentence, item.Origin); + //return FindTextInRange(sentence, item.Origin); } - catch (Exception) + catch (Exception e) { + Logger.Error("find by sentence error",e); } return null; @@ -521,7 +454,7 @@ namespace AIProofread if (prevOffset >= paraText.Length) { // 查找位置已经超过了整段长度了 - LogHelper.Log("prevOffset:" + prevOffset + " paraText.Length:" + paraText.Length); + Logger.Debug("prevOffset:" + prevOffset + " paraText.Length:" + paraText.Length); return null; } // 执行查找 @@ -608,7 +541,7 @@ namespace AIProofread } catch (Exception e) { - LogHelper.Log(e); + Logger.Error("导出勘误表失败",e); Globals.ThisAddIn.ShowDialog("导出勘误表失败,请重试", null, null); } } @@ -751,7 +684,7 @@ namespace AIProofread } catch (Exception e) { - LogHelper.Log(e); + Logger.Error(e); } var oriCell = row.CreateCell(3); @@ -862,7 +795,7 @@ namespace AIProofread } catch (Exception ex) { - LogHelper.Log(ex); + Logger.Error(ex); } id++; } diff --git a/AIProofread/core/Tools.cs b/AIProofread/core/Tools.cs index 2b946e3..d9c2b01 100644 --- a/AIProofread/core/Tools.cs +++ b/AIProofread/core/Tools.cs @@ -153,6 +153,9 @@ namespace AIProofread public static string GetReadDocumentFilePath(Microsoft.Office.Interop.Word.Document doc) { + + // 保存文档确保内容是最新的 + doc.Save(); // string docPath = doc.FullName; string ext = Path.GetExtension(docPath);