Code Coverage Statistics for Source File
c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Document\FoldingStrategy\FoldMarker.cs
|
Sequence Point Coverage
N/A
0 of 0
|
Branch Coverage
N/A
0 of 0
|
Lines
174
|
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: 2063 $</version> |
|
6 |
// </file> |
|
7 |
||
8 |
using System; |
|
9 |
||
10 |
namespace ICSharpCode.TextEditor.Document |
|
11 |
{ |
|
12 |
public enum FoldType { |
|
13 |
Unspecified, |
|
14 |
MemberBody, |
|
15 |
Region, |
|
16 |
TypeBody |
|
17 |
} |
|
18 |
||
19 |
public class FoldMarker : AbstractSegment, IComparable |
|
20 |
{ |
|
21 |
bool isFolded = false; |
|
22 |
string foldText = "..."; |
|
23 |
FoldType foldType = FoldType.Unspecified; |
|
24 |
IDocument document = null; |
|
25 |
int startLine = -1, startColumn, endLine = -1, endColumn; |
|
26 |
||
27 |
static void GetPointForOffset(IDocument document, int offset, out int line, out int column) |
|
28 |
{ |
|
29 |
if (offset > document.TextLength) { |
|
30 |
line = document.TotalNumberOfLines + 1; |
|
31 |
column = 1; |
|
32 |
} else if (offset < 0) { |
|
33 |
line = -1; |
|
34 |
column = -1; |
|
35 |
} else { |
|
36 |
line = document.GetLineNumberForOffset(offset); |
|
37 |
column = offset - document.GetLineSegment(line).Offset; |
|
38 |
} |
|
39 |
} |
|
40 |
||
41 |
public FoldType FoldType { |
|
42 |
get { return foldType; } |
|
43 |
set { foldType = value; } |
|
44 |
} |
|
45 |
||
46 |
public int StartLine { |
|
47 |
get { |
|
48 |
if (startLine < 0) { |
|
49 |
GetPointForOffset(document, offset, out startLine, out startColumn); |
|
50 |
} |
|
51 |
return startLine; |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
public int StartColumn { |
|
56 |
get { |
|
57 |
if (startLine < 0) { |
|
58 |
GetPointForOffset(document, offset, out startLine, out startColumn); |
|
59 |
} |
|
60 |
return startColumn; |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
public int EndLine { |
|
65 |
get { |
|
66 |
if (endLine < 0) { |
|
67 |
GetPointForOffset(document, offset + length, out endLine, out endColumn); |
|
68 |
} |
|
69 |
return endLine; |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
public int EndColumn { |
|
74 |
get { |
|
75 |
if (endLine < 0) { |
|
76 |
GetPointForOffset(document, offset + length, out endLine, out endColumn); |
|
77 |
} |
|
78 |
return endColumn; |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
public override int Offset { |
|
83 |
get { return base.Offset; } |
|
84 |
set { |
|
85 |
base.Offset = value; |
|
86 |
startLine = -1; endLine = -1; |
|
87 |
} |
|
88 |
} |
|
89 |
public override int Length { |
|
90 |
get { return base.Length; } |
|
91 |
set { |
|
92 |
base.Length = value; |
|
93 |
endLine = -1; |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
public bool IsFolded { |
|
98 |
get { |
|
99 |
return isFolded; |
|
100 |
} |
|
101 |
set { |
|
102 |
isFolded = value; |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
public string FoldText { |
|
107 |
get { |
|
108 |
return foldText; |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
public string InnerText { |
|
113 |
get { |
|
114 |
return document.GetText(offset, length); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
public FoldMarker(IDocument document, int offset, int length, string foldText, bool isFolded) |
|
119 |
{ |
|
120 |
this.document = document; |
|
121 |
this.offset = offset; |
|
122 |
this.length = length; |
|
123 |
this.foldText = foldText; |
|
124 |
this.isFolded = isFolded; |
|
125 |
} |
|
126 |
||
127 |
public FoldMarker(IDocument document, int startLine, int startColumn, int endLine, int endColumn) : this(document, startLine, startColumn, endLine, endColumn, FoldType.Unspecified) |
|
128 |
{ |
|
129 |
} |
|
130 |
||
131 |
public FoldMarker(IDocument document, int startLine, int startColumn, int endLine, int endColumn, FoldType foldType) : this(document, startLine, startColumn, endLine, endColumn, foldType, "...") |
|
132 |
{ |
|
133 |
} |
|
134 |
||
135 |
public FoldMarker(IDocument document, int startLine, int startColumn, int endLine, int endColumn, FoldType foldType, string foldText) : this(document, startLine, startColumn, endLine, endColumn, foldType, foldText, false) |
|
136 |
{ |
|
137 |
} |
|
138 |
||
139 |
public FoldMarker(IDocument document, int startLine, int startColumn, int endLine, int endColumn, FoldType foldType, string foldText, bool isFolded) |
|
140 |
{ |
|
141 |
this.document = document; |
|
142 |
||
143 |
startLine = Math.Min(document.TotalNumberOfLines - 1, Math.Max(startLine, 0)); |
|
144 |
ISegment startLineSegment = document.GetLineSegment(startLine); |
|
145 |
||
146 |
endLine = Math.Min(document.TotalNumberOfLines - 1, Math.Max(endLine, 0)); |
|
147 |
ISegment endLineSegment = document.GetLineSegment(endLine); |
|
148 |
||
149 |
// Prevent the region from completely disappearing |
|
150 |
if (string.IsNullOrEmpty(foldText)) { |
|
151 |
foldText = "..."; |
|
152 |
} |
|
153 |
||
154 |
this.FoldType = foldType; |
|
155 |
this.foldText = foldText; |
|
156 |
this.offset = startLineSegment.Offset + Math.Min(startColumn, startLineSegment.Length); |
|
157 |
this.length = (endLineSegment.Offset + Math.Min(endColumn, endLineSegment.Length)) - this.offset; |
|
158 |
this.isFolded = isFolded; |
|
159 |
} |
|
160 |
||
161 |
public int CompareTo(object o) |
|
162 |
{ |
|
163 |
if (!(o is FoldMarker)) { |
|
164 |
throw new ArgumentException(); |
|
165 |
} |
|
166 |
FoldMarker f = (FoldMarker)o; |
|
167 |
if (offset != f.offset) { |
|
168 |
return offset.CompareTo(f.offset); |
|
169 |
} |
|
170 |
||
171 |
return length.CompareTo(f.length); |
|
172 |
} |
|
173 |
} |
|
174 |
} |