add some class methods to wrap the NERDTreeCreator public methods

This is needed because some versions of vim dont let you chain method
calls together. So do the work in NERDTreeCreator instead of forcing all
callers to break the New().createXXX() calls out onto 2 lines with an
intermediate variable.

Fixes #226.
This commit is contained in:
Martin Grenfell
2013-01-09 00:41:34 +00:00
parent 7cbaee253a
commit c3b63d2fd9
5 changed files with 38 additions and 14 deletions

View File

@@ -42,7 +42,7 @@ endfunction
"inits a secondary nerd tree in the current buffer if appropriate "inits a secondary nerd tree in the current buffer if appropriate
function! nerdtree#checkForBrowse(dir) function! nerdtree#checkForBrowse(dir)
if a:dir != '' && isdirectory(a:dir) if a:dir != '' && isdirectory(a:dir)
call g:NERDTreeCreator.New().createSecondary(a:dir) call g:NERDTreeCreator.CreateSecondary(a:dir)
endif endif
endfunction endfunction
@@ -193,14 +193,14 @@ function! nerdtree#findAndRevealPath()
endtry endtry
if p.isUnder(cwd) if p.isUnder(cwd)
call g:NERDTreeCreator.New().createPrimary(cwd.str()) call g:NERDTreeCreator.CreatePrimary(cwd.str())
else else
call g:NERDTreeCreator.New().createPrimary(p.getParent().str()) call g:NERDTreeCreator.CreatePrimary(p.getParent().str())
endif endif
else else
if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path) if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path)
if !nerdtree#isTreeOpen() if !nerdtree#isTreeOpen()
call g:NERDTreeCreator.New().togglePrimary('') call g:NERDTreeCreator.TogglePrimary('')
else else
call nerdtree#putCursorInTreeWin() call nerdtree#putCursorInTreeWin()
endif endif
@@ -208,7 +208,7 @@ function! nerdtree#findAndRevealPath()
call nerdtree#chRoot(g:NERDTreeDirNode.New(p.getParent())) call nerdtree#chRoot(g:NERDTreeDirNode.New(p.getParent()))
else else
if !nerdtree#isTreeOpen() if !nerdtree#isTreeOpen()
call g:NERDTreeCreator.New().togglePrimary("") call g:NERDTreeCreator.TogglePrimary("")
endif endif
endif endif
endif endif

View File

@@ -149,11 +149,11 @@ runtime plugin/nerdtree/creator.vim
" SECTION: Commands {{{1 " SECTION: Commands {{{1
"============================================================ "============================================================
"init the command that users start the nerd tree with "init the command that users start the nerd tree with
command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.New().createPrimary('<args>') command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.CreatePrimary('<args>')
command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.New().togglePrimary('<args>') command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.TogglePrimary('<args>')
command! -n=0 -bar NERDTreeClose :call nerdtree#closeTreeIfOpen() command! -n=0 -bar NERDTreeClose :call nerdtree#closeTreeIfOpen()
command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.New().createPrimary('<args>') command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.CreatePrimary('<args>')
command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.New().createMirror() command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.CreateMirror()
command! -n=0 -bar NERDTreeFind call nerdtree#findAndRevealPath() command! -n=0 -bar NERDTreeFind call nerdtree#findAndRevealPath()
command! -n=0 -bar NERDTreeFocus call NERDTreeFocus() command! -n=0 -bar NERDTreeFocus call NERDTreeFocus()
command! -n=0 -bar NERDTreeCWD call NERDTreeCWD() command! -n=0 -bar NERDTreeCWD call NERDTreeCWD()
@@ -201,7 +201,7 @@ function! NERDTreeFocus()
if nerdtree#isTreeOpen() if nerdtree#isTreeOpen()
call nerdtree#putCursorInTreeWin() call nerdtree#putCursorInTreeWin()
else else
call g:NERDTreeCreator.New().togglePrimary("") call g:NERDTreeCreator.TogglePrimary("")
endif endif
endfunction endfunction

View File

@@ -27,6 +27,12 @@ function! s:Creator._broadcastInitEvent()
silent doautocmd User NERDTreeInit silent doautocmd User NERDTreeInit
endfunction endfunction
"FUNCTION: s:Creator.CreatePrimary(a:name) {{{1
function! s:Creator.CreatePrimary(name)
let creator = s:Creator.New()
call creator.createPrimary(a:name)
endfunction
"FUNCTION: s:Creator.createPrimary(a:name) {{{1 "FUNCTION: s:Creator.createPrimary(a:name) {{{1
"name: the name of a bookmark or a directory "name: the name of a bookmark or a directory
function! s:Creator.createPrimary(name) function! s:Creator.createPrimary(name)
@@ -63,6 +69,12 @@ function! s:Creator.createPrimary(name)
call self._broadcastInitEvent() call self._broadcastInitEvent()
endfunction endfunction
"FUNCTION: s:Creator.CreateSecondary(dir) {{{1
function! s:Creator.CreateSecondary(dir)
let creator = s:Creator.New()
call creator.createSecondary(a:dir)
endfunction
"FUNCTION: s:Creator.createSecondary(dir) {{{1 "FUNCTION: s:Creator.createSecondary(dir) {{{1
function! s:Creator.createSecondary(dir) function! s:Creator.createSecondary(dir)
try try
@@ -94,6 +106,12 @@ function! s:Creator.createSecondary(dir)
call self._broadcastInitEvent() call self._broadcastInitEvent()
endfunction endfunction
" FUNCTION: s:Creator.CreateMirror() {{{1
function! s:Creator.CreateMirror()
let creator = s:Creator.New()
call creator.createMirror()
endfunction
" FUNCTION: s:Creator.createMirror() {{{1 " FUNCTION: s:Creator.createMirror() {{{1
function! s:Creator.createMirror() function! s:Creator.createMirror()
"get the names off all the nerd tree buffers "get the names off all the nerd tree buffers
@@ -248,6 +266,12 @@ function! s:Creator._setupStatusline()
endif endif
endfunction endfunction
"FUNCTION: s:Creator.TogglePrimary(dir) {{{1
function! s:Creator.TogglePrimary(dir)
let creator = s:Creator.New()
call creator.togglePrimary(a:dir)
endfunction
"FUNCTION: s:Creator.togglePrimary(dir) {{{1 "FUNCTION: s:Creator.togglePrimary(dir) {{{1
"Toggles the NERD tree. I.e the NERD tree is open, it is closed, if it is "Toggles the NERD tree. I.e the NERD tree is open, it is closed, if it is
"closed it is restored or initialized (if it doesnt exist) "closed it is restored or initialized (if it doesnt exist)

View File

@@ -185,7 +185,7 @@ endfunction
function! s:Opener._openDirectory(node) function! s:Opener._openDirectory(node)
if self._treetype ==# "secondary" if self._treetype ==# "secondary"
call self._gotoTargetWin() call self._gotoTargetWin()
call g:NERDTreeCreator.New().createSecondary(a:node.path.str()) call g:NERDTreeCreator.CreateSecondary(a:node.path.str())
else else
call self._gotoTargetWin() call self._gotoTargetWin()
if empty(self._where) if empty(self._where)
@@ -193,9 +193,9 @@ function! s:Opener._openDirectory(node)
call nerdtree#renderView() call nerdtree#renderView()
call a:node.putCursorHere(0, 0) call a:node.putCursorHere(0, 0)
elseif self._where == 't' elseif self._where == 't'
call g:NERDTreeCreator.New().createPrimary(a:node.path.str()) call g:NERDTreeCreator.CreatePrimary(a:node.path.str())
else else
call g:NERDTreeCreator.New().createSecondary(a:node.path.str()) call g:NERDTreeCreator.CreateSecondary(a:node.path.str())
endif endif
endif endif

View File

@@ -351,7 +351,7 @@ endfunction
"FUNCTION: TreeDirNode._openInNewTab() {{{1 "FUNCTION: TreeDirNode._openInNewTab() {{{1
function! s:TreeDirNode._openInNewTab() function! s:TreeDirNode._openInNewTab()
tabnew tabnew
call g:NERDTreeCreator.New().createPrimary(self.path.str()) call g:NERDTreeCreator.CreatePrimary(self.path.str())
endfunction endfunction
"FUNCTION: TreeDirNode.openRecursively() {{{1 "FUNCTION: TreeDirNode.openRecursively() {{{1