Code Coverage Statistics for Source File

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

Sequence Point Coverage
N/A
0 of 0
Branch Coverage
N/A
0 of 0
Lines
101
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: 915 $</version>
6
// </file>
7
8
using System;
9
using System.Collections.Generic;
10
using System.Xml;
11
12
namespace ICSharpCode.TextEditor.Document
13
{
14
	/// <summary>
15
	/// This class is used for storing the state of a bookmark manager 
16
	/// </summary>
17
	public class BookmarkManagerMemento
18
	{
19
		List<int> bookmarks = new List<int>();
20
		
21
		/// <value>
22
		/// Contains all bookmarks as int values
23
		/// </value>
24
		public List<int> Bookmarks {
25
			get {
26
				return bookmarks;
27
			}
28
			set {
29
				bookmarks = value;
30
			}
31
		}
32
		
33
		/// <summary>
34
		/// Validates all bookmarks if they're in range of the document.
35
		/// (removing all bookmarks &lt; 0 and bookmarks &gt; max. line number
36
		/// </summary>
37
		public void CheckMemento(IDocument document)
38
		{
39
			for (int i = 0; i < bookmarks.Count; ++i) {
40
				int mark = (int)bookmarks[i];
41
				if (mark < 0 || mark >= document.TotalNumberOfLines) {
42
					bookmarks.RemoveAt(i);
43
					--i;
44
				}
45
			}
46
		}
47
		
48
		/// <summary>
49
		/// Creates a new instance of <see cref="BookmarkManagerMemento"/>
50
		/// </summary>
51
		public BookmarkManagerMemento()
52
		{
53
		}
54
		
55
		/// <summary>
56
		/// Creates a new instance of <see cref="BookmarkManagerMemento"/>
57
		/// </summary>
58
		public BookmarkManagerMemento(XmlElement element)
59
		{
60
			foreach (XmlElement el in element.ChildNodes) {
61
				bookmarks.Add(Int32.Parse(el.Attributes["line"].InnerText));
62
			}
63
		}
64
		
65
		/// <summary>
66
		/// Creates a new instance of <see cref="BookmarkManagerMemento"/>
67
		/// </summary>
68
		public BookmarkManagerMemento(List<int> bookmarks)
69
		{
70
			this.bookmarks = bookmarks;
71
		}
72
		
73
		/// <summary>
74
		/// Converts a xml element to a <see cref="BookmarkManagerMemento"/> object
75
		/// </summary>
76
		public object FromXmlElement(XmlElement element)
77
		{
78
			return new BookmarkManagerMemento(element);
79
		}
80
		
81
		/// <summary>
82
		/// Converts this <see cref="BookmarkManagerMemento"/> to a xml element
83
		/// </summary>
84
		public XmlElement ToXmlElement(XmlDocument doc)
85
		{
86
			XmlElement bookmarknode  = doc.CreateElement("Bookmarks");
87
			
88
			foreach (int line in bookmarks) {
89
				XmlElement markNode = doc.CreateElement("Mark");
90
				
91
				XmlAttribute lineAttr = doc.CreateAttribute("line");
92
				lineAttr.InnerText = line.ToString();
93
				markNode.Attributes.Append(lineAttr);
94
						
95
				bookmarknode.AppendChild(markNode);
96
			}
97
			
98
			return bookmarknode;
99
		}
100
	}
101
}