Skip to content

Commit 1acf632

Browse files
author
Martin Grenfell
committed
refactor the activate method so the code is now in the models
1 parent e164980 commit 1acf632

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

plugin/NERD_tree.vim

+27-18
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ endif
176176
"CLASS: Bookmark {{{2
177177
"============================================================
178178
let s:Bookmark = {}
179+
" FUNCTION: Bookmark.activate() {{{3
180+
function! s:Bookmark.activate()
181+
if self.path.isDirectory
182+
call self.toRoot()
183+
else
184+
if self.validate()
185+
let n = s:TreeFileNode.New(self.path)
186+
call n.open()
187+
endif
188+
endif
189+
endfunction
179190
" FUNCTION: Bookmark.AddBookmark(name, path) {{{3
180191
" Class method to add a new bookmark to the list, if a previous bookmark exists
181192
" with the same name, just update the path for that bookmark
@@ -426,6 +437,13 @@ endfunction
426437
"classes.
427438
"============================================================
428439
let s:TreeFileNode = {}
440+
"FUNCTION: TreeFileNode.activate(forceKeepWinOpen) {{{3
441+
function! s:TreeFileNode.activate(forceKeepWinOpen)
442+
call self.open()
443+
if !a:forceKeepWinOpen
444+
call s:closeTreeIfQuitOnOpen()
445+
end
446+
endfunction
429447
"FUNCTION: TreeFileNode.bookmark(name) {{{3
430448
"bookmark this node with a:name
431449
function! s:TreeFileNode.bookmark(name)
@@ -974,6 +992,13 @@ function! s:TreeDirNode.AbsoluteTreeRoot()
974992
endwhile
975993
return currentNode
976994
endfunction
995+
"FUNCTION: TreeDirNode.activate(forceKeepWinOpen) {{{3
996+
unlet s:TreeDirNode.activate
997+
function! s:TreeDirNode.activate(forceKeepWinOpen)
998+
call self.toggleOpen()
999+
call s:renderView()
1000+
call self.putCursorHere(0, 0)
1001+
endfunction
9771002
"FUNCTION: TreeDirNode.addChild(treenode, inOrder) {{{3
9781003
"Adds the given treenode to the list of children for this node
9791004
"
@@ -3028,27 +3053,11 @@ function! s:activateNode(forceKeepWindowOpen)
30283053

30293054
let treenode = s:TreeFileNode.GetSelected()
30303055
if treenode != {}
3031-
if treenode.path.isDirectory
3032-
call treenode.toggleOpen()
3033-
call s:renderView()
3034-
call treenode.putCursorHere(0, 0)
3035-
else
3036-
call treenode.open()
3037-
if !a:forceKeepWindowOpen
3038-
call s:closeTreeIfQuitOnOpen()
3039-
end
3040-
endif
3056+
call treenode.activate(a:forceKeepWindowOpen)
30413057
else
30423058
let bookmark = s:getSelectedBookmark()
30433059
if !empty(bookmark)
3044-
if bookmark.path.isDirectory
3045-
call bookmark.toRoot()
3046-
else
3047-
if bookmark.validate()
3048-
let n = s:TreeFileNode.New(bookmark.path)
3049-
call n.open()
3050-
endif
3051-
endif
3060+
call bookmark.activate()
30523061
endif
30533062
endif
30543063
endfunction

0 commit comments

Comments
 (0)