Ejemplo n.º 1
0
        internal void AddItem(object item, bool allowSorting, IList wrappedList)
        {
            int index = ProtectedItems.Count;

            if (allowSorting && !(item is CollectionViewGroup))
            {
                var comparer = Sorters.Count > 0 ? new PropertyComparer(Sorters) : null;

                for (int i = 0; i < ProtectedItems.Count; i++)
                {
                    int comparison;
                    if (comparer != null)
                    {
                        comparison = comparer.Compare(item, ProtectedItems [i]);
                    }
                    else
                    {
                        comparison = wrappedList.IndexOf(item).CompareTo(wrappedList.IndexOf(ProtectedItems [i]));
                    }

                    if (comparison < 0)
                    {
                        index = i;
                        break;
                    }
                }
            }

            ProtectedItems.Insert(index, item);
            if (!(item is StandardCollectionViewGroup))
            {
                IncrementCount();
            }
        }
Ejemplo n.º 2
0
        internal void InsertSpecialItem(int index, object item, bool loading)
        {
            ChangeCounts(item, +1);
            ProtectedItems.Insert(index, item);

            if (!loading)
            {
                int globalIndex = this.LeafIndexFromItem(item, index);
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, globalIndex));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Insert a new item or subgroup and return its index.  Seed is a
        /// representative from the subgroup (or the item itself) that
        /// is used to position the new item/subgroup w.r.t. the order given
        /// by the comparer. (If comparer is null, just add at the end).
        /// </summary>
        /// <param name="item">Item we are looking for</param>
        /// <param name="seed">Seed of the item we are looking for</param>
        /// <param name="comparer">Comparer used to find the item</param>
        /// <returns>The index where the item was inserted</returns>
        internal int Insert(object item, object seed, IComparer comparer)
        {
            // never insert the new item/group before the explicit subgroups
            int low   = (GroupBy == null) ? 0 : GroupBy.GroupNames.Count;
            int index = FindIndex(item, seed, comparer, low, ProtectedItems.Count);

            // now insert the item
            ChangeCounts(item, +1);
            ProtectedItems.Insert(index, item);

            return(index);
        }
        // insert a new item or subgroup and return its index.  Seed is a
        // representative from the subgroup (or the item itself) that
        // is used to position the new item/subgroup w.r.t. the order given
        // by the comparer.  (If comparer is null, just add at the end).
        internal int Insert(object item, object seed, IComparer comparer)
        {
            // when group sorting is not declared,
            // never insert the new item/group before the explicit subgroups
            int low = 0;

            if (_groupComparer == null && GroupBy != null)
            {
                low = GroupBy.GroupNames.Count;
            }

            int index = FindIndex(item, seed, comparer, low, ProtectedItems.Count);

            // now insert the item
            ChangeCounts(item, +1);
            ProtectedItems.Insert(index, item);

            return(index);
        }
Ejemplo n.º 5
0
        internal void AddItem(object item, bool allowSorting)
        {
            int index = ProtectedItems.Count;

            if (allowSorting && Sorters.Count > 0 && !(item is CollectionViewGroup))
            {
                var comparer = new PropertyComparer(Sorters);
                for (int i = 0; i < ProtectedItems.Count; i++)
                {
                    if (comparer.Compare(item, ProtectedItems [i]) < 0)
                    {
                        index = i;
                        break;
                    }
                }
            }

            ProtectedItems.Insert(index, item);
            if (!(item is StandardCollectionViewGroup))
            {
                IncrementCount();
            }
        }
 /// <summary>
 /// Insert a new item or subgroup.
 /// </summary>
 /// <param name="item">The item being inserted.</param>
 /// <param name="index">The index at which to insert the item.</param>
 internal void Insert(object item, int index)
 {
     this.ChangeCounts(item, +1);
     ProtectedItems.Insert(index, item);
 }