make TreeDirNode use the new open() interface

This commit is contained in:
Martin Grenfell
2012-01-06 14:47:10 +00:00
parent 9832d4a84a
commit 92248f92ca

View File

@@ -1574,10 +1574,11 @@ function! s:TreeDirNode.AbsoluteTreeRoot()
endwhile endwhile
return currentNode return currentNode
endfunction endfunction
"FUNCTION: TreeDirNode.activate(forceKeepWinOpen) {{{3 "FUNCTION: TreeDirNode.activate([options]) {{{3
unlet s:TreeDirNode.activate unlet s:TreeDirNode.activate
function! s:TreeDirNode.activate(forceKeepWinOpen) function! s:TreeDirNode.activate(...)
call self.toggleOpen() let opts = a:0 ? a:1 : {}
call self.toggleOpen(opts)
call s:renderView() call s:renderView()
call self.putCursorHere(0, 0) call self.putCursorHere(0, 0)
endfunction endfunction
@@ -1838,17 +1839,42 @@ function! s:TreeDirNode.New(path)
return newTreeNode return newTreeNode
endfunction endfunction
"FUNCTION: TreeDirNode.open() {{{3 "FUNCTION: TreeDirNode.open([opts]) {{{3
"Reads in all this nodes children "Open the dir in the current tree or in a new tree elsewhere.
"
"Args:
"
"A dictionary containing the following keys (all optional):
" 'split': 't' if the tree should be opened in a new tab
" 'keepopen': dont close the tree window
" 'preview': open the file, but keep the cursor in the tree win
" "
"Return: the number of child nodes read
unlet s:TreeDirNode.open unlet s:TreeDirNode.open
function! s:TreeDirNode.open(...) function! s:TreeDirNode.open(...)
let self.isOpen = 1 let opts = a:0 ? a:1 : {}
if self.children ==# []
return self._initChildren(0) if has_key(opts, 'split') && opts['split'] == 't'
let currentBuf = bufnr("")
let currentTab = tabpagenr()
call self._openInNewTab()
if s:has_opt(opts, 'preview')
call s:exec('normal ' . currentTab . 'gt')
call s:exec(bufwinnr(currentBuf) . 'wincmd w')
endif
if !s:has_opt(opts, 'keepTreeOpen')
call s:closeTreeIfQuitOnOpen()
endif
else else
return 0 let self.isOpen = 1
if self.children ==# []
return self._initChildren(0)
else
return 0
endif
endif endif
endfunction endfunction
@@ -1868,18 +1894,14 @@ endfunction
"FUNCTION: TreeDirNode.openInNewTab(options) {{{3 "FUNCTION: TreeDirNode.openInNewTab(options) {{{3
unlet s:TreeDirNode.openInNewTab unlet s:TreeDirNode.openInNewTab
function! s:TreeDirNode.openInNewTab(options) function! s:TreeDirNode.openInNewTab(options)
let currentTab = tabpagenr() call s:deprecated('TreeDirNode.openInNewTab', 'is deprecated, use open() instead')
call self.open({'split': 't'})
if !s:has_opt(a:options, 'keepTreeOpen') endfunction
call s:closeTreeIfQuitOnOpen() "FUNCTION: TreeDirNode._openInNewTab() {{{3
endif unlet s:TreeDirNode._openInNewTab
function! s:TreeDirNode._openInNewTab()
tabnew tabnew
call s:initNerdTree(self.path.str()) call s:initNerdTree(self.path.str())
if s:has_opt(a:options, 'stayInCurrentTab')
exec "tabnext " . currentTab
endif
endfunction endfunction
"FUNCTION: TreeDirNode.openRecursively() {{{3 "FUNCTION: TreeDirNode.openRecursively() {{{3
"Opens this treenode and all of its children whose paths arent 'ignored' "Opens this treenode and all of its children whose paths arent 'ignored'
@@ -2019,13 +2041,14 @@ function! s:TreeDirNode.sortChildren()
call sort(self.children, CompareFunc) call sort(self.children, CompareFunc)
endfunction endfunction
"FUNCTION: TreeDirNode.toggleOpen() {{{3 "FUNCTION: TreeDirNode.toggleOpen([options]) {{{3
"Opens this directory if it is closed and vice versa "Opens this directory if it is closed and vice versa
function! s:TreeDirNode.toggleOpen() function! s:TreeDirNode.toggleOpen(...)
let opts = a:0 ? a:1 : {}
if self.isOpen ==# 1 if self.isOpen ==# 1
call self.close() call self.close()
else else
call self.open() call self.open(opts)
endif endif
endfunction endfunction