示例#1
0
        public static void ExpandBranch(TreeNode tn, ImageList imageList)
        {
            CursorHelper.ShowWaitCursor(tn.TreeView, true);

            // if there's a dummy node present, clear it and replace with actual contents
            if (tn.Nodes.Count == 1 && tn.Nodes[0].Tag.ToString() == "DUMMYNODE")
            {
                tn.Nodes.Clear();

                string dir = tn.Tag as string;
                if (string.IsNullOrEmpty(dir) == false && Directory.Exists(dir))
                {
                    foreach (string subdir in PathUtils.EnumDirectories(dir))
                    {
                        TreeNode ntn = CreateTreeNode(subdir, imageList, true);
                        tn.Nodes.Add(ntn);
                        CheckForSubDirs(ntn, imageList);

                        CursorHelper.ShowWaitCursor(tn.TreeView, true);
                    }
                }
            }

            CursorHelper.ShowWaitCursor(tn.TreeView, false);
        }
示例#2
0
        private static void FillSubDirectories(TreeNode tn, ref int imageCount, ImageList imageList, bool getIcons)
        {
            try
            {
                CursorHelper.ShowWaitCursor(tn.TreeView, true);

                string dir = tn.Tag as string;
                if (string.IsNullOrEmpty(dir) == false && Directory.Exists(dir))
                {
                    foreach (string subdir in PathUtils.EnumDirectories(dir))
                    {
                        TreeNode ntn = CreateTreeNode(subdir, imageList, getIcons);
                        tn.Nodes.Add(ntn);
                        CheckForSubDirs(ntn, imageList);

                        CursorHelper.ShowWaitCursor(tn.TreeView, true);
                    }
                }
            }
            catch { }
            finally
            {
                CursorHelper.ShowWaitCursor(tn.TreeView, false);
            }
        }
示例#3
0
        private static void CheckForSubDirs(TreeNode tn, ImageList imageList)
        {
            CursorHelper.ShowWaitCursor(tn.TreeView, true);

            if (tn.Nodes.Count == 0)
            {
                try
                {
                    // create dummy nodes for any subfolders that have further subfolders
                    string dir = tn.Tag as string;
                    if (string.IsNullOrEmpty(dir) == false && Directory.Exists(dir))
                    {
                        bool hasFolders = (PathUtils.EnumDirectories(dir).Count > 0);
                        if (hasFolders)
                        {
                            TreeNode ntn = new TreeNode();
                            ntn.Tag = "DUMMYNODE";
                            tn.Nodes.Add(ntn);
                        }
                    }
                }
                catch
                {
                }
            }

            CursorHelper.ShowWaitCursor(tn.TreeView, false);
        }
示例#4
0
        private static void AddRootNodes(OPMTreeView tree, ImageList imageList, bool getIcons, bool showSpecialFolders)
        {
            CursorHelper.ShowWaitCursor(tree, true);

            tree.Nodes.Clear();

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

            try
            {
                System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
                foreach (System.IO.DriveInfo di in drives)
                {
                    roots.Add(di.RootDirectory.FullName);
                }

                if (showSpecialFolders)
                {
                    foreach (Environment.SpecialFolder sf in SpecialFolders)
                    {
                        string path = Environment.GetFolderPath(sf, Environment.SpecialFolderOption.Create);
                        if (Directory.Exists(path))
                        {
                            roots.Add(path);
                        }
                    }
                }
            }
            catch
            {
            }

            foreach (string dir in roots)
            {
                TreeNode rootNode = CreateTreeNode(dir, imageList, true);
                tree.Nodes.Add(rootNode);
                CheckForSubDirs(rootNode, imageList);
            }

            CursorHelper.ShowWaitCursor(tree, false);
        }
        private void Explore(bool keepSelection)
        {
            if (InvokeRequired)
            {
                Invoke(new ExploreHandler(Explore), keepSelection);
                return;
            }

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

            if (keepSelection)
            {
                selection.AddRange(SelectedPaths);
            }

            int selIdx = 0;

            try
            {
                selIdx = this.SelectedIndices[0];
            }
            catch
            {
                selIdx = 0;
            }

            lock (syncRoot)
            {
                try
                {
                    ignoreEvents = true;

                    bool isUncPathRoot = false;

                    CursorHelper.ShowWaitCursor(this, true);

                    // Check if current path is valid.
                    if (!Directory.Exists(m_strDirPath))
                    {
                        m_strDirPath = FindFirstUsablePath(m_strDirPath, ref isUncPathRoot);
                    }

                    AppConfig.LastExploredFolder = m_strDirPath;

                    if (!isUncPathRoot && PathUtils.IsRootPath(m_strDirPath))
                    {
                        m_strDirPath = m_strDirPath.TrimEnd(string.Copy(PathUtils.DirectorySeparator).ToCharArray()) + PathUtils.DirectorySeparator;
                    }

                    ShareCollection shares = null;
                    List <string>   dirs   = null;
                    List <string>   files  = null;

                    if (isUncPathRoot)
                    {
                        try
                        {
                            shares = ShareCollection.GetShares(m_strDirPath);
                        }
                        catch { }
                    }
                    else
                    {
                        try
                        {
                            dirs = PathUtils.EnumDirectories(m_strDirPath);
                        }
                        catch { }

                        try
                        {
                            files = PathUtils.EnumFilesUsingMultiFilter(m_strDirPath, this.SearchPattern);
                        }
                        catch { }
                    }

                    ClearCurrentContents();

                    CreateParentFolderRow();

                    if (isUncPathRoot && shares != null)
                    {
                        foreach (Share share in shares)
                        {
                            if (!share.IsFileSystem)
                            {
                                continue;
                            }

                            if (Directory.Exists(share.Root.FullName) == false)
                            {
                                continue;
                            }

                            CreateNewRow(share.Root.FullName);
                        }
                    }
                    else
                    {
                        if (dirs != null)
                        {
                            foreach (string dir in dirs)
                            {
                                if (Directory.Exists(dir) == false)
                                {
                                    continue;
                                }

                                CreateNewRow(dir);
                                int tt = 0;
                            }
                        }

                        if (files != null)
                        {
                            foreach (string file in files)
                            {
                                if (File.Exists(file) == false)
                                {
                                    continue;
                                }

                                CreateNewRow(file);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
                finally
                {
                    CursorHelper.ShowWaitCursor(this, false);
                    ignoreEvents = true;
                }

                if (this.Items.Count <= 0)
                {
                    CreateMessageRow(string.Empty);
                    CreateMessageRow(Translator.Translate("TXT_FOLDERNOTACCESSIBLE"));
                }
            }

            this.Sort();

            //ClearSelection();
            this.SelectedItems.Clear();

            bool selectedSomething = false;

            if (keepSelection || _pathToSelect != null)
            {
                if ((selection != null && selection.Count > 0) || _pathToSelect != null)
                {
                    bool focusSet = false;

                    foreach (ListViewItem item in Items)
                    {
                        string path = item.Tag as string;
                        if (selection.Contains(path) || (string.Compare(_pathToSelect, path, true) == 0))
                        {
                            if (!focusSet)
                            {
                                item.Focused = true;
                                focusSet     = true;
                            }

                            item.Selected = true;
                            EnsureVisible(item.Index);
                            selectedSomething = true;
                        }
                    }
                }
            }
            else if (m_strPrevDirPath != null && m_strPrevDirPath.Length > 0)
            {
                int lastVisibleIndex = 0;
                foreach (ListViewItem item in this.Items)
                {
                    string path = item.Tag as string;
                    if (string.IsNullOrEmpty(path) == false)
                    {
                        item.Selected = false;

                        if (string.Compare(path, m_strPrevDirPath, false) == 0)
                        {
                            item.Selected = true;
                            item.Focused  = true;

                            lastVisibleIndex = item.Index;

                            break;
                        }
                    }
                }

                EnsureVisible(lastVisibleIndex);
                selectedSomething = true;
            }

            if (!selectedSomething)
            {
                if (selIdx < 0)
                {
                    selIdx = 0;
                }
                if (selIdx >= this.Items.Count)
                {
                    selIdx = this.Items.Count - 1;
                }

                this.Items[selIdx].Selected = true;
                this.Items[selIdx].Focused  = true;
                EnsureVisible(selIdx);
            }

            this.Select();
            this.Focus();
        }