Esempio n. 1
0
        protected static bool TryInsert(BulkUpdateableCollection <T> collection, IReadOnlyList <T> items)
        {
            if (items.Count > collection.Count && collection.Count > 0)
            {
                var si = 0;
                foreach (var ce in collection)
                {
                    var found = false;
                    for (var i = si; i < items.Count; i++)
                    {
                        if (items[i] == ce)
                        {
                            si    = i + 1;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        return(false);
                    }
                }

                for (var i = 0; i < items.Count; i++)
                {
                    var e = items[i];
                    if (collection.ElementAtOrDefault(i) != e)
                    {
                        collection.Insert(i, e);
                    }
                }
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        protected static bool TryRemove(BulkUpdateableCollection <T> collection, IReadOnlyList <T> items)
        {
            if (0 < items.Count && items.Count < collection.Count)
            {
                var si = 0;
                foreach (var e in items)
                {
                    var found = false;
                    for (var i = si; i < collection.Count; i++)
                    {
                        if (collection[i] == e)
                        {
                            si    = i + 1;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        return(false);
                    }
                }

                for (var i = collection.Count - 1; i >= 0; i--)
                {
                    if (collection[i] != items.ElementAtOrDefault(items.Count - collection.Count + i))
                    {
                        collection.RemoveAt(i);
                    }
                }

                return(true);
            }
            return(false);
        }
Esempio n. 3
0
    public MenuPageItemViewModel(MenuPageGroupViewModel group, CommandViewModelBase command, bool isExtension = false)
    {
        Group       = group;
        Command     = command;
        SubCommands = new BulkUpdateableCollection <CommandViewModelBase>();
        IsExtension = isExtension;

        Command.PropertyChanged += Command_PropertyChanged;
    }
Esempio n. 4
0
        protected override void OnReplace(BulkUpdateableCollection <T> collection, IReadOnlyList <T> items)
        {
            collection.Items.Clear();

            foreach (var e in items)
            {
                collection.Items.Add(e);
            }

            collection.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
Esempio n. 5
0
    public InteractionServiceWindowViewModel(InteractionService interaction)
    {
        interaction.RegisterModal(typeof(CalculatorModalViewModel), vm => new CalculatorControl()
        {
            DataContext = vm
        });

        Interaction = interaction;
        Logs        = new BulkUpdateableCollection <LogViewModel>();
        BindingOperations.EnableCollectionSynchronization(Logs, ((ICollection)Logs).SyncRoot);
    }
Esempio n. 6
0
        protected virtual void OnReplace(BulkUpdateableCollection <T> collection, IReadOnlyList <T> items)
        {
            if (TryInsert(collection, items) ||
                TryRemove(collection, items))
            {
                return;
            }

            collection.Clear();

            foreach (var e in items)
            {
                collection.Add(e);
            }
        }
Esempio n. 7
0
 public virtual int RemoveAll(BulkUpdateableCollection <T> collection, Func <T, bool> predicate)
 {
     lock (((ICollection)collection).SyncRoot)
     {
         var c = 0;
         for (var i = collection.Count - 1; i >= 0; i--)
         {
             if (predicate(collection[i]))
             {
                 collection.RemoveAt(i);
                 c++;
             }
         }
         return(c);
     }
 }
Esempio n. 8
0
 public void Set(BulkUpdateableCollection <T> collection, IEnumerable <T> items)
 {
     if (items != collection)
     {
         lock (((ICollection)collection).SyncRoot)
         {
             var list = items as IReadOnlyList <T> ?? items?.ToList();
             if (list?.Count > 0)
             {
                 OnReplace(collection, list);
             }
             else if (collection.Items.Any())
             {
                 OnClear(collection);
             }
         }
     }
 }
Esempio n. 9
0
 public override int RemoveAll(BulkUpdateableCollection <T> collection, Func <T, bool> predicate)
 {
     lock (((ICollection)collection).SyncRoot)
     {
         var c = 0;
         for (var i = collection.Count - 1; i >= 0; i--)
         {
             if (predicate(collection[i]))
             {
                 collection.Items.RemoveAt(i);
                 c++;
             }
         }
         if (c > 0)
         {
             collection.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
         }
         return(c);
     }
 }
Esempio n. 10
0
 public ObjectValidator(object target, bool useExpressionBinding = false)
 {
     Target               = target;
     ValidationResults    = new BulkUpdateableCollection <ValidationResult>();
     UseExpressionBinding = useExpressionBinding;
 }
Esempio n. 11
0
 protected override void OnClear(BulkUpdateableCollection <T> collection)
 {
     collection.Clear();
     collection.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
 }
Esempio n. 12
0
 protected virtual void OnClear(BulkUpdateableCollection <T> collection)
 => collection.Clear();
Esempio n. 13
0
 public MenuPageGroupViewModel(string title)
 {
     Title = title;
     Items = new BulkUpdateableCollection <MenuPageItemViewModel>();
 }
Esempio n. 14
0
 public EntitySelectorComboBox()
 {
     _Items              = new BulkUpdateableCollection <Item>();
     DataContextChanged += EntitySelectorComboBox_DataContextChanged;
 }