protected override void OnAfterSelect(TreeViewEventArgs e) { if (e.Node == null) { return; } FBTreeNode fbnode = e.Node as FBTreeNode; if (fbnode.RealPath == null || fbnode.RealPath.IndexOf("://") != -1) { parentDialog.okButton.Enabled = false; parentDialog.newFolderButton.Enabled = false; parentDialog.newFolderMenuItem.Enabled = false; dont_enable = true; } else { parentDialog.okButton.Enabled = true; parentDialog.newFolderButton.Enabled = true; parentDialog.newFolderMenuItem.Enabled = true; parentDialog.selectedPath = fbnode.RealPath; dont_enable = false; } base.OnAfterSelect(e); }
private FBTreeNode FindPathInNodes(string path, TreeNodeCollection nodes) { // On Windows the devices can be passed as C: yet match // the C:\ form // // Hackish, but works if (!XplatUI.RunningOnUnix && path.Length == 2) { path += Path.DirectorySeparatorChar; } foreach (TreeNode node in nodes) { FBTreeNode fbnode = node as FBTreeNode; if (fbnode != null && fbnode.RealPath != null) { if (fbnode.RealPath == path) { return(fbnode); } } FBTreeNode n = FindPathInNodes(path, node.Nodes); if (n != null) { return(n); } } return(null); }
protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e) { if (e.Label != null) { if (e.Label.Length > 0) { FBTreeNode fbnode = e.Node as FBTreeNode; string originalPath = fbnode.RealPath; string newPath = Path.Combine(parent_real_path, e.Label); if (vfs.MoveFolder(originalPath, newPath)) { fbnode.Tag = fbnode.RealPath = newPath; } else { e.CancelEdit = true; e.Node.BeginEdit(); return; } } else { e.CancelEdit = true; e.Node.BeginEdit(); return; } } // select new folder only if both the curren node under // mouse pointer and SelectedNode are the same (match .Net) if (node_under_mouse == SelectedNode) { SelectedNode = e.Node; } // disable LabelEdit when either edit has finished // or has been cancelled, to prevent the user from // editing label of existing folders LabelEdit = false; }
private void FillNode(TreeNode node) { BeginUpdate(); node.Nodes.Clear(); vfs.ChangeDirectory((string)node.Tag); ArrayList folders = vfs.GetFoldersOnly(); foreach (FSEntry fsentry in folders) { if (fsentry.Name.StartsWith(".")) { continue; } FBTreeNode child = new FBTreeNode(fsentry.Name); child.Tag = fsentry.FullName; child.RealPath = fsentry.RealName == null ? fsentry.FullName : fsentry.RealName; child.ImageIndex = NodeImageIndex(fsentry.FullName); vfs.ChangeDirectory(fsentry.FullName); ArrayList sub_folders = vfs.GetFoldersOnly(); foreach (FSEntry fsentry_sub in sub_folders) { if (!fsentry_sub.Name.StartsWith(".")) { child.Nodes.Add(new TreeNode(String.Empty)); break; } } node.Nodes.Add(child); } EndUpdate(); }
private void SetSelectedPath(string path) { BeginUpdate(); FBTreeNode node = FindPathInNodes(path, Nodes); if (node == null) { Stack stack = new Stack(); string path_cut = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar)); if (!XplatUI.RunningOnUnix && path_cut.Length == 2) { path_cut += Path.DirectorySeparatorChar; } while (node == null && path_cut.Length > 0) { node = FindPathInNodes(path_cut, Nodes); if (node == null) { string path_cut_new = path_cut.Substring(0, path_cut.LastIndexOf(Path.DirectorySeparatorChar)); string leftover = path_cut.Replace(path_cut_new, string.Empty); stack.Push(leftover); path_cut = path_cut_new; } } // If we didn't find anything, just display the full, unselected tree if (node == null) { EndUpdate(); RootFolder = rootFolder; return; } FillNode(node); node.Expand(); // walk through the subdirs and fill the nodes while (stack.Count > 0) { string part_name = stack.Pop() as string; foreach (TreeNode treeNode in node.Nodes) { FBTreeNode fbnode = treeNode as FBTreeNode; if (path_cut + part_name == fbnode.RealPath) { node = fbnode; path_cut += part_name; FillNode(node); node.Expand(); break; } } } // finally find the node for the complete path foreach (TreeNode treeNode in node.Nodes) { FBTreeNode fbnode = treeNode as FBTreeNode; if (path == fbnode.RealPath) { node = fbnode; break; } } } if (node != null) { SelectedNode = node; node.EnsureVisible(); } EndUpdate(); }
public void CreateNewFolder() { FBTreeNode fbnode = node_under_mouse == null ? SelectedNode as FBTreeNode : node_under_mouse as FBTreeNode; if (fbnode == null || fbnode.RealPath == null) { return; } string tmp_filename = "New Folder"; if (Directory.Exists(Path.Combine(fbnode.RealPath, tmp_filename))) { int i = 1; if (XplatUI.RunningOnUnix) { tmp_filename = tmp_filename + "-" + i; } else { tmp_filename = tmp_filename + " (" + i + ")"; } while (Directory.Exists(Path.Combine(fbnode.RealPath, tmp_filename))) { i++; if (XplatUI.RunningOnUnix) { tmp_filename = "New Folder" + "-" + i; } else { tmp_filename = "New Folder" + " (" + i + ")"; } } } parent_real_path = fbnode.RealPath; FillNode(fbnode); dont_do_onbeforeexpand = true; fbnode.Expand(); dont_do_onbeforeexpand = false; // to match MS, immediately create the new folder // and rename it once the label edit completes string fullPath = Path.Combine(fbnode.RealPath, tmp_filename); if (!vfs.CreateFolder(fullPath)) { return; } FBTreeNode new_node = new FBTreeNode(tmp_filename); new_node.ImageIndex = NodeImageIndex(tmp_filename); new_node.Tag = new_node.RealPath = fullPath; fbnode.Nodes.Add(new_node); LabelEdit = true; new_node.BeginEdit(); }
private void FillNode (TreeNode node) { BeginUpdate (); node.Nodes.Clear (); vfs.ChangeDirectory ((string)node.Tag); ArrayList folders = vfs.GetFoldersOnly (); foreach (FSEntry fsentry in folders) { if (fsentry.Name.StartsWith (".")) continue; FBTreeNode child = new FBTreeNode (fsentry.Name); child.Tag = fsentry.FullName; child.RealPath = fsentry.RealName == null ? fsentry.FullName : fsentry.RealName; child.ImageIndex = NodeImageIndex (fsentry.FullName); vfs.ChangeDirectory (fsentry.FullName); ArrayList sub_folders = vfs.GetFoldersOnly (); foreach (FSEntry fsentry_sub in sub_folders) { if (!fsentry_sub.Name.StartsWith (".")) { child.Nodes.Add (new TreeNode (String.Empty)); break; } } node.Nodes.Add (child); } EndUpdate (); }
public void CreateNewFolder () { FBTreeNode fbnode = node_under_mouse == null ? SelectedNode as FBTreeNode : node_under_mouse as FBTreeNode; if (fbnode == null || fbnode.RealPath == null) return; string tmp_filename = "New Folder"; if (Directory.Exists (Path.Combine (fbnode.RealPath, tmp_filename))) { int i = 1; if (XplatUI.RunningOnUnix) { tmp_filename = tmp_filename + "-" + i; } else { tmp_filename = tmp_filename + " (" + i + ")"; } while (Directory.Exists (Path.Combine (fbnode.RealPath, tmp_filename))) { i++; if (XplatUI.RunningOnUnix) { tmp_filename = "New Folder" + "-" + i; } else { tmp_filename = "New Folder" + " (" + i + ")"; } } } parent_real_path = fbnode.RealPath; FillNode (fbnode); dont_do_onbeforeexpand = true; fbnode.Expand (); dont_do_onbeforeexpand = false; // to match MS, immediately create the new folder // and rename it once the label edit completes string fullPath = Path.Combine (fbnode.RealPath, tmp_filename); if (!vfs.CreateFolder (fullPath)) return; FBTreeNode new_node = new FBTreeNode (tmp_filename); new_node.ImageIndex = NodeImageIndex (tmp_filename); new_node.Tag = new_node.RealPath = fullPath; fbnode.Nodes.Add (new_node); LabelEdit = true; new_node.BeginEdit(); }