commit 642c2b76fc5a3b11333bcc060c38f71fc3110fa8
parent 6b7760e6e4298ba628263f4d0bc5b51a78201c61
Author: Martin Grenfell <martin_grenfell@msn.com>
Date: Sat, 7 Jun 2008 17:36:14 +1200
add oFileNode#MakeRoot() and refactor s:ChRoot()
not that as of this commit, you can now use the C mapping on a file node
and its parent dir node will become the new root
Diffstat:
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim
@@ -290,6 +290,22 @@ function! s:oTreeFileNode.IsRoot() dict
return self.Equals(t:NERDTreeRoot)
endfunction
+"FUNCTION: oTreeFileNode.MakeRoot() {{{3
+"Make this node the root of the tree
+function! s:oTreeFileNode.MakeRoot() dict
+ if self.path.isDirectory
+ let t:NERDTreeRoot = self
+ else
+ let t:NERDTreeRoot = self.parent
+ endif
+
+ call t:NERDTreeRoot.Open()
+
+ "change dir to the dir of the new root if instructed to
+ if g:NERDTreeChDirMode == 2
+ exec "cd " . t:NERDTreeRoot.path.StrForEditCmd()
+ endif
+endfunction
"FUNCTION: oTreeFileNode.New(path) {{{3
"Returns a new TreeNode object with the given path and parent
"
@@ -2507,23 +2523,12 @@ endfunction
" changes the current root to the selected one
function! s:ChRoot()
let treenode = s:GetSelectedNode()
- if treenode == {} || treenode.path.isDirectory == 0
- call s:Echo("Select a directory node first")
+ if treenode == {}
+ call s:Echo("Select a node first")
return
endif
- if treenode.isOpen == 0
- call treenode.Open()
- endif
-
- let t:NERDTreeRoot = treenode
-
- "change dir to the dir of the new root if instructed to
- if g:NERDTreeChDirMode == 2
- exec "cd " . treenode.path.StrForEditCmd()
- endif
-
-
+ call treenode.MakeRoot()
call s:RenderView()
call s:PutCursorOnNode(t:NERDTreeRoot, 0, 0)
endfunction