~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor.Completion/XmlCompletionDataCollection.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// MonoDevelop XML Editor
 
3
//
 
4
// Copyright (C) 2005-2006 Matthew Ward
 
5
//
 
6
 
 
7
using MonoDevelop.Projects.Gui.Completion;
 
8
using System;
 
9
using System.Collections;
 
10
 
 
11
namespace MonoDevelop.XmlEditor.Completion
 
12
{
 
13
        /// <summary>
 
14
        ///   A collection that stores <see cref='XmlCompletionData'/> objects.
 
15
        /// </summary>
 
16
        [Serializable()]
 
17
        public class XmlCompletionDataCollection : CollectionBase {
 
18
                
 
19
                /// <summary>
 
20
                ///   Initializes a new instance of <see cref='XmlCompletionDataCollection'/>.
 
21
                /// </summary>
 
22
                public XmlCompletionDataCollection()
 
23
                {
 
24
                }
 
25
                
 
26
                /// <summary>
 
27
                ///   Initializes a new instance of <see cref='XmlCompletionDataCollection'/> based on another <see cref='XmlCompletionDataCollection'/>.
 
28
                /// </summary>
 
29
                /// <param name='val'>
 
30
                ///   A <see cref='XmlCompletionDataCollection'/> from which the contents are copied
 
31
                /// </param>
 
32
                public XmlCompletionDataCollection(XmlCompletionDataCollection val)
 
33
                {
 
34
                        this.AddRange(val);
 
35
                }
 
36
                
 
37
                /// <summary>
 
38
                ///   Initializes a new instance of <see cref='XmlCompletionDataCollection'/> containing any array of <see cref='XmlCompletionData'/> objects.
 
39
                /// </summary>
 
40
                /// <param name='val'>
 
41
                ///       A array of <see cref='XmlCompletionData'/> objects with which to intialize the collection
 
42
                /// </param>
 
43
                public XmlCompletionDataCollection(XmlCompletionData[] val)
 
44
                {
 
45
                        this.AddRange(val);
 
46
                }
 
47
                
 
48
                /// <summary>
 
49
                ///   Represents the entry at the specified index of the <see cref='XmlCompletionData'/>.
 
50
                /// </summary>
 
51
                /// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
 
52
                /// <value>The entry at the specified index of the collection.</value>
 
53
                /// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
 
54
                public XmlCompletionData this[int index] {
 
55
                        get {
 
56
                                return ((XmlCompletionData)(List[index]));
 
57
                        }
 
58
                        set {
 
59
                                List[index] = value;
 
60
                        }
 
61
                }
 
62
                
 
63
                /// <summary>
 
64
                ///   Adds a <see cref='XmlCompletionData'/> with the specified value to the 
 
65
                ///   <see cref='XmlCompletionDataCollection'/>.
 
66
                /// </summary>
 
67
                /// <remarks>
 
68
                /// If the completion data already exists in the collection it is not added.
 
69
                /// </remarks>
 
70
                /// <param name='val'>The <see cref='XmlCompletionData'/> to add.</param>
 
71
                /// <returns>The index at which the new element was inserted.</returns>
 
72
                /// <seealso cref='XmlCompletionDataCollection.AddRange'/>
 
73
                public int Add(XmlCompletionData val)
 
74
                {
 
75
                        int index = -1;
 
76
                        if (!Contains(val)) {
 
77
                                index = List.Add(val);
 
78
                        }
 
79
                        return index;
 
80
                }
 
81
                
 
82
                /// <summary>
 
83
                ///   Copies the elements of an array to the end of the <see cref='XmlCompletionDataCollection'/>.
 
84
                /// </summary>
 
85
                /// <param name='val'>
 
86
                ///    An array of type <see cref='XmlCompletionData'/> containing the objects to add to the collection.
 
87
                /// </param>
 
88
                /// <seealso cref='XmlCompletionDataCollection.Add'/>
 
89
                public void AddRange(XmlCompletionData[] val)
 
90
                {
 
91
                        for (int i = 0; i < val.Length; i++) {
 
92
                                this.Add(val[i]);
 
93
                        }
 
94
                }
 
95
                
 
96
                /// <summary>
 
97
                ///   Adds the contents of another <see cref='XmlCompletionDataCollection'/> to the end of the collection.
 
98
                /// </summary>
 
99
                /// <param name='val'>
 
100
                ///    A <see cref='XmlCompletionDataCollection'/> containing the objects to add to the collection.
 
101
                /// </param>
 
102
                /// <seealso cref='XmlCompletionDataCollection.Add'/>
 
103
                public void AddRange(XmlCompletionDataCollection val)
 
104
                {
 
105
                        for (int i = 0; i < val.Count; i++)
 
106
                        {
 
107
                                this.Add(val[i]);
 
108
                        }
 
109
                }
 
110
                
 
111
                /// <summary>
 
112
                ///   Gets a value indicating whether the 
 
113
                ///    <see cref='XmlCompletionDataCollection'/> contains the specified <see cref='XmlCompletionData'/>.
 
114
                /// </summary>
 
115
                /// <param name='val'>The <see cref='XmlCompletionData'/> to locate.</param>
 
116
                /// <returns>
 
117
                /// <see langword='true'/> if the <see cref='XmlCompletionData'/> is contained in the collection; 
 
118
                ///   otherwise, <see langword='false'/>.
 
119
                /// </returns>
 
120
                /// <seealso cref='XmlCompletionDataCollection.IndexOf'/>
 
121
                public bool Contains(XmlCompletionData val)
 
122
                {
 
123
                        if (!string.IsNullOrEmpty (val.DisplayText)) {
 
124
                                return Contains (val.DisplayText);
 
125
                        }
 
126
                        return false;
 
127
                }
 
128
                
 
129
                public bool Contains(string name)
 
130
                {
 
131
                        bool contains = false;
 
132
                        
 
133
                        foreach (XmlCompletionData data in this) {
 
134
                                if (!string.IsNullOrEmpty (data.DisplayText)) {
 
135
                                        if (data.DisplayText == name) {
 
136
                                                contains = true;
 
137
                                                break;
 
138
                                        }
 
139
                                }
 
140
                        }
 
141
                        
 
142
                        return contains;
 
143
                }
 
144
                
 
145
                /// <summary>
 
146
                ///   Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the 
 
147
                ///    specified index.
 
148
                /// </summary>
 
149
                /// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='XmlCompletionDataCollection'/>.</param>
 
150
                /// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
 
151
                /// <exception cref='ArgumentException'>
 
152
                ///   <para><paramref name='array'/> is multidimensional.</para>
 
153
                ///   <para>-or-</para>
 
154
                ///   <para>The number of elements in the <see cref='XmlCompletionDataCollection'/> is greater than
 
155
                ///         the available space between <paramref name='arrayIndex'/> and the end of
 
156
                ///         <paramref name='array'/>.</para>
 
157
                /// </exception>
 
158
                /// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
 
159
                /// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
 
160
                /// <seealso cref='Array'/>
 
161
                public void CopyTo(XmlCompletionData[] array, int index)
 
162
                {
 
163
                        List.CopyTo(array, index);
 
164
                }
 
165
                
 
166
                /// <summary>
 
167
                ///   Copies the <see cref='XmlCompletionDataCollection'/> values to a one-dimensional <see cref='Array'/> instance at the 
 
168
                ///    specified index.
 
169
                /// </summary>
 
170
                public void CopyTo(ICompletionData[] array, int index)
 
171
                {
 
172
                        List.CopyTo(array, index);
 
173
                }               
 
174
                
 
175
                /// <summary>
 
176
                ///    Returns the index of a <see cref='XmlCompletionData'/> in 
 
177
                ///       the <see cref='XmlCompletionDataCollection'/>.
 
178
                /// </summary>
 
179
                /// <param name='val'>The <see cref='XmlCompletionData'/> to locate.</param>
 
180
                /// <returns>
 
181
                ///   The index of the <see cref='XmlCompletionData'/> of <paramref name='val'/> in the 
 
182
                ///   <see cref='XmlCompletionDataCollection'/>, if found; otherwise, -1.
 
183
                /// </returns>
 
184
                /// <seealso cref='XmlCompletionDataCollection.Contains'/>
 
185
                public int IndexOf(XmlCompletionData val)
 
186
                {
 
187
                        return List.IndexOf(val);
 
188
                }
 
189
                
 
190
                /// <summary>
 
191
                ///   Inserts a <see cref='XmlCompletionData'/> into the <see cref='XmlCompletionDataCollection'/> at the specified index.
 
192
                /// </summary>
 
193
                /// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
 
194
                /// <param name='val'>The <see cref='XmlCompletionData'/> to insert.</param>
 
195
                /// <seealso cref='XmlCompletionDataCollection.Add'/>
 
196
                public void Insert(int index, XmlCompletionData val)
 
197
                {
 
198
                        List.Insert(index, val);
 
199
                }
 
200
                
 
201
                /// <summary>
 
202
                /// Returns an array of <see cref="ICompletionData"/> items.
 
203
                /// </summary>
 
204
                /// <returns></returns>
 
205
                public ICompletionData[] ToArray()
 
206
                {
 
207
                        ICompletionData[] data = new ICompletionData[Count];
 
208
                        CopyTo(data, 0);
 
209
                        return data;
 
210
                }
 
211
                
 
212
                /// <summary>
 
213
                ///  Returns an enumerator that can iterate through the <see cref='XmlCompletionDataCollection'/>.
 
214
                /// </summary>
 
215
                /// <seealso cref='IEnumerator'/>
 
216
                public new XmlCompletionDataEnumerator GetEnumerator()
 
217
                {
 
218
                        return new XmlCompletionDataEnumerator(this);
 
219
                }
 
220
                
 
221
                /// <summary>
 
222
                ///   Removes a specific <see cref='XmlCompletionData'/> from the <see cref='XmlCompletionDataCollection'/>.
 
223
                /// </summary>
 
224
                /// <param name='val'>The <see cref='XmlCompletionData'/> to remove from the <see cref='XmlCompletionDataCollection'/>.</param>
 
225
                /// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
 
226
                public void Remove(XmlCompletionData val)
 
227
                {
 
228
                        List.Remove(val);
 
229
                }
 
230
                
 
231
                /// <summary>
 
232
                ///   Enumerator that can iterate through a XmlCompletionDataCollection.
 
233
                /// </summary>
 
234
                /// <seealso cref='IEnumerator'/>
 
235
                /// <seealso cref='XmlCompletionDataCollection'/>
 
236
                /// <seealso cref='XmlCompletionData'/>
 
237
                public class XmlCompletionDataEnumerator : IEnumerator
 
238
                {
 
239
                        IEnumerator baseEnumerator;
 
240
                        IEnumerable temp;
 
241
                        
 
242
                        /// <summary>
 
243
                        ///   Initializes a new instance of <see cref='XmlCompletionDataEnumerator'/>.
 
244
                        /// </summary>
 
245
                        public XmlCompletionDataEnumerator(XmlCompletionDataCollection mappings)
 
246
                        {
 
247
                                this.temp = ((IEnumerable)(mappings));
 
248
                                this.baseEnumerator = temp.GetEnumerator();
 
249
                        }
 
250
                        
 
251
                        /// <summary>
 
252
                        ///   Gets the current <see cref='XmlCompletionData'/> in the <seealso cref='XmlCompletionDataCollection'/>.
 
253
                        /// </summary>
 
254
                        public XmlCompletionData Current {
 
255
                                get {
 
256
                                        return ((XmlCompletionData)(baseEnumerator.Current));
 
257
                                }
 
258
                        }
 
259
                        
 
260
                        object IEnumerator.Current {
 
261
                                get {
 
262
                                        return baseEnumerator.Current;
 
263
                                }
 
264
                        }
 
265
                        
 
266
                        /// <summary>
 
267
                        ///   Advances the enumerator to the next <see cref='XmlCompletionData'/> of the <see cref='XmlCompletionDataCollection'/>.
 
268
                        /// </summary>
 
269
                        public bool MoveNext()
 
270
                        {
 
271
                                return baseEnumerator.MoveNext();
 
272
                        }
 
273
                        
 
274
                        /// <summary>
 
275
                        ///   Sets the enumerator to its initial position, which is before the first element in the <see cref='XmlCompletionDataCollection'/>.
 
276
                        /// </summary>
 
277
                        public void Reset()
 
278
                        {
 
279
                                baseEnumerator.Reset();
 
280
                        }
 
281
                }
 
282
        }
 
283
}