put the open-in-new-tab logic in the models, make NERDTreeQuitOnOpen effect T and t

This commit is contained in:
marty
2009-11-24 00:11:02 +13:00
parent 1537d42706
commit b047d7f312
2 changed files with 53 additions and 23 deletions

View File

@@ -808,7 +808,7 @@ Values: 0 or 1.
Default: 0 Default: 0
If set to 1, the NERD tree window will close after opening a file with the If set to 1, the NERD tree window will close after opening a file with the
|NERDTree-o| or |NERDTree-i| mappings. |NERDTree-o|, |NERDTree-i|, |NERDTree-t| and |NERDTree-T| mappings.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'NERDTreeShowBookmarks'* *'NERDTreeShowBookmarks'*

View File

@@ -377,6 +377,21 @@ function! s:Bookmark.New(name, path)
let newBookmark.path = a:path let newBookmark.path = a:path
return newBookmark return newBookmark
endfunction endfunction
" FUNCTION: Bookmark.openInNewTab(options) {{{3
" Create a new bookmark object with the given name and path object
function! s:Bookmark.openInNewTab(options)
let currentTab = tabpagenr()
if self.path.isDirectory
tabnew
call s:initNerdTree(self.name)
else
exec "tabedit " . bookmark.path.str({'format': 'Edit'})
endif
if has_key(a:options, 'stayInCurrentTab')
exec "tabnext " . currentTab
endif
endfunction
" Function: Bookmark.setPath(path) {{{3 " Function: Bookmark.setPath(path) {{{3
" makes this bookmark point to the given path " makes this bookmark point to the given path
function! s:Bookmark.setPath(path) function! s:Bookmark.setPath(path)
@@ -1201,6 +1216,21 @@ function! s:TreeFileNode.openVSplit()
exec("silent vertical resize ". winwidth) exec("silent vertical resize ". winwidth)
call s:exec('wincmd p') call s:exec('wincmd p')
endfunction endfunction
"FUNCTION: TreeFileNode.openInNewTab(options) {{{3
function! s:TreeFileNode.openInNewTab(options)
let currentTab = tabpagenr()
if !has_key(a:options, 'keepTreeOpen')
call s:closeTreeIfQuitOnOpen()
endif
exec "tabedit " . self.path.str({'format': 'Edit'})
if has_key(a:options, 'stayInCurrentTab') && a:options['stayInCurrentTab']
exec "tabnext " . currentTab
endif
endfunction
"FUNCTION: TreeFileNode.putCursorHere(isJump, recurseUpward){{{3 "FUNCTION: TreeFileNode.putCursorHere(isJump, recurseUpward){{{3
"Places the cursor on the line number this node is rendered on "Places the cursor on the line number this node is rendered on
" "
@@ -1630,6 +1660,22 @@ function! s:TreeDirNode.openExplorer()
exec ("silent edit " . self.path.str({'format': 'Edit'})) exec ("silent edit " . self.path.str({'format': 'Edit'}))
endif endif
endfunction endfunction
"FUNCTION: TreeDirNode.openInNewTab(options) {{{3
unlet s:TreeDirNode.openInNewTab
function! s:TreeDirNode.openInNewTab(options)
let currentTab = tabpagenr()
if !has_key(a:options, 'keepTreeOpen') || !a:options['keepTreeOpen']
call s:closeTreeIfQuitOnOpen()
endif
tabnew
call s:initNerdTree(self.path.str())
if has_key(a:options, 'stayInCurrentTab') && a:options['stayInCurrentTab']
exec "tabnext " . currentTab
endif
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'
"because of the file filters. "because of the file filters.
@@ -3830,29 +3876,13 @@ endfunction
" stayCurrentTab: if 1 then vim will stay in the current tab, if 0 then vim " stayCurrentTab: if 1 then vim will stay in the current tab, if 0 then vim
" will go to the tab where the new file is opened " will go to the tab where the new file is opened
function! s:openInNewTab(stayCurrentTab) function! s:openInNewTab(stayCurrentTab)
let currentTab = tabpagenr() let target = s:TreeFileNode.GetSelected()
if target == {}
let treenode = s:TreeFileNode.GetSelected() let target = s:Bookmark.GetSelected()
if treenode != {}
if treenode.path.isDirectory
tabnew
call s:initNerdTree(treenode.path.str())
else
exec "tabedit " . treenode.path.str({'format': 'Edit'})
endif
else
let bookmark = s:getSelectedBookmark()
if bookmark != {}
if bookmark.path.isDirectory
tabnew
call s:initNerdTree(bookmark.name)
else
exec "tabedit " . bookmark.path.str({'format': 'Edit'})
endif
endif
endif endif
if a:stayCurrentTab
exec "tabnext " . currentTab if target != {}
call target.openInNewTab({'stayInCurrentTab': a:stayCurrentTab})
endif endif
endfunction endfunction