Compare commits

...

10 Commits

29 changed files with 779 additions and 203 deletions

Binary file not shown.

View File

@ -373,6 +373,7 @@
<Compile Include="core\CorrectionCharacter.cs" />
<Compile Include="core\CorrectionFragmentAbstract.cs" />
<Compile Include="core\CorrectionRangeAbstract.cs" />
<Compile Include="core\DocumentReader.cs" />
<Compile Include="core\DocumentText.cs" />
<Compile Include="core\DocumentUtil.cs" />
<Compile Include="core\EventForwarder.cs" />
@ -389,6 +390,7 @@
<Compile Include="Model\DocumentList.cs" />
<Compile Include="Model\ExportDataItem.cs" />
<Compile Include="Model\InsertMarkData.cs" />
<Compile Include="Model\ProofreadRangeInfo.cs" />
<Compile Include="ProofreadItem.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
@ -551,6 +553,15 @@
<ItemGroup>
<None Include="Resources\icon-ai-robot-wps.jpg" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\icon-manual.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\icon-manual-wps.jpg" />
</ItemGroup>
<ItemGroup>
<Content Include="favicon.ico" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
@ -578,6 +589,9 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>favicon.ico</ApplicationIcon>
</PropertyGroup>
<!-- Include the build rules for a C# project. -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Include additional build rules for an Office application add-in. -->

View File

@ -7,6 +7,8 @@ using Microsoft.Office.Tools.Word;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
using Newtonsoft.Json;
using NPOI;
using NPOI.SS.Formula;
using NPOI.XSSF.UserModel;
using NPOI.XWPF.UserModel;
using Org.BouncyCastle.Asn1.Crmf;
@ -45,7 +47,7 @@ namespace AIProofread
public static Dictionary<int, ProofreadItem> marks;
private static int selectProofreadId = -1;
//private static int selectProofreadId = -1;
private static object missing = System.Reflection.Missing.Value;
@ -245,6 +247,8 @@ namespace AIProofread
ProcessStartInfo processStartInfo = new ProcessStartInfo(Path.Combine(applicationBase, Path.GetFileName(path)))
{
WorkingDirectory = applicationBase,
UseShellExecute = true,
Verb="runas"
};
Process.Start(processStartInfo);
}
@ -335,12 +339,12 @@ namespace AIProofread
if (ShouldUpgradeForced())
{
data.Add("code", 2);
data.Add("message", "请升级插件后再进行校对");
data.Add("message", "请升级插件后再进行校对");
}
else if (doc.ProtectionType != WdProtectionType.wdNoProtection)
{
data.Add("code", 3);
data.Add("message", "文档受保护,无法编辑");
data.Add("message", "文档受保护,请另存文档后再进行校对");
}
else if (doc.ReadOnly)
{
@ -368,7 +372,22 @@ namespace AIProofread
data.Add("documentId", GeIdBytDocument(doc));
data.Add("wordsCount", doc.Words.Count);
data.Add("charactersCount", doc.Characters.Count);
data.Add("content", Tools.GetAllText(doc));
try
{
data.Add("content", Tools.GetAllText(doc));
}
catch (POIXMLException ex)
{
Logger.Log(ex);
data["code"] = 5;
data["message"] = "文档格式有误,请另存文档后再进行校对";
}
catch (Exception ex)
{
Logger.Log(ex);
throw ex;
}
//if (loadingDialog != null && !loadingDialog.IsDisposed)
//{
// loadingDialog.Close();
@ -377,6 +396,22 @@ namespace AIProofread
return Tools.GetJSONString(data);
}
public string GetDocumentInfo(int documentId)
{
Dictionary<string, object> data = new Dictionary<string, object>();
var documentInfo = documentId > 0 ? Globals.ThisAddIn.GetDocumentById(documentId) : Globals.ThisAddIn.ActiveDocument;
var doc = documentInfo.CurrentDocument;
data.Add("code", 0);
data.Add("message", "success");
data.Add("name", doc.Name);
//data.Add("documentId", Globals.ThisAddIn.ActiveDocument.Id);
data.Add("fullName", doc.FullName);
data.Add("documentId", GeIdBytDocument(doc));
data.Add("wordsCount", doc.Words.Count);
data.Add("charactersCount", doc.Characters.Count);
return Tools.GetJSONString(data);
}
/// <summary>
/// 根据位置获取文档区域文本
/// </summary>
@ -514,11 +549,21 @@ namespace AIProofread
public void ClearCurrentDocumentMarks() => Globals.ThisAddIn.ActiveDocument?.ClearAllProofreadMark();
public void removeBookmark(string markId) => DocumentUtil.RemoveBookmark(markId);
/// <summary>
/// 获取设备ID
/// </summary>
/// <returns></returns>
public string GetDeviceId()
{
return Config.DeviceId;
}
/// <summary>
/// 设置帮助文档地址
/// </summary>
/// <param name="url"></param>
public void SetHelpUrl(string url) => Config.USER_MANUAL_URL = url;
public string getAllBookmark()
{
return ToJSON(DocumentUtil.GetAllBookmark());
@ -715,15 +760,16 @@ namespace AIProofread
/// 导出勘误表
/// </summary>
/// <returns></returns>
public string ExportProofreadResult()
public string ExportProofreadResult(string modelType)
{
try
{
Globals.ThisAddIn.ActiveDocument.ExportResult();
Globals.ThisAddIn.ActiveDocument.ExportResult(modelType);
return BridgeResult.Success();
}
catch (Exception ex)
{
Logger.Log("导出勘误表失败:" + ex.Message + "\n" + ex.StackTrace + "\n\n");
return BridgeResult.Error(-1, ex.Message);
}
}
@ -747,6 +793,11 @@ namespace AIProofread
Globals.ThisAddIn.ActiveDocument.FocusToPanel();
}
public string GetProofreadOriginData()
{
return Tools.GetJSONString(Globals.ThisAddIn.ActiveDocument.GetProofreadOriginData());
}
public string SaveCache(int documentId, string cache, bool silent)
{
var document = Globals.ThisAddIn.GetDocumentById(documentId);
@ -833,12 +884,13 @@ namespace AIProofread
return BridgeResult.Success(result == DialogResult.Yes ? "yes" : "no");
}
public string InitProofreadCacheList(string content)
public string InitProofreadCacheList(string content,string originData)
{
try
{
List<CorrectContext> list = JsonConvert.DeserializeObject<List<CorrectContext>>(content);
Globals.ThisAddIn.InitProofreadCacheList(list);
Dictionary<int,ProofreadRangeInfo> dics = string.IsNullOrEmpty(originData) ? null : JsonConvert.DeserializeObject<Dictionary<int, ProofreadRangeInfo>>(originData);
Globals.ThisAddIn.InitProofreadCacheList(list, dics);
return BridgeResult.Success();
}
catch (Exception ex)

View File

@ -12,15 +12,16 @@ namespace AIProofread
public class Config
{
public static readonly string APP_NAME = "AI校对王";
public static readonly string APP_VERSION = "2.1.1";
public static readonly string APP_VERSION = "2.2.2";
public static bool IS_WPS = false;
public static bool UpgradeForcedNotice = false;
public static readonly string APP_BASE_DIR = AppDomain.CurrentDomain.BaseDirectory;
public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.json";
public static string USER_MANUAL_URL = "https://aiprhelp.guomai.cn/";
/// <summary>
/// 文本背景色
/// </summary>
public static readonly string TextBackgroundColor = "#D6AA69";
public static readonly string TextBackgroundColor = "#E9DABB"; // e9dabb D6AA69
public static string DeviceId = "";
#if DEBUG
/// <summary>

View File

@ -40,7 +40,7 @@
this.WebViewContact.Dock = System.Windows.Forms.DockStyle.Fill;
this.WebViewContact.Location = new System.Drawing.Point(0, 0);
this.WebViewContact.Name = "WebViewContact";
this.WebViewContact.Size = new System.Drawing.Size(380, 216);
this.WebViewContact.Size = new System.Drawing.Size(620, 450);
this.WebViewContact.TabIndex = 0;
this.WebViewContact.ZoomFactor = 1D;
//
@ -48,7 +48,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(380, 216);
this.ClientSize = new System.Drawing.Size(620, 450);
this.Controls.Add(this.WebViewContact);
this.Name = "FormContact";
this.ShowIcon = false;

View File

@ -4,12 +4,15 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AIProofread.Controls
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public partial class FormContact : BaseWinForm
{
public FormContact()

View File

@ -5,7 +5,7 @@ namespace AIProofread.Controls
{
public partial class FormLogger : Form
{
private ListView LogListView;
private ListView LogListView = new ListView();
public FormLogger()
{

View File

@ -31,7 +31,8 @@ namespace AIProofread.Controls
private void FormLogin_Load(object sender, EventArgs e)
{
//this.web.Source = new Uri(Config.WebPath("#login"));
InitWebView(web, Config.WebPath("login?action=" + this.action), "login");
var r = new FormLogin();
InitWebView(web, Config.WebPath("login?action=" + this.action + "&version=" + Config.APP_VERSION + "&t=" + DateTime.Now.Ticks), "login");
}

View File

@ -23,7 +23,6 @@ namespace AIProofread
if (LoggerForm != null && !LoggerForm.IsDisposed && LoggerForm.Visible)
{
LoggerForm.Log(time, tag, message);
return;
}
string path = Config.APP_LOG_PATH + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
if (!Directory.Exists(Config.APP_LOG_PATH))
@ -41,7 +40,7 @@ namespace AIProofread
streamWriter.Close();
streamWriter.Dispose();
}
catch (Exception e) { }
catch (Exception) { }
}
public static void Log(string msg)
{

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using AIProofread.Controls;
@ -158,7 +159,7 @@ namespace AIProofread.Model
private void ShowDocumentStatus(string tag)
{
Logger.Log($"{fileName} {tag} PaneVisible is {PaneVisible} Poofread is {Proofread} Proofreading is {Proofreading}");
// Logger.Log($"{fileName} {tag} PaneVisible is {PaneVisible} Poofread is {Proofread} Proofreading is {Proofreading}");
}
/// <summary>
@ -211,6 +212,13 @@ namespace AIProofread.Model
{
try
{
// 释放com
try
{
Marshal.ReleaseComObject(CurrentDocument);
}
catch (Exception) { }
if(TaskPane.Control.IsDisposed) return;
ProofreadMainControl control = (ProofreadMainControl)TaskPane.Control;
control.ResetWeb();
@ -604,9 +612,13 @@ namespace AIProofread.Model
//object goNext = WdGoToDirection.wdGoToNext;
//Globals.ThisAddIn.Application.ActiveWindow.Selection.GoTo(ref goToLine, ref goNext, ref lineNum);
//
object bookmark = WdGoToItem.wdGoToBookmark;
object bookmarkName = mark.Name;
Globals.ThisAddIn.Application.ActiveWindow.Selection.GoTo(ref bookmark, ref missing, ref missing, ref bookmarkName);
//object bookmark = WdGoToItem.wdGoToBookmark;
//object bookmarkName = mark.Name;
var targetRange = mark.Range;
// 选中
targetRange.Select();
Globals.ThisAddIn.Application.ActiveWindow.ScrollIntoView(targetRange);//.Selection.GoTo(ref bookmark, ref missing, ref missing, ref bookmarkName);
//
//mark.DisableCharacterSpaceGrid = false;
// 先滚动到可视区域
@ -642,7 +654,7 @@ namespace AIProofread.Model
foreach (var item in correct.CorrectItems)
{
if (marks.ContainsKey(item.Id)) continue;
Logger.Log(string.Format("mark type {0} data {1}->{2}", item.Tag, item.Origin, item.Text));
// Logger.Log(string.Format("mark type {0} data {1}->{2}", item.Tag, item.Origin, item.Text));
int _prev = prevOffset;
bool isDisabled = false;
// 判断查找内容是否在原始数据中,否则直跳过
@ -745,7 +757,7 @@ namespace AIProofread.Model
}
public void InitProofreadCache(List<CorrectContext> list)
public void InitProofreadCache(List<CorrectContext> list,Dictionary<int, ProofreadRangeInfo> itemInfoDic)
{
marks.Clear();
@ -757,6 +769,19 @@ namespace AIProofread.Model
if (mark != null)
{
var pi = new ProofreadItem(item, correct.Insert, mark, Id);
// 是否存在样式信息
if (itemInfoDic!= null && itemInfoDic.ContainsKey(item.Id))
{
// 获取样式信息并还原
var info = itemInfoDic[item.Id];
try
{
pi.originColor = info.Color;
pi.originBackgroundColor = info.Background;
pi.originSize = info.Size;
}
catch (Exception ex) { Logger.Log(ex); }
}
marks.Add(item.Id, pi);
}
});
@ -870,7 +895,7 @@ namespace AIProofread.Model
TaskPane.Control.Focus();
}
internal void Close()
public void Close()
{
try
{
@ -878,7 +903,8 @@ namespace AIProofread.Model
marks.Clear();
// 清除区域相关数据
ranges.Clear();
TaskPane.Dispose();
// TaskPane.Dispose();
this.Dispose();
}
catch (Exception ex)
{
@ -886,15 +912,15 @@ namespace AIProofread.Model
}
}
public void ExportResult()
public void ExportResult(string modelType)
{
TaskPane.Control.BeginInvoke(new Action(() =>
{
DocumentUtil.ExportProofreadResult();
DocumentUtil.ExportProofreadResult(modelType);
}));
}
internal void ShowUpgrade(string data, bool force)
public void ShowUpgrade(string data, bool force)
{
TaskPane.Control.BeginInvoke(new Action(() =>
{
@ -904,6 +930,7 @@ namespace AIProofread.Model
if (force)
{
// 已经强制更新但被忽略过则不再提示
if (Config.UpgradeForcedNotice) return;
var result = MessageBox.Show(upgradeData.Message, "是否确认更新", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
@ -971,5 +998,31 @@ namespace AIProofread.Model
}
}));
}
public Dictionary<int, ProofreadRangeInfo> GetProofreadOriginData()
{
Dictionary<int,ProofreadRangeInfo> dic = new Dictionary<int, ProofreadRangeInfo>();
// 变量文档所有marks 记录mark对应range的背景、大小、颜色
foreach (var item in marks)
{
if (item.Value.mark != null)
{
// 添加到数据
dic.Add(item.Key, new ProofreadRangeInfo()
{
Background = item.Value.originBackgroundColor,
Color = item.Value.originColor,
Size = item.Value.originSize
});
}
}
return dic;
}
internal void CheckPanel()
{
Logger.Log(CurrentDocument.FullName + $" TaskPane visible {PaneVisible} has " + (TaskPane == null ? "null" : "exists"));
if (TaskPane == null) CreateTaskPane();
}
}
}

View File

@ -1,5 +1,7 @@
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using UtilLib;
@ -30,6 +32,25 @@ namespace AIProofread.Model
{
return sentence;
}
// 截取中间位置
try
{
var middlePosition = MAX_WORD_LENGTH / 2;
var cutStart = item.content.Start - middlePosition;
// 越界了
if (cutStart < 0)
{
cutStart = 0;
}
var originText = sentence.Substring(cutStart, Math.Min(sentence.Length, MAX_WORD_LENGTH));
if (!isInsert)
{
item.content.Start = item.content.Start - cutStart;
item.content.End = item.content.End - cutStart;
return originText;
}
}
catch (Exception ex) { Logger.Log(ex); }
var range = item.mark.Range;
// 获取range所在句子
@ -50,6 +71,7 @@ namespace AIProofread.Model
}
}
var first = sentences.First;
// 内容位置:用于后续标红
item.content.Start = range.Start - first.Start;
item.content.End = range.End - first.Start;
return sb.ToString().Trim();

View File

@ -0,0 +1,11 @@
using Microsoft.Office.Interop.Word;
namespace AIProofread.Model
{
public class ProofreadRangeInfo
{
public float Size { get; set; }
public WdColor Background { get; set; }
public WdColor Color { get; set; }
}
}

View File

@ -14,13 +14,13 @@ namespace UtilLib
public Bookmark mark;
public string OriginSentence { get; set; }
public CorrectItem content;
private float originSize;
private WdColor originColor;
private WdColor originBackgroundColor;
public float originSize;
public WdColor originColor;
public WdColor originBackgroundColor;
public string Name { get; set; }
public int DocumentId { get; set; }
public ProofreadItem(CorrectItem content,string originSentence,int documentId)
public ProofreadItem(CorrectItem content, string originSentence, int documentId)
{
this.content = content;
this.DocumentId = documentId;
@ -76,7 +76,7 @@ namespace UtilLib
private void OnMarkSelected(object sender, Microsoft.Office.Tools.Word.SelectionEventArgs e)
{
//throw new System.NotImplementedException();
Bridge.bridge.SelectMarkById(content.Id,DocumentId);
Bridge.bridge.SelectMarkById(content.Id, DocumentId);
}
public void Select()
@ -134,6 +134,33 @@ namespace UtilLib
Logger.Log(e);
}
}
private void PrepareCommentProcess(Bookmark mark)
{
var doc = Globals.ThisAddIn.Application.ActiveDocument;
var fullRange = doc.Range();
var range = mark.Range;
var checkRange = doc.Range(
Math.Max(range.Start - 2, fullRange.Start),
Math.Min(range.End + 2, fullRange.End)
);
var comments = checkRange.Comments;
// 判断当前书签选区内容是否有评论
if (comments != null && comments.Count > 0)
{
Logger.Log("有批注");
foreach (Microsoft.Office.Interop.Word.Comment item in comments)
{
// 判断当前评论和书签选区是否一致
if (item.Scope.Start == range.Start && item.Scope.End == range.End)
{
Logger.Log("删除批注:" + item.Range.Text);
// 删除评论
item.Delete();
}
}
}
}
/// <summary>
/// 处理校对项
@ -148,6 +175,7 @@ namespace UtilLib
// 采纳
if (status == AcceptStatus.Accept)
{
PrepareCommentProcess(mark);
if (content.Tag == "r" || content.Tag == "i")
{
mark.Text = content.Text;
@ -194,12 +222,20 @@ namespace UtilLib
// 判断书签范围内是否有批注
if (rng.Text?.IndexOf("%") != -1 && rng.Comments != null && rng.Comments.Count > 0)
if (rng.Text?.IndexOf("%") != -1)
{
for (var i = 1; i < rng.Comments.Count; i++)
Logger.Log($"处理百分号问题:有批注");
if (rng.Comments != null && rng.Comments.Count > 0)
{
var comment = rng.Comments[i];
comment.Scope.Text = comment.Scope.Text.Replace("%", "");
for (var i = 1; i < rng.Comments.Count; i++)
{
var comment = rng.Comments[i];
comment.Scope.Text = comment.Scope.Text.Replace("%", "");
}
}
else
{
rng.Text = rng.Text.Replace("%", "");
}
}
}

View File

@ -7,11 +7,11 @@ using System.Security;
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AI校对王")]
[assembly: AssemblyDescription("AI校对王 2.1.0")]
[assembly: AssemblyDescription("AI校对王 2.2.1")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("果麦文化")]
[assembly: AssemblyProduct("AI校对王 2.1.0")]
[assembly: AssemblyCopyright("Copyright © GuoMai 2024")]
[assembly: AssemblyCompany("果麦文化传媒股份有限公司")]
[assembly: AssemblyProduct("AI校对王 2.2.1")]
[assembly: AssemblyCopyright("Copyright © 果麦文化传媒股份有限公司 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -34,5 +34,5 @@ using System.Security;
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.2.1.0")]

View File

@ -230,6 +230,26 @@ namespace AIProofread.Properties {
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap icon_manual {
get {
object obj = ResourceManager.GetObject("icon-manual", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap icon_manual_wps {
get {
object obj = ResourceManager.GetObject("icon-manual-wps", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>

View File

@ -136,6 +136,9 @@
<data name="icon-history" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-history.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-proofread" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-phone" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-phone.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@ -178,11 +181,14 @@
<data name="favicon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\favicon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-ai-robot-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-ai-robot-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-refresh-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-refresh-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-clear" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-export" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="button_default" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\button_default.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
@ -196,11 +202,14 @@
<data name="logo_no_text" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_no_text.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-ai-robot" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-ai-robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="logo_wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-export" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-clear" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-phone-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-phone-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
@ -208,9 +217,6 @@
<data name="icon-history-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-history-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-panel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="logo_no_text_wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@ -220,13 +226,13 @@
<data name="icon_close" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon_close.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-proofread" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-panel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-ai-robot" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-ai-robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-manual" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-manual.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-ai-robot-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-ai-robot-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-manual-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-manual-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

@ -42,6 +42,9 @@ namespace AIProofread
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();
this.BtnExportProofreadResult = this.Factory.CreateRibbonButton();
this.btnClear = this.Factory.CreateRibbonButton();
this.btnOpenLexicon = this.Factory.CreateRibbonButton();
@ -62,6 +65,7 @@ namespace AIProofread
this.LblNickname = this.Factory.CreateRibbonLabel();
this.group2 = this.Factory.CreateRibbonGroup();
this.BtnShowPanel = this.Factory.CreateRibbonButton();
this.BtnShowManual = this.Factory.CreateRibbonButton();
this.grpDebug = this.Factory.CreateRibbonGroup();
this.btnShowPane = this.Factory.CreateRibbonButton();
this.btnHidePane = this.Factory.CreateRibbonButton();
@ -94,6 +98,7 @@ 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);
this.group1.Items.Add(this.btnOpenLexicon);
@ -108,8 +113,34 @@ namespace AIProofread
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);
this.menuProofreadList.Label = "全文校对\r\n";
this.menuProofreadList.Name = "menuProofreadList";
this.menuProofreadList.ShowImage = true;
//
// BtnProofreadExact
//
this.BtnProofreadExact.Label = "优先查准";
this.BtnProofreadExact.Name = "BtnProofreadExact";
this.BtnProofreadExact.ShowImage = true;
this.BtnProofreadExact.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnProofreadExact_Click);
//
// BtnProofreadFull
//
this.BtnProofreadFull.Label = "优先查全";
this.BtnProofreadFull.Name = "BtnProofreadFull";
this.BtnProofreadFull.ShowImage = true;
this.BtnProofreadFull.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnProofreadFull_Click);
//
// BtnExportProofreadResult
//
this.BtnExportProofreadResult.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
@ -265,6 +296,7 @@ namespace AIProofread
// group2
//
this.group2.Items.Add(this.BtnShowPanel);
this.group2.Items.Add(this.BtnShowManual);
this.group2.Name = "group2";
//
// BtnShowPanel
@ -276,6 +308,15 @@ namespace AIProofread
this.BtnShowPanel.ShowImage = true;
this.BtnShowPanel.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnShowPanel_Click);
//
// BtnShowManual
//
this.BtnShowManual.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.BtnShowManual.Image = global::AIProofread.Properties.Resources.icon_manual;
this.BtnShowManual.Label = "用户手册\r\n";
this.BtnShowManual.Name = "BtnShowManual";
this.BtnShowManual.ShowImage = true;
this.BtnShowManual.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.BtnShowManual_Click);
//
// grpDebug
//
this.grpDebug.Items.Add(this.btnShowPane);
@ -407,6 +448,10 @@ namespace AIProofread
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionAll;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionParagraph;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionHistory;
internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnShowManual;
internal Microsoft.Office.Tools.Ribbon.RibbonMenu menuProofreadList;
internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnProofreadExact;
internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnProofreadFull;
}
partial class ThisRibbonCollection

View File

@ -11,13 +11,13 @@ using System.Text;
using AIProofread.core;
using System.Windows.Forms;
using AIProofread.Properties;
using System.Security.Policy;
namespace AIProofread
{
public partial class Ribbon1
{
private bool IS_LOGIN = false;
private static bool IS_WPS = false;
private Userinfo currentLoginUserinfo;
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
@ -42,7 +42,9 @@ namespace AIProofread
public void SetCommonBtnStatus(bool status)
{
BtnProofreadAll.Enabled = status;
// BtnProofreadAll.Enabled = status;
menuProofreadList.Enabled = status;
btnClear.Enabled = status;
btnOpenLexicon.Enabled = status;
btnSetting.Enabled = status;
@ -68,6 +70,7 @@ namespace AIProofread
else if (key == "disable-by-upgrade")
{
SetCommonBtnStatus(status);
BtnUpdate.Enabled = true;
BtnShowPanel.Enabled = status;
}
}
@ -77,9 +80,9 @@ namespace AIProofread
/// </summary>
public void InitWPS()
{
IS_WPS = true;
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;
btnSetting.Image = AIProofread.Properties.Resources.icon_setting_wps;
@ -95,6 +98,7 @@ namespace AIProofread
BtnShowPanel.Image = AIProofread.Properties.Resources.icon_panel_wps;
// 导出校对结果
BtnExportProofreadResult.Image = AIProofread.Properties.Resources.icon_export_wps;
BtnShowManual.Image = AIProofread.Properties.Resources.icon_manual_wps;
}
public void ProcessLoginInfo(Userinfo userinfo)
@ -181,7 +185,11 @@ namespace AIProofread
private void BtnGetContact_Click(object sender, RibbonControlEventArgs e)
{
(new FormContact()).ShowDialog();
var frm = new FormContact();
Globals.ThisAddIn.ActiveDocument.RunInMainThread(() =>
{
frm.ShowDialog();
});
}
private void BtnUpdate_Click(object sender, RibbonControlEventArgs e)
@ -608,5 +616,28 @@ namespace AIProofread
btnDetectionAll.Enabled = allStatus;
btnDetectionParagraph.Enabled = rangeStatus;
}
private void BtnShowManual_Click(object sender, RibbonControlEventArgs e)
{
try
{
Process.Start(Config.USER_MANUAL_URL);
}catch (Exception) {
Globals.ThisAddIn.ActiveDocument.ShowMessage("打开用户手册失败", 2000, false);
}
}
private void BtnProofreadExact_Click(object sender, RibbonControlEventArgs e)
{
//
Globals.ThisAddIn.ActiveDocument.CheckPanel();
Globals.ThisAddIn.SendMessageToWeb("start", "exact");
}
private void BtnProofreadFull_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.ActiveDocument.CheckPanel();
Globals.ThisAddIn.SendMessageToWeb("start", "full");
}
}
}

View File

@ -117,22 +117,118 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="tabAIProofread.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<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>
<metadata name="BtnProofreadExact.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnProofreadFull.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnExportProofreadResult.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnClear.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnOpenLexicon.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="menuSencenDect.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnDetectionAll.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnDetectionParagraph.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnDetectionHistory.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnSetting.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Group.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ButtonSaveCache.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ButtonLoadCache.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="grpOther.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnGetContact.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnUpdate.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnLogin.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnLogout.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="LblDate.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="LblNickname.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="group2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnShowPanel.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnShowManual.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="grpDebug.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnShowPane.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btnHidePane.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnOpenLog.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="button1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnOpenLogger.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnTest.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnOpenAppDir.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="BtnShowVersion.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="dropDown1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -10,6 +10,7 @@ using AIProofread.Model;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Text;
//using CustomTaskPane = Microsoft.Office.Core.CustomTaskPane;
//using CustomTaskPane = Microsoft.Office.Tools.CustomTaskPane;
//using NPOI.SS.Formula.Functions;
@ -92,9 +93,9 @@ namespace AIProofread
formCommonsenseDetection = null;
}
private void ProcessApplicationException(object sender,UnhandledExceptionEventArgs e)
private void ProcessApplicationException(object sender, UnhandledExceptionEventArgs e)
{
Logger.Log("UnhandledException",e.ExceptionObject as Exception);
Logger.Log("UnhandledException", e.ExceptionObject as Exception);
}
private void ProcessApplicationFormException(object sender, System.Threading.ThreadExceptionEventArgs e)
@ -122,8 +123,8 @@ namespace AIProofread
Application.WindowActivate += Application_WindowActivate;
//Application.WindowDeactivate += Application_WindowDeactivate;
Application.DocumentBeforeSave += Application_DocumentBeforeSave; ;
Application.DocumentBeforeSave += Application_DocumentBeforeSave;
(Application as ApplicationEvents4_Event).NewDocument += Application_NewDocument;
Application.DocumentChange += Application_DocumentChange;
// 选区发生变化事件
@ -139,7 +140,7 @@ namespace AIProofread
}
catch (Exception ex1)
{
Logger.Log("Startup", ex1.ToString());
Logger.Log("Startup Error" + ex1.ToString());
}
}
@ -163,33 +164,59 @@ namespace AIProofread
}
catch (Exception ex)
{
Logger.Log("InitDeviceId", ex.ToString());
Logger.Log("InitDeviceId Error:" + ex.ToString());
}
});
}
public void CheckDocumentClosed(object sender, System.Timers.ElapsedEventArgs e)
{
var existsList = new List<string>();
//Logger.Log("检测文档是否关闭 ...");
try
{
if (documentList.Count == 0 || CurrentWordApplication.Documents.Count == documentList.Count) return;
var docList = CurrentWordApplication.Documents;
if (documentList.Count == 0 || docList.Count == existsList.Count) return;
existsList.Clear();
foreach (Document item in CurrentWordApplication.Documents)
foreach (Document item in docList)
{
existsList.Add(item.FullName);
}
// 检测文档是否关闭
foreach (var item in documentList.documentList)
for (int i = documentList.documentList.Count - 1; i >= 0; i--)
{
if (!existsList.Contains(item.fileName))
var item = documentList.documentList[i];
// 可能出现另存问题 所以需要更新文件名称
var oldName = item.fileName;
var currentName = item.CurrentDocument.FullName;
if(oldName != currentName)
{
Logger.Log("检测到文档关闭,已移除:" + item.fileName);
documentList.Remove(item);
item.fileName = currentName;
}
if (!existsList.Contains(currentName))
{
Logger.Log("检测到文档关闭,已移除:" + currentName);
try
{
item.RunInMainThread(() =>
{
item.Dispose();
});
}
catch (Exception ext)
{
Logger.Log(ext);
}
try
{
documentList.Remove(item);
}
catch (Exception ext)
{
Logger.Log(ext);
}
}
}
}
@ -320,6 +347,7 @@ namespace AIProofread
// 设置当前文档
ActiveDocument = documentList.SetActiveDocument(CurrentWordApplication.ActiveDocument);
ActiveDocument.CheckBtnStatus();
CheckDocumentClosed(null, null);
Logger.Log("Application_DocumentChange -- " + ActiveDocument.fileName);
}
@ -378,6 +406,11 @@ namespace AIProofread
/// <param name="Cancel"></param>
private void Application_DocumentBeforeClose(Document currentDoc, ref bool Cancel)
{
var doc = documentList.Get(currentDoc);
if (doc != null)
{
doc.HidePane();
}
Logger.Log("DocumentBeforeClose", currentDoc.FullName);
//if (allMarks.ContainsKey(currentDoc))
//{
@ -400,12 +433,12 @@ namespace AIProofread
private void Application_NewDocument(Document doc)
{
Logger.Log("NewDocument", doc.Name);
Logger.Log("NewDocument" + doc.Name);
}
private void Application_DocumentOpen(Document doc)
{
Logger.Log("DocumentOpen", doc.Name);
Logger.Log("DocumentOpen " + doc.Name);
}
@ -531,7 +564,7 @@ namespace AIProofread
System.Windows.Forms.Application.ThreadException -= ProcessApplicationFormException;
Logger.Log("shutdown");
documentList.Clear();
if(_timer != null)
if (_timer != null)
{
_timer.Stop();
}
@ -563,7 +596,7 @@ namespace AIProofread
public DocumentInfo GetDocumentById(int id)
{
return documentList.GetById(id);
return id <= 0 ? ActiveDocument : documentList.GetById(id);
}
@ -586,8 +619,8 @@ namespace AIProofread
}
//public string LoadCacheByPath()
//{
//public string LoadCacheByPath()
//{
//}
@ -603,15 +636,15 @@ namespace AIProofread
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
public void InitProofreadCacheList(System.Collections.Generic.List<CorrectContext> list)
public void InitProofreadCacheList(List<CorrectContext> list, Dictionary<int, ProofreadRangeInfo> dics)
{
ActiveDocument?.InitProofreadCache(list);
ActiveDocument?.InitProofreadCache(list, dics);
}
#endregion

View File

@ -0,0 +1,76 @@
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System;
using Word = Microsoft.Office.Interop.Word;
using System.Collections.Generic;
namespace AIProofread.core
{
public class ProcessingContext
{
public Word.Range Range { get; set; }
public int GlobalIndex { get; set; }
}
public class DocumentReader
{
private static readonly Stack<ProcessingContext> _processingStack = new Stack<ProcessingContext>();
public static List<DocumentText> ReadByVSTO(Word.Document _doc, Word.Application _app, List<DocumentText> list)
{
//List<DocumentText> list = new List<DocumentText>();
try
{
// 关闭屏幕更新
_app.ScreenUpdating = false;
// 初始化堆栈:处理所有顶级 StoryRanges
foreach (Word.Range storyRange in _doc.StoryRanges)
{
_processingStack.Push(new ProcessingContext
{
Range = storyRange,
GlobalIndex = 0,
});
}
// 迭代处理堆栈中的每个 Range
while (_processingStack.Count > 0)
{
var context = _processingStack.Pop();
ProcessElement(context.Range, context.GlobalIndex, list);
Marshal.ReleaseComObject(context.Range);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
_app.ScreenUpdating = true;
Marshal.ReleaseComObject(_doc);
}
return list;
}
private static void ProcessElement(Word.Range range, int globalIndex, List<DocumentText> list)
{
if (range.Text?.Trim() == "\r\a")
{
globalIndex++;
return;
}
var paragraphs = range.Paragraphs;
// Debug.WriteLine($"Processing element: {range.Text}");
// 处理段落
foreach (Word.Paragraph paragraph in paragraphs)
{
list.Add(new DocumentText
{
Text = paragraph.Range.Text,
ParagraphNumber = globalIndex + 1
});
Marshal.ReleaseComObject(paragraph);
globalIndex++;
}
}
}
}

View File

@ -112,6 +112,12 @@ namespace AIProofread
//mark.Range.Underline = WdUnderline.wdUnderlineNone;
try
{
// feat(20250305): 清除批注的时候,如果监测到书签位置是空格,把空格给删了吧(无缓冲记录时)
string text = mark.Range.Text;
if (text != null && text.Trim().Length == 0)
{
mark.Range.Text = "";
}
mark.Delete();
}
catch (Exception e)
@ -571,14 +577,15 @@ namespace AIProofread
}
public static void ExportProofreadResult()
public static void ExportProofreadResult(string modelType)
{
string currentName = Globals.ThisAddIn.Application.ActiveDocument.Name;
// 去掉文件名后缀
currentName = currentName.Substring(0, currentName.LastIndexOf("."));
SaveFileDialog sfd = new SaveFileDialog();
modelType = modelType == "full" ? "查全" : "查准";
// 设置默认文件名
sfd.FileName = currentName + "_勘误表.xlsx";
sfd.FileName = currentName + $"_勘误表_优先{modelType}.xlsx";
sfd.Filter = "Excel文件|*.xlsx";
var result = sfd.ShowDialog();
// 如果用户取消选择,则返回
@ -593,7 +600,7 @@ namespace AIProofread
// 判断原始文件是否可以删除
if (File.GetAttributes(sfd.FileName).HasFlag(FileAttributes.ReadOnly))
{
Globals.ThisAddIn.ShowDialog("已经存在名勘误表文件,请更换名称或手动删除", null, null);
Globals.ThisAddIn.ShowDialog("已经存在名勘误表文件,请更换名称或手动删除", null, null);
return;
}
// 删除文件 重新写入新数据避免出现未知不可控bug
@ -841,6 +848,10 @@ namespace AIProofread
{
tag = "黑名单";
}
else if(it.Type == "fallen_officers")
{
tag = "落马官员";
}
else if (it.Tag == "i")
{
startIndex = it.Text.Length + 1;

View File

@ -1,11 +1,14 @@
using Microsoft.Office.Interop.Word;
using AIProofread.core;
using Microsoft.Office.Interop.Word;
using Newtonsoft.Json;
using NPOI;
using NPOI.POIFS.FileSystem;
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace AIProofread
@ -36,55 +39,25 @@ namespace AIProofread
// 获取当前文档所有文本
string allText = doc.Range().Text;
List<DocumentText> list = new List<DocumentText>();
//DocumentReader.ReadByVSTO(doc, Globals.ThisAddIn.Application, list);
using (FileStream stream = new FileStream(docPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
XWPFDocument ndoc = new XWPFDocument(stream);
var paragraphs = ndoc.Paragraphs;
int paragraphNumber = 1;
foreach (var bodyElement in ndoc.BodyElements)
{
// normal paragraph
if (bodyElement is XWPFParagraph p)
{
// 处理普通段落
list.Add(new DocumentText(p.ParagraphText.Replace("\u0002", ""), paragraphNumber));
paragraphNumber++;
}
// table -- vsto对于每个单元格的分段也会有
else if (bodyElement is XWPFTable table)
{
foreach (var row in table.Rows)
{
foreach (var cell in row.GetTableCells())
{
foreach (var pc in cell.Paragraphs)
{
list.Add(new DocumentText(pc.ParagraphText.Replace("\u0002", ""), paragraphNumber));
paragraphNumber++;
}
}
//list.Add(string.Empty);
paragraphNumber++;
}
}
// 目录处理
else if (bodyElement is XWPFSDT sdt)
{
string tocText = sdt.Content.Text;
// 如果需要,可以进一步解析目录项// 例如,按换行符拆分目录内容
var tocEntries = tocText.Split(new string[] { "\n", "\r", "\r\n", "\f" }, StringSplitOptions.None);
foreach (string entry in tocEntries)
{
list.Add(new DocumentText(entry.Replace("\u0002", ""), paragraphNumber));
paragraphNumber++;
}
}
}
ReadTextByNPOI(stream, list);
//try
//{
//}
//catch (POIXMLException npoiError)
//{
// Logger.Log("GetAllText Error", npoiError);
// // Logger.Log("GetAllText", e);
// // return GetAllTextByVSTO(doc);
// // 读取文档
// DocumentReader.ReadByVSTO(doc, Globals.ThisAddIn.Application, list);
//}
}
Debug.WriteLine("GetAllText End ==>", DateTime.Now.ToLongTimeString());
var map = new Dictionary<string, object>
{
{ "list", list },
@ -95,6 +68,55 @@ namespace AIProofread
return map;
}
private static void ReadTextByNPOI(FileStream stream, List<DocumentText> list)
{
XWPFDocument ndoc = new XWPFDocument(stream);
var paragraphs = ndoc.Paragraphs;
int paragraphNumber = 1;
foreach (var bodyElement in ndoc.BodyElements)
{
// normal paragraph
if (bodyElement is XWPFParagraph p)
{
// 处理普通段落
list.Add(new DocumentText(p.ParagraphText.Replace("\u0002", ""), paragraphNumber));
paragraphNumber++;
}
// table -- vsto对于每个单元格的分段也会有
else if (bodyElement is XWPFTable table)
{
foreach (var row in table.Rows)
{
foreach (var cell in row.GetTableCells())
{
foreach (var pc in cell.Paragraphs)
{
list.Add(new DocumentText(pc.ParagraphText.Replace("\u0002", ""), paragraphNumber));
paragraphNumber++;
}
}
//list.Add(string.Empty);
paragraphNumber++;
}
}
// 目录处理
else if (bodyElement is XWPFSDT sdt)
{
string tocText = sdt.Content.Text;
// 如果需要,可以进一步解析目录项// 例如,按换行符拆分目录内容
var tocEntries = tocText.Split(new string[] { "\n", "\r", "\r\n", "\f" }, StringSplitOptions.None);
paragraphNumber+= tocEntries.Length;
// 暂时跳过目录
//foreach (string entry in tocEntries)
//{
// list.Add(new DocumentText(entry.Replace("\u0002", ""), paragraphNumber));
// paragraphNumber++;
//}
}
}
}
public static string GetReadDocumentFilePath(Microsoft.Office.Interop.Word.Document doc)
{
//
@ -155,8 +177,7 @@ namespace AIProofread
// 获取当前文档所有文本
string allText = doc.Range().Text;
List<DocumentText> list = new List<DocumentText>();
// // 开始分割
MD5 md5 = new MD5CryptoServiceProvider();
Paragraphs paragraphs = doc.Paragraphs;
@ -166,18 +187,22 @@ namespace AIProofread
foreach (Paragraph p in paragraphs)
{
paragraphNumber++;
if (paragraphNumber % 20 == 0)
{
Debug.WriteLine("process paragraphNumber{0}", paragraphNumber);
}
//if (paragraphNumber % 20 == 0)
//{
// Debug.WriteLine("process paragraphNumber{0}", paragraphNumber);
//}
Range r = p.Range;
string text = p.Range.Text;
if (text.Trim().Length == 0 || text.EndsWith("\r\a") || r.Tables.Count > 0)
{
continue;
}
list.Add(new DocumentText(text.Replace("\u0002", ""), paragraphNumber));
Marshal.ReleaseComObject(p);
}
Marshal.ReleaseComObject(paragraphs);
//for (; paragraphNumber <= total; paragraphNumber++)
//{

BIN
AIProofread/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -19,6 +19,7 @@ namespace updater
{
private UpgradeInfo localVersion;
private UpgradeInfo upgradeInfo;
private OfficeStarter appStarter = new OfficeStarter();
private static readonly string ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
private static readonly string LocalVersionFilePath = ApplicationBase + Path.GetFileName("version.json");
public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.json";
@ -30,9 +31,9 @@ namespace updater
* gm-plugin.gachafun.com
*/
#if DEBUG
private static string UpgradeInfoURI = "http://pre-gm-plugin.gachafun.com/";
private static string UpgradeInfoURI = "https://gm-plugin.gachafun.com/";
#else
private static string UpgradeInfoURI = "https://pre-gm-plugin.gachafun.com/";
private static string UpgradeInfoURI = "https://gm-plugin.gachafun.com/";
#endif
private string updateSource;
@ -125,17 +126,22 @@ namespace updater
public string CheckHostAppRunning()
{
Process[] array = Process.GetProcesses();
var hasWPS = false;
var hasWord = false;
foreach (Process item2 in array)
{
if (item2.ProcessName.Equals("wps"))
if (item2.ProcessName.Equals("WINWORD"))
{
return "WPS";
hasWord = true;
}
else if (item2.ProcessName.Equals("WINWORD"))
else if (item2.ProcessName.Equals("wps"))
{
return "Word";
hasWPS = true;
}
}
if (hasWord && hasWPS) return "WPS与Word";
if (hasWord) return "Word";
if (hasWPS) return "WPS";
return null;
}
@ -253,36 +259,63 @@ namespace updater
progressBar1.Value = 100;
// 获取升级包路径
string updateFileName = UpgradeDir + Path.GetFileName(upgradeInfo.DownloadUrl);
if (updateFileName.EndsWith(".exe"))
try
{
StartInstallExe(updateFileName);
return;
}
// 可以考虑备份旧文件
//string destinationFolder = Path.Combine(applicationBase, "update\\old");
//CopyDirectory(applicationBase, destinationFolder);
//ZipFile.ExtractToDirectory(zipFilePath, applicationBase);
using (ZipArchive zip = ZipFile.OpenRead(updateFileName))
{
foreach (ZipArchiveEntry entry in zip.Entries)
if (updateFileName.EndsWith(".exe"))
{
// 采用覆盖模式进行解压
try
{
entry.ExtractToFile(Path.Combine(ApplicationBase, entry.FullName), true);
}
catch (Exception)
{
StartInstallExe(updateFileName);
return;
}
// 可以考虑备份旧文件
//string destinationFolder = Path.Combine(applicationBase, "update\\old");
//CopyDirectory(applicationBase, destinationFolder);
//ZipFile.ExtractToDirectory(zipFilePath, applicationBase);
using (ZipArchive zip = ZipFile.OpenRead(updateFileName))
{
foreach (ZipArchiveEntry entry in zip.Entries)
{
// 采用覆盖模式进行解压
try
{
entry.ExtractToFile(Path.Combine(ApplicationBase, entry.FullName), true);
}
catch (Exception)
{
}
}
}
MessageBox.Show("更新完成, 您可以打开文档继续校对");
// 保存最新版本日志
try
{
File.WriteAllText(LocalVersionFilePath, updateSource);
}
catch (Exception) { }
appStarter.StartWPS();
appStarter.StartMSOffice();
this.Close();
}
catch (Exception)
{
try
{
File.Delete(updateFileName);
}catch { }
var ret = MessageBox.Show("升级失败,是否需要手动执行更新?", "更新失败", MessageBoxButtons.YesNo);
if (ret == DialogResult.Yes)
{
Process.Start(upgradeInfo.DownloadUrl);
this.Close();
}
else
{
ButtonProcess.Visible = true;
ButtonProcess.Text = "重新更新";
}
}
MessageBox.Show("更新完成, 您可以打开文档继续校对");
// 保存最新版本日志
File.WriteAllText(LocalVersionFilePath, updateSource);
this.Close();
}
public static void CopyDirectory(string sourceFolder, string destinationFolder)
{

View File

@ -7,51 +7,59 @@ namespace updater
{
public void StartWPS()
{
if (UpdateData.GetInstance().ShouldRebootWPS)
try
{
string text = RegistHelper.GetRegistData(Registry.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Kingsoft Office", "DisplayIcon");
if (string.IsNullOrWhiteSpace(text))
if (UpdateData.GetInstance().ShouldRebootWPS)
{
text = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Kingsoft Office", "DisplayIcon");
}
if (!string.IsNullOrWhiteSpace(text))
{
text = text.Substring(0, text.LastIndexOf("WPS Office")) + "WPS Office\\ksolaunch.exe";
Process.Start(text);
string text = RegistHelper.GetRegistData(Registry.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Kingsoft Office", "DisplayIcon");
if (string.IsNullOrWhiteSpace(text))
{
text = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Kingsoft Office", "DisplayIcon");
}
if (!string.IsNullOrWhiteSpace(text))
{
text = text.Substring(0, text.LastIndexOf("WPS Office")) + "WPS Office\\ksolaunch.exe";
Process.Start(text);
}
}
}
catch { }
}
public void StartMSOffice()
{
if (UpdateData.GetInstance().ShouldRebootMSOffice)
try
{
string allRegistData = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Office\\16.0\\Word\\InstallRoot", "Path");
//检查2016 / 2019 / 365版本路径
if (string.IsNullOrWhiteSpace(allRegistData))
if (UpdateData.GetInstance().ShouldRebootMSOffice)
{
allRegistData = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Office\\15.0\\Common\\InstallRoot", "Path");
// 检查2013版本路径
string allRegistData = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Office\\16.0\\Word\\InstallRoot", "Path");
//检查2016 / 2019 / 365版本路径
if (string.IsNullOrWhiteSpace(allRegistData))
{
allRegistData = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Office\\15.0\\Common\\InstallRoot", "Path");
// 检查2013版本路径
}
if (string.IsNullOrWhiteSpace(allRegistData))
{
allRegistData = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Office\\14.0\\Common\\InstallRoot", "Path");
// 检查2010版本路径
}
if (string.IsNullOrWhiteSpace(allRegistData))
{
allRegistData = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Office\\12.0\\Common\\InstallRoot", "Path");
//检查2007版本路径
}
if (!string.IsNullOrWhiteSpace(allRegistData))
{
allRegistData += "WINWORD.exe";
//MSOffice启动路径
Process.Start(allRegistData);
}
// 未能从注册表找到MS Office 安装路径
// 没有找到 直接不处理了
}
if (string.IsNullOrWhiteSpace(allRegistData))
{
allRegistData = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Office\\14.0\\Common\\InstallRoot", "Path");
// 检查2010版本路径
}
if (string.IsNullOrWhiteSpace(allRegistData))
{
allRegistData = RegistHelper.GetAllRegistData(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Office\\12.0\\Common\\InstallRoot", "Path");
//检查2007版本路径
}
if (!string.IsNullOrWhiteSpace(allRegistData))
{
allRegistData += "WINWORD.exe";
//MSOffice启动路径
Process.Start(allRegistData);
}
// 未能从注册表找到MS Office 安装路径
// 没有找到 直接不处理了
}
catch{}
}
}
}

View File

@ -31,7 +31,7 @@ namespace UtilLib
/// <summary>
/// 标识类型index字符型数字
/// </summary>
public int Index { get; set; }
public string Index { get; set; }
/// <summary>
/// 标识类型(校对所属分类)
/// </summary>
@ -39,7 +39,7 @@ namespace UtilLib
/// <summary>
/// 校对状态
/// </summary>
[JsonProperty("is_accept")]
[JsonProperty("isAccept")]
public int IsAccept { get; set; }
/// <summary>
/// 校对项颜色