예제 #1
0
            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();
            }
예제 #2
0
            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();
            }