/// <summary> /// Determines the index of a specific <see cref="ToolItem"/> in the current instance. /// </summary> /// <param name="item">The <see cref="ToolItem"/> to locate in the current instance.</param> /// <returns>The index of value if found in the current instance; otherwise, -1.</returns> public int IndexOf(ToolItem item) { if (item == null) { throw new ArgumentNullException("item"); } return(_items.IndexOf(item)); }
/// <summary> /// Determines whether a <see cref="ToolItem"/> is in the collection. /// </summary> /// <param name="item">The <see cref="ToolItem"/> to locate in the collection. The element to locate can be a null reference.</param> /// <returns>true if value is found in the collection; otherwise, false.</returns> public bool Contains(ToolItem item) { if (item == null) { return(false); } return(_items.Contains(item)); }
/// <summary> /// Adds a <see cref="ToolItem"/> to the collection. /// </summary> /// <param name="item">The <see cref="ToolItem"/> to add to the collection.</param> /// <returns>The position into which the new element was inserted.</returns> public int Add(ToolItem item) { if (item == null) { throw new ArgumentNullException("item"); } if (_isTrackingViewState) { ((IStateManager)item).TrackViewState(); item.SetDirty(); } return(_items.Add(item)); }
/// <summary> /// Inserts a <see cref="ToolItem"/> to the collection at the specified position. /// </summary> /// <param name="index">The zero-based index at which value should be inserted.</param> /// <param name="item">The <see cref="ToolItem"/> to insert into the Collection.</param> public void Insert(int index, ToolItem item) { if (item == null) { throw new ArgumentNullException("item"); } _items.Insert(index, item); if (_isTrackingViewState) { ((IStateManager)item).TrackViewState(); _saveAll = true; } }
/// <summary> /// When implemented by a class, saves the changes to a server control's view state to an /// <see cref="T:System.Object"/> . /// </summary> /// <returns> /// The <see langword="Object"/> that contains the view state changes. /// </returns> public object SaveViewState() { if (_saveAll == true) { // Save all items. ArrayList states = new ArrayList(Count); for (int i = 0; i < Count; i++) { ToolItem toolItem = (ToolItem)_items[i]; toolItem.SetDirty(); states.Add(((IStateManager)toolItem).SaveViewState()); } if (states.Count > 0) { return(states); } else { return(null); } } else { // Save only the dirty items. ArrayList indices = new ArrayList(); ArrayList states = new ArrayList(); for (int i = 0; i < Count; i++) { ToolItem toolItem = (ToolItem)_items[i]; object state = ((IStateManager)toolItem).SaveViewState(); if (state != null) { states.Add(state); indices.Add(i); } } if (indices.Count > 0) { return(new Pair(indices, states)); } } return(null); }
/// <summary> /// Removes the first occurrence of a specific <see cref="ToolItem"/> from the collection. /// </summary> /// <param name="item">The <see cref="ToolItem"/> to remove from the collection.</param> public void Remove(ToolItem item) { if (item == null) { throw new ArgumentNullException("item"); } int index = IndexOf(item); if (index >= 0) { RemoveAt(index); } if (_isTrackingViewState) { _saveAll = true; } }
void IStateManager.LoadViewState(object savedState) { if (savedState == null) { return; } if (savedState is Pair) { Pair p = (Pair)savedState; ArrayList indices = (ArrayList)p.First; ArrayList states = (ArrayList)p.Second; for (int i = 0; i < indices.Count; i++) { int index = (int)indices[i]; if (index < this.Count) { ((IStateManager)_items[index]).LoadViewState(states[i]); } else { ToolItem toolItem = new ToolItem(); Add(toolItem); ((IStateManager)toolItem).LoadViewState(states[i]); } } } else if (savedState is ArrayList) { _saveAll = true; ArrayList states = (ArrayList)savedState; _items = new ArrayList(states.Count); for (int i = 0; i < states.Count; i++) { ToolItem toolItem = new ToolItem(); Add(toolItem); ((IStateManager)toolItem).LoadViewState(states[i]); } } }