first commit
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ICSharpCode.TextEditor.Document
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the list of markers and provides ways to retrieve markers for specific positions.
|
||||
/// </summary>
|
||||
public sealed class MarkerStrategy
|
||||
{
|
||||
List<TextMarker> textMarker = new List<TextMarker>();
|
||||
IDocument document;
|
||||
|
||||
public IDocument Document {
|
||||
get {
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TextMarker> TextMarker {
|
||||
get {
|
||||
return textMarker.AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddMarker(TextMarker item)
|
||||
{
|
||||
markersTable.Clear();
|
||||
textMarker.Add(item);
|
||||
}
|
||||
|
||||
public void InsertMarker(int index, TextMarker item)
|
||||
{
|
||||
markersTable.Clear();
|
||||
textMarker.Insert(index, item);
|
||||
}
|
||||
|
||||
public void RemoveMarker(TextMarker item)
|
||||
{
|
||||
markersTable.Clear();
|
||||
textMarker.Remove(item);
|
||||
}
|
||||
|
||||
public void RemoveAll(Predicate<TextMarker> match)
|
||||
{
|
||||
markersTable.Clear();
|
||||
textMarker.RemoveAll(match);
|
||||
}
|
||||
|
||||
public MarkerStrategy(IDocument document)
|
||||
{
|
||||
this.document = document;
|
||||
document.DocumentChanged += new DocumentEventHandler(DocumentChanged);
|
||||
}
|
||||
|
||||
Dictionary<int, List<TextMarker>> markersTable = new Dictionary<int, List<TextMarker>>();
|
||||
|
||||
public List<TextMarker> GetMarkers(int offset)
|
||||
{
|
||||
if (!markersTable.ContainsKey(offset)) {
|
||||
List<TextMarker> markers = new List<TextMarker>();
|
||||
for (int i = 0; i < textMarker.Count; ++i) {
|
||||
TextMarker marker = (TextMarker)textMarker[i];
|
||||
if (marker.Offset <= offset && offset <= marker.EndOffset) {
|
||||
markers.Add(marker);
|
||||
}
|
||||
}
|
||||
markersTable[offset] = markers;
|
||||
}
|
||||
return markersTable[offset];
|
||||
}
|
||||
|
||||
public List<TextMarker> GetMarkers(int offset, int length)
|
||||
{
|
||||
int endOffset = offset + length - 1;
|
||||
List<TextMarker> markers = new List<TextMarker>();
|
||||
for (int i = 0; i < textMarker.Count; ++i) {
|
||||
TextMarker marker = (TextMarker)textMarker[i];
|
||||
if (// start in marker region
|
||||
marker.Offset <= offset && offset <= marker.EndOffset ||
|
||||
// end in marker region
|
||||
marker.Offset <= endOffset && endOffset <= marker.EndOffset ||
|
||||
// marker start in region
|
||||
offset <= marker.Offset && marker.Offset <= endOffset ||
|
||||
// marker end in region
|
||||
offset <= marker.EndOffset && marker.EndOffset <= endOffset
|
||||
)
|
||||
{
|
||||
markers.Add(marker);
|
||||
}
|
||||
}
|
||||
return markers;
|
||||
}
|
||||
|
||||
public List<TextMarker> GetMarkers(TextLocation position)
|
||||
{
|
||||
if (position.Y >= document.TotalNumberOfLines || position.Y < 0) {
|
||||
return new List<TextMarker>();
|
||||
}
|
||||
LineSegment segment = document.GetLineSegment(position.Y);
|
||||
return GetMarkers(segment.Offset + position.X);
|
||||
}
|
||||
|
||||
void DocumentChanged(object sender, DocumentEventArgs e)
|
||||
{
|
||||
// reset markers table
|
||||
markersTable.Clear();
|
||||
document.UpdateSegmentListOnDocumentChange(textMarker, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ICSharpCode.TextEditor.Document
|
||||
{
|
||||
public enum TextMarkerType
|
||||
{
|
||||
Invisible,
|
||||
SolidBlock,
|
||||
Underlined,
|
||||
WaveLine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks a part of a document.
|
||||
/// </summary>
|
||||
public class TextMarker : AbstractSegment
|
||||
{
|
||||
TextMarkerType textMarkerType;
|
||||
Color color;
|
||||
Color foreColor;
|
||||
string toolTip = null;
|
||||
bool overrideForeColor = false;
|
||||
|
||||
public TextMarkerType TextMarkerType {
|
||||
get {
|
||||
return textMarkerType;
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color {
|
||||
get {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
public Color ForeColor {
|
||||
get {
|
||||
return foreColor;
|
||||
}
|
||||
}
|
||||
|
||||
public bool OverrideForeColor {
|
||||
get {
|
||||
return overrideForeColor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the text segment as read-only.
|
||||
/// </summary>
|
||||
public bool IsReadOnly { get; set; }
|
||||
|
||||
public string ToolTip {
|
||||
get {
|
||||
return toolTip;
|
||||
}
|
||||
set {
|
||||
toolTip = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last offset that is inside the marker region.
|
||||
/// </summary>
|
||||
public int EndOffset {
|
||||
get {
|
||||
return Offset + Length - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public TextMarker(int offset, int length, TextMarkerType textMarkerType) : this(offset, length, textMarkerType, Color.Red)
|
||||
{
|
||||
}
|
||||
|
||||
public TextMarker(int offset, int length, TextMarkerType textMarkerType, Color color)
|
||||
{
|
||||
if (length < 1) length = 1;
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
this.textMarkerType = textMarkerType;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public TextMarker(int offset, int length, TextMarkerType textMarkerType, Color color, Color foreColor)
|
||||
{
|
||||
if (length < 1) length = 1;
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
this.textMarkerType = textMarkerType;
|
||||
this.color = color;
|
||||
this.foreColor = foreColor;
|
||||
this.overrideForeColor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user