Code Coverage Statistics for Source File
c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Document\CustomLineManager\CustomLineManager.cs
|
Sequence Point Coverage
N/A
0 of 0
|
Branch Coverage
N/A
0 of 0
|
Lines
217
|
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="Ivo Kovacka" email="ivok@internet.sk"/> |
|
5 |
// <version>$Revision: 2691 $</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 |
/// This class is used to store a pair of lineNr and its color |
|
16 |
/// </summary> |
|
17 |
public class CustomLine |
|
18 |
{ |
|
19 |
public int StartLineNr; |
|
20 |
public int EndLineNr; |
|
21 |
public Color Color; |
|
22 |
public bool ReadOnly; |
|
23 |
||
24 |
public CustomLine(int lineNr, Color customColor, bool readOnly) |
|
25 |
{ |
|
26 |
this.StartLineNr = this.EndLineNr = lineNr; |
|
27 |
this.Color = customColor; |
|
28 |
this.ReadOnly = readOnly; |
|
29 |
} |
|
30 |
||
31 |
public CustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly) |
|
32 |
{ |
|
33 |
this.StartLineNr = startLineNr; |
|
34 |
this.EndLineNr = endLineNr; |
|
35 |
this.Color = customColor; |
|
36 |
this.ReadOnly = readOnly; |
|
37 |
} |
|
38 |
} |
|
39 |
||
40 |
/// <summary> |
|
41 |
/// This class handles the bookmarks for a buffer |
|
42 |
/// </summary> |
|
43 |
public class CustomLineManager : ICustomLineManager |
|
44 |
{ |
|
45 |
List<CustomLine> lines = new List<CustomLine>(); |
|
46 |
||
47 |
/// <summary> |
|
48 |
/// Creates a new instance of <see cref="CustomLineManager"/> |
|
49 |
/// </summary> |
|
50 |
internal CustomLineManager(LineManager lineTracker) |
|
51 |
{ |
|
52 |
lineTracker.LineCountChanged += MoveIndices; |
|
53 |
} |
|
54 |
||
55 |
/// <value> |
|
56 |
/// Contains all custom lines |
|
57 |
/// </value> |
|
58 |
public List<CustomLine> CustomLines { |
|
59 |
get { |
|
60 |
return lines; |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
/// <remarks> |
|
65 |
/// Returns the Color if the line <code>lineNr</code> has custom bg color |
|
66 |
/// otherwise returns <code>defaultColor</code> |
|
67 |
/// </remarks> |
|
68 |
public Color GetCustomColor(int lineNr, Color defaultColor) |
|
69 |
{ |
|
70 |
foreach(CustomLine line in lines) |
|
71 |
if (line.StartLineNr <= lineNr && line.EndLineNr >= lineNr) |
|
72 |
return line.Color; |
|
73 |
return defaultColor; |
|
74 |
} |
|
75 |
||
76 |
/// <remarks> |
|
77 |
/// Returns the ReadOnly if the line <code>lineNr</code> is custom |
|
78 |
/// otherwise returns <code>default</code> |
|
79 |
/// </remarks> |
|
80 |
public bool IsReadOnly(int lineNr, bool defaultReadOnly) |
|
81 |
{ |
|
82 |
foreach(CustomLine line in lines) |
|
83 |
if (line.StartLineNr <= lineNr && line.EndLineNr >= lineNr) |
|
84 |
return line.ReadOnly; |
|
85 |
return defaultReadOnly; |
|
86 |
} |
|
87 |
||
88 |
/// <remarks> |
|
89 |
/// Returns true if <code>selection</code> is read only |
|
90 |
/// </remarks> |
|
91 |
public bool IsReadOnly(ISelection selection, bool defaultReadOnly) |
|
92 |
{ |
|
93 |
int startLine = selection.StartPosition.Y; |
|
94 |
int endLine = selection.EndPosition.Y; |
|
95 |
foreach (CustomLine customLine in lines) { |
|
96 |
if (customLine.ReadOnly == false) |
|
97 |
continue; |
|
98 |
if (startLine < customLine.StartLineNr && endLine < customLine.StartLineNr) |
|
99 |
continue; |
|
100 |
if (startLine > customLine.EndLineNr && endLine > customLine.EndLineNr) |
|
101 |
continue; |
|
102 |
return true; |
|
103 |
} |
|
104 |
return defaultReadOnly; |
|
105 |
} |
|
106 |
||
107 |
/// <remarks> |
|
108 |
/// Clears all custom lines |
|
109 |
/// </remarks> |
|
110 |
public void Clear() |
|
111 |
{ |
|
112 |
OnBeforeChanged(); |
|
113 |
lines.Clear(); |
|
114 |
OnChanged(); |
|
115 |
} |
|
116 |
||
117 |
/// <remarks> |
|
118 |
/// Is fired before the change |
|
119 |
/// </remarks> |
|
120 |
public event EventHandler BeforeChanged; |
|
121 |
||
122 |
/// <remarks> |
|
123 |
/// Is fired after the change |
|
124 |
/// </remarks> |
|
125 |
public event EventHandler Changed; |
|
126 |
||
127 |
||
128 |
||
129 |
void OnChanged() |
|
130 |
{ |
|
131 |
if (Changed != null) { |
|
132 |
Changed(this, null); |
|
133 |
} |
|
134 |
} |
|
135 |
void OnBeforeChanged() |
|
136 |
{ |
|
137 |
if (BeforeChanged != null) { |
|
138 |
BeforeChanged(this, null); |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
/// <remarks> |
|
143 |
/// Set Custom Line at the line <code>lineNr</code> |
|
144 |
/// </remarks> |
|
145 |
public void AddCustomLine(int lineNr, Color customColor, bool readOnly) |
|
146 |
{ |
|
147 |
OnBeforeChanged(); |
|
148 |
lines.Add(new CustomLine(lineNr, customColor, readOnly)); |
|
149 |
OnChanged(); |
|
150 |
} |
|
151 |
||
152 |
/// <remarks> |
|
153 |
/// Add Custom Lines from the line <code>startLineNr</code> to the line <code>endLineNr</code> |
|
154 |
/// </remarks> |
|
155 |
public void AddCustomLine(int startLineNr, int endLineNr, Color customColor, bool readOnly) |
|
156 |
{ |
|
157 |
OnBeforeChanged(); |
|
158 |
lines.Add(new CustomLine(startLineNr, endLineNr, customColor, readOnly)); |
|
159 |
OnChanged(); |
|
160 |
} |
|
161 |
||
162 |
/// <remarks> |
|
163 |
/// Remove Custom Line at the line <code>lineNr</code> |
|
164 |
/// </remarks> |
|
165 |
public void RemoveCustomLine(int lineNr) |
|
166 |
{ |
|
167 |
for (int i = 0; i < lines.Count; ++i) { |
|
168 |
if (((CustomLine)lines[i]).StartLineNr <= lineNr && ((CustomLine)lines[i]).EndLineNr >= lineNr) { |
|
169 |
OnBeforeChanged(); |
|
170 |
lines.RemoveAt(i); |
|
171 |
OnChanged(); |
|
172 |
return; |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
/// <summary> |
|
178 |
/// This method moves all indices from index upward count lines |
|
179 |
/// (useful for deletion/insertion of text) |
|
180 |
/// </summary> |
|
181 |
void MoveIndices(object sender, LineCountChangeEventArgs e) |
|
182 |
{ |
|
183 |
bool changed = false; |
|
184 |
OnBeforeChanged(); |
|
185 |
for (int i = 0; i < lines.Count; ++i) { |
|
186 |
int startLineNr = ((CustomLine)lines[i]).StartLineNr; |
|
187 |
int endLineNr = ((CustomLine)lines[i]).EndLineNr; |
|
188 |
if (e.LineStart >= startLineNr && e.LineStart < endLineNr) { |
|
189 |
changed = true; |
|
190 |
((CustomLine)lines[i]).EndLineNr += e.LinesMoved; |
|
191 |
} |
|
192 |
else if (e.LineStart < startLineNr) { |
|
193 |
((CustomLine)lines[i]).StartLineNr += e.LinesMoved; |
|
194 |
((CustomLine)lines[i]).EndLineNr += e.LinesMoved; |
|
195 |
} |
|
196 |
else { |
|
197 |
} |
|
198 |
/* |
|
199 |
if (e.LinesMoved < 0 && lineNr == e.LineStart) { |
|
200 |
lines.RemoveAt(i); |
|
201 |
--i; |
|
202 |
changed = true; |
|
203 |
} else if (lineNr > e.LineStart + 1 || (e.LinesMoved < 0 && lineNr > e.LineStart)) { |
|
204 |
changed = true; |
|
205 |
((CustomLine)lines[i]).StartLineNr += e.LinesMoved; |
|
206 |
((CustomLine)lines[i]).EndLineNr += e.LinesMoved; |
|
207 |
} |
|
208 |
*/ |
|
209 |
} |
|
210 |
||
211 |
if (changed) { |
|
212 |
OnChanged(); |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
} |
|
217 |
} |