private void Moveup()
        {
            var selectedItem  = _right.First(x => x.IsSelected);
            var selectedIndex = _right.IndexOf(selectedItem);

            _right.Remove(selectedItem);
            _right.Insert(--selectedIndex, selectedItem);

            _columnsService.ShowColumns(_identifier, _right.Select(x => x.Name));
        }
        public void Write_InsertElement_ElementInserted()
        {
            var col = new RangeObservableCollection <string>(new[] { "a", "b", "c" });

            col.Insert(1, "x");
            CollectionAssert.AreEqual(col, new[] { "a", "x", "b", "c" });
        }
Пример #3
0
        public void SetOrder(TValue tuple)
        {
            _validateLoaded();
            _items.Dispatch(delegate {
                if (_items.ItemsSource == null)
                {
                    return;
                }

                RangeObservableCollection <TValue> allItems = (RangeObservableCollection <TValue>)_items.ItemsSource;

                List <TValue> items = allItems.ToList();
                var oldInex         = items.IndexOf(tuple);

                if (oldInex < 0)
                {
                    var index = items.BinarySearch(tuple, _entryComparer);
                    if (index < 0)
                    {
                        index = ~index;
                    }
                    allItems.Insert(index, tuple);
                }
                else
                {
                    items.Remove(tuple);
                    var index = items.BinarySearch(tuple, _entryComparer);
                    if (index < 0)
                    {
                        index = ~index;
                    }
                    allItems.Move(oldInex, index);
                }
            });
        }
Пример #4
0
        public void CollectionChanges()
        {
            var numbers = new RangeObservableCollection <int>(Enumerable.Range(1, 10));
            var values  = new BlockingCollection <int>();

            using (var expr = ActiveExpression.Create(p1 => p1[5], numbers))
            {
                var disconnect = expr.OnPropertyChanged(ae => ae.Value, value => values.Add(value));
                values.Add(expr.Value);
                numbers.Add(11);
                numbers.Insert(0, 0);
                numbers.Remove(11);
                numbers.Remove(0);
                numbers[4] = 50;
                numbers[4] = 5;
                numbers[5] = 60;
                numbers[5] = 6;
                numbers[6] = 70;
                numbers[6] = 7;
                numbers.Move(0, 1);
                numbers.Move(0, 1);
                numbers.MoveRange(0, 5, 5);
                numbers.MoveRange(0, 5, 5);
                numbers.MoveRange(5, 0, 5);
                numbers.MoveRange(5, 0, 5);
                numbers.Reset(numbers.Select(i => i * 10).ToImmutableArray());
                disconnect();
            }
            Assert.IsTrue(new int[] { 6, 5, 6, 60, 6, 1, 6, 1, 6, 60 }.SequenceEqual(values));
        }
Пример #5
0
        public void Write_InsertElement_ElementInserted()
        {
            var col = new RangeObservableCollection <string>(new[] { "a", "b", "c" });

            col.Insert(1, "x");

            col.Should().BeEquivalentTo("a", "x", "b", "c");
        }
        public void Write_ComplexOperation_CollectionUpdatedProperly()
        {
            var col = new RangeObservableCollection <string>(new[] { "a", "b", "c" });

            col.Add("d");
            col.Remove("b");
            col.Insert(0, "x");
            col.AddRange(new[] { "z", "f", "y" });
            col.RemoveAt(4);
            col.RemoveRange(new[] { "y", "c" });
            col[2] = "p";
            CollectionAssert.AreEquivalent(new[] { "x", "a", "p", "f" }, col);
        }
        public void Write_InsertElement_FiresAddEvent()
        {
            var col = new RangeObservableCollection <string>(new[] { "a", "b", "c" });
            NotifyCollectionChangedEventArgs receivedArgs = null;

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Add)
                {
                    receivedArgs = args;
                }
            };
            col.Insert(1, "x");
            Assert.That(receivedArgs.NewStartingIndex, Is.EqualTo(1), "Index is wrong");
            CollectionAssert.AreEquivalent(receivedArgs.NewItems, new[] { "x" }, "New items collection wrong");
        }
Пример #8
0
        public void Write_InsertElement_FiresAddEvent()
        {
            var col = new RangeObservableCollection <string>(new[] { "a", "b", "c" });
            NotifyCollectionChangedEventArgs receivedArgs = null;

            col.CollectionChanged += (sender, args) =>
            {
                if (args.Action == NotifyCollectionChangedAction.Add)
                {
                    receivedArgs = args;
                }
            };
            col.Insert(1, "x");

            receivedArgs.NewStartingIndex.Should().Be(1, "the item should be inserted at the correct position");
            receivedArgs.NewItems.Should().BeEquivalentTo(new[] { "x" }, "the new items collection should be correct");
        }
Пример #9
0
        public void AddTuple(TValue tuple)
        {
            _validateLoaded();
            _items.Dispatch(delegate {
                if (_items.ItemsSource == null)
                {
                    return;
                }

                RangeObservableCollection <TValue> allItems = (RangeObservableCollection <TValue>)_items.ItemsSource;

                var index = allItems.ToList().BinarySearch(tuple, _entryComparer);
                if (index < 0)
                {
                    index = ~index;
                }
                allItems.Insert(index, tuple);
            });
        }
Пример #10
0
        public void SourceManipulation()
        {
            var numbers = new RangeObservableCollection <int>(System.Linq.Enumerable.Range(0, 10));

            using (var query = numbers.ActiveElementAt(9))
            {
                Assert.IsNull(query.OperationFault);
                Assert.AreEqual(9, query.Value);
                numbers.Remove(9);
                Assert.IsNotNull(query.OperationFault);
                Assert.AreEqual(0, query.Value);
                numbers.Add(30);
                Assert.IsNull(query.OperationFault);
                Assert.AreEqual(30, query.Value);
                numbers.Insert(9, 15);
                Assert.IsNull(query.OperationFault);
                Assert.AreEqual(15, query.Value);
            }
        }
        private void _move(bool up)
        {
            if (!_enableEvents)
            {
                return;
            }

            try {
                if (_primaryShop.ShopItems.Count == 0)
                {
                    return;
                }

                if (_lvItems.SelectedItems.Count == 0)
                {
                    return;
                }

                _enableEvents = false;

                var selectedItem  = _lvItems.SelectedItem as ShopItem;
                var shopItems     = _lvItems.SelectedItems.Cast <ShopItem>().ToList();
                var shopItemsData = shopItems.Select(p => p.ShopItemData).ToList();

                if (up && shopItemsData.Any(p => p == _primaryShop.ShopItems[0]))
                {
                    return;
                }
                else if (!up && shopItemsData.Any(p => p == _primaryShop.ShopItems[_primaryShop.ShopItems.Count - 1]))
                {
                    return;
                }

                for (int i = up ? 0 : _primaryShop.ShopItems.Count - 1;
                     up?i < _primaryShop.ShopItems.Count : i >= 0;
                     i = up ? i + 1 : i - 1)
                {
                    var index = shopItemsData.IndexOf(_primaryShop.ShopItems[i]);

                    if (index > -1)
                    {
                        var shopItemData = shopItemsData[index];
                        var shopItem     = shopItems[index];

                        _primaryShop.ShopItems.RemoveAt(i);
                        _shopItems.RemoveAt(i);

                        if (up)
                        {
                            _primaryShop.ShopItems.Insert(i - 1, shopItemData);
                            _shopItems.Insert(i - 1, shopItem);
                        }
                        else
                        {
                            _primaryShop.ShopItems.Insert(i + 1, shopItemData);
                            _shopItems.Insert(i + 1, shopItem);
                        }
                    }
                }

                shopItems.Remove(selectedItem);
                shopItems.Insert(0, selectedItem);

                _lvItems.SelectedItems.Clear();
                _lvItems.SelectItems(shopItems);

                _primaryShop.Reload();
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
            finally {
                _enableEvents = true;
            }
        }
Пример #12
0
 protected void Insert(int index, ICanvasObject child)
 {
     children.Insert(index, child);
     child.RedrawEvent += EmitRedrawEvent;
 }