Inheritance: ExplorerNode
Exemplo n.º 1
0
        private void treFileBrowser_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            ExplorerNode node = (ExplorerNode)e.Node;
            node.Children.Clear();
            node.Nodes.Clear();

            DirectoryInfo directoryInfo = new DirectoryInfo(node.AbsolutePath);

            foreach (DirectoryInfo directory in directoryInfo.GetDirectories())
            {
                FolderNode directoryNode = new FolderNode(node, directory.Name);
                directoryNode.SelectedImageIndex = directoryNode.ImageIndex;

                if (directory.GetFiles().Length != 0 | directory.GetDirectories().Length != 0)
                {
                    directoryNode.Nodes.Add("*DUMMY*");
                }

                node.Nodes.Add(directoryNode);
                node.Children.Add(directoryNode);
            }

            foreach(FileInfo file in directoryInfo.GetFiles())
            {
                if(file.Extension == ".prg")
                {
                    FileNode fileNode = new FileNode(node, file.Name);

                    node.Nodes.Add(fileNode);
                    node.Children.Add(fileNode);
                }
            }
        }
Exemplo n.º 2
0
        private void newFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExplorerNode explorerNode = (ExplorerNode)treFileBrowser.SelectedNode;

            int folderNumber = 1;
            bool folderCreated = false;
            string folderPath = explorerNode.AbsolutePath;

            while (!folderCreated)
            {
                if (Directory.Exists(folderPath + @"\NewFolder" + folderNumber))
                {
                    folderNumber++;
                }
                else
                {
                    try
                    {
                        Directory.CreateDirectory(folderPath + @"\NewFolder" + folderNumber);

                        FolderNode folderNode = new FolderNode(explorerNode, "NewFolder" + folderNumber);

                        explorerNode.Nodes.Add(folderNode);
                        explorerNode.Children.Add(folderNode);
                        treFileBrowser.SelectedNode = folderNode;
                        treFileBrowser.LabelEdit = true;
                        folderNode.BeginEdit();
                        folderCreated = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, Application.ExecutablePath, MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
            }
        }