/// <summary>
        /// Loads children items for the provided item in to the specified nodes.
        /// Loaded children are cached until <see cref="ResetCache"/> method is called.
        /// For file type items it also loads icons associated with these types at the OS level.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="nodes"></param>
        /// <param name="imageCollection"></param>
        /// <remarks>The method DOES NOT check any input parameters for performance reasons.</remarks>
        public void LoadChildren(IGitItem item, TreeNodeCollection nodes, ImageList.ImageCollection imageCollection)
        {
            var childrenItems = _cachedItems.GetOrAdd(item.Guid, _revisionInfoProvider.LoadChildren(item));

            if (childrenItems == null)
            {
                return;
            }

            foreach (var childItem in childrenItems.OrderBy(gi => gi, new GitFileTreeComparer()))
            {
                var subNode = nodes.Add(childItem.Name);
                subNode.Tag = childItem;

                var gitItem = childItem as GitItem;
                if (gitItem == null)
                {
                    subNode.Nodes.Add(new TreeNode());
                    continue;
                }

                switch (gitItem.ObjectType)
                {
                case GitObjectType.Tree:
                {
                    subNode.ImageIndex = subNode.SelectedImageIndex = TreeNodeImages.Folder;
                    subNode.Nodes.Add(new TreeNode());
                    break;
                }

                case GitObjectType.Commit:
                {
                    subNode.ImageIndex = subNode.SelectedImageIndex = TreeNodeImages.Submodule;
                    subNode.Text       = $@"{childItem.Name} (Submodule)";
                    break;
                }

                case GitObjectType.Blob:
                {
                    var extension = Path.GetExtension(gitItem.FileName);
                    if (string.IsNullOrWhiteSpace(extension))
                    {
                        continue;
                    }
                    if (!imageCollection.ContainsKey(extension))
                    {
                        var fileIcon = _iconProvider.Get(_module.WorkingDir, gitItem.FileName);
                        if (fileIcon == null)
                        {
                            continue;
                        }
                        imageCollection.Add(extension, fileIcon);
                    }
                    subNode.ImageKey = subNode.SelectedImageKey = extension;
                    break;
                }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Loads the provided items in the specified nodes.
        /// For file type items it also loads icons associated with these types at the OS level.
        /// </summary>
        /// <param name="items"></param>
        /// <param name="node"></param>
        /// <param name="imageCollection"></param>
        /// <remarks>The method DOES NOT check any input parameters for performance reasons.</remarks>
        public void LoadItemsInTreeView(IEnumerable <IGitItem> items, TreeNodeCollection node, ImageList.ImageCollection imageCollection)
        {
            var sortedItems = items.OrderBy(gi => gi, new GitFileTreeComparer());

            foreach (var item in sortedItems)
            {
                var subNode = node.Add(item.Name);
                subNode.Tag = item;

                var gitItem = item as GitItem;
                if (gitItem == null)
                {
                    subNode.Nodes.Add(new TreeNode());
                    continue;
                }

                if (gitItem.IsTree)
                {
                    subNode.ImageIndex = subNode.SelectedImageIndex = TreeNodeImages.Folder;
                    subNode.Nodes.Add(new TreeNode());
                    continue;
                }

                if (gitItem.IsCommit)
                {
                    subNode.ImageIndex = subNode.SelectedImageIndex = TreeNodeImages.Submodule;
                    subNode.Text       = $@"{item.Name} (Submodule)";
                    continue;
                }

                if (gitItem.IsBlob)
                {
                    var extension = Path.GetExtension(gitItem.FileName);
                    if (string.IsNullOrWhiteSpace(extension))
                    {
                        continue;
                    }
                    if (!imageCollection.ContainsKey(extension))
                    {
                        var fileIcon = _iconProvider.Get(_module.WorkingDir, gitItem.FileName);
                        if (fileIcon == null)
                        {
                            continue;
                        }
                        imageCollection.Add(extension, fileIcon);
                    }
                    subNode.ImageKey = subNode.SelectedImageKey = extension;
                }
            }
        }