1.优化面板尺寸监听;

2.校对标签颜色;
3.添加文档id存储避免网页刷新;
This commit is contained in:
LittleBoy 2024-06-02 17:42:32 +08:00
parent a5ed094f2d
commit b4c4af198f
18 changed files with 98 additions and 65 deletions

Binary file not shown.

View File

@ -8,18 +8,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.Linq;
using UtilLib; using UtilLib;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
using Document = Microsoft.Office.Interop.Word.Document; using Document = Microsoft.Office.Interop.Word.Document;
namespace AIProofread namespace AIProofread
@ -84,6 +75,20 @@ namespace AIProofread
} }
} }
public void SetCurrentDocumentId(int id)
{
var doc = Globals.ThisAddIn.Application.ActiveDocument;
Globals.ThisAddIn.documentIdDics[doc] = id;
}
public int GetCurrentDocumentId()
{
var doc = Globals.ThisAddIn.Application.ActiveDocument;
var dics = Globals.ThisAddIn.documentIdDics;
return dics.ContainsKey(doc) ? dics[doc] : 0;
}
// 打开网页 // 打开网页
public void OpenUrlWithOsBrowser(string url) public void OpenUrlWithOsBrowser(string url)
{ {
@ -149,8 +154,11 @@ namespace AIProofread
{ {
Dictionary<string, object> data = new Dictionary<string, object>(); Dictionary<string, object> data = new Dictionary<string, object>();
var name = Globals.ThisAddIn.Application.ActiveDocument.Name; var name = Globals.ThisAddIn.Application.ActiveDocument.Name;
var doc = Globals.ThisAddIn.Application.ActiveDocument;
data.Add("name", name); data.Add("name", name);
data.Add("fullName", Globals.ThisAddIn.Application.ActiveDocument.FullName); data.Add("fullName", doc.FullName);
data.Add("wordsCount", doc.Words.Count);
data.Add("charactersCount", doc.Characters.Count);
data.Add("content", Tools.GetAllText()); data.Add("content", Tools.GetAllText());
return Tools.GetJSONString(data); return Tools.GetJSONString(data);
} }
@ -243,7 +251,8 @@ namespace AIProofread
{ {
// 清空marks // 清空marks
marks.Clear(); marks.Clear();
}catch (Exception) { } }
catch (Exception) { }
} }
public void removeBookmark(string markId) public void removeBookmark(string markId)
@ -376,6 +385,7 @@ namespace AIProofread
public void SelectMarkById(int proofreadId) public void SelectMarkById(int proofreadId)
{ {
// 设置当前文档数据 // 设置当前文档数据
Globals.ThisAddIn.ActiveCurrentDocumentMarks(); Globals.ThisAddIn.ActiveCurrentDocumentMarks();
@ -434,6 +444,8 @@ namespace AIProofread
} }
public void InitContent(string content) public void InitContent(string content)
{
try
{ {
List<DocumentCorrectItem> list = JsonConvert.DeserializeObject<List<DocumentCorrectItem>>(content); List<DocumentCorrectItem> list = JsonConvert.DeserializeObject<List<DocumentCorrectItem>>(content);
// 先清除所有数据 // 先清除所有数据
@ -480,6 +492,10 @@ namespace AIProofread
} }
} }
} }
}catch (Exception ex)
{
Logger.Log("Initial Content error:" + ex.Message + "\n" + ex.StackTrace + "\n\n");
}
} }
@ -520,7 +536,8 @@ namespace AIProofread
try try
{ {
controls.Remove(markName); controls.Remove(markName);
}catch (Exception) { } }
catch (Exception) { }
} }
Range findRange = null; Range findRange = null;
if (paragraphIndex > document.Paragraphs.Count) return null; if (paragraphIndex > document.Paragraphs.Count) return null;

View File

@ -6,7 +6,7 @@ namespace AIProofread
public class Config public class Config
{ {
public static readonly string APP_NAME = "AI校对王"; public static readonly string APP_NAME = "AI校对王";
public static readonly string APP_VERSION = "1.0.4"; public static readonly string APP_VERSION = "1.0.7";
public static bool IS_WPS = false; public static bool IS_WPS = false;
public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.json"; public static readonly string CONFIG_FILE = AppDomain.CurrentDomain.BaseDirectory + "app.json";

View File

@ -51,8 +51,9 @@
this.ClientSize = new System.Drawing.Size(400, 310); this.ClientSize = new System.Drawing.Size(400, 310);
this.Controls.Add(this.WebViewContact); this.Controls.Add(this.WebViewContact);
this.Name = "FormContact"; this.Name = "FormContact";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "FormContact"; this.Text = "联系客服";
this.Load += new System.EventHandler(this.FormContact_Load); this.Load += new System.EventHandler(this.FormContact_Load);
((System.ComponentModel.ISupportInitialize)(this.WebViewContact)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.WebViewContact)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -53,6 +53,7 @@
this.Controls.Add(this.web); this.Controls.Add(this.web);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FormLogin"; this.Name = "FormLogin";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "登录"; this.Text = "登录";
this.Load += new System.EventHandler(this.FormLogin_Load); this.Load += new System.EventHandler(this.FormLogin_Load);

View File

@ -55,7 +55,7 @@
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "FormSetting"; this.Name = "FormSetting";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FormSetting"; this.Text = "插件设置";
this.Load += new System.EventHandler(this.FormSetting_Load); this.Load += new System.EventHandler(this.FormSetting_Load);
((System.ComponentModel.ISupportInitialize)(this.WebViewSetting)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.WebViewSetting)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -9,12 +9,17 @@ namespace AIProofread.Controls
{ {
private Document doc; private Document doc;
private int minWidth; private int minWidth;
public ProofreadMainControl(Document doc,int minWidth) public ProofreadMainControl(Document doc,int minWidth)
{ {
InitializeComponent(); InitializeComponent();
this.doc = doc; this.doc = doc;
this.minWidth = minWidth; this.minWidth = minWidth;
Bridge.InitWebEnvAsync("main", web); Bridge.InitWebEnvAsync("main", web);
//this.minWidth = 420 * LabelWidth() / 42;
//this.MinimumSize = new System.Drawing.Size(this.minWidth, 0);
} }

View File

@ -13,6 +13,8 @@ namespace UtilLib
public Bookmark mark; public Bookmark mark;
public CorrectedContent content; public CorrectedContent content;
private float originSize; private float originSize;
private WdColor originColor;
private WdColor originBackgroundColor;
public string Name { get; set; } public string Name { get; set; }
public ProofreadItem(CorrectedContent content) public ProofreadItem(CorrectedContent content)
{ {
@ -34,6 +36,8 @@ namespace UtilLib
this.mark = bookmark; this.mark = bookmark;
// 记录目前字体 // 记录目前字体
originSize = bookmark.Range.Font.Size; originSize = bookmark.Range.Font.Size;
originBackgroundColor = bookmark.Shading.BackgroundPatternColor;
originColor = bookmark.Shading.ForegroundPatternColor;
mark.Selected += OnMarkSelected; mark.Selected += OnMarkSelected;
} }
SetMarkName(); SetMarkName();
@ -49,11 +53,8 @@ namespace UtilLib
{ {
// 记录目前字体 // 记录目前字体
originSize = mark.Range.Font.Size; originSize = mark.Range.Font.Size;
// 设置下划线
mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick;
// 设置名称 // 设置名称
mark.Name = Config.BuildBookmarkName(content.id); mark.Name = Config.BuildBookmarkName(content.id);
//mark.SelectionChange += OnMarkSelectionChange;
} }
} }
@ -81,6 +82,7 @@ namespace UtilLib
{ {
if (mark == null) return; if (mark == null) return;
mark.Range.Font.Size = originSize; // 还原 mark.Range.Font.Size = originSize; // 还原
mark.Shading.ForegroundPatternColor = originColor;
} }
private void SetMarkStyle() private void SetMarkStyle()
@ -98,7 +100,9 @@ namespace UtilLib
{ {
mark.Range.Font.Size = originSize; // 还原 mark.Range.Font.Size = originSize; // 还原
//mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone; //mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;
mark.Range.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic; //originBackgroundColor = bookmark.Shading.BackgroundPatternColor;
mark.Shading.ForegroundPatternColor = originColor;
mark.Range.Shading.BackgroundPatternColor = originColor;// Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
} }
catch (Exception) { } catch (Exception) { }
} }

View File

@ -45,6 +45,7 @@ namespace AIProofread
public Dictionary<Word.Document, CustomTaskPane> taskPanels = new Dictionary<Word.Document, CustomTaskPane>(); public Dictionary<Word.Document, CustomTaskPane> taskPanels = new Dictionary<Word.Document, CustomTaskPane>();
public Dictionary<Word.Document, bool> panelsVisibleStatus = new Dictionary<Word.Document, bool>(); public Dictionary<Word.Document, bool> panelsVisibleStatus = new Dictionary<Word.Document, bool>();
public Dictionary<Word.Document, int> documentIdDics = new Dictionary<Word.Document, int>();
public CustomTaskPane currentDocumentTaskPane; public CustomTaskPane currentDocumentTaskPane;
private static readonly Dictionary<Word.Document, Dictionary<int, ProofreadItem>> allMarks = new Dictionary<Word.Document, Dictionary<int, ProofreadItem>>(); private static readonly Dictionary<Word.Document, Dictionary<int, ProofreadItem>> allMarks = new Dictionary<Word.Document, Dictionary<int, ProofreadItem>>();
@ -181,21 +182,16 @@ namespace AIProofread
this.currentDocumentTaskPane = panel; this.currentDocumentTaskPane = panel;
taskPanels.Add(doc, panel); taskPanels.Add(doc, panel);
panel.Visible = false; panel.Visible = false;
panel.VisibleChanged += Panel_VisibleChanged; // 设置宽度
control.Width = MinWidth; control.Width = MinWidth;
panel.Width = MinWidth; panel.Width = MinWidth;
// 监听尺寸变化 防止最小尺寸小于设置值 // 监听尺寸变化 防止最小尺寸小于设置值
control.SizeChanged += Control_SizeChanged; control.SizeChanged += Control_SizeChanged;
//new CustomTaskPaneHandler(control, MinWidth);
return panel; return panel;
} }
private void Panel_VisibleChanged(object sender, EventArgs e)
{
if (currentDocumentTaskPane == sender)
{
}
}
/// <summary> /// <summary>
/// word创建面板 /// word创建面板
@ -205,12 +201,20 @@ namespace AIProofread
return ShowPanel(doc, !IsWPS); return ShowPanel(doc, !IsWPS);
} }
/// <summary>
/// 添加变量控制重复调用
/// </summary>
private bool isResizing = false;
private void Control_SizeChanged(object sender, EventArgs e) private void Control_SizeChanged(object sender, EventArgs e)
{ {
if (currentDocumentTaskPane != null && currentDocumentTaskPane.Width < MinWidth) if (isResizing) return;
if (currentDocumentTaskPane != null && currentDocumentTaskPane.Visible && currentDocumentTaskPane.Width < MinWidth)
{ {
isResizing = true;
SendKeys.Send("{ESC}"); SendKeys.Send("{ESC}");
currentDocumentTaskPane.Width = MinWidth; currentDocumentTaskPane.Width = MinWidth;
isResizing = false;
} }
} }
@ -257,7 +261,8 @@ namespace AIProofread
} }
} }
} }
}catch (Exception) { } }
catch (Exception) { }
} }
private void ThisAddIn_Startup(object sender, System.EventArgs e) private void ThisAddIn_Startup(object sender, System.EventArgs e)

View File

@ -1 +1 @@
c42860264b8acb7028e263a703e52b2dc93d902c0171fb7e18b49cb7e7de737a 45c1006d89b86a8263132b8f944b694a4253831b72578a761854fd2065ca7135

View File

@ -49,6 +49,6 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Ribbon1.resources C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Ribbon1.resources
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.GenerateResource.cache C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.GenerateResource.cache
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.CoreCompileInputs.cache C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.CoreCompileInputs.cache
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.csproj.CopyComplete
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.pdb C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.pdb
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofr.8811D769.Up2Date