Esempio n. 1
0
        protected virtual void ApplyCollectionItemRemove(ApplyingCollectionChangeBundle bundle)
        {
            var contentContentChange = bundle.ContentContentChange;
            var oldItems             = contentContentChange.OldItems;

            if (oldItems is null)
            {
                throw new ArgumentException("No old content-content-items were given although a remove collection change action has been triggered.");
            }

            var oldItemsCount = oldItems.Count;
            var oldIndex      = contentContentChange.OldIndex;

            for (var oldItemIndex = oldItemsCount - 1; oldItemIndex >= 0; oldItemIndex--)
            {
                var removeIndex = oldItemIndex + oldIndex;
#if DEBUG
                var removingContent = ContentList[removeIndex];
                var oldContent      = oldItems[oldItemIndex];

                if (!EqualityComparer.Equals(removingContent, oldContent))
                {
                    throw new Exception("Removing item is not equals old item that should be removed instead");
                }
#endif
                ItemList.RemoveAt(removeIndex);
                ContentList.RemoveAt(removeIndex);
            }
        }
Esempio n. 2
0
        protected virtual void ApplyCollectionChangeBundle(ApplyingCollectionChangeBundle bundle)
        {
            switch (bundle.ContentContentChange.Action)
            {
            case NotifyCollectionChangedAction.Remove:
                ApplyCollectionItemRemove(bundle);
                break;

            case NotifyCollectionChangedAction.Add:
                ApplyCollectionItemAdd(bundle);
                break;

            case NotifyCollectionChangedAction.Move:
                ApplyCollectionItemMove(bundle);
                break;

            case NotifyCollectionChangedAction.Replace:
                ApplyCollectionItemReplace(bundle);
                break;

            case NotifyCollectionChangedAction.Reset:
                ApplyCollectionReset(bundle);
                break;
            }
        }
Esempio n. 3
0
        protected virtual void ApplyCollectionReset(ApplyingCollectionChangeBundle bundle)
        {
            var change         = bundle.ItemContentChange;
            var newContentList = change.NewItems ?? throw new ArgumentNullException(nameof(change.NewItems));
            var newItemList    = newContentList.Select(x => CreateItem(x));

            void resetList <T>(IList <T> list, IEnumerable <T> newList)
            {
                list.Clear();

                if (list is List <T> typedList)
                {
                    typedList.AddRange(newList);
                }
                else
                {
                    foreach (var item in newList)
                    {
                        list.Add(item);
                    }
                }
            }

            resetList(ItemList, newItemList);
            resetList(ContentList, newContentList);
        }
Esempio n. 4
0
        private void applyCollectionChange(ICollectionChange <ContentType, ContentType> contentContentChange, out ICollectionChangeBundle <ItemType, ContentType> appliedBundle)
        {
            var itemContentChange = CreateItemContentCollectionChange(contentContentChange);
            var applyingBundle    = new ApplyingCollectionChangeBundle(itemContentChange, contentContentChange);

            ApplyCollectionChangeBundle(applyingBundle);
            appliedBundle = GetAppliedCollectionChangeBundle(applyingBundle);
        }
Esempio n. 5
0
        protected AppliedCollectionChangeBundle GetAppliedCollectionChangeBundle(ApplyingCollectionChangeBundle applyingBundle)
        {
            var itemContentChange = applyingBundle.ItemContentChange;
            var newItemList       = itemContentChange.GetNewItems(ItemList);
            var itemItemChange    = itemContentChange.CreateOf(itemContentChange.OldItems, newItemList);
            var appliedBundle     = new AppliedCollectionChangeBundle(itemItemChange, applyingBundle.ItemContentChange, applyingBundle.ContentContentChange);

            return(appliedBundle);
        }
Esempio n. 6
0
        /// <summary>
        /// Does regards <see cref="ObservableCollection{T}.Move(int, int)"/>, otherwise
        /// it fallbacks to <see cref="IListGenericExtensions.Move{T}(IList{T}, int, int)"/>
        /// </summary>
        /// <param name="change"></param>
        protected virtual void ApplyCollectionItemMove(ApplyingCollectionChangeBundle bundle)
        {
            var change = bundle.ItemContentChange;

            void moveItem <T>(IList <T> list)
            {
                if (list is ObservableCollection <ItemType> observableList)
                {
                    observableList.Move(change.OldIndex, change.NewIndex);
                }
                else
                {
                    list.Move(change.OldIndex, change.NewIndex);
                }
            }

            moveItem(ItemList);
            moveItem(ContentList);
        }
Esempio n. 7
0
        protected virtual void ApplyCollectionItemAdd(ApplyingCollectionChangeBundle bundle)
        {
            var itemContentChange      = bundle.ItemContentChange;
            var newContentContentItems = itemContentChange.NewItems;

            if (newContentContentItems is null)
            {
                throw new ArgumentException("No new item-content-items were given although an add collection change action has been triggered.");
            }

            var newItemsCount = newContentContentItems.Count;

            for (int itemIndex = 0; itemIndex < newItemsCount; itemIndex++)
            {
                var content         = newContentContentItems[itemIndex];
                var itemInsertIndex = itemContentChange.NewIndex + itemIndex;
                var item            = CreateItem(content);

                ItemList.Insert(itemInsertIndex, item);
                ContentList.Insert(itemInsertIndex, content);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// This method has no code inside and is ready for override.
 /// </summary>
 protected virtual void ApplyCollectionItemReplace(ApplyingCollectionChangeBundle bundle)
 {
 }