From 25b80b8a16bcea662117b2a5dcfc1169dd740c77 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Tue, 8 Jan 2013 00:01:14 +0000 Subject: [PATCH] extract the tree creation functions out into their own class Add the NERDTreeCreator class. Stick all functions related to creating a primary/secondary/mirror nerdtree in there. We may break this down further in the future, but this is a good starting point. Make some of the interface binding functions in autoload/nerdtree public. This is needed since we are accessing some of them from NERDTreeCreator. Should be temporary until we get some kind of proper interface binding system set up. --- autoload/nerdtree.vim | 283 ++---------------------------- plugin/NERD_tree.vim | 11 +- plugin/nerdtree/creator.vim | 274 +++++++++++++++++++++++++++++ plugin/nerdtree/opener.vim | 6 +- plugin/nerdtree/tree_dir_node.vim | 2 +- 5 files changed, 302 insertions(+), 274 deletions(-) create mode 100644 plugin/nerdtree/creator.vim diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index 7622302..d0f984f 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -42,7 +42,7 @@ endfunction "inits a secondary nerd tree in the current buffer if appropriate function! nerdtree#checkForBrowse(dir) if a:dir != '' && isdirectory(a:dir) - call nerdtree#initNerdTreeInPlace(a:dir) + call g:NERDTreeCreator.New().createSecondary(a:dir) endif endfunction @@ -193,14 +193,14 @@ function! nerdtree#findAndRevealPath() endtry if p.isUnder(cwd) - call nerdtree#initNerdTree(cwd.str()) + call g:NERDTreeCreator.New().createPrimary(cwd.str()) else - call nerdtree#initNerdTree(p.getParent().str()) + call g:NERDTreeCreator.New().createPrimary(p.getParent().str()) endif else if !p.isUnder(g:NERDTreeFileNode.GetRootForTab().path) if !nerdtree#isTreeOpen() - call nerdtree#createTreeWin() + call g:NERDTreeCreator.New().togglePrimary('') else call nerdtree#putCursorInTreeWin() endif @@ -208,7 +208,7 @@ function! nerdtree#findAndRevealPath() call nerdtree#chRoot(g:NERDTreeDirNode.New(p.getParent())) else if !nerdtree#isTreeOpen() - call nerdtree#toggle("") + call g:NERDTreeCreator.New().togglePrimary("") endif endif endif @@ -225,152 +225,6 @@ function! nerdtree#has_opt(options, name) return has_key(a:options, a:name) && a:options[a:name] == 1 endfunction -"FUNCTION: nerdtree#initNerdTree(name) {{{2 -"Initialise the nerd tree for this tab. The tree will start in either the -"given directory, or the directory associated with the given bookmark -" -"Args: -"name: the name of a bookmark or a directory -function! nerdtree#initNerdTree(name) - let path = {} - if g:NERDTreeBookmark.BookmarkExistsFor(a:name) - let path = g:NERDTreeBookmark.BookmarkFor(a:name).path - else - let dir = a:name ==# '' ? getcwd() : a:name - - "hack to get an absolute path if a relative path is given - if dir =~# '^\.' - let dir = getcwd() . g:NERDTreePath.Slash() . dir - endif - let dir = g:NERDTreePath.Resolve(dir) - - try - let path = g:NERDTreePath.New(dir) - catch /^NERDTree.InvalidArgumentsError/ - call nerdtree#echo("No bookmark or directory found for: " . a:name) - return - endtry - endif - if !path.isDirectory - let path = path.getParent() - endif - - "if instructed to, then change the vim CWD to the dir the NERDTree is - "inited in - if g:NERDTreeChDirMode != 0 - call path.changeToDir() - endif - - if nerdtree#treeExistsForTab() - if nerdtree#isTreeOpen() - call nerdtree#closeTree() - endif - unlet t:NERDTreeBufName - endif - - let newRoot = g:NERDTreeDirNode.New(path) - call newRoot.open() - - call nerdtree#createTreeWin() - let b:treeShowHelp = 0 - let b:NERDTreeIgnoreEnabled = 1 - let b:NERDTreeShowFiles = g:NERDTreeShowFiles - let b:NERDTreeShowHidden = g:NERDTreeShowHidden - let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks - let b:NERDTreeRoot = newRoot - let b:NERDTreeType = "primary" - - call nerdtree#renderView() - call b:NERDTreeRoot.putCursorHere(0, 0) - - silent doautocmd User NERDTreeInit -endfunction - -"FUNCTION: nerdtree#initNerdTreeInPlace(dir) {{{2 -function! nerdtree#initNerdTreeInPlace(dir) - try - let path = g:NERDTreePath.New(a:dir) - catch /^NERDTree.InvalidArgumentsError/ - call nerdtree#echo("Invalid directory name:" . a:name) - return - endtry - - "we want the directory buffer to disappear when we do the :edit below - setlocal bufhidden=wipe - - let previousBuf = expand("#") - - "we need a unique name for each secondary tree buffer to ensure they are - "all independent - exec "silent edit " . nerdtree#nextBufferName() - - let b:NERDTreePreviousBuf = bufnr(previousBuf) - - let b:NERDTreeRoot = g:NERDTreeDirNode.New(path) - call b:NERDTreeRoot.open() - - call nerdtree#setCommonBufOptions() - let b:NERDTreeType = "secondary" - - call nerdtree#renderView() - - silent doautocmd User NERDTreeInit -endfunction - -" FUNCTION: nerdtree#initNerdTreeMirror() {{{2 -function! nerdtree#initNerdTreeMirror() - - "get the names off all the nerd tree buffers - let treeBufNames = [] - for i in range(1, tabpagenr("$")) - let nextName = nerdtree#tabpagevar(i, 'NERDTreeBufName') - if nextName != -1 && (!exists("t:NERDTreeBufName") || nextName != t:NERDTreeBufName) - call add(treeBufNames, nextName) - endif - endfor - let treeBufNames = nerdtree#unique(treeBufNames) - - "map the option names (that the user will be prompted with) to the nerd - "tree buffer names - let options = {} - let i = 0 - while i < len(treeBufNames) - let bufName = treeBufNames[i] - let treeRoot = getbufvar(bufName, "NERDTreeRoot") - let options[i+1 . '. ' . treeRoot.path.str() . ' (buf name: ' . bufName . ')'] = bufName - let i = i + 1 - endwhile - - "work out which tree to mirror, if there is more than 1 then ask the user - let bufferName = '' - if len(keys(options)) > 1 - let choices = ["Choose a tree to mirror"] - let choices = extend(choices, sort(keys(options))) - let choice = inputlist(choices) - if choice < 1 || choice > len(options) || choice ==# '' - return - endif - - let bufferName = options[sort(keys(options))[choice-1]] - elseif len(keys(options)) ==# 1 - let bufferName = values(options)[0] - else - call nerdtree#echo("No trees to mirror") - return - endif - - if nerdtree#treeExistsForTab() && nerdtree#isTreeOpen() - call nerdtree#closeTree() - endif - - let t:NERDTreeBufName = bufferName - call nerdtree#createTreeWin() - exec 'buffer ' . bufferName - if !&hidden - call nerdtree#renderView() - endif -endfunction - " FUNCTION: nerdtree#invokeKeyMap(key) {{{2 "this is needed since I cant figure out how to invoke dict functions from a "key map @@ -533,6 +387,11 @@ function! nerdtree#centerView() endif endfunction +" FUNCTION: nerdtree#chRoot(node) {{{2 +" changes the current root to the selected one +function! nerdtree#chRoot(node) + call s:chRoot(a:node) +endfunction "FUNCTION: nerdtree#closeTree() {{{2 "Closes the primary NERD tree window for this tab function! nerdtree#closeTree() @@ -573,27 +432,6 @@ function! nerdtree#closeTreeIfQuitOnOpen() endif endfunction -"FUNCTION: nerdtree#createTreeWin() {{{2 -"Inits the NERD tree window. ie. opens it, sizes it, sets all the local -"options etc -function! nerdtree#createTreeWin() - "create the nerd tree window - let splitLocation = g:NERDTreeWinPos ==# "left" ? "topleft " : "botright " - let splitSize = g:NERDTreeWinSize - - if !exists('t:NERDTreeBufName') - let t:NERDTreeBufName = nerdtree#nextBufferName() - silent! exec splitLocation . 'vertical ' . splitSize . ' new' - silent! exec "edit " . t:NERDTreeBufName - else - silent! exec splitLocation . 'vertical ' . splitSize . ' split' - silent! exec "buffer " . t:NERDTreeBufName - endif - - setlocal winfixwidth - call nerdtree#setCommonBufOptions() -endfunction - "FUNCTION: nerdtree#dumpHelp {{{2 "prints out the quick help function! nerdtree#dumpHelp() @@ -1093,51 +931,6 @@ function! nerdtree#saveScreenState() endtry endfunction -"FUNCTION: nerdtree#setCommonBufOptions() {{{2 -function! nerdtree#setCommonBufOptions() - "throwaway buffer options - setlocal noswapfile - setlocal buftype=nofile - setlocal bufhidden=hide - setlocal nowrap - setlocal foldcolumn=0 - setlocal foldmethod=manual - setlocal nofoldenable - setlocal nobuflisted - setlocal nospell - if g:NERDTreeShowLineNumbers - setlocal nu - else - setlocal nonu - if v:version >= 703 - setlocal nornu - endif - endif - - iabc - - if g:NERDTreeHighlightCursorline - setlocal cursorline - endif - - call nerdtree#setupStatusline() - - let b:treeShowHelp = 0 - let b:NERDTreeIgnoreEnabled = 1 - let b:NERDTreeShowFiles = g:NERDTreeShowFiles - let b:NERDTreeShowHidden = g:NERDTreeShowHidden - let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks - setfiletype nerdtree - call nerdtree#bindMappings() -endfunction - -"FUNCTION: nerdtree#setupStatusline() {{{2 -function! nerdtree#setupStatusline() - if g:NERDTreeStatusline != -1 - let &l:statusline = g:NERDTreeStatusline - endif -endfunction - "FUNCTION: nerdtree#stripMarkupFromLine(line, removeLeadingSpaces){{{2 "returns the given line with all the tree parts stripped off " @@ -1175,29 +968,6 @@ function! nerdtree#stripMarkupFromLine(line, removeLeadingSpaces) return line endfunction -"FUNCTION: nerdtree#toggle(dir) {{{2 -"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) -" -"Args: -"dir: the full path for the root node (is only used if the NERD tree is being -"initialized. -function! nerdtree#toggle(dir) - if nerdtree#treeExistsForTab() - if !nerdtree#isTreeOpen() - call nerdtree#createTreeWin() - if !&hidden - call nerdtree#renderView() - endif - call nerdtree#restoreScreenState() - else - call nerdtree#closeTree() - endif - else - call nerdtree#initNerdTree(a:dir) - endif -endfunction - "SECTION: Interface bindings {{{1 "============================================================ @@ -1226,26 +996,9 @@ function! s:activateBookmark(bm) call a:bm.activate(!a:bm.path.isDirectory ? {'where': 'p'} : {}) endfunction -"FUNCTION: nerdtree#bindMappings() {{{2 -function! nerdtree#bindMappings() - call g:NERDTreeKeyMap.BindAll() - - "make do the same as the default 'o' mapping - exec "nnoremap :call nerdtree#invokeKeyMap('". g:NERDTreeMapActivateNode ."')" - - command! -buffer -nargs=? Bookmark :call bookmarkNode('') - command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 RevealBookmark :call revealBookmark('') - command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark :call openBookmark('') - command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=* ClearBookmarks call clearBookmarks('') - command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=+ BookmarkToRoot call g:NERDTreeBookmark.ToRoot('') - command! -buffer -nargs=0 ClearAllBookmarks call g:NERDTreeBookmark.ClearAll() call nerdtree#renderView() - command! -buffer -nargs=0 ReadBookmarks call g:NERDTreeBookmark.CacheBookmarks(0) call nerdtree#renderView() - command! -buffer -nargs=0 WriteBookmarks call g:NERDTreeBookmark.Write() -endfunction - -" FUNCTION: s:bookmarkNode(name) {{{2 +" FUNCTION: nerdtree#bookmarkNode(name) {{{2 " Associate the current node with the given name -function! s:bookmarkNode(...) +function! nerdtree#bookmarkNode(...) let currentNode = g:NERDTreeFileNode.GetSelected() if currentNode != {} let name = a:1 @@ -1295,8 +1048,8 @@ function! s:chRootCwd() call nerdtree#chRoot(g:NERDTreeDirNode.New(cwd)) endfunction -" FUNCTION: s:clearBookmarks(bookmarks) {{{2 -function! s:clearBookmarks(bookmarks) +" FUNCTION: nerdtree#clearBookmarks(bookmarks) {{{2 +function! nerdtree#clearBookmarks(bookmarks) if a:bookmarks ==# '' let currentNode = g:NERDTreeFileNode.GetSelected() if currentNode != {} @@ -1464,9 +1217,9 @@ function! s:jumpToPrevSibling(node) call nerdtree#jumpToSibling(a:node, 0) endfunction -" FUNCTION: s:openBookmark(name) {{{2 +" FUNCTION: nerdtree#openBookmark(name) {{{2 " put the cursor on the given bookmark and, if its a file, open it -function! s:openBookmark(name) +function! nerdtree#openBookmark(name) try let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0) call targetNode.putCursorHere(0, 1) @@ -1532,9 +1285,9 @@ function! s:previewNodeVSplit(node) call a:node.open({'stay': 1, 'where': 'v', 'keepopen': 1}) endfunction -" FUNCTION: s:revealBookmark(name) {{{2 +" FUNCTION: nerdtree#revealBookmark(name) {{{2 " put the cursor on the node associate with the given name -function! s:revealBookmark(name) +function! nerdtree#revealBookmark(name) try let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0) call targetNode.putCursorHere(0, 1) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 08ae997..667c20b 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -144,15 +144,16 @@ runtime plugin/nerdtree/bookmark.vim runtime plugin/nerdtree/tree_file_node.vim runtime plugin/nerdtree/tree_dir_node.vim runtime plugin/nerdtree/opener.vim +runtime plugin/nerdtree/creator.vim " SECTION: Commands {{{1 "============================================================ "init the command that users start the nerd tree with -command! -n=? -complete=dir -bar NERDTree :call nerdtree#initNerdTree('') -command! -n=? -complete=dir -bar NERDTreeToggle :call nerdtree#toggle('') +command! -n=? -complete=dir -bar NERDTree :call g:NERDTreeCreator.New().createPrimary('') +command! -n=? -complete=dir -bar NERDTreeToggle :call g:NERDTreeCreator.New().togglePrimary('') command! -n=0 -bar NERDTreeClose :call nerdtree#closeTreeIfOpen() -command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call nerdtree#initNerdTree('') -command! -n=0 -bar NERDTreeMirror call nerdtree#initNerdTreeMirror() +command! -n=1 -complete=customlist,nerdtree#completeBookmarks -bar NERDTreeFromBookmark call g:NERDTreeCreator.New().createPrimary('') +command! -n=0 -bar NERDTreeMirror call g:NERDTreeCreator.New().createMirror() command! -n=0 -bar NERDTreeFind call nerdtree#findAndRevealPath() command! -n=0 -bar NERDTreeFocus call NERDTreeFocus() command! -n=0 -bar NERDTreeCWD call NERDTreeCWD() @@ -200,7 +201,7 @@ function! NERDTreeFocus() if nerdtree#isTreeOpen() call nerdtree#putCursorInTreeWin() else - call nerdtree#toggle("") + call g:NERDTreeCreator.New().togglePrimary("") endif endfunction diff --git a/plugin/nerdtree/creator.vim b/plugin/nerdtree/creator.vim new file mode 100644 index 0000000..b167286 --- /dev/null +++ b/plugin/nerdtree/creator.vim @@ -0,0 +1,274 @@ +"CLASS: Creator +"Creates primary/secondary/mirror nerdtree windows. Sets up all the window and +"buffer options and key mappings etc. +"============================================================ +let s:Creator = {} +let g:NERDTreeCreator = s:Creator + +"FUNCTION: s:Creator._bindMappings() {{{1 +function! s:Creator._bindMappings() + call g:NERDTreeKeyMap.BindAll() + + "make do the same as the default 'o' mapping + exec "nnoremap :call nerdtree#invokeKeyMap('". g:NERDTreeMapActivateNode ."')" + + command! -buffer -nargs=? Bookmark :call nerdtree#bookmarkNode('') + command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 RevealBookmark :call nerdtree#revealBookmark('') + command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark :call nerdtree#openBookmark('') + command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=* ClearBookmarks call nerdtree#clearBookmarks('') + command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=+ BookmarkToRoot call g:NERDTreeBookmark.ToRoot('') + command! -buffer -nargs=0 ClearAllBookmarks call g:NERDTreeBookmark.ClearAll() call nerdtree#renderView() + command! -buffer -nargs=0 ReadBookmarks call g:NERDTreeBookmark.CacheBookmarks(0) call nerdtree#renderView() + command! -buffer -nargs=0 WriteBookmarks call g:NERDTreeBookmark.Write() +endfunction + +"FUNCTION: s:Creator._broadcastInitEvent() {{{1 +function! s:Creator._broadcastInitEvent() + silent doautocmd User NERDTreeInit +endfunction + +"FUNCTION: s:Creator.createPrimary(a:name) {{{1 +"name: the name of a bookmark or a directory +function! s:Creator.createPrimary(name) + let path = self._pathForString(a:name) + + "if instructed to, then change the vim CWD to the dir the NERDTree is + "inited in + if g:NERDTreeChDirMode != 0 + call path.changeToDir() + endif + + if nerdtree#treeExistsForTab() + if nerdtree#isTreeOpen() + call nerdtree#closeTree() + endif + unlet t:NERDTreeBufName + endif + + let newRoot = g:NERDTreeDirNode.New(path) + call newRoot.open() + + call self._createTreeWin() + let b:treeShowHelp = 0 + let b:NERDTreeIgnoreEnabled = 1 + let b:NERDTreeShowFiles = g:NERDTreeShowFiles + let b:NERDTreeShowHidden = g:NERDTreeShowHidden + let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks + let b:NERDTreeRoot = newRoot + let b:NERDTreeType = "primary" + + call nerdtree#renderView() + call b:NERDTreeRoot.putCursorHere(0, 0) + + call self._broadcastInitEvent() +endfunction + +"FUNCTION: s:Creator.createSecondary(dir) {{{1 +function! s:Creator.createSecondary(dir) + try + let path = g:NERDTreePath.New(a:dir) + catch /^NERDTree.InvalidArgumentsError/ + call nerdtree#echo("Invalid directory name:" . a:name) + return + endtry + + "we want the directory buffer to disappear when we do the :edit below + setlocal bufhidden=wipe + + let previousBuf = expand("#") + + "we need a unique name for each secondary tree buffer to ensure they are + "all independent + exec "silent edit " . nerdtree#nextBufferName() + + let b:NERDTreePreviousBuf = bufnr(previousBuf) + + let b:NERDTreeRoot = g:NERDTreeDirNode.New(path) + call b:NERDTreeRoot.open() + + call self._setCommonBufOptions() + let b:NERDTreeType = "secondary" + + call nerdtree#renderView() + + call self._broadcastInitEvent() +endfunction + +" FUNCTION: s:Creator.createMirror() {{{1 +function! s:Creator.createMirror() + "get the names off all the nerd tree buffers + let treeBufNames = [] + for i in range(1, tabpagenr("$")) + let nextName = nerdtree#tabpagevar(i, 'NERDTreeBufName') + if nextName != -1 && (!exists("t:NERDTreeBufName") || nextName != t:NERDTreeBufName) + call add(treeBufNames, nextName) + endif + endfor + let treeBufNames = nerdtree#unique(treeBufNames) + + "map the option names (that the user will be prompted with) to the nerd + "tree buffer names + let options = {} + let i = 0 + while i < len(treeBufNames) + let bufName = treeBufNames[i] + let treeRoot = getbufvar(bufName, "NERDTreeRoot") + let options[i+1 . '. ' . treeRoot.path.str() . ' (buf name: ' . bufName . ')'] = bufName + let i = i + 1 + endwhile + + "work out which tree to mirror, if there is more than 1 then ask the user + let bufferName = '' + if len(keys(options)) > 1 + let choices = ["Choose a tree to mirror"] + let choices = extend(choices, sort(keys(options))) + let choice = inputlist(choices) + if choice < 1 || choice > len(options) || choice ==# '' + return + endif + + let bufferName = options[sort(keys(options))[choice-1]] + elseif len(keys(options)) ==# 1 + let bufferName = values(options)[0] + else + call nerdtree#echo("No trees to mirror") + return + endif + + if nerdtree#treeExistsForTab() && nerdtree#isTreeOpen() + call nerdtree#closeTree() + endif + + let t:NERDTreeBufName = bufferName + call self._createTreeWin() + exec 'buffer ' . bufferName + if !&hidden + call nerdtree#renderView() + endif +endfunction + +"FUNCTION: s:Creator._createTreeWin() {{{1 +"Inits the NERD tree window. ie. opens it, sizes it, sets all the local +"options etc +function! s:Creator._createTreeWin() + "create the nerd tree window + let splitLocation = g:NERDTreeWinPos ==# "left" ? "topleft " : "botright " + let splitSize = g:NERDTreeWinSize + + if !exists('t:NERDTreeBufName') + let t:NERDTreeBufName = nerdtree#nextBufferName() + silent! exec splitLocation . 'vertical ' . splitSize . ' new' + silent! exec "edit " . t:NERDTreeBufName + else + silent! exec splitLocation . 'vertical ' . splitSize . ' split' + silent! exec "buffer " . t:NERDTreeBufName + endif + + setlocal winfixwidth + call self._setCommonBufOptions() +endfunction + +"FUNCTION: s:Creator.New() {{{1 +function! s:Creator.New() + let newCreator = copy(self) + return newCreator +endfunction + +"FUNCTION: s:Creator._pathForString(str) {{{1 +"find a bookmark or adirectory for the given string +function! s:Creator._pathForString(str) + let path = {} + if g:NERDTreeBookmark.BookmarkExistsFor(a:str) + let path = g:NERDTreeBookmark.BookmarkFor(a:str).path + else + let dir = a:str ==# '' ? getcwd() : a:str + + "hack to get an absolute path if a relative path is given + if dir =~# '^\.' + let dir = getcwd() . g:NERDTreePath.Slash() . dir + endif + let dir = g:NERDTreePath.Resolve(dir) + + try + let path = g:NERDTreePath.New(dir) + catch /^NERDTree.InvalidArgumentsError/ + call nerdtree#echo("No bookmark or directory found for: " . a:str) + return + endtry + endif + if !path.isDirectory + let path = path.getParent() + endif + + return path +endfunction + +"FUNCTION: s:Creator._setCommonBufOptions() {{{1 +function! s:Creator._setCommonBufOptions() + "throwaway buffer options + setlocal noswapfile + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal nowrap + setlocal foldcolumn=0 + setlocal foldmethod=manual + setlocal nofoldenable + setlocal nobuflisted + setlocal nospell + if g:NERDTreeShowLineNumbers + setlocal nu + else + setlocal nonu + if v:version >= 703 + setlocal nornu + endif + endif + + iabc + + if g:NERDTreeHighlightCursorline + setlocal cursorline + endif + + call self._setupStatusline() + + let b:treeShowHelp = 0 + let b:NERDTreeIgnoreEnabled = 1 + let b:NERDTreeShowFiles = g:NERDTreeShowFiles + let b:NERDTreeShowHidden = g:NERDTreeShowHidden + let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks + setfiletype nerdtree + call self._bindMappings() +endfunction + +"FUNCTION: s:Creator._setupStatusline() {{{1 +function! s:Creator._setupStatusline() + if g:NERDTreeStatusline != -1 + let &l:statusline = g:NERDTreeStatusline + endif +endfunction + +"FUNCTION: s:Creator.togglePrimary(dir) {{{1 +"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) +" +"Args: +"dir: the full path for the root node (is only used if the NERD tree is being +"initialized. +function! s:Creator.togglePrimary(dir) + if nerdtree#treeExistsForTab() + if !nerdtree#isTreeOpen() + call self._createTreeWin() + if !&hidden + call nerdtree#renderView() + endif + call nerdtree#restoreScreenState() + else + call nerdtree#closeTree() + endif + else + call self.createPrimary(a:dir) + endif +endfunction + +" vim: set sw=4 sts=4 et fdm=marker: diff --git a/plugin/nerdtree/opener.vim b/plugin/nerdtree/opener.vim index 947d5e1..df25099 100644 --- a/plugin/nerdtree/opener.vim +++ b/plugin/nerdtree/opener.vim @@ -185,7 +185,7 @@ endfunction function! s:Opener._openDirectory(node) if self._treetype ==# "secondary" call self._gotoTargetWin() - call nerdtree#initNerdTreeInPlace(a:node.path.str()) + call g:NERDTreeCreator.New().createSecondary(a:node.path.str()) else call self._gotoTargetWin() if empty(self._where) @@ -193,9 +193,9 @@ function! s:Opener._openDirectory(node) call nerdtree#renderView() call a:node.putCursorHere(0, 0) elseif self._where == 't' - call nerdtree#initNerdTree(a:node.path.str()) + call g:NERDTreeCreator.New().createPrimary(a:node.path.str()) else - call nerdtree#initNerdTreeInPlace(a:node.path.str()) + call g:NERDTreeCreator.New().createSecondary(a:node.path.str()) endif endif diff --git a/plugin/nerdtree/tree_dir_node.vim b/plugin/nerdtree/tree_dir_node.vim index 25f1034..63becf5 100644 --- a/plugin/nerdtree/tree_dir_node.vim +++ b/plugin/nerdtree/tree_dir_node.vim @@ -351,7 +351,7 @@ endfunction "FUNCTION: TreeDirNode._openInNewTab() {{{1 function! s:TreeDirNode._openInNewTab() tabnew - call nerdtree#initNerdTree(self.path.str()) + call g:NERDTreeCreator.New().createPrimary(self.path.str()) endfunction "FUNCTION: TreeDirNode.openRecursively() {{{1