Exemple #1
0
        private void populateTree()
        {
            if (this.mainForm.CurrentProject != null)
            {

                DirectoryInfo info = new DirectoryInfo(this.mainForm.CurrentProject.ProjectPath);
                if (info.Exists)
                {

                    rootNode = new FolderExplorerItem(info);
                    GetDirectories(info.GetDirectories(), rootNode);
                    treeView1.Nodes.Add(rootNode);

                    // Create a new FileSystemWatcher and set its properties.
                    FileSystemWatcher watcher = new FileSystemWatcher();
                    watcher.Path = this.mainForm.CurrentProject.ProjectPath;
                    /* Watch for changes in LastAccess and LastWrite times, and
                       the renaming of files or directories. */
                    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                       | NotifyFilters.FileName | NotifyFilters.DirectoryName;

                    watcher.IncludeSubdirectories = true;

                    // Add event handlers.
                    watcher.Created += new FileSystemEventHandler(watcher_Changed);
                    watcher.Deleted += new FileSystemEventHandler(watcher_Changed);
                    watcher.Renamed += new RenamedEventHandler(watcher_Renamed);

                    // Begin watching.
                    watcher.EnableRaisingEvents = true;
                }
            }
        }
Exemple #2
0
        private FolderExplorerItem getFolderNode(FolderExplorerItem parentFolder,string path)
        {
            if(this.rootNode != null)
            {

                if (parentFolder.FolderInfo.FullName.Equals(path))
                {
                    return parentFolder;
                }

                for (int i = 0; i < parentFolder.Nodes.Count; i++)
                {
                    if (parentFolder.Nodes[i] is FolderExplorerItem)
                    {
                        FolderExplorerItem item = parentFolder.Nodes[i] as FolderExplorerItem;
                        if (item.FolderInfo.FullName.Equals(path))
                        {
                            return item;
                        }
                        else
                        {
                            FolderExplorerItem sub = this.getFolderNode(item, path);
                            if (sub != null)
                                return sub;
                        }
                    }

                }
            }

            return null;
        }
Exemple #3
0
        private void getFiles(DirectoryInfo parentDir, FolderExplorerItem nodeToAddTo)
        {
            FileExplorerItem aNode;
            FileInfo[] files = parentDir.GetFiles();

            foreach (FileInfo file in files)
            {
                aNode = this.getFileNode(file.FullName);
                if (aNode == null)
                {
                    aNode = new FileExplorerItem(file);
                    nodeToAddTo.Nodes.Add(aNode);
                }

            }
        }
Exemple #4
0
        private void GetDirectories(DirectoryInfo[] subDirs,
            TreeNode nodeToAddTo)
        {
            FolderExplorerItem aNode;
            DirectoryInfo[] subSubDirs;
            foreach (DirectoryInfo subDir in subDirs)
            {
                aNode = new FolderExplorerItem(subDir);
                subSubDirs = subDir.GetDirectories();
                if (subSubDirs.Length != 0)
                {
                    GetDirectories(subSubDirs, aNode);
                }
                nodeToAddTo.Nodes.Add(aNode);

                this.getFiles(subDir, aNode);
            }
        }
Exemple #5
0
        private FileExplorerItem directoryHasNode(FolderExplorerItem dir,string path)
        {
            if (dir != null)
            {
                for (int i = 0; i < dir.Nodes.Count; i++)
                {
                    if (dir.Nodes[i] is FileExplorerItem)
                    {
                        FileExplorerItem item = dir.Nodes[i] as FileExplorerItem;
                        if (item.FileInfo.FullName.Equals(path))
                        {
                            return item;
                        }
                    }
                    else if (dir.Nodes[i] is FolderExplorerItem)
                    {
                        FolderExplorerItem item = dir.Nodes[i] as FolderExplorerItem;
                        FileExplorerItem itemFound =  directoryHasNode(item,path);
                        if (itemFound != null)
                            return itemFound;
                    }

                }
            }

            return null;
        }
Exemple #6
0
        private FolderExplorerItem createFolderNode(DirectoryInfo info)
        {
            FolderExplorerItem itemExisting = this.getFolderNode(this.rootNode,info.FullName);
            if (itemExisting != null)
            {
                itemExisting.FolderInfo = info;
                itemExisting.Text = info.Name;
                this.treeView1.Sort();
                return itemExisting;
            }
            else
            {
                FolderExplorerItem folderParent = this.getFolderNode(this.rootNode,info.Parent.FullName);
                if (folderParent != null)
                {
                    FolderExplorerItem item = new FolderExplorerItem(info);
                    folderParent.Nodes.Add(item);
                    this.treeView1.Sort();

                    return item;
                }

                return null;
            }
        }