Exemplo n.º 1
0
        public static TreeNode ToTreeNode(this BasicTreeNode <TextureEntry> node)
        {
            bool   leaf  = node.IsLeaf;
            var    value = node.Value;
            string text;

            if (leaf)
            {
                text = value.FileName;
            }
            else
            {
                text = string.Format("{0} ({1})", node.Key, node.ChildCount);
            }
            var tNode = new TreeNode(text);

            tNode.Tag = node;
            if (leaf)
            {
                var    dims = value.ImageSize;
                string path = value.FullPath;
                // StateImageIndex works super well but only supports 0-14...
                tNode.ImageKey    = tNode.SelectedImageKey = path;
                tNode.ToolTipText = string.Format("{0:D}x{1:D}\r\n{2}", dims.Width, dims.Height, path);
            }
            else
            {
                tNode.ImageIndex = tNode.SelectedImageIndex = 0;
                // ensure that it has a plus sign
                tNode.Nodes.Add(CreateDummy());
            }
            return(tNode);
        }
Exemplo n.º 2
0
 public void AddChild(BasicTreeNode <T> child)
 {
     if (children == null)
     {
         children = new List <BasicTreeNode <T> >(32);
     }
     children.Add(child);
 }
Exemplo n.º 3
0
        public BasicTreeNode <TextureEntry> AsTree()
        {
            BasicTreeNode <TextureEntry> child, root = new BasicTreeNode <TextureEntry>(string.
                                                                                        Empty, null);

            foreach (var entry in this)
            {
                BasicTreeNode <TextureEntry> node = root, next;
                string[] folders = SplitPath(entry.FullPath);
                int      last = folders.Length - 1;
                for (int i = 0; i <= last; i++)
                {
                    string folder = folders[i];
                    // Value if the node were to be put into this level
                    var thisValue = (i == last) ? entry : null;
                    next = null;
                    if (!node.IsLeaf)
                    {
                        // Search for node
                        foreach (var childNode in node.Children)
                        {
                            if (childNode.Key == folder)
                            {
                                next = childNode;
                                break;
                            }
                        }
                    }
                    if (next == null)
                    {
                        // Add new node
                        node.AddChild(next = new BasicTreeNode <TextureEntry>(folder,
                                                                              thisValue));
                    }
                    else if (i == last)
                    {
                        throw new ArgumentException("Duplicate file names in pack / mod!");
                    }
                    node = next;
                }
            }
            while (root.ChildCount == 1 && (child = root.FirstChild) != null && !child.IsLeaf)
            {
                // 0 child count is not equal to 1
                root = child;
            }
            return(root);
        }
Exemplo n.º 4
0
        public static bool Matches <T>(this TreeNodeCollection nodes, BasicTreeNode <T> tree)
        {
            int count = nodes.Count;

            return(count == tree.ChildCount && (count != 1 || nodes[0]?.Tag != DUMMY_TAG));
        }