/// <inheritdoc/>
        public override int Remove(T item, Action <int> actionBeforeRemove = null)
        {
            if (!PassesFilter(item))
            {
                var isRemoved = FilteredItems.Remove(item);
                Debug.Assert(isRemoved);
                RemoveLiveShapingItemFor(item);
                return(-1);
            }

            return(base.Remove(item, actionBeforeRemove));
        }
Exemplo n.º 2
0
        public MainViewModel()
        {
            LoadData();
            filter = "allValues"; //Set default filter
            FilterData();

            /*
             * currencies.Add("EUR");
             * currencies.Add("USD");
             * currencies.Add("GBP");
             */

            BtnDeleteClicked = new RelayCommand(() => FilteredItems.Remove(selectedItem), () => { return(selectedItem != null); });
            BtnFilterClicked = new RelayCommand(FilterData);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes the data object from the filtered items
        /// </summary>
        /// <param name="value">Data object to be removed</param>
        public void Remove(object value)
        {
            bool wasRemoved = false;

            foreach (FilterableContentListItem item in FilteredItems.ToArray())
            {
                if (item.DataObject.Equals(value))
                {
                    FilteredItems.Remove(item);
                    wasRemoved = true;
                    break;
                }
            }
            if (!wasRemoved)
            {
                Debug.WriteLine("BasecodeLib warning: Cannot remove item. Doesn't exist in the collection.");
            }
        }
        private void OnDependencyPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            T item = (T)(LiveShapingItem <T>)dependencyObject;

            switch (GetCategoryOfDependencyProperty(args.Property))
            {
            case LiveShapingCategory.Sorting:
                int originalBinarySearchIndex = InternalBinarySearchWithEqualityCheck(item);
                int actualIndex;
                int targetIndex;

                if (originalBinarySearchIndex >= 0)
                {
                    Debug.Assert(BackingList[originalBinarySearchIndex].Equals(item));

                    actualIndex = originalBinarySearchIndex;
                    targetIndex = FindCorrectLocation(item);
                }
                else
                {
                    actualIndex = LinearSearch(item);
                    targetIndex = ~originalBinarySearchIndex;
                }

                LiveShapingItems[item].IsSortDirty = false;
                if (actualIndex >= 0)
                {
                    // adjust targetIndex if the item at actualIndex will no longer be there
                    if (actualIndex < targetIndex)
                    {
                        targetIndex--;
                    }
                    if (targetIndex != actualIndex)
                    {
                        BackingList.Move(actualIndex, targetIndex);
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, item, targetIndex,
                                                                                 actualIndex));
                    }
                }
                break;

            case LiveShapingCategory.Filtering:
                var passesFilter = PassesFilter(item);

                if (passesFilter)
                {
                    if (FilteredItems.Remove(item))
                    {
                        var insertionIndex = base.Add(item);
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, insertionIndex));
                    }
                }
                else
                {
                    if (!FilteredItems.Contains(item))
                    {
                        var removalIndex = IndexOf(item);

                        // It is possible that the liveshapingitem has been registered but the item has not yet been added to this collection (causing index = -1), in which case this is a noop
                        if (removalIndex >= 0)
                        {
                            base.RemoveAt(removalIndex);
                            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, removalIndex));
                            FilteredItems.Add(item);
                        }
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            /* Debug.WriteLine(args.Property + "  " + string.Join(", ",
             *                   BackingList.OfType<GameFolderPair>()
             *                              .Select(
             *                                  folderPair => {
             *                                      if (folderPair.DestinationEntry == null) return "-99";
             *
             *                                      return SizeToStringConverter.Instance.Convert(folderPair.DestinationEntry?.Size)
             + (LiveShapingItems[folderPair as T].IsSortDirty ? "" : "✓");
             +                                  })
             +               ));*/
        }