181 lines
5.9 KiB
C#
181 lines
5.9 KiB
C#
using Microsoft.Office.Interop.Word;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using UtilLib;
|
|
|
|
namespace TestWordAddIn1
|
|
{
|
|
public partial class ProofreadItem : UserControl
|
|
{
|
|
|
|
private readonly Color BG_NORMAL = Colors.FromHex("f9f8f8");
|
|
private readonly Color BG_HOVER = Colors.FromHex("b7dde8");
|
|
private readonly Color BG_ACTIVE = Colors.FromHex("b7dde8");
|
|
public DiffItem diffItem;
|
|
private int currentStart;
|
|
private Microsoft.Office.Tools.Word.Document document;
|
|
private Microsoft.Office.Tools.Word.Bookmark bookmark;
|
|
private bool processed = false;
|
|
private bool Selected = false;
|
|
|
|
public ProofreadItem()
|
|
{
|
|
InitializeComponent();
|
|
this.BackColor = BG_NORMAL;
|
|
this.document = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
|
|
this.Click += ProofreadItem_Click1;
|
|
}
|
|
|
|
|
|
private void ProofreadItem_MouseEnter(object sender, EventArgs e)
|
|
{
|
|
SetSelect();
|
|
Console.WriteLine("ProofreadItem_MouseEnter");
|
|
}
|
|
|
|
public void SetSelect()
|
|
{
|
|
this.BackColor = BG_HOVER;
|
|
}
|
|
public void SetNormal()
|
|
{
|
|
this.BackColor = BG_NORMAL;
|
|
}
|
|
|
|
private void ProofreadItem_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
SetNormal();
|
|
Console.WriteLine("ProofreadItem_MouseLeave");
|
|
}
|
|
|
|
public event EventHandler BookmarkClick;
|
|
|
|
private void AddBookmark(Color color)
|
|
{
|
|
int rangeStart = this.currentStart + this.diffItem.Start,
|
|
rangeEnd = this.currentStart + this.diffItem.End;
|
|
|
|
Range r = this.document.Range(rangeStart, rangeEnd);
|
|
|
|
this.bookmark = this.document.Controls.AddBookmark(r,"mark_" + this.diffItem.Id);
|
|
this.bookmark.Selected += Bookmark_Selected;
|
|
if (this.diffItem.Tag != "i")
|
|
{
|
|
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(color);
|
|
}
|
|
}
|
|
|
|
private void Bookmark_Selected(object sender, Microsoft.Office.Tools.Word.SelectionEventArgs e)
|
|
{
|
|
if(this.BookmarkClick != null)
|
|
{
|
|
this.BookmarkClick(this, null);
|
|
}
|
|
}
|
|
private void ProofreadItem_Click1(object sender, EventArgs e)
|
|
{
|
|
if(this.BackColor == BG_ACTIVE)
|
|
{
|
|
this.BackColor = BG_NORMAL;
|
|
return;
|
|
}
|
|
if (this.diffItem == null || this.bookmark == null
|
|
|| (this.diffItem.IsAccept == AcceptEnum.Accept && this.diffItem.Tag == "d"))
|
|
{
|
|
return;
|
|
}
|
|
this.BackColor = BG_ACTIVE;
|
|
try { this.bookmark.Select(); }catch(Exception ex) { }
|
|
}
|
|
|
|
public void SetProofreadItem(DiffItem it, int start)
|
|
{
|
|
this.diffItem = it;
|
|
this.currentStart = start;
|
|
this.ProcessView();
|
|
|
|
var typeConfig = TypeConfig.Get(it.Type);
|
|
type.Text = typeConfig.Text;
|
|
type.Visible = false;
|
|
var c = Colors.FromHex(typeConfig.Color);
|
|
typePanel.BackColor = c;
|
|
//if (it.Tag != "i")
|
|
//{
|
|
AddBookmark(c);
|
|
//}
|
|
|
|
if (it.Type == ProofreadType.blackWord
|
|
|| it.Type == ProofreadType.blackWordBlock
|
|
|| it.Type == ProofreadType.sensitive)
|
|
{
|
|
description.Text = "【敏感词】建议查看";
|
|
}
|
|
else
|
|
{
|
|
if (it.Tag == "r")
|
|
{
|
|
origin.Text = it.Origin + ">" + it.Text;
|
|
description.Text = string.Format("【{0}】建议选用“{1}”", typeConfig.Text, it.Text);
|
|
}
|
|
else if (it.Tag == "i")
|
|
{
|
|
origin.Text = it.Text + " 新增";
|
|
description.Text = string.Format("【{0}】建议新增", typeConfig.Text);
|
|
}
|
|
else
|
|
{
|
|
origin.Text = it.Origin + " 删除";
|
|
description.Text = string.Format("【{0}】建议删除", typeConfig.Text);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void ProcessView()
|
|
{
|
|
var showBtn = this.diffItem.IsAccept == AcceptEnum.Default;
|
|
btnAccept.Visible = showBtn;
|
|
btnIgnore.Visible = showBtn;
|
|
processStatus.Visible = !showBtn;
|
|
if (!showBtn)
|
|
{
|
|
processStatus.Text = (this.diffItem.IsAccept == AcceptEnum.Accept) ? "已采纳" : "已忽略";
|
|
}
|
|
}
|
|
|
|
private void ProofreadItem_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnIgnore_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.diffItem.IsAccept != AcceptEnum.Default) return;
|
|
this.diffItem.IsAccept = AcceptEnum.Ignore;
|
|
//this.bookmark.Range.Shading.BackgroundPatternColor = WdColor.wdColorAutomatic;
|
|
this.bookmark.Range.Shading.BackgroundPatternColorIndex = WdColorIndex.wdAuto;
|
|
MessageBox.Show("忽略" + this.currentStart + this.diffItem.Text);
|
|
this.ProcessView();
|
|
}
|
|
|
|
private void btnAccept_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.diffItem.IsAccept != AcceptEnum.Default) return;
|
|
this.diffItem.IsAccept = AcceptEnum.Accept;
|
|
var rng = this.bookmark.Range;
|
|
//rng.Shading.BackgroundPatternColor = WdColor.wdColorAutomatic;
|
|
rng.Shading.BackgroundPatternColorIndex = WdColorIndex.wdAuto;
|
|
if (this.diffItem.Tag == "d")
|
|
{
|
|
rng.Delete();
|
|
}
|
|
else
|
|
{
|
|
rng.Text = this.diffItem.Text;
|
|
}
|
|
this.ProcessView();
|
|
}
|
|
}
|
|
}
|