private void PopulateNode(TreeNode treenode) { DirectoryFileTreeNode node = treenode.Tag as DirectoryFileTreeNode; if (node.ChildrenPopulated || node.children.Count == 0) { return; } node.ChildrenPopulated = true; m_RM.ListFolder(node.children[0].Path, (string path, DirectoryFile[] files) => { node.children[0].Populate(path, files); // do the rest on-thread for (int i = 1; i < node.children.Count; i++) { if (!node.children[i].IsDirectory || node.children[i].HasPopulated) { continue; } m_RM.ListFolder(node.children[i].Path, (string a, DirectoryFile[] b) => { node.children[i].Populate(a, b); }); } }); BeginInvoke(new Action(UpdateViewsFromData)); }
public void Populate(string path, DirectoryFile[] files) { HasPopulated = true; if (files.Length == 1 && files[0].flags.HasFlag(DirectoryFileProperty.ErrorAccessDenied)) { AccessDenied = true; return; } foreach (DirectoryFile file in files) { DirectoryFileTreeNode child = new DirectoryFileTreeNode(); child.Filename = file.filename; if (Path == "/") { child.Path = Path + file.filename; } else { child.Path = Path + "/" + file.filename; } child.IsHidden = file.flags.HasFlag(DirectoryFileProperty.Hidden); child.IsExecutable = file.flags.HasFlag(DirectoryFileProperty.Executable); child.IsDirectory = file.flags.HasFlag(DirectoryFileProperty.Directory); children.Add(child); } }
private void InitialPopulate() { bool populated = false; m_RM.GetHomeFolder((string path, DirectoryFile[] f) => { currentDir = path; history.Add(currentDir); // check if we're NT paths or unix paths, and populate the roots if (currentDir[0].IsAlpha() && currentDir[1] == ':') { NTPaths = true; m_RM.ListFolder("/", (string p, DirectoryFile[] files) => { foreach (var root in files) { DirectoryFileTreeNode node = new DirectoryFileTreeNode(); node.Path = node.Filename = root.filename; node.IsDirectory = true; roots.Add(node); m_RM.ListFolder(root.filename, (string a, DirectoryFile[] b) => { node.Populate(a, b); }); } }); } else { NTPaths = false; DirectoryFileTreeNode node = new DirectoryFileTreeNode(); node.Path = node.Filename = "/"; node.IsDirectory = true; roots.Add(node); m_RM.ListFolder("/", (string a, DirectoryFile[] b) => { node.Populate(a, b); }); } // we will populate the rest of the folders when expanding to the current directory populated = true; BeginInvoke(new Action(UpdateViewsFromData)); }); // wait a second for the results to come in SpinWait.SpinUntil((Func <bool>)(() => { return(populated); }), 1000); }
private void AddDirTreeNodeRecursive(DirectoryFileTreeNode node, TreeNode parent) { if (!node.IsDirectory) { return; } if (node.directoryNode == null) { TreeNode treenode = new TreeNode(); treenode.Text = node.Filename; treenode.SelectedImageIndex = treenode.ImageIndex = ICON_DIRECTORY; treenode.Tag = node; node.directoryNode = treenode; parent.Nodes.Add(treenode); } foreach (var child in node.children) { AddDirTreeNodeRecursive(child, node.directoryNode); } }
private bool TryOpenFile(bool doubleclick) { // double clicking enters directories, it doesn't choose them if (m_DirBrowse && !doubleclick) { DirectoryFileTreeNode node = GetNode(Directory); if (node != null) { OnOpened(new FileOpenedEventArgs(NTPaths, Directory)); Close(); return(true); } return(false); } int idx = currentFiles.FindIndex(f => f.Filename == FileName); if (idx >= 0) { if (currentFiles[idx].IsDirectory) { ChangeDirectory(Directory + "/" + currentFiles[idx].Filename); return(true); } OnOpened(new FileOpenedEventArgs(NTPaths, ChosenPath)); Close(); return(true); } return(false); }
public void Populate(string path, DirectoryFile[] files) { HasPopulated = true; if (files.Length == 1 && files[0].flags.HasFlag(DirectoryFileProperty.ErrorAccessDenied)) { AccessDenied = true; return; } foreach (DirectoryFile file in files) { DirectoryFileTreeNode child = new DirectoryFileTreeNode(); child.Filename = file.filename; if (Path == "/") child.Path = Path + file.filename; else child.Path = Path + "/" + file.filename; child.IsHidden = file.flags.HasFlag(DirectoryFileProperty.Hidden); child.IsExecutable = file.flags.HasFlag(DirectoryFileProperty.Executable); child.IsDirectory = file.flags.HasFlag(DirectoryFileProperty.Directory); children.Add(child); } }
private void UpdateFileList() { fileList.BeginUpdate(); fileList.Clear(); fileList.EndUpdate(); currentFiles.Clear(); // return, we haven't populated anything yet if (roots.Count == 0) { return; } DirectoryFileTreeNode node = GetNode(Directory); if (node == null) { return; } string match = ".*"; if (FileName.IndexOf('*') != -1 || FileName.IndexOf('?') != -1) { match = Regex.Escape(FileName).Replace(@"\*", ".*").Replace(@"\?", "."); } fileList.BeginUpdate(); foreach (var child in node.children) { if (child.IsHidden && !showHidden.Checked) { continue; } var res = Regex.Match(child.Filename, match); // always display directories even if they don't match a glob if (!res.Success && !child.IsDirectory) { continue; } int imgidx = ICON_FILE; if (child.IsDirectory) { imgidx = ICON_DIRECTORY; } else if (child.IsExecutable) { imgidx = ICON_EXECUTABLE; } // skip non-executables if (imgidx == ICON_FILE && fileType.SelectedIndex == 0) { continue; } if (child.IsHidden) { imgidx = ICON_FILE_FADED; if (child.IsDirectory) { imgidx = ICON_DIRECTORY_FADED; } else if (child.IsExecutable) { imgidx = ICON_EXECUTABLE_FADED; } } ListViewItem item = new ListViewItem(child.Filename, imgidx); item.Tag = child; fileList.Items.Add(item); currentFiles.Add(child); } fileList.EndUpdate(); }
private bool ChangeDirectory(string dir, bool recordHistory) { if (Directory == dir) { return(true); } // normalise input dir = dir.Replace('\\', '/'); if (dir[dir.Length - 1] == '/') { dir = dir.Substring(0, dir.Length - 1); } if (NTPaths) { dir = dir.Replace("://", ":/"); } DirectoryFileTreeNode node = GetNode(dir); if (node != null && node.AccessDenied) { ShowAccessDeniedMessage(dir); return(false); } if (node == null) { bool immediateError = false; m_RM.ListFolder(dir, (string a, DirectoryFile[] b) => { if (b.Length == 1 && b[0].flags.HasFlag(DirectoryFileProperty.ErrorInvalidPath)) { ShowFileNotFoundMessage(dir); immediateError = true; return; } if (b.Length == 1 && b[0].flags.HasFlag(DirectoryFileProperty.ErrorAccessDenied)) { ShowAccessDeniedMessage(dir); immediateError = true; return; } if (recordHistory) { if (historyidx < history.Count - 1) { history.RemoveRange(historyidx, history.Count - 1 - historyidx); } history.Add(dir); historyidx = history.Count - 1; } currentDir = dir; UpdateViewsFromData(); }); if (immediateError) { return(false); } return(true); } if (recordHistory) { if (historyidx < history.Count - 1) { history.RemoveRange(historyidx, history.Count - 1 - historyidx); } history.Add(dir); historyidx = history.Count - 1; } currentDir = dir; UpdateViewsFromData(); return(true); }
private void UpdateViewsFromData() { if (insideUpdateViews) { return; } insideUpdateViews = true; location.Text = Directory; directoryTree.BeginUpdate(); foreach (var root in roots) { if (root.directoryNode == null) { TreeNode treenode = new TreeNode(); treenode.Text = root.Filename; treenode.SelectedImageIndex = treenode.ImageIndex = ICON_DRIVE; treenode.Tag = root; root.directoryNode = treenode; directoryTree.Nodes.Add(treenode); } AddDirTreeNodeRecursive(root, root.directoryNode); } directoryTree.EndUpdate(); string[] components = Directory.Split('/'); DirectoryFileTreeNode node = null; // expand down to the current directory for (int i = 1; i < components.Length; i++) { string dir = NTPaths ? components[0] : ""; for (int j = 1; j < i; j++) { dir += "/" + components[j]; } if (dir == "") { dir = "/"; } node = GetNode(dir); if (node == null || node.directoryNode == null) { break; } node.directoryNode.Expand(); } node = GetNode(Directory); if (node != null && node.directoryNode != null) { directoryTree.SelectedNode = node.directoryNode; } UpdateFileList(); up.Enabled = !IsRoot; back.Enabled = history.Count > 0 && historyidx > 0; forward.Enabled = historyidx < history.Count - 1; insideUpdateViews = false; }
private void InitialPopulate() { bool populated = false; m_RM.GetHomeFolder((string path, DirectoryFile[] f) => { currentDir = path; history.Add(currentDir); // check if we're NT paths or unix paths, and populate the roots if (currentDir[0].IsAlpha() && currentDir[1] == ':') { NTPaths = true; CheckRemote(m_RM.ListFolder("/", (string p, DirectoryFile[] files) => { foreach (var root in files) { DirectoryFileTreeNode node = new DirectoryFileTreeNode(); node.Path = node.Filename = root.filename; node.IsDirectory = true; roots.Add(node); CheckRemote(m_RM.ListFolder(root.filename, (string a, DirectoryFile[] b) => { node.Populate(a, b); })); } })); } else { NTPaths = false; DirectoryFileTreeNode node = new DirectoryFileTreeNode(); node.Path = node.Filename = "/"; node.IsDirectory = true; roots.Add(node); CheckRemote(m_RM.ListFolder("/", (string a, DirectoryFile[] b) => { node.Populate(a, b); })); } // we will populate the rest of the folders when expanding to the current directory populated = true; BeginInvoke(new Action(UpdateViewsFromData)); }); // wait a second for the results to come in SpinWait.SpinUntil((Func<bool>)(() => { return populated; }), 1000); }
private void AddDirTreeNodeRecursive(DirectoryFileTreeNode node, TreeNode parent) { if (!node.IsDirectory) return; if (node.directoryNode == null) { TreeNode treenode = new TreeNode(); treenode.Text = node.Filename; treenode.SelectedImageIndex = treenode.ImageIndex = ICON_DIRECTORY; treenode.Tag = node; node.directoryNode = treenode; parent.Nodes.Add(treenode); } foreach (var child in node.children) { AddDirTreeNodeRecursive(child, node.directoryNode); } }