Exemple #1
0
        /// <summary>
        /// Function to add a directory to the tree.
        /// </summary>
        /// <param name="nodes">Source collection.</param>
        /// <param name="directory">Directory to add.</param>
        /// <param name="autoExpand">TRUE to expand the new node (if it has children) after it's been added, FALSE to leave collapsed.</param>
        /// <returns>The new node.</returns>
        public static TreeNodeDirectory AddDirectory(this TreeNodeCollection nodes, GorgonFileSystemDirectory directory, bool autoExpand)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            // Find check to ensure the node is unique.
            TreeNodeDirectory result = (from node in nodes.Cast <TreeNode>()
                                        let dirNode = node as TreeNodeDirectory
                                                      where dirNode != null &&
                                                      string.Equals(node.Name, directory.FullPath, StringComparison.OrdinalIgnoreCase)
                                                      select dirNode).FirstOrDefault();

            if (result != null)
            {
                return(result);
            }

            result = new TreeNodeDirectory(directory)
            {
                ForeColor = Color.White,
                Text      = directory.Name
            };

            if ((directory.Directories.Count > 0) || (directory.Files.Count > 0))
            {
                // Add a dummy node to indicate that there are children.
                result.Nodes.Add("DummyNode");
            }

            nodes.Add(result);

            // Expand the parent.
            if ((result.Parent != null) &&
                (!result.Parent.IsExpanded))
            {
                TreeNode parent = result.Parent;
                parent.Expand();
                result = (TreeNodeDirectory)parent.Nodes[result.Name];
            }

            // Expand the node if necessary.
            if ((autoExpand) &&
                (result.Nodes.Count > 0))
            {
                result.Expand();
            }

            return(result);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DragDirectory"/> class.
 /// </summary>
 /// <param name="directoryNode">The directory node.</param>
 /// <param name="mouseButton">The mouse button used to drag.</param>
 public DragDirectory(TreeNodeDirectory directoryNode, MouseButtons mouseButton)
     : base(mouseButton)
 {
     DirectoryNode = directoryNode;
 }