From b047d7f31202e9bf7dc15467c804f0db7e1ef3fc Mon Sep 17 00:00:00 2001 From: marty Date: Tue, 24 Nov 2009 00:11:02 +1300 Subject: [PATCH] put the open-in-new-tab logic in the models, make NERDTreeQuitOnOpen effect T and t --- doc/NERD_tree.txt | 2 +- plugin/NERD_tree.vim | 74 +++++++++++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/doc/NERD_tree.txt b/doc/NERD_tree.txt index 0b39e01..ca83fe7 100644 --- a/doc/NERD_tree.txt +++ b/doc/NERD_tree.txt @@ -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'* diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 6d300df..d517fdd 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -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) @@ -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 " @@ -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. @@ -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