예제 #1
0
        public static int UniversalComparer(CustomListBoxItem item1, CustomListBoxItem item2)
        {
            if (item1.GetType() == item2.GetType())
            {
                switch (item1)
                {
                case BranchListItem branchItem:
                    return(BranchListItem.CompareByName(branchItem, (BranchListItem)item2));

                case RemoteBranchListItem remoteBranchItem:
                    return(RemoteBranchListItem.CompareByName(remoteBranchItem, (RemoteBranchListItem)item2));

                case RemoteListItem remoteItem:
                    return(RemoteListItem.CompareByName(remoteItem, (RemoteListItem)item2));

                case TagListItem tagItem:
                    return(TagListItem.CompareByName(tagItem, (TagListItem)item2));

                default: return(0);
                }
            }
            else
            {
                switch (item1)
                {
                case BranchListItem _:       return(-1);

                case RemoteBranchListItem _: return(item2 is BranchListItem ? 1 : -1);

                case RemoteListItem _:       return(item2 is TagListItem ? 1 : -1);

                default: return(1);
                }
            }
        }
예제 #2
0
        private void OnTagCreated(object sender, TagEventArgs e)
        {
            var tag = e.Object;

            if (_predicate == null || _predicate(tag))
            {
                CustomListBoxItemsCollection host;
                var item = new TagListItem(tag);
                item.Activated += OnItemActivated;
                if (_groupItems)
                {
                    host = Tags.Items;
                }
                else
                {
                    host = _itemHost;
                }
                host.AddSafe(item);
            }
        }
예제 #3
0
        public ReferenceTreeBinding(CustomListBoxItemsCollection itemHost, Repository repository,
                                    bool groupItems, bool groupRemoteBranches, Predicate <IRevisionPointer> predicate, ReferenceType referenceTypes)
        {
            Verify.Argument.IsNotNull(itemHost, nameof(itemHost));
            Verify.Argument.IsNotNull(repository, nameof(repository));

            _itemHost  = itemHost;
            Repository = repository;

            _groupItems     = groupItems;
            _groupRemotes   = groupRemoteBranches;
            _predicate      = predicate;
            _referenceTypes = referenceTypes;

            _itemHost.Clear();
            if (groupItems)
            {
                Heads = new ReferenceGroupListItem(repository, ReferenceType.LocalBranch);
                Heads.Items.Comparison = BranchListItem.CompareByName;
                Remotes = new ReferenceGroupListItem(repository, ReferenceType.RemoteBranch);
                if (groupRemoteBranches)
                {
                    Remotes.Items.Comparison = RemoteListItem.CompareByName;
                }
                else
                {
                    Remotes.Items.Comparison = RemoteBranchListItem.CompareByName;
                }
                Tags = new ReferenceGroupListItem(repository, ReferenceType.Tag);
                Tags.Items.Comparison = TagListItem.CompareByName;
                _itemHost.Comparison  = null;
            }
            else
            {
                Heads   = null;
                Remotes = null;
                Tags    = null;
                _itemHost.Comparison = ReferenceListItemBase.UniversalComparer;
            }

            _remotes = groupRemoteBranches ? new List <RemoteListItem>(repository.Remotes.Count) : null;

            if ((referenceTypes & ReferenceType.LocalBranch) == ReferenceType.LocalBranch)
            {
                var refs = Repository.Refs.Heads;
                lock (refs.SyncRoot)
                {
                    foreach (var branch in refs)
                    {
                        if (predicate != null && !predicate(branch))
                        {
                            continue;
                        }
                        var item = new BranchListItem(branch);
                        item.Activated += OnItemActivated;
                        CustomListBoxItemsCollection host;
                        if (groupItems)
                        {
                            host = Heads.Items;
                        }
                        else
                        {
                            host = _itemHost;
                        }
                        host.Add(item);
                    }
                    refs.ObjectAdded += OnBranchCreated;
                }
            }

            if ((referenceTypes & ReferenceType.RemoteBranch) == ReferenceType.RemoteBranch)
            {
                var refs = repository.Refs.Remotes;
                lock (refs.SyncRoot)
                {
                    foreach (var branch in refs)
                    {
                        if (predicate != null && !predicate(branch))
                        {
                            continue;
                        }
                        var host = groupItems ? Remotes.Items : _itemHost;
                        var item = new RemoteBranchListItem(branch);
                        item.Activated += OnItemActivated;
                        if (groupRemoteBranches)
                        {
                            var ritem = GetRemoteListItem(branch);
                            if (ritem != null)
                            {
                                host = ritem.Items;
                            }
                        }
                        host.Add(item);
                    }
                    refs.ObjectAdded += OnRemoteBranchCreated;
                }
            }

            if ((referenceTypes & ReferenceType.Tag) == ReferenceType.Tag)
            {
                var refs = repository.Refs.Tags;
                lock (refs.SyncRoot)
                {
                    foreach (var tag in refs)
                    {
                        if (predicate != null && !predicate(tag))
                        {
                            continue;
                        }
                        var item = new TagListItem(tag);
                        item.Activated += OnItemActivated;
                        CustomListBoxItemsCollection host;
                        if (groupItems)
                        {
                            host = Tags.Items;
                        }
                        else
                        {
                            host = _itemHost;
                        }
                        host.Add(item);
                    }
                    refs.ObjectAdded += OnTagCreated;
                }
            }

            if (groupItems)
            {
                _itemHost.Add(Heads);
                _itemHost.Add(Remotes);
                _itemHost.Add(Tags);
            }
        }
예제 #4
0
 public static int UniversalComparer(CustomListBoxItem item1, CustomListBoxItem item2)
 {
     if (item1.GetType() == item2.GetType())
     {
         var branchItem = item1 as BranchListItem;
         if (branchItem != null)
         {
             return(BranchListItem.CompareByName(branchItem, (BranchListItem)item2));
         }
         var remoeBranchItem = item1 as RemoteBranchListItem;
         if (remoeBranchItem != null)
         {
             return(RemoteBranchListItem.CompareByName(branchItem, (RemoteBranchListItem)item2));
         }
         var remoteItem = item1 as RemoteListItem;
         if (remoteItem != null)
         {
             return(RemoteListItem.CompareByName(remoteItem, (RemoteListItem)item2));
         }
         var tagItem = item1 as TagListItem;
         if (tagItem != null)
         {
             return(TagListItem.CompareByName(tagItem, (TagListItem)item2));
         }
         return(0);
     }
     else
     {
         var branchItem = item1 as BranchListItem;
         if (branchItem != null)
         {
             return(-1);
         }
         var remoteBranchItem = item1 as RemoteBranchListItem;
         if (remoteBranchItem != null)
         {
             var branchItem2 = item2 as BranchListItem;
             if (branchItem2 != null)
             {
                 return(1);
             }
             else
             {
                 return(-1);
             }
         }
         var remoteListItem = item1 as RemoteListItem;
         if (remoteListItem != null)
         {
             var tagItem2 = item2 as TagListItem;
             if (tagItem2 == null)
             {
                 return(-1);
             }
             else
             {
                 return(1);
             }
         }
         return(1);
     }
 }