Exemple #1
0
        public void ExpandTreeNode(MyTreeNode treeNode)
        {
            // look at the first child of this tree. If the node
            // associated with it isn't null, then we've already
            // done the expansion before.
            MyTreeNode childTreeNode = (MyTreeNode)treeNode.Nodes[0];

            if (childTreeNode.Node != null)
            {
                return;
            }

            treeNode.Nodes.Clear();                     // get rid of null entry

            DirectoryNode directoryNode = (DirectoryNode)treeNode.Node;

            // As we walk though the tree, we need to figure out the
            // percentages for each item. We do that based upon the
            // full size of this directory.
            float dirSize = directoryNode.SizeTree;

            foreach (DirectoryNode subdir in directoryNode.GetDirectories())
            {
                PopulateTreeNode(treeNode.Nodes, subdir);
            }

            foreach (FileNode fileNode in directoryNode.GetFiles())
            {
                TreeNode treeFileNode = new MyTreeNode(fileNode.NameSize, fileNode);
                treeFileNode.ImageIndex         = FractionToIndex(fileNode);
                treeFileNode.SelectedImageIndex = treeFileNode.ImageIndex;
                treeNode.Nodes.Add(treeFileNode);
            }
        }
Exemple #2
0
        protected void treeContextMenuClick(object sender, EventArgs e)
        {
            MenuItem   menuItem = (MenuItem)sender;
            MyTreeNode treeNode = (MyTreeNode)treeView1.SelectedNode;
            BaseNode   baseNode = treeNode.Node;

            bool updateSizes = false;

            switch (menuItem.Index)
            {
            case menuIndexDelete:
                if (baseNode.Delete(true))
                {
                    updateSizes = true;
                    treeNode.Remove();
                }
                break;

            case menuIndexDeleteContents:
                if (((DirectoryNode)baseNode).DeleteContents())
                {
                    foreach (MyTreeNode childNode in treeNode.Nodes)
                    {
                        childNode.Remove();
                    }
                    updateSizes = true;
                }
                break;

            case menuIndexViewInNotepad:
                ProcessStartInfo processStartInfo = new ProcessStartInfo();
                processStartInfo.FileName  = "notepad";
                processStartInfo.Arguments = baseNode.FullName;
                Process.Start(processStartInfo);
                break;

            case menuIndexLaunch:
                try
                {
                    processStartInfo          = new ProcessStartInfo();
                    processStartInfo.FileName = baseNode.FullName;
                    Process.Start(processStartInfo);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.ToString());
                }
                break;
            }

            if (updateSizes)
            {
                directoryNode.ClearSizeCache();
                UpdateTreeNodes(this.treeView1.Nodes);
                if (directoryNodeBaseline != null)
                {
                    directoryNode.CompareTrees(directoryNodeBaseline);
                }
            }
        }
Exemple #3
0
        public void PopulateTreeNode(TreeNodeCollection treeNodeCollection,
                                     DirectoryNode directoryNode)
        {
            TreeNode treeNode = new MyTreeNode(directoryNode.NameSize, directoryNode);

            treeNode.ImageIndex         = FractionToIndex(directoryNode);
            treeNode.SelectedImageIndex = treeNode.ImageIndex;

            // Adding an item to the list has to be done on the
            // main thread of the control. We can get to it by
            // setting up a delegate that we want to call,
            // and then calling Invoke() on the treeview control.
            AddDelegate addDelegate = new AddDelegate(treeNodeCollection.Add);

            // Bug: Invoke should be declared with params.
            treeView1.Invoke(addDelegate, new object[] { treeNode });

            if (directoryNode.SizeTree != 0)
            {
                // Add a fake entry to this node so that there will be
                // a + sign in front of it.
                // Use invoke to delegate this call to the control.
                addDelegate = new AddDelegate(treeNode.Nodes.Add);
                treeView1.Invoke(addDelegate, new Object[] { new MyTreeNode("", null) });
            }
        }
Exemple #4
0
        void DeleteTreeNode(MyTreeNode nodeToDelete)
        {
            MyTreeNode parentNode = (MyTreeNode)nodeToDelete.Parent;

            // Delete the node from this directory, and update
            // the sizes...
            ((DirectoryNode)parentNode.Node).DeleteNode(nodeToDelete.Node);
        }