Compare commits

...

3 Commits

14 changed files with 182 additions and 106 deletions

Binary file not shown.

View File

@ -386,6 +386,7 @@
<Compile Include="Controls\ProofreadMainControl.Designer.cs">
<DependentUpon>ProofreadMainControl.cs</DependentUpon>
</Compile>
<Compile Include="core\AppModule.cs" />
<Compile Include="core\BridgeResult.cs" />
<Compile Include="core\CommonSenseDetection.cs" />
<Compile Include="core\CorrectionCharacter.cs" />

View File

@ -576,6 +576,7 @@ namespace AIProofread
webViewDict.Add(name, webView);
}
Logger.Error("初始化Main Pane Web环境 开始");
// 禁用web安全允许跨域 否则需要web编译为umd加载模式
var ops = new CoreWebView2EnvironmentOptions("--disable-web-security");
var env = await CoreWebView2Environment.CreateAsync(null, Config.WEB_DATA_PATH, ops);
@ -586,12 +587,13 @@ namespace AIProofread
// 添加 js与客户端代理
webView.CoreWebView2.AddHostObjectToScript("bridge", bridge);
Logger.Error("初始化Main Pane Web环境 结束");
}
catch (Exception ex)
{
Debug.WriteLine("初始化web环境失败" + ex.Message);
Logger.Error("初始化web环境失败", ex);
LogHelper.Log(ex);
//LogHelper.Log(ex);
}
}

View File

@ -56,9 +56,9 @@ namespace AIProofread
public static bool RUN_IN_DEBUG = true;
public static AppEnvironment APP_ENV = AppEnvironment.Dev;
#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;
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 readonly string APP_DATA_PATH = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ai_proofread";

View File

@ -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" ));

View File

@ -8,6 +8,7 @@ using System.Windows.Forms;
using AIProofread.Controls;
using AIProofread.core;
using AIProofread.Util;
using log4net;
using Microsoft.Office.Interop.Word;
using Newtonsoft.Json;
using UtilLib;
@ -20,6 +21,7 @@ namespace AIProofread.Model
/// </summary>
public class DocumentInfo
{
public ILog Logger = LogHelper.GetLogger(typeof(DocumentInfo));
public static readonly int MIN_WIDTH = 420;
private static char[] ArticleSpecialChars = new char[4] { '\a', '\r', '\v', '\f' };
@ -74,8 +76,8 @@ namespace AIProofread.Model
}
}
public bool IsActive { get; internal set; }
public bool PaneVisible { get; set; }
public bool IsActive { get; internal set; } = false;
public bool PaneVisible { get; set; } = false;
public int Id { get; set; }
public CustomTaskPane TaskPane { get; set; }
@ -102,26 +104,33 @@ namespace AIProofread.Model
/// </summary>
public void ShowPane()
{
if (null != TaskPane)
{
TaskPane.Visible = PaneVisible = true;
}
else
if(null == TaskPane)
{
CreateTaskPane();
}
Logger.Debug("TaskPane.Visible {"+TaskPane==null?"null":(TaskPane.Visible?"true":"false")+" => true");
TaskPane.Visible = PaneVisible = true;
}
/// <summary>
/// 隐藏面板
/// </summary>
public void HidePane()
{
if (!PaneVisible) return;
ShowDocumentStatus("HidePane");
Logger.Debug($"TaskPane.Visible {TaskPane.Visible} => false");
TaskPane.Visible = PaneVisible = false;
}
public void RunInMainThread(Action action)
{
if (null != TaskPane)
{
TaskPane.Control.BeginInvoke(action);
}
else
Logger.Debug($"RunInMainThread {action}");
if (null == TaskPane)
{
CreateTaskPane();
}
TaskPane.Control.BeginInvoke(action);
}
public void ShowDialog(string message, string confirmText, string confirmAction)
@ -167,16 +176,7 @@ namespace AIProofread.Model
private void ShowDocumentStatus(string tag)
{
// Logger.Log($"{fileName} {tag} PaneVisible is {PaneVisible} Poofread is {Proofread} Proofreading is {Proofreading}");
}
/// <summary>
/// 隐藏面板
/// </summary>
public void HidePane()
{
ShowDocumentStatus(" HidePane");
if (null != TaskPane) TaskPane.Visible = PaneVisible = false;
// Logger.Log($"{fileName} {tag} PaneVisible is {PaneVisible} Poofread is {Proofread} Proofreading is {Proofreading}");
}
/// <summary>
@ -184,7 +184,7 @@ namespace AIProofread.Model
/// </summary>
public void Active()
{
ShowDocumentStatus(" Active");
ShowDocumentStatus("Active");
IsActive = true;
if (Config.IS_WPS && null != TaskPane && PaneVisible)
{
@ -194,7 +194,7 @@ namespace AIProofread.Model
public void Deactive()
{
ShowDocumentStatus(" Deactive");
ShowDocumentStatus("Deactive");
IsActive = false;
if (Config.IS_WPS)
{
@ -203,7 +203,7 @@ namespace AIProofread.Model
// 异步等待一段时间 重新设置为true防止面板关闭时触发事件
ThreadPool.QueueUserWorkItem(state =>
{
Thread.Sleep(1000);
Thread.Sleep(500);
PaneVisible = true;
});
}
@ -270,6 +270,7 @@ namespace AIProofread.Model
// 创建pane 并初始化
public void CreateTaskPane()
{
Logger.Debug("CreateTaskPane");
var control = new ProofreadMainControl();
if (MinWidth < 10)
{
@ -312,7 +313,12 @@ namespace AIProofread.Model
this.fileName = CurrentDocument.FullName;
ranges.Clear();
ComputeUniqueId();
if (TaskPane == null) CreateTaskPane();
if (TaskPane == null)
{
Logger.Debug("init document Initialize(318) and CreateTaskPane");
CreateTaskPane();
}
}

View File

@ -1,9 +1,9 @@
using Microsoft.Office.Interop.Word;
using log4net;
using log4net.Repository.Hierarchy;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AIProofread.Model
{
@ -12,6 +12,7 @@ namespace AIProofread.Model
/// </summary>
public class DocumentList
{
public ILog Logger = LogHelper.GetLogger(typeof(DocumentList));
public List<DocumentInfo> documentList = new List<DocumentInfo>();
public DocumentInfo ActiveDocument { get; set; }
public int Count => documentList.Count;
@ -109,17 +110,17 @@ namespace AIProofread.Model
/// <param name="originDocument"></param>
public DocumentInfo SetActiveDocument(Document originDocument)
{
Logger.Debug("SetActiveDocument(113): " + originDocument.Name);
if (originDocument == null) return null;
var document = Get(originDocument);
// 如果不存在,则添加
var document = InitDocument(originDocument);
if (document == null)
{
document = new DocumentInfo(originDocument);
Add(document);
Logger.Error("Document not exists SetActiveDocument");
return null;
}
if (ActiveDocument == document) return document;
else if (Globals.ThisAddIn.IsWPS)
if (Globals.ThisAddIn.IsWPS)
{
// WPS 只有一个窗口 所以需要先关闭之前文档的面板
ActiveDocument?.Deactive();
@ -135,5 +136,19 @@ namespace AIProofread.Model
{
documentList.ForEach(d => d.HidePane());
}
public DocumentInfo InitDocument(Document originDocument)
{
var document = Get(originDocument);
// 如果不存在,则添加
if (document == null)
{
Logger.Debug("Document not exists,InitDocument: " + originDocument.Name);
document = new DocumentInfo(originDocument);
Add(document);
}
return document;
}
}
}

View File

@ -41,7 +41,6 @@ namespace AIProofread
Microsoft.Office.Tools.Ribbon.RibbonDropDownItem ribbonDropDownItemImpl3 = this.Factory.CreateRibbonDropDownItem();
this.tabAIProofread = this.Factory.CreateRibbonTab();
this.group1 = this.Factory.CreateRibbonGroup();
this.BtnProofreadAll = this.Factory.CreateRibbonButton();
this.menuProofreadList = this.Factory.CreateRibbonMenu();
this.BtnProofreadExact = this.Factory.CreateRibbonButton();
this.BtnProofreadFull = this.Factory.CreateRibbonButton();
@ -97,7 +96,6 @@ namespace AIProofread
//
// group1
//
this.group1.Items.Add(this.BtnProofreadAll);
this.group1.Items.Add(this.menuProofreadList);
this.group1.Items.Add(this.BtnExportProofreadResult);
this.group1.Items.Add(this.btnClear);
@ -106,20 +104,9 @@ namespace AIProofread
this.group1.Items.Add(this.btnSetting);
this.group1.Name = "group1";
//
// BtnProofreadAll
//
this.BtnProofreadAll.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.BtnProofreadAll.Image = global::AIProofread.Properties.Resources.icon_proofread;
this.BtnProofreadAll.Label = "全文校对\r\n";
this.BtnProofreadAll.Name = "BtnProofreadAll";
this.BtnProofreadAll.ShowImage = true;
this.BtnProofreadAll.Visible = false;
this.BtnProofreadAll.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnProofreadAll_Click);
//
// menuProofreadList
//
this.menuProofreadList.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.menuProofreadList.Enabled = false;
this.menuProofreadList.Image = global::AIProofread.Properties.Resources.icon_proofread;
this.menuProofreadList.Items.Add(this.BtnProofreadExact);
this.menuProofreadList.Items.Add(this.BtnProofreadFull);
@ -302,6 +289,7 @@ namespace AIProofread
// BtnShowPanel
//
this.BtnShowPanel.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.BtnShowPanel.Enabled = false;
this.BtnShowPanel.Image = global::AIProofread.Properties.Resources.icon_panel;
this.BtnShowPanel.Label = "显示面板\r\n";
this.BtnShowPanel.Name = "BtnShowPanel";
@ -421,7 +409,6 @@ namespace AIProofread
internal Microsoft.Office.Tools.Ribbon.RibbonLabel LblNickname;
internal Microsoft.Office.Tools.Ribbon.RibbonLabel LblDate;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnLogin;
internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnProofreadAll;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnClear;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnOpenLexicon;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnSetting;

View File

@ -24,20 +24,29 @@ namespace AIProofread
{
//btnLogin.Label = "用户\n登录";
//btnLogout.Label = "退出\n登录";
Globals.ThisAddIn.ribbon = this;
ShowDebug();
InitModule();
}
/// <summary>
/// 用于调试或测试
/// </summary>
public void ShowDebug()
public void InitModule()
{
if (Config.RUN_IN_DEBUG)
{
grpDebug.Visible = true;
}
menuProofreadList.Visible = AppModule.ENABLE_PROOFREAD;
BtnExportProofreadResult.Visible = AppModule.ENABLE_EXPORT_PROOFREAD_RESULT;
btnOpenLexicon.Visible = AppModule.ENABLE_LEXICON_MANAGE;
menuSencenDect.Visible = AppModule.ENABLE_COMMONSENSE_CHECK;
btnSetting.Visible = AppModule.ENABLE_SETTING;
ButtonSaveCache.Visible = AppModule.ENABLE_SAVE_CACHE;
ButtonLoadCache.Visible = AppModule.ENABLE_LOAD_CACHE;
BtnGetContact.Visible = AppModule.ENABLE_CUSTOMER_SERVICE;
BtnUpdate.Visible = AppModule.ENABLE_UPGRADE;
BtnShowManual.Visible = AppModule.ENABLE_HELP;
// 调试面板
grpDebug.Visible = Config.RUN_IN_DEBUG;
}
public void SetCommonBtnStatus(bool status)
@ -80,8 +89,6 @@ namespace AIProofread
/// </summary>
public void InitWPS()
{
BtnProofreadAll.Image = AIProofread.Properties.Resources.icon_proofread_wps;
menuProofreadList.Image = AIProofread.Properties.Resources.icon_proofread_wps;
btnClear.Image = AIProofread.Properties.Resources.icon_clear_wps;
btnOpenLexicon.Image = AIProofread.Properties.Resources.icon_book_wps;
@ -199,12 +206,6 @@ namespace AIProofread
Bridge.bridge.ShowUpgradeView();
}
private void BtnProofreadAll_Click(object sender, RibbonControlEventArgs e)
{
string time = DateTime.Now.ToString("yyyy - MM - dd HH: mm:ss: fff:ffffff");
Globals.ThisAddIn.SendMessageToWeb("start", time);
}
private void btnClear_Click(object sender, RibbonControlEventArgs e)
{
//DocumentUtil.ClearProofreadMarks();

View File

@ -123,9 +123,6 @@
<metadata name="group1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnProofreadAll.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="menuProofreadList.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View File

@ -9,6 +9,8 @@ using UtilLib;
using AIProofread.Model;
using System.Collections.Generic;
using log4net;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.EMMA;
namespace AIProofread
@ -109,7 +111,7 @@ namespace AIProofread
//formCommonsenseDetection.ShowInTaskbar = false;
//formCommonsenseDetection.Show();
Logger.Debug("ThisAddIn_Startup Platform --> " + (IsWPS?"WPS":"WORD"));
Logger.Debug("ThisAddIn_Startup Platform --> " + (IsWPS ? "WPS" : "WORD"));
// 捕获全局异常
AppDomain.CurrentDomain.UnhandledException += ProcessApplicationException;
System.Windows.Forms.Application.ThreadException += ProcessApplicationFormException;
@ -121,7 +123,7 @@ namespace AIProofread
Application.WindowActivate += Application_WindowActivate;
//Application.WindowDeactivate += Application_WindowDeactivate;
Application.DocumentBeforeSave += Application_DocumentBeforeSave;
(Application as ApplicationEvents4_Event).NewDocument += Application_NewDocument;
Application.DocumentChange += Application_DocumentChange;
// 选区发生变化事件
@ -130,14 +132,32 @@ namespace AIProofread
// CheckDocumentClosedTick();
// 定时检测文档是否关闭
_timer = new System.Timers.Timer(10000);
_timer.Elapsed += CheckDocumentClosed;
_timer.AutoReset = true;
_timer.Enabled = true;
//_timer = new System.Timers.Timer(10000);
//_timer.Elapsed += CheckDocumentClosed;
//_timer.AutoReset = true;
//_timer.Enabled = true;
try
{
// 默认已经打开了文档 直接初始化
if (Application.Documents.Count > 0 && Application.ActiveDocument != null)
{
Logger.Debug("ThisAddIn_Startup 开始初始化当前文档");
ActiveDocument = documentList.InitDocument(Application.ActiveDocument);
// 直接初始化面板
// info.CheckPanel();
Logger.Debug("ThisAddIn_Startup 结束初始化当前文档");
}
}
catch (Exception ex)
{
Logger.Error("Initialize documentlist Error ", ex);
}
}
catch (Exception ex1)
{
Logger.Error("Startup Error",ex1);
Logger.Error("Startup Error", ex1);
}
}
@ -161,7 +181,7 @@ namespace AIProofread
}
catch (Exception ex)
{
Logger.Error("InitDeviceId Error:",ex);
Logger.Error("InitDeviceId Error:", ex);
}
});
}
@ -184,10 +204,16 @@ namespace AIProofread
for (int i = documentList.documentList.Count - 1; i >= 0; i--)
{
var item = documentList.documentList[i];
// 判断文档对象是否已经被移除
if (item.CurrentDocument == null)
{
documentList.Remove(item);
continue;
}
// 可能出现另存问题 所以需要更新文件名称
var oldName = item.fileName;
var currentName = item.CurrentDocument.FullName;
if(oldName != currentName)
if (oldName != currentName)
{
item.fileName = currentName;
}
@ -219,7 +245,7 @@ namespace AIProofread
}
catch (Exception ex)
{
Logger.Debug(ex.Message,ex);
Logger.Debug(ex.Message, ex);
}
//await System.Threading.Tasks.Task.Run(() =>
// {
@ -244,7 +270,7 @@ namespace AIProofread
}
catch (Exception ex)
{
Logger.Error("检测升级信息异常: ",ex);
Logger.Error("检测升级信息异常: ", ex);
}
});
}
@ -274,6 +300,7 @@ namespace AIProofread
// 启动地址
applicationStartupPath = System.Windows.Forms.Application.StartupPath;
Logger.Debug("applicationStartupPath --> " + applicationStartupPath);
// 判断是否是WPS
if (applicationStartupPath.Contains("WPS"))
{
@ -286,7 +313,7 @@ namespace AIProofread
}
catch (Exception ex)
{
Logger.Error("Init WPS Error ",ex);
Logger.Error("Init WPS Error ", ex);
}
}
string verTextFile = Config.APP_BASE_DIR + Path.GetFileName("app_version.txt");
@ -324,10 +351,10 @@ namespace AIProofread
);
}
Config.RUN_IN_DEBUG = config.AppRunInDebug;
if (Config.APP_ENV != AppEnvironment.Prod && this.ribbon != null)
{
this.ribbon.ShowDebug();
}
//if (Config.APP_ENV != AppEnvironment.Prod && this.ribbon != null)
//{
// this.ribbon.Ini();
//}
}
}
catch (Exception) { }
@ -335,20 +362,27 @@ namespace AIProofread
private void Application_DocumentChange()
{
// 检测是否存在打开的文档
if (CurrentWordApplication.Documents.Count == 0)
{
return;
}
//var document = CurrentWordApplication.ActiveDocument;
var document = CurrentWordApplication.ActiveDocument;
Logger.Debug("Application_DocumentChange -- " + document.Name + " 修订模式: is " + document.TrackRevisions);
// 设置当前文档
ActiveDocument = documentList.SetActiveDocument(CurrentWordApplication.ActiveDocument);
ActiveDocument = documentList.SetActiveDocument(document);
if (ActiveDocument == null)
{
return;
}
ActiveDocument.CheckBtnStatus();
CheckDocumentClosed(null, null);
if (formCommonsenseDetection != null) {
if (formCommonsenseDetection != null)
{
formCommonsenseDetection.SendMessageToWeb("document-change", null);
}
//LogHelper.Log("Application_DocumentChange -- " + ActiveDocument.fileName + " track is " + ActiveDocument.CurrentDocument.TrackRevisions);
//
}
public void SetActiveDocument(Document doc)
@ -373,10 +407,10 @@ namespace AIProofread
/// <param name="Wn"></param>
private void Application_WindowActivate(Document activeDoc, Window Wn)
{
if(activeDoc != null && (ActiveDocument == null || activeDoc != ActiveDocument.CurrentDocument))
Logger.Debug("Application_WindowActivate -- " + activeDoc.Name);
if (activeDoc != null && (ActiveDocument == null || activeDoc != ActiveDocument.CurrentDocument))
{
ActiveDocument = documentList.SetActiveDocument(activeDoc);
Logger.Info("Application_WindowActivate -- " + ActiveDocument.fileName);
documentList.SetActiveDocument(activeDoc);
}
//// 当前文档添加书签集合
//if (!allMarks.ContainsKey(activeDoc))
@ -455,16 +489,6 @@ namespace AIProofread
FmainThreadContext.Send(d, null);
}
//private void ProofreadPanel_SizeChanged(object sender, EventArgs e)
//{
// // 处理最小宽度
// if (customTaskPane != null && customTaskPane.Width < MinWidth && customTaskPane.Visible)
// {
// SendKeys.Send("{ESC}");
// customTaskPane.Width = MinWidth;
// }
//}
private void Application_WindowSelectionChange(Selection s)
{
ribbon.ParseSelectionChange(s);
@ -512,6 +536,7 @@ namespace AIProofread
// 显示面板
public void ShowPanel()
{
Logger.Debug("ShowPanel");
ActiveDocument?.ShowPane();
}

View File

@ -0,0 +1,42 @@
namespace AIProofread.core
{
public class AppModule
{
/// <summary>
/// 是否启用导出校对结果
/// </summary>
public const bool ENABLE_EXPORT_PROOFREAD_RESULT = true;
/// <summary>
/// 是否词库管理
/// </summary>
public const bool ENABLE_LEXICON_MANAGE = true;
/// <summary>
/// 是否启用常识性检测
/// </summary>
public const bool ENABLE_COMMONSENSE_CHECK = true;
/// <summary>
/// 设置功能
/// </summary>
public const bool ENABLE_SETTING = true;
/// <summary>
/// 是否校对功能
/// </summary>
public const bool ENABLE_PROOFREAD = true;
/// <summary>
/// 优先查全
/// </summary>
public const bool ENABLE_PROOFREAD_FULL = true;
/// <summary>
/// 优先查准exact
/// </summary>
public const bool ENABLE_PROOFREAD_EXACT = true;
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;
}
}