Code Coverage Statistics for Source File

c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Document\BookmarkManager\Bookmark.cs

Sequence Point Coverage
N/A
0 of 0
Branch Coverage
N/A
0 of 0
Lines
137
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: 2691 $</version>
6
// </file>
7
8
using System;
9
using System.Drawing;
10
using SWF = System.Windows.Forms;
11
12
namespace ICSharpCode.TextEditor.Document
13
{
14
	/// <summary>
15
	/// Description of Bookmark.
16
	/// </summary>
17
	public class Bookmark
18
	{
19
		IDocument document;
20
		LineSegment line;
21
		int lineNumber;
22
		bool isEnabled = true;
23
		
24
		public IDocument Document {
25
			get {
26
				return document;
27
			}
28
			set {
29
				if (document != value) {
30
					if (line != null) {
31
						lineNumber = line.LineNumber;
32
						line = null;
33
					}
34
					document = value;
35
					if (document != null) {
36
						line = document.GetLineSegment(Math.Min(lineNumber, document.TotalNumberOfLines-1));
37
					}
38
					OnDocumentChanged(EventArgs.Empty);
39
				}
40
			}
41
		}
42
		
43
		public event EventHandler DocumentChanged;
44
		
45
		protected virtual void OnDocumentChanged(EventArgs e)
46
		{
47
			if (DocumentChanged != null) {
48
				DocumentChanged(this, e);
49
			}
50
		}
51
		
52
		public bool IsEnabled {
53
			get {
54
				return isEnabled;
55
			}
56
			set {
57
				if (isEnabled != value) {
58
					isEnabled = value;
59
					if (document != null) {
60
						document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineNumber));
61
						document.CommitUpdate();
62
					}
63
					OnIsEnabledChanged(EventArgs.Empty);
64
				}
65
			}
66
		}
67
		
68
		public event EventHandler IsEnabledChanged;
69
		
70
		protected virtual void OnIsEnabledChanged(EventArgs e)
71
		{
72
			if (IsEnabledChanged != null) {
73
				IsEnabledChanged(this, e);
74
			}
75
		}
76
		
77
		/// <summary>
78
		/// Gets the line the bookmark belongs to.
79
		/// Is null if the bookmark is not connected to a document.
80
		/// </summary>
81
		public LineSegment Line {
82
			get { return line; }
83
		}
84
		
85
		public int LineNumber {
86
			get {
87
				if (line != null)
88
					return line.LineNumber;
89
				else
90
					return lineNumber;
91
			}
92
			set {
93
				if (value < 0)
94
					throw new ArgumentOutOfRangeException("value", value, "line number must be >= 0");
95
				if (document == null) {
96
					lineNumber = value;
97
				} else {
98
					line = document.GetLineSegment(value);
99
				}
100
			}
101
		}
102
		
103
		/// <summary>
104
		/// Gets if the bookmark can be toggled off using the 'set/unset bookmark' command.
105
		/// </summary>
106
		public virtual bool CanToggle {
107
			get {
108
				return true;
109
			}
110
		}
111
		
112
		public Bookmark(IDocument document, int lineNumber) : this(document, lineNumber, true)
113
		{
114
		}
115
		
116
		public Bookmark(IDocument document, int lineNumber, bool isEnabled)
117
		{
118
			this.document   = document;
119
			this.isEnabled  = isEnabled;
120
			this.LineNumber = lineNumber;
121
		}
122
		
123
		public virtual bool Click(SWF.Control parent, SWF.MouseEventArgs e)
124
		{
125
			if (e.Button == SWF.MouseButtons.Left && CanToggle) {
126
				document.BookmarkManager.RemoveMark(this);
127
				return true;
128
			}
129
			return false;
130
		}
131
		
132
		public virtual void Draw(IconBarMargin margin, Graphics g, Point p)
133
		{
134
			margin.DrawBookmark(g, p.Y, isEnabled);
135
		}
136
	}
137
}