Implement highlighting for item comments.

This commit is contained in:
Daniel Kraus
2015-09-06 11:48:43 +02:00
parent bf15d264ba
commit c733c238de
11 changed files with 143 additions and 67 deletions

View File

@ -21,6 +21,7 @@ using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using System.Text.RegularExpressions;
using System.Collections.ObjectModel;
namespace zaaReloaded2.Formatter
{
@ -192,6 +193,7 @@ namespace zaaReloaded2.Formatter
{
string[] substrings = _markupRegex.Split(text);
Selection sel = Document.ActiveWindow.Selection;
Highlights hightlights = new Highlights();
foreach (string substring in substrings)
{
switch (substring)
@ -214,6 +216,12 @@ namespace zaaReloaded2.Formatter
case "</u>":
sel.Font.Underline = WdUnderline.wdUnderlineNone;
break;
case "<highlight>":
hightlights.Start(sel.Range);
break;
case "</highlight>":
hightlights.Stop(sel.Range);
break;
case "</style>":
sel.ClearCharacterStyle();
break;
@ -230,6 +238,7 @@ namespace zaaReloaded2.Formatter
break;
}
}
hightlights.ApplyHighlights();
}
#endregion
@ -241,8 +250,53 @@ namespace zaaReloaded2.Formatter
// The splitting pattern must not contain subgroups!
static readonly Regex _markupRegex = new Regex(@"(<[^ >]+>)");
static readonly Regex _styleRegex = new Regex(@"<style:(?<style>[^>]+)>");
static Range _highlightStart;
#endregion
#region Helper class for highlighting
/// <summary>
/// Embedded helper class to manage highlights.
/// </summary>
class Highlights
{
public void Start(Range start)
{
if (_currentHighlight == null)
{
_currentHighlight = start;
_highlights.Add(_currentHighlight);
}
}
public void Stop(Range stop)
{
if (_currentHighlight != null)
{
_currentHighlight.End = stop.End;
_currentHighlight = null;
}
}
public void ApplyHighlights()
{
foreach (Range r in _highlights)
{
r.HighlightColorIndex = WdColorIndex.wdYellow;
}
}
public Highlights()
{
_highlights = new Collection<Range>();
_currentHighlight = null;
}
Collection<Range> _highlights;
Range _currentHighlight;
}
#endregion
}
}