//
//
//
//
// $Revision$
//
using System;
using System.Collections.Generic;
using System.Xml;
namespace ICSharpCode.TextEditor.Document
{
///
/// This class is used for storing the state of a bookmark manager
///
public class BookmarkManagerMemento
{
List bookmarks = new List();
///
/// Contains all bookmarks as int values
///
public List Bookmarks {
get {
return bookmarks;
}
set {
bookmarks = value;
}
}
///
/// Validates all bookmarks if they're in range of the document.
/// (removing all bookmarks < 0 and bookmarks > max. line number
///
public void CheckMemento(IDocument document)
{
for (int i = 0; i < bookmarks.Count; ++i) {
int mark = (int)bookmarks[i];
if (mark < 0 || mark >= document.TotalNumberOfLines) {
bookmarks.RemoveAt(i);
--i;
}
}
}
///
/// Creates a new instance of
///
public BookmarkManagerMemento()
{
}
///
/// Creates a new instance of
///
public BookmarkManagerMemento(XmlElement element)
{
foreach (XmlElement el in element.ChildNodes) {
bookmarks.Add(Int32.Parse(el.Attributes["line"].InnerText));
}
}
///
/// Creates a new instance of
///
public BookmarkManagerMemento(List bookmarks)
{
this.bookmarks = bookmarks;
}
///
/// Converts a xml element to a object
///
public object FromXmlElement(XmlElement element)
{
return new BookmarkManagerMemento(element);
}
///
/// Converts this to a xml element
///
public XmlElement ToXmlElement(XmlDocument doc)
{
XmlElement bookmarknode = doc.CreateElement("Bookmarks");
foreach (int line in bookmarks) {
XmlElement markNode = doc.CreateElement("Mark");
XmlAttribute lineAttr = doc.CreateAttribute("line");
lineAttr.InnerText = line.ToString();
markNode.Attributes.Append(lineAttr);
bookmarknode.AppendChild(markNode);
}
return bookmarknode;
}
}
}