Exemplo n.º 1
0
        /// <summary>
        /// Determines the index of a specific <see cref="ToolButtonMenuItem"/> in the current instance.
        /// </summary>
        /// <param name="item">The <see cref="ToolButtonMenuItem"/> to locate in the current instance.</param>
        /// <returns>The index of value if found in the current instance; otherwise, -1.</returns>
        public int IndexOf(ToolButtonMenuItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            return(_items.IndexOf(item));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether a <see cref="ToolButtonMenuItem"/> is in the collection.
        /// </summary>
        /// <param name="item">The <see cref="ToolButtonMenuItem"/> 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(ToolButtonMenuItem item)
        {
            if (item == null)
            {
                return(false);
            }

            return(_items.Contains(item));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a <see cref="ToolButtonMenuItem"/> to the collection.
        /// </summary>
        /// <param name="item">The <see cref="ToolButtonMenuItem"/> to add to the collection.</param>
        /// <returns>The position into which the new element was inserted.</returns>
        public int Add(ToolButtonMenuItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (_isTrackingViewState)
            {
                ((IStateManager)item).TrackViewState();
                item.SetDirty();
            }

            return(_items.Add(item));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Inserts a <see cref="ToolButtonMenuItem"/> 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="ToolButtonMenuItem"/> to insert into the Collection.</param>
        public void Insert(int index, ToolButtonMenuItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            _items.Insert(index, item);

            if (_isTrackingViewState)
            {
                ((IStateManager)item).TrackViewState();
                _saveAll = true;
            }
        }
Exemplo n.º 5
0
        /// <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++)
                {
                    ToolButtonMenuItem toolButtonMenuItem = (ToolButtonMenuItem)_items[i];
                    toolButtonMenuItem.SetDirty();
                    states.Add(((IStateManager)toolButtonMenuItem).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++)
                {
                    ToolButtonMenuItem toolButtonMenuItem = (ToolButtonMenuItem)_items[i];
                    object             state = ((IStateManager)toolButtonMenuItem).SaveViewState();
                    if (state != null)
                    {
                        states.Add(state);
                        indices.Add(i);
                    }
                }

                if (indices.Count > 0)
                {
                    return(new Pair(indices, states));
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Removes the first occurrence of a specific <see cref="ToolButtonMenuItem"/> from the collection.
        /// </summary>
        /// <param name="item">The <see cref="ToolButtonMenuItem"/> to remove from the collection.</param>
        public void Remove(ToolButtonMenuItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            int index = IndexOf(item);

            if (index >= 0)
            {
                RemoveAt(index);
            }

            if (_isTrackingViewState)
            {
                _saveAll = true;
            }
        }
Exemplo n.º 7
0
        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
                    {
                        ToolButtonMenuItem toolButtonMenuItem = new ToolButtonMenuItem();
                        Add(toolButtonMenuItem);
                        ((IStateManager)toolButtonMenuItem).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++)
                {
                    ToolButtonMenuItem toolButtonMenuItem = new ToolButtonMenuItem();
                    Add(toolButtonMenuItem);
                    ((IStateManager)toolButtonMenuItem).LoadViewState(states[i]);
                }
            }
        }