#region Disclaimer / License // Copyright (C) 2013, Jackie Ng // http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com // // Original code from SharpDevelop 3.2.1 licensed under the same terms (LGPL 2.1) // Copyright 2002-2010 by // // AlphaSierraPapa, Christoph Wille // Vordernberger Strasse 27/8 // A-8700 Leoben // Austria // // email: office@alphasierrapapa.com // court of jurisdiction: Landesgericht Leoben // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // #endregion Disclaimer / License using ICSharpCode.TextEditor.Gui.CompletionWindow; using System; using System.Collections; namespace Maestro.Editors.Generic.XmlEditor.AutoCompletion { /// /// A collection that stores objects. /// [Serializable] internal class XmlCompletionDataCollection : CollectionBase { /// /// Initializes a new instance of . /// public XmlCompletionDataCollection() { } /// /// Initializes a new instance of based on another . /// /// /// A from which the contents are copied /// public XmlCompletionDataCollection(XmlCompletionDataCollection val) { this.AddRange(val); } /// /// Initializes a new instance of containing any array of objects. /// /// /// A array of objects with which to intialize the collection /// public XmlCompletionDataCollection(XmlCompletionData[] val) { this.AddRange(val); } /// /// Represents the entry at the specified index of the . /// /// The zero-based index of the entry to locate in the collection. /// The entry at the specified index of the collection. /// is outside the valid range of indexes for the collection. public XmlCompletionData this[int index] { get { return ((XmlCompletionData)(List[index])); } set { List[index] = value; } } /// /// Adds a with the specified value to the /// . /// /// /// If the completion data already exists in the collection it is not added. /// /// The to add. /// The index at which the new element was inserted. public int Add(XmlCompletionData val) { int index = -1; if (!Contains(val)) { index = List.Add(val); } return index; } /// /// Copies the elements of an array to the end of the . /// /// /// An array of type containing the objects to add to the collection. /// /// public void AddRange(XmlCompletionData[] val) { for (int i = 0; i < val.Length; i++) { this.Add(val[i]); } } /// /// Adds the contents of another to the end of the collection. /// /// /// A containing the objects to add to the collection. /// /// public void AddRange(XmlCompletionDataCollection val) { for (int i = 0; i < val.Count; i++) { this.Add(val[i]); } } /// /// Gets a value indicating whether the /// contains the specified . /// /// The to locate. /// /// if the is contained in the collection; /// otherwise, . /// /// public bool Contains(XmlCompletionData val) { if (val.Text != null) { if (val.Text.Length > 0) { return Contains(val.Text); } } return false; } public bool Contains(string name) { bool contains = false; foreach (XmlCompletionData data in this) { if (data.Text != null) { if (data.Text.Length > 0) { if (data.Text == name) { contains = true; break; } } } } return contains; } /// /// Copies the values to a one-dimensional instance at the /// specified index. /// /// The one-dimensional that is the destination of the values copied from . /// The index in where copying begins. /// /// is multidimensional. /// -or- /// The number of elements in the is greater than /// the available space between and the end of /// . /// /// is . /// is less than 's lowbound. /// public void CopyTo(XmlCompletionData[] array, int index) { List.CopyTo(array, index); } /// /// Copies the values to a one-dimensional instance at the /// specified index. /// public void CopyTo(ICompletionData[] array, int index) { List.CopyTo(array, index); } /// /// Returns the index of a in /// the . /// /// The to locate. /// /// The index of the of in the /// , if found; otherwise, -1. /// public int IndexOf(XmlCompletionData val) { return List.IndexOf(val); } /// /// Inserts a into the at the specified index. /// /// The zero-based index where should be inserted. /// The to insert. /// public void Insert(int index, XmlCompletionData val) { List.Insert(index, val); } /// /// Returns an array of items. /// /// public ICompletionData[] ToArray() { ICompletionData[] data = new ICompletionData[Count]; CopyTo(data, 0); return data; } /// /// Returns an enumerator that can iterate through the . /// /// public new XmlCompletionDataEnumerator GetEnumerator() { return new XmlCompletionDataEnumerator(this); } /// /// Removes a specific from the . /// /// The to remove from the . /// is not found in the Collection. public void Remove(XmlCompletionData val) { List.Remove(val); } /// /// Enumerator that can iterate through a XmlCompletionDataCollection. /// /// /// /// public class XmlCompletionDataEnumerator : IEnumerator { private readonly IEnumerator baseEnumerator; private IEnumerable temp; /// /// Initializes a new instance of . /// public XmlCompletionDataEnumerator(XmlCompletionDataCollection mappings) { this.temp = ((IEnumerable)(mappings)); this.baseEnumerator = temp.GetEnumerator(); } /// /// Gets the current in the . /// public XmlCompletionData Current { get { return ((XmlCompletionData)(baseEnumerator.Current)); } } object IEnumerator.Current { get { return baseEnumerator.Current; } } /// /// Advances the enumerator to the next of the . /// public bool MoveNext() { return baseEnumerator.MoveNext(); } /// /// Sets the enumerator to its initial position, which is before the first element in the . /// public void Reset() { baseEnumerator.Reset(); } } } }