void MoveTestHelper()
        {
            ObservableCollectionEx <GenericParameterHelper> target = CreateTargetHelper <GenericParameterHelper>();

            GenericParameterHelper item0 = new GenericParameterHelper(0);
            GenericParameterHelper item1 = new GenericParameterHelper(1);
            GenericParameterHelper item2 = new GenericParameterHelper(2);
            GenericParameterHelper item3 = new GenericParameterHelper(3);
            GenericParameterHelper item4 = new GenericParameterHelper(4);

            target.Add(item0);
            target.Add(item1);
            target.Add(item2);
            target.Add(item3);
            target.Add(item4);

            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();

            Assert.IsTrue(1 == target.IndexOf(item1));
            target.Move(1, 3);
            Assert.IsTrue(3 == target.IndexOf(item1));

            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();
            using (var iDisabled = target.DisableNotifications())
            {
                iDisabled.Move(3, 1);
                iDisabled.Move(1, 3);
                iDisabled.Move(3, 1);
                iDisabled.Move(1, 3);
                iDisabled.Move(3, 1);
            }
            Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");

            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();
            using (var iDelayed = target.DelayNotifications())
            {
                iDelayed.Move(1, 3);
                try
                {
                    iDelayed.Move(3, 1);
                    Assert.Fail("Only one move allowed");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(InvalidOperationException));
                }
            }
            Assert.IsTrue(1 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");
        }
Example #2
0
        public void Sort()
        {
            var list = _listViewItemCollection.OfType <SearchTreeViewItem>().ToList();

            list.Sort((x, y) =>
            {
                int c = x.Value.SearchItem.Name.CompareTo(y.Value.SearchItem.Name);
                if (c != 0)
                {
                    return(c);
                }
                c = x.Hit.CompareTo(y.Hit);
                if (c != 0)
                {
                    return(c);
                }

                return(x.GetHashCode().CompareTo(y.GetHashCode()));
            });

            for (int i = 0; i < list.Count; i++)
            {
                var o = _listViewItemCollection.IndexOf(list[i]);

                if (i != o)
                {
                    _listViewItemCollection.Move(o, i);
                }
            }

            foreach (var item in this.Items.OfType <SearchTreeViewItem>())
            {
                item.Sort();
            }
        }
Example #3
0
        private void Sort()
        {
            var list = _children.OfType <SearchTreeViewModel>().ToList();

            list.Sort((x, y) =>
            {
                int c = x.Value.SearchItem.Name.CompareTo(y.Value.SearchItem.Name);
                if (c != 0)
                {
                    return(c);
                }
                c = x.Count.CompareTo(y.Count);
                if (c != 0)
                {
                    return(c);
                }

                return(x.GetHashCode().CompareTo(y.GetHashCode()));
            });

            for (int i = 0; i < list.Count; i++)
            {
                var o = _children.IndexOf(list[i]);

                if (i != o)
                {
                    _children.Move(o, i);
                }
            }
        }
Example #4
0
        private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
        {
            if (e != null)
            {
                var item = e.OriginalSource as GridViewColumnHeader;
                if (item == null || item.Role == GridViewColumnHeaderRole.Padding)
                {
                    return;
                }

                string headerClicked = item.Column.Header as string;
                if (headerClicked == null)
                {
                    return;
                }

                ListSortDirection direction;

                if (headerClicked != Settings.Instance.DownloadControl_LastHeaderClicked)
                {
                    direction = ListSortDirection.Ascending;
                }
                else
                {
                    if (Settings.Instance.DownloadControl_ListSortDirection == ListSortDirection.Ascending)
                    {
                        direction = ListSortDirection.Descending;
                    }
                    else
                    {
                        direction = ListSortDirection.Ascending;
                    }
                }

                this.Sort(headerClicked, direction);

                Settings.Instance.DownloadControl_LastHeaderClicked = headerClicked;
                Settings.Instance.DownloadControl_ListSortDirection = direction;
            }
            else
            {
                _listView.Items.SortDescriptions.Clear();

                if (Settings.Instance.DownloadControl_LastHeaderClicked != null)
                {
                    var list = Sort(_listViewItemCollection, Settings.Instance.DownloadControl_LastHeaderClicked, Settings.Instance.DownloadControl_ListSortDirection).ToList();

                    for (int i = 0; i < list.Count; i++)
                    {
                        var o = _listViewItemCollection.IndexOf(list[i]);

                        if (i != o)
                        {
                            _listViewItemCollection.Move(o, i);
                        }
                    }
                }
            }
        }
Example #5
0
        public void Sort()
        {
            var list = _listViewItemCollection.OfType <BoxTreeViewItem>().ToList();

            list.Sort((x, y) =>
            {
                int c = x.Value.Name.CompareTo(y.Value.Name);
                if (c != 0)
                {
                    return(c);
                }
                c = (x.Value.Certificate == null).CompareTo(y.Value.Certificate == null);
                if (c != 0)
                {
                    return(c);
                }
                if (x.Value.Certificate != null && x.Value.Certificate != null)
                {
                    c = CollectionUtilities.Compare(x.Value.Certificate.PublicKey, y.Value.Certificate.PublicKey);
                    if (c != 0)
                    {
                        return(c);
                    }
                }
                c = y.Value.Seeds.Count.CompareTo(x.Value.Seeds.Count);
                if (c != 0)
                {
                    return(c);
                }
                c = y.Value.Boxes.Count.CompareTo(x.Value.Boxes.Count);
                if (c != 0)
                {
                    return(c);
                }

                return(x.GetHashCode().CompareTo(y.GetHashCode()));
            });

            for (int i = 0; i < list.Count; i++)
            {
                var o = _listViewItemCollection.IndexOf(list[i]);

                if (i != o)
                {
                    _listViewItemCollection.Move(o, i);
                }
            }

            foreach (var item in this.Items.OfType <BoxTreeViewItem>())
            {
                item.Sort();
            }
        }
Example #6
0
        private void Sort()
        {
            _listView.Items.SortDescriptions.Clear();

            if (Settings.Instance.DownloadControl_LastHeaderClicked != null)
            {
                var list = Sort(_listViewModelCollection, Settings.Instance.DownloadControl_LastHeaderClicked, Settings.Instance.DownloadControl_ListSortDirection).ToList();

                for (int i = 0; i < list.Count; i++)
                {
                    var o = _listViewModelCollection.IndexOf(list[i]);

                    if (i != o)
                    {
                        _listViewModelCollection.Move(o, i);
                    }
                }
            }
        }
        public void Sort()
        {
            var list = _listViewItemCollection.Cast <TreeViewItem>().ToList();

            list.Sort((x, y) =>
            {
                if (x is StoreCategorizeTreeViewItem)
                {
                    if (y is StoreCategorizeTreeViewItem)
                    {
                        var vx = ((StoreCategorizeTreeViewItem)x).Value;
                        var vy = ((StoreCategorizeTreeViewItem)y).Value;

                        int c = vx.Name.CompareTo(vy.Name);
                        if (c != 0)
                        {
                            return(c);
                        }
                        c = vx.StoreTreeItems.Count.CompareTo(vy.StoreTreeItems.Count);
                        if (c != 0)
                        {
                            return(c);
                        }
                        c = vx.GetHashCode().CompareTo(vy.GetHashCode());
                        if (c != 0)
                        {
                            return(c);
                        }
                    }
                    else if (y is StoreTreeViewItem)
                    {
                        return(-1);
                    }
                }
                else if (x is StoreTreeViewItem)
                {
                    if (y is StoreTreeViewItem)
                    {
                        var vx = ((StoreTreeViewItem)x).Value;
                        var vy = ((StoreTreeViewItem)y).Value;

                        int c = vx.Signature.CompareTo(vy.Signature);
                        if (c != 0)
                        {
                            return(c);
                        }
                        c = vx.Boxes.Count.CompareTo(vy.Boxes.Count);
                        if (c != 0)
                        {
                            return(c);
                        }
                        c = vx.GetHashCode().CompareTo(vy.GetHashCode());
                        if (c != 0)
                        {
                            return(c);
                        }
                    }
                    else if (y is StoreCategorizeTreeViewItem)
                    {
                        return(1);
                    }
                }

                return(0);
            });

            for (int i = 0; i < list.Count; i++)
            {
                var o = _listViewItemCollection.IndexOf(list[i]);

                if (i != o)
                {
                    _listViewItemCollection.Move(o, i);
                }
            }
        }
        public void Sort()
        {
            var list = _children.Cast <TreeViewModelBase>().ToList();

            list.Sort((x, y) =>
            {
                if (x is ChatCategorizeTreeViewModel)
                {
                    if (y is ChatCategorizeTreeViewModel)
                    {
                        var vx = ((ChatCategorizeTreeViewModel)x).Value;
                        var vy = ((ChatCategorizeTreeViewModel)y).Value;

                        int c = vx.Name.CompareTo(vy.Name);
                        if (c != 0)
                        {
                            return(c);
                        }
                        c = vx.ChatTreeItems.Count.CompareTo(vy.ChatTreeItems.Count);
                        if (c != 0)
                        {
                            return(c);
                        }
                        c = vx.GetHashCode().CompareTo(vy.GetHashCode());
                        if (c != 0)
                        {
                            return(c);
                        }
                    }
                    else if (y is ChatTreeViewModel)
                    {
                        return(1);
                    }
                }
                else if (x is ChatTreeViewModel)
                {
                    if (y is ChatTreeViewModel)
                    {
                        var vx = ((ChatTreeViewModel)x).Value;
                        var vy = ((ChatTreeViewModel)y).Value;

                        int c = vx.Tag.Name.CompareTo(vy.Tag.Name);
                        if (c != 0)
                        {
                            return(c);
                        }
                        c = CollectionUtils.Compare(vx.Tag.Id, vy.Tag.Id);
                        if (c != 0)
                        {
                            return(c);
                        }
                        c = vx.GetHashCode().CompareTo(vy.GetHashCode());
                        if (c != 0)
                        {
                            return(c);
                        }
                    }
                    else if (y is ChatCategorizeTreeViewModel)
                    {
                        return(-1);
                    }
                }

                return(0);
            });

            for (int i = 0; i < list.Count; i++)
            {
                var o = _children.IndexOf(list[i]);

                if (i != o)
                {
                    _children.Move(o, i);
                }
            }
        }