Пример #1
0
        private void NavigateToFolder(object folder, EventArgs e)
        {
            string folderInfo = folder as string;

            //check if refresh requested
            if (folderInfo.EndsWith(@":"))
            {
                FileTree.CollapseAll();
                folderInfo = folderInfo.TrimEnd(':');
                if (_spectraFolders.ContainsKey(folderInfo))
                {
                    _spectraFolders.Remove((folderInfo));
                }
            }

            //process the info
            var      dirList     = BreadCrumbControl.PathToDirectoryList(folderInfo);
            TreeNode currentNode = null;

            foreach (TreeNode node in FileTree.Nodes)
            {
                if (String.Equals(node.Text, dirList[0], StringComparison.InvariantCultureIgnoreCase))
                {
                    currentNode = node;
                    currentNode.Expand();
                }
                else
                {
                    node.Collapse();
                }
            }

            //if you cant find the root you cant go anywhere
            if (currentNode == null)
            {
                return;
            }
            dirList.RemoveAt(0);
            foreach (var item in dirList)
            {
                var found = false;
                if (!currentNode.IsExpanded)
                {
                    currentNode.Expand();
                }
                foreach (TreeNode node in currentNode.Nodes)
                {
                    if (node.Text.ToLower() == item.ToLower())
                    {
                        found       = true;
                        currentNode = node;
                    }
                    else
                    {
                        node.Collapse();
                    }
                }
                if (!found)
                {
                    break;
                }
            }
            SelectAndPreviewNode(currentNode);
        }
Пример #2
0
        public void MakeFileTree()
        {
            FileTree.Nodes.Clear();

            treeNodesAndSubfiles = new Dictionary <TreeNode, Subfile>();
            foldersProcessed     = new Dictionary <string, TreeNode>();


            FileTree.BeginUpdate();

            List <Subfile> subfiles = global.activePackage.subfiles;


            foreach (Subfile file in subfiles)
            {
                //now add entries to the file tree

                List <string> dirs = new List <string>();

                string tempfilepath = Path.GetFileName(global.activePackage.filename).Replace("/", "");;


                if (file.filename[0] != '/')
                {
                    tempfilepath += "/";
                }
                tempfilepath += file.filename;

                if (tempfilepath[tempfilepath.Length - 1] == '/')
                {
                    tempfilepath.Remove(tempfilepath.Length - 1);
                }

                if (tempfilepath[0] == '/')
                {
                    tempfilepath = tempfilepath.Substring(1, tempfilepath.Length - 1);
                }

                int number_of_dir_levels = tempfilepath.Split('/').Length;

                for (int d = 0; d < number_of_dir_levels - 1; d++)  //store a string for each level of the directory, so that we can check each folder individually (by this I mean checking whether or not it already exists in the tree)
                {
                    dirs.Add(Path.GetDirectoryName(tempfilepath));
                    tempfilepath = Path.GetDirectoryName(tempfilepath);

                    if (tempfilepath[tempfilepath.Length - 1] == '/')
                    {
                        tempfilepath.Remove(tempfilepath.Length - 1);
                    }
                }

                bool     isRoot     = true;
                TreeNode newestNode = new TreeNode();

                for (int f = dirs.Count - 1; f >= 0; f--)
                {
                    if (!foldersProcessed.Keys.Contains(dirs[f].ToLower()))    //if the folder isn't in the tree yet
                    {
                        if (!isRoot)
                        {   //add to the chain of nodes
                            FileTree.SelectedNode         = newestNode;
                            newestNode                    = new TreeNode(Path.GetFileName(dirs[f]));
                            newestNode.ImageIndex         = 0;
                            newestNode.SelectedImageIndex = 0;
                            FileTree.SelectedNode.Nodes.Add(newestNode);
                        }
                        else
                        { //create a root node first
                            newestNode                    = new TreeNode(Path.GetFileName(dirs[f]));
                            newestNode.ImageIndex         = 0;
                            newestNode.SelectedImageIndex = 0;
                            FileTree.Nodes.Add(newestNode);
                            isRoot = false;
                        }

                        foldersProcessed.Add(dirs[f].ToLower(), newestNode);  //add it to the list of folders we've put in the tree
                    }
                    else
                    {
                        newestNode                    = foldersProcessed[dirs[f].ToLower()]; //set the parent node of the next folder to the existing node
                        newestNode.ImageIndex         = 0;
                        newestNode.SelectedImageIndex = 0;
                        FileTree.SelectedNode         = newestNode;
                        isRoot = false;
                    }
                }
                FileTree.SelectedNode         = newestNode;
                newestNode                    = new TreeNode(Path.GetFileName(file.filename));
                newestNode.ImageIndex         = 1;
                newestNode.SelectedImageIndex = 1;
                FileTree.SelectedNode.Nodes.Add(newestNode);
                file.treeNode = newestNode;
                treeNodesAndSubfiles.Add(newestNode, file);
            }

            FileTree.Sort();
            FileTree.CollapseAll();
            FileTree.EndUpdate();
        }
Пример #3
0
 private void shrinkAllDirectoriesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     FileTree.CollapseAll();
 }