Exemplo n.º 1
0
 private bool TrySetRevisionText(BranchListItem listItem)
 {
     if (listItem != null)
     {
         var branch = listItem.DataContext;
         _txtRevision.Text = branch.Name;
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
 private bool TrySetRevisionText(BranchListItem listItem)
 {
     if(listItem != null)
     {
         var branch = listItem.DataContext;
         _txtRevision.Text = branch.Name;
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
        public ReferenceTreeBinding(CustomListBoxItemsCollection itemHost, Repository repository,
            bool groupItems, bool groupRemoteBranches, Predicate<IRevisionPointer> predicate, ReferenceType referenceTypes)
        {
            Verify.Argument.IsNotNull(itemHost, "itemHost");
            Verify.Argument.IsNotNull(repository, "repository");

            _itemHost = itemHost;
            _repository = repository;

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

            _itemHost.Clear();
            if(groupItems)
            {
                _refsHeads = new ReferenceGroupListItem(repository, ReferenceType.LocalBranch);
                _refsHeads.Items.Comparison = BranchListItem.CompareByName;
                _refsRemotes = new ReferenceGroupListItem(repository, ReferenceType.RemoteBranch);
                if(groupRemoteBranches)
                {
                    _refsRemotes.Items.Comparison = RemoteListItem.CompareByName;
                }
                else
                {
                    _refsRemotes.Items.Comparison = RemoteBranchListItem.CompareByName;
                }
                _refsTags = new ReferenceGroupListItem(repository, ReferenceType.Tag);
                _refsTags.Items.Comparison = TagListItem.CompareByName;
                _itemHost.Comparison = null;
            }
            else
            {
                _refsHeads = null;
                _refsRemotes = null;
                _refsTags = 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 = _refsHeads.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 ? _refsRemotes.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 = _refsTags.Items;
                        }
                        else
                        {
                            host = _itemHost;
                        }
                        host.Add(item);
                    }
                    refs.ObjectAdded += OnTagCreated;
                }
            }

            if(groupItems)
            {
                _itemHost.Add(_refsHeads);
                _itemHost.Add(_refsRemotes);
                _itemHost.Add(_refsTags);
            }
        }
Exemplo n.º 4
0
 private void OnBranchCreated(object sender, BranchEventArgs e)
 {
     var branch = e.Object;
     if(_predicate == null || _predicate(branch))
     {
         var item = new BranchListItem(branch);
         item.Activated += OnItemActivated;
         CustomListBoxItemsCollection host;
         if(_groupItems)
         {
             host = _refsHeads.Items;
         }
         else
         {
             host = _itemHost;
         }
         host.AddSafe(item);
     }
 }