Esempio n. 1
0
        public RepositoryGroupBinding(CustomListBoxItemsCollection items, RepositoryGroup group)
        {
            Verify.Argument.IsNotNull(items, nameof(items));
            Verify.Argument.IsNotNull(group, nameof(group));

            _items               = items;
            _group               = group;
            _groupsMapping       = new Dictionary <RepositoryGroup, RepositoryGroupListItem>();
            _repositoriesMapping = new Dictionary <RepositoryLink, RepositoryListItem>();

            foreach (var subGroup in group.Groups)
            {
                var item = new RepositoryGroupListItem(subGroup);
                _groupsMapping.Add(subGroup, item);
                items.Add(item);
            }
            foreach (var repository in group.Respositories)
            {
                var item = new RepositoryListItem(repository);
                _repositoriesMapping.Add(repository, item);
                items.Add(item);
            }

            group.Groups.Changed        += OnGroupsChanged;
            group.Respositories.Changed += OnRepositoriesChanged;
        }
Esempio n. 2
0
        private void OnGroupsChanged(object sender, NotifyCollectionEventArgs e)
        {
            switch (e.Event)
            {
            case NotifyEvent.Insert:
                for (int i = e.StartIndex; i <= e.EndIndex; ++i)
                {
                    var group = _group.Groups[i];
                    var item  = new RepositoryGroupListItem(group);
                    _groupsMapping.Add(group, item);
                    _items.Insert(i, item);
                }
                break;

            case NotifyEvent.Remove:
                for (int i = e.StartIndex; i <= e.EndIndex; ++i)
                {
                    var item = _items[i] as RepositoryGroupListItem;
                    if (item != null)
                    {
                        _groupsMapping.Remove(item.DataContext);
                    }
                }
                _items.RemoveRange(e.StartIndex, e.ModifiedItems);
                break;

            case NotifyEvent.Set:
                for (int i = e.StartIndex; i <= e.EndIndex; ++i)
                {
                    var item = _items[i] as RepositoryGroupListItem;
                    if (item != null)
                    {
                        _groupsMapping.Remove(item.DataContext);
                    }
                    var group = _group.Groups[i];
                    item = new RepositoryGroupListItem(group);
                    _groupsMapping.Add(group, item);
                    _items[i] = item;
                }
                break;

            case NotifyEvent.Clear:
                _groupsMapping.Clear();
                _items.RemoveRange(0, e.ModifiedItems);
                break;
            }
        }