private void SetUpDialog()
        {
            _historyQueue = new List<string>();
            ArrowPicture.Tag = new ContextMenu();
            _unfilteredItems = new List<ListViewItem>();
            _spectraFolders = new Dictionary<string, List<string[]>>();
            _spectraFiles = new Dictionary<string, List<string[]>>();
            DataSources = new List<string>();
            sourceTypeComboBox.SelectedIndex = 0;

            var folderNames = new List<string>();

            //Desktop
            var specialLocation = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
            var node = new TreeNode("Desktop")
                           {
                               Tag = specialLocation.FullName,
                               ImageIndex = 1
                           };
            if (specialLocation.GetDirectories().Any())
            {
                var placeholder = new TreeNode("<<Placeholder>>");
                node.Nodes.Add(placeholder);
            }
            FileTree.Nodes.Add(node);
            folderNames.Add((string)node.Tag);

            //My Documents
            specialLocation = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            node = new TreeNode("My Documents")
                       {
                           Tag = specialLocation.FullName,
                           ImageIndex = 2
                       };
            if (specialLocation.GetDirectories().Any())
            {
                var placeholder = new TreeNode("<<Placeholder>>");
                node.Nodes.Add(placeholder);
            }
            FileTree.Nodes.Add(node);
            folderNames.Add((string)node.Tag);

            //Add drives
            foreach (var drive in DriveInfo.GetDrives())
            {
                var tn = new TreeNode(drive.Name) {Tag = drive.Name};
                switch (drive.DriveType)
                {
                    case DriveType.CDRom:
                    case DriveType.Removable:
                        tn.ImageIndex = 6;
                        break;
                    case DriveType.Fixed:
                        tn.ImageIndex = 5;
                        break;
                    default:
                        tn.ImageIndex = 7;
                        break;
                }
                bool canExpand;

                try
                {
                    canExpand = drive.RootDirectory.GetDirectories().Any();
                }
                catch (Exception)
                {
                    canExpand = false;
                }

                if (canExpand)
                {
                    var placeholder = new TreeNode("<<Placeholder>>");
                    tn.Nodes.Add(placeholder);
                }
                FileTree.Nodes.Add(tn);
                folderNames.Add((string)tn.Tag);
            }

            //add Bread crumbs
            BreadCrumbs = new BreadCrumbControl { Parent = BreadCrumbPanel, Dock = DockStyle.Fill };
            BreadCrumbs.Navigate += NavigateToFolder;
        }
예제 #2
0
        private void SetUpDialog()
        {
            _historyQueue    = new List <string>();
            ArrowPicture.Tag = new ContextMenu();
            _unfilteredItems = new List <ListViewItem>();
            _spectraFolders  = new Dictionary <string, List <string[]> >();
            _spectraFiles    = new Dictionary <string, List <string[]> >();
            DataSources      = new List <string>();
            sourceTypeComboBox.SelectedIndex = 0;

            var folderNames = new List <string>();

            //Desktop
            var specialLocation = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
            var node            = new TreeNode("Desktop")
            {
                Tag        = specialLocation.FullName,
                ImageIndex = 1
            };

            if (specialLocation.GetDirectories().Any())
            {
                var placeholder = new TreeNode("<<Placeholder>>");
                node.Nodes.Add(placeholder);
            }
            FileTree.Nodes.Add(node);
            folderNames.Add((string)node.Tag);

            //My Documents
            specialLocation = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            node            = new TreeNode("My Documents")
            {
                Tag        = specialLocation.FullName,
                ImageIndex = 2
            };
            if (specialLocation.GetDirectories().Any())
            {
                var placeholder = new TreeNode("<<Placeholder>>");
                node.Nodes.Add(placeholder);
            }
            FileTree.Nodes.Add(node);
            folderNames.Add((string)node.Tag);

            //Add drives
            foreach (var drive in DriveInfo.GetDrives())
            {
                var tn = new TreeNode(drive.Name)
                {
                    Tag = drive.Name
                };
                switch (drive.DriveType)
                {
                case DriveType.CDRom:
                case DriveType.Removable:
                    tn.ImageIndex = 6;
                    break;

                case DriveType.Fixed:
                    tn.ImageIndex = 5;
                    break;

                default:
                    tn.ImageIndex = 7;
                    break;
                }
                bool canExpand;

                try
                {
                    canExpand = drive.RootDirectory.GetDirectories().Any();
                }
                catch (Exception)
                {
                    canExpand = false;
                }

                if (canExpand)
                {
                    var placeholder = new TreeNode("<<Placeholder>>");
                    tn.Nodes.Add(placeholder);
                }
                FileTree.Nodes.Add(tn);
                folderNames.Add((string)tn.Tag);
            }

            //add Bread crumbs
            BreadCrumbs = new BreadCrumbControl {
                Parent = BreadCrumbPanel, Dock = DockStyle.Fill
            };
            BreadCrumbs.Navigate += NavigateToFolder;
        }
예제 #3
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);
        }
예제 #4
0
        private void FileTree_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            e.Node.Nodes.Clear();
            var fullName            = (string)e.Node.Tag;
            var nonFolderContents   = new List <string[]>();
            var foldersAlreadyFound = _spectraFolders.ContainsKey((string)e.Node.Tag);
            var nodeList            = new List <TreeNode>();

            if (BreadCrumbControl.PathToDirectoryList(fullName).Count == 1)
            {
                var di = new DriveInfo(fullName);
                foreach (var folder in di.RootDirectory.GetDirectories())
                {
                    var newFolder = new TreeNode(folder.Name)
                    {
                        ImageIndex = 8, Tag = folder.FullName
                    };
                    try
                    {
                        if (folder.GetDirectories().Any())
                        {
                            newFolder.Nodes.Add("<<Placeholder>>");
                        }
                    }
                    catch
                    {
                        //cannot access folder
                    }

                    if (foldersAlreadyFound)
                    {
                        var info = folder;
                        if (!_spectraFolders[(string)e.Node.Tag].Any(item => item[0] == info.FullName))
                        {
                            nodeList.Add(newFolder);
                        }
                    }
                    else
                    {
                        var sourceType = FolderType(folder.FullName);
                        if (sourceType == "File Folder")
                        {
                            nodeList.Add(newFolder);
                        }
                        else if (!string.IsNullOrEmpty(sourceType))
                        {
                            nonFolderContents.Add(new[] { folder.FullName, sourceType });
                        }
                    }
                }

                var sortedList = nodeList.OrderBy(x => x.Text);

                foreach (var item in sortedList)
                {
                    e.Node.Nodes.Add(item);
                }
            }
            else
            {
                var di = new DirectoryInfo(fullName);
                foreach (var folder in di.GetDirectories())
                {
                    var newFolder = new TreeNode(folder.Name)
                    {
                        ImageIndex = 8, Name = folder.FullName, Tag = folder.FullName
                    };
                    try
                    {
                        if (folder.GetDirectories().Any())
                        {
                            newFolder.Nodes.Add("<<Placeholder>>");
                        }
                    }
                    catch
                    {
                        //cannot access folder
                    }

                    if (foldersAlreadyFound)
                    {
                        var info = folder;
                        if (!_spectraFolders[(string)e.Node.Tag].Any(item => item[0] == info.FullName))
                        {
                            nodeList.Add(newFolder);
                        }
                    }
                    else
                    {
                        var sourceType = FolderType(folder.FullName);
                        if (sourceType == "File Folder")
                        {
                            nodeList.Add(newFolder);
                        }
                        else if (!string.IsNullOrEmpty(sourceType))
                        {
                            nonFolderContents.Add(new[] { folder.FullName, sourceType });
                        }
                    }
                }

                var sortedList = nodeList.OrderBy(x => x.Text);

                foreach (var item in sortedList)
                {
                    e.Node.Nodes.Add(item);
                }
            }

            if (!foldersAlreadyFound)
            {
                _spectraFolders.Add((string)e.Node.Tag, nonFolderContents);
            }
        }
예제 #5
0
        private void SetUpDialog()
        {
            _historyQueue = new List<string>();
            ArrowPicture.Tag = new ContextMenu();
            _spectraFolders = new Dictionary<string, List<string[]>>();
            _spectraFiles = new Dictionary<string, List<string[]>>();
            DataSources = new List<string>();

            SubfolderBox.Checked = Properties.Settings.Default.CheckSubdirectories;
            if (!Properties.Settings.Default.FileType.IsNullOrEmpty())
                sourceTypeComboBox.SelectedIndex = Math.Max(0, sourceTypeComboBox.Items.IndexOf(Properties.Settings.Default.FileType));
            else
                sourceTypeComboBox.SelectedIndex = 0;
            
            var folderNames = new List<string>();

            //Desktop
            var specialLocation = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
            var node = new TreeNode("Desktop")
                           {
                               Tag = specialLocation.FullName,
                               ImageIndex = 1,
                               SelectedImageIndex = 1
                           };
            if (specialLocation.GetDirectories().Any())
            {
                var placeholder = new TreeNode("<<Placeholder>>");
                node.Nodes.Add(placeholder);
            }
            FileTree.Nodes.Add(node);
            folderNames.Add((string)node.Tag);

            //My Documents
            specialLocation = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            node = new TreeNode("My Documents")
                       {
                           Tag = specialLocation.FullName,
                           ImageIndex = 2,
                           SelectedImageIndex = 2
                       };
            if (specialLocation.GetDirectories().Any())
            {
                var placeholder = new TreeNode("<<Placeholder>>");
                node.Nodes.Add(placeholder);
            }
            FileTree.Nodes.Add(node);
            folderNames.Add((string)node.Tag);

            //Add drives
            foreach (var drive in DriveInfo.GetDrives())
            {
                var tn = new TreeNode(drive.Name) {Tag = drive.Name};
                switch (drive.DriveType)
                {
                    case DriveType.CDRom:
                    case DriveType.Removable:
                        tn.ImageIndex = 6;
                        tn.SelectedImageIndex = 6;
                        break;
                    case DriveType.Fixed:
                        tn.ImageIndex = 5;
                        tn.SelectedImageIndex = 5;
                        break;
                    default:
                        tn.ImageIndex = 7;
                        tn.SelectedImageIndex = 7;
                        break;
                }
                bool canExpand;

                try
                {
                    canExpand = drive.RootDirectory.GetDirectories().Any();
                }
                catch (Exception)
                {
                    canExpand = false;
                }

                if (canExpand)
                {
                    var placeholder = new TreeNode("<<Placeholder>>");
                    tn.Nodes.Add(placeholder);
                }
                FileTree.Nodes.Add(tn);
                folderNames.Add((string)tn.Tag);
            }

            //add Bread crumbs
            BreadCrumbs = new BreadCrumbControl { Parent = BreadCrumbPanel, Dock = DockStyle.Fill };
            BreadCrumbs.Navigate += NavigateToFolder;
            BreadCrumbs.BoxCreated += (x, y) =>
                                          {
                                              this.AcceptButton = null;
                                              this.CancelButton = null;
                                          };
            BreadCrumbs.BoxRemoved += (x, y) =>
                                          {
                                              this.AcceptButton = this.openButton;
                                              this.CancelButton = this.cancelButton;
                                              this.Focus();
                                          };
        }