Skip to content

Commit

Permalink
put the open-in-new-tab logic in the models, make NERDTreeQuitOnOpen …
Browse files Browse the repository at this point in the history
…effect T and t
  • Loading branch information
marty committed Nov 23, 2009
1 parent 1537d42 commit b047d7f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
2 changes: 1 addition & 1 deletion doc/NERD_tree.txt
Expand Up @@ -808,7 +808,7 @@ Values: 0 or 1.
Default: 0

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'*
Expand Down
74 changes: 52 additions & 22 deletions plugin/NERD_tree.vim
Expand Up @@ -377,6 +377,21 @@ function! s:Bookmark.New(name, path)
let newBookmark.path = a:path
return newBookmark
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
" makes this bookmark point to the given path
function! s:Bookmark.setPath(path)
Expand Down Expand Up @@ -1201,6 +1216,21 @@ function! s:TreeFileNode.openVSplit()
exec("silent vertical resize ". winwidth)
call s:exec('wincmd p')
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
"Places the cursor on the line number this node is rendered on
"
Expand Down Expand Up @@ -1630,6 +1660,22 @@ function! s:TreeDirNode.openExplorer()
exec ("silent edit " . self.path.str({'format': 'Edit'}))
endif
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
"Opens this treenode and all of its children whose paths arent 'ignored'
"because of the file filters.
Expand Down Expand Up @@ -3830,29 +3876,13 @@ endfunction
" 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
function! s:openInNewTab(stayCurrentTab)
let currentTab = tabpagenr()

let treenode = s:TreeFileNode.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
let target = s:TreeFileNode.GetSelected()
if target == {}
let target = s:Bookmark.GetSelected()
endif
if a:stayCurrentTab
exec "tabnext " . currentTab

if target != {}
call target.openInNewTab({'stayInCurrentTab': a:stayCurrentTab})
endif
endfunction

Expand Down

0 comments on commit b047d7f

Please sign in to comment.