146 lines
4.7 KiB
C#
146 lines
4.7 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 = Color.WhiteSmoke;
|
|
private readonly Color BG_HOVER = Color.AliceBlue;
|
|
private readonly Color BG_ACTIVE = Color.AliceBlue;
|
|
private DiffItem diffItem;
|
|
private int currentStart;
|
|
private Document document;
|
|
private Bookmark bookmark;
|
|
private bool processed = false;
|
|
|
|
public ProofreadItem()
|
|
{
|
|
InitializeComponent();
|
|
this.BackColor = BG_NORMAL;
|
|
this.document = Globals.ThisAddIn.Application.ActiveDocument;
|
|
}
|
|
|
|
private void ProofreadItem_MouseEnter(object sender, EventArgs e)
|
|
{
|
|
this.BackColor = BG_HOVER;
|
|
Console.WriteLine("ProofreadItem_MouseEnter");
|
|
}
|
|
|
|
private void ProofreadItem_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
this.BackColor = BG_NORMAL;
|
|
Console.WriteLine("ProofreadItem_MouseLeave");
|
|
}
|
|
|
|
private void ProofreadItem_Click(object sender, EventArgs e)
|
|
{
|
|
this.BackColor = BG_ACTIVE;
|
|
Console.WriteLine("ProofreadItem_Click");
|
|
}
|
|
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.Bookmarks.Add("mark_" + this.diffItem.Id, r);
|
|
if (this.diffItem.Tag != "i")
|
|
{
|
|
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(color);
|
|
}
|
|
}
|
|
|
|
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;
|
|
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;
|
|
if (this.diffItem.Tag == "d")
|
|
{
|
|
rng.Delete();
|
|
}
|
|
else
|
|
{
|
|
rng.Text = this.diffItem.Text;
|
|
}
|
|
this.ProcessView();
|
|
}
|
|
}
|
|
}
|