From 1acf6321a5d2c55db80efe8aa3f1f833fb40af9a Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sat, 18 Jul 2009 01:04:40 +1200 Subject: [PATCH] refactor the activate method so the code is now in the models --- plugin/NERD_tree.vim | 45 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 54996cf..b2e1f1e 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -176,6 +176,17 @@ endif "CLASS: Bookmark {{{2 "============================================================ let s:Bookmark = {} +" FUNCTION: Bookmark.activate() {{{3 +function! s:Bookmark.activate() + if self.path.isDirectory + call self.toRoot() + else + if self.validate() + let n = s:TreeFileNode.New(self.path) + call n.open() + endif + endif +endfunction " FUNCTION: Bookmark.AddBookmark(name, path) {{{3 " Class method to add a new bookmark to the list, if a previous bookmark exists " with the same name, just update the path for that bookmark @@ -426,6 +437,13 @@ endfunction "classes. "============================================================ let s:TreeFileNode = {} +"FUNCTION: TreeFileNode.activate(forceKeepWinOpen) {{{3 +function! s:TreeFileNode.activate(forceKeepWinOpen) + call self.open() + if !a:forceKeepWinOpen + call s:closeTreeIfQuitOnOpen() + end +endfunction "FUNCTION: TreeFileNode.bookmark(name) {{{3 "bookmark this node with a:name function! s:TreeFileNode.bookmark(name) @@ -974,6 +992,13 @@ function! s:TreeDirNode.AbsoluteTreeRoot() endwhile return currentNode endfunction +"FUNCTION: TreeDirNode.activate(forceKeepWinOpen) {{{3 +unlet s:TreeDirNode.activate +function! s:TreeDirNode.activate(forceKeepWinOpen) + call self.toggleOpen() + call s:renderView() + call self.putCursorHere(0, 0) +endfunction "FUNCTION: TreeDirNode.addChild(treenode, inOrder) {{{3 "Adds the given treenode to the list of children for this node " @@ -3028,27 +3053,11 @@ function! s:activateNode(forceKeepWindowOpen) let treenode = s:TreeFileNode.GetSelected() if treenode != {} - if treenode.path.isDirectory - call treenode.toggleOpen() - call s:renderView() - call treenode.putCursorHere(0, 0) - else - call treenode.open() - if !a:forceKeepWindowOpen - call s:closeTreeIfQuitOnOpen() - end - endif + call treenode.activate(a:forceKeepWindowOpen) else let bookmark = s:getSelectedBookmark() if !empty(bookmark) - if bookmark.path.isDirectory - call bookmark.toRoot() - else - if bookmark.validate() - let n = s:TreeFileNode.New(bookmark.path) - call n.open() - endif - endif + call bookmark.activate() endif endif endfunction