Code Coverage Statistics for Source File
c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Document\MarkerStrategy\MarkerStrategy.cs
|
Sequence Point Coverage
N/A
0 of 0
|
Branch Coverage
N/A
0 of 0
|
Lines
119
|
Highlight:
Uncovered Code
Covered Code
| L | V | Source |
|---|---|---|
1 |
// <file> |
|
2 |
// <copyright see="prj:///doc/copyright.txt"/> |
|
3 |
// <license see="prj:///doc/license.txt"/> |
|
4 |
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> |
|
5 |
// <version>$Revision: 2659 $</version> |
|
6 |
// </file> |
|
7 |
||
8 |
using System; |
|
9 |
using System.Collections.Generic; |
|
10 |
using System.Drawing; |
|
11 |
||
12 |
namespace ICSharpCode.TextEditor.Document |
|
13 |
{ |
|
14 |
/// <summary> |
|
15 |
/// Manages the list of markers and provides ways to retrieve markers for specific positions. |
|
16 |
/// </summary> |
|
17 |
public sealed class MarkerStrategy |
|
18 |
{ |
|
19 |
List<TextMarker> textMarker = new List<TextMarker>(); |
|
20 |
IDocument document; |
|
21 |
||
22 |
public IDocument Document { |
|
23 |
get { |
|
24 |
return document; |
|
25 |
} |
|
26 |
} |
|
27 |
||
28 |
public IEnumerable<TextMarker> TextMarker { |
|
29 |
get { |
|
30 |
return textMarker.AsReadOnly(); |
|
31 |
} |
|
32 |
} |
|
33 |
||
34 |
public void AddMarker(TextMarker item) |
|
35 |
{ |
|
36 |
markersTable.Clear(); |
|
37 |
textMarker.Add(item); |
|
38 |
} |
|
39 |
||
40 |
public void InsertMarker(int index, TextMarker item) |
|
41 |
{ |
|
42 |
markersTable.Clear(); |
|
43 |
textMarker.Insert(index, item); |
|
44 |
} |
|
45 |
||
46 |
public void RemoveMarker(TextMarker item) |
|
47 |
{ |
|
48 |
markersTable.Clear(); |
|
49 |
textMarker.Remove(item); |
|
50 |
} |
|
51 |
||
52 |
public void RemoveAll(Predicate<TextMarker> match) |
|
53 |
{ |
|
54 |
markersTable.Clear(); |
|
55 |
textMarker.RemoveAll(match); |
|
56 |
} |
|
57 |
||
58 |
public MarkerStrategy(IDocument document) |
|
59 |
{ |
|
60 |
this.document = document; |
|
61 |
document.DocumentChanged += new DocumentEventHandler(DocumentChanged); |
|
62 |
} |
|
63 |
||
64 |
Dictionary<int, List<TextMarker>> markersTable = new Dictionary<int, List<TextMarker>>(); |
|
65 |
||
66 |
public List<TextMarker> GetMarkers(int offset) |
|
67 |
{ |
|
68 |
if (!markersTable.ContainsKey(offset)) { |
|
69 |
List<TextMarker> markers = new List<TextMarker>(); |
|
70 |
for (int i = 0; i < textMarker.Count; ++i) { |
|
71 |
TextMarker marker = (TextMarker)textMarker[i]; |
|
72 |
if (marker.Offset <= offset && offset <= marker.EndOffset) { |
|
73 |
markers.Add(marker); |
|
74 |
} |
|
75 |
} |
|
76 |
markersTable[offset] = markers; |
|
77 |
} |
|
78 |
return markersTable[offset]; |
|
79 |
} |
|
80 |
||
81 |
public List<TextMarker> GetMarkers(int offset, int length) |
|
82 |
{ |
|
83 |
int endOffset = offset + length - 1; |
|
84 |
List<TextMarker> markers = new List<TextMarker>(); |
|
85 |
for (int i = 0; i < textMarker.Count; ++i) { |
|
86 |
TextMarker marker = (TextMarker)textMarker[i]; |
|
87 |
if (// start in marker region |
|
88 |
marker.Offset <= offset && offset <= marker.EndOffset || |
|
89 |
// end in marker region |
|
90 |
marker.Offset <= endOffset && endOffset <= marker.EndOffset || |
|
91 |
// marker start in region |
|
92 |
offset <= marker.Offset && marker.Offset <= endOffset || |
|
93 |
// marker end in region |
|
94 |
offset <= marker.EndOffset && marker.EndOffset <= endOffset |
|
95 |
) |
|
96 |
{ |
|
97 |
markers.Add(marker); |
|
98 |
} |
|
99 |
} |
|
100 |
return markers; |
|
101 |
} |
|
102 |
||
103 |
public List<TextMarker> GetMarkers(TextLocation position) |
|
104 |
{ |
|
105 |
if (position.Y >= document.TotalNumberOfLines || position.Y < 0) { |
|
106 |
return new List<TextMarker>(); |
|
107 |
} |
|
108 |
LineSegment segment = document.GetLineSegment(position.Y); |
|
109 |
return GetMarkers(segment.Offset + position.X); |
|
110 |
} |
|
111 |
||
112 |
void DocumentChanged(object sender, DocumentEventArgs e) |
|
113 |
{ |
|
114 |
// reset markers table |
|
115 |
markersTable.Clear(); |
|
116 |
document.UpdateSegmentListOnDocumentChange(textMarker, e); |
|
117 |
} |
|
118 |
} |
|
119 |
} |