move b:NERDTreeType into the NERDTree class and add some query methods

This commit is contained in:
Martin Grenfell 2015-11-14 12:01:55 +00:00
parent 848857d18b
commit 5c20274761
6 changed files with 25 additions and 16 deletions

View File

@ -106,7 +106,7 @@ Stick this in your vimrc to open NERDTree with `Ctrl+n` (you can set whatever ke
Stick this in your vimrc: Stick this in your vimrc:
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
> Can I have different highlighting for different file extensions? > Can I have different highlighting for different file extensions?

View File

@ -208,7 +208,7 @@ endfunction
" FUNCTION: s:closeTreeWindow() {{{1 " FUNCTION: s:closeTreeWindow() {{{1
" close the tree window " close the tree window
function! s:closeTreeWindow() function! s:closeTreeWindow()
if b:NERDTreeType ==# "window" && b:NERDTreePreviousBuf != -1 if b:NERDTree.isWinTree() && b:NERDTreePreviousBuf != -1
exec "buffer " . b:NERDTreePreviousBuf exec "buffer " . b:NERDTreePreviousBuf
else else
if winnr("$") > 1 if winnr("$") > 1

View File

@ -42,7 +42,7 @@ endfunction
"name: the name of a bookmark or a directory "name: the name of a bookmark or a directory
function! s:Creator.createTabTree(name) function! s:Creator.createTabTree(name)
let path = self._pathForString(a:name) let path = self._pathForString(a:name)
"abort if exception was thrown (bookmark/dir doesn't exist) "abort if exception was thrown (bookmark/dir doesn't exist)
if empty(path) if empty(path)
return return
@ -66,8 +66,7 @@ function! s:Creator.createTabTree(name)
endif endif
call self._createTreeWin() call self._createTreeWin()
call self._createNERDTree(path) call self._createNERDTree(path, "tab")
let b:NERDTreeType = "tab"
let b:treeShowHelp = 0 let b:treeShowHelp = 0
let b:NERDTreeIgnoreEnabled = 1 let b:NERDTreeIgnoreEnabled = 1
let b:NERDTreeShowFiles = g:NERDTreeShowFiles let b:NERDTreeShowFiles = g:NERDTreeShowFiles
@ -105,9 +104,8 @@ function! s:Creator.createWindowTree(dir)
exec "silent edit " . self._nextBufferName() exec "silent edit " . self._nextBufferName()
let b:NERDTreePreviousBuf = bufnr(previousBuf) let b:NERDTreePreviousBuf = bufnr(previousBuf)
call self._createNERDTree(path) call self._createNERDTree(path, "window")
call self._setCommonBufOptions() call self._setCommonBufOptions()
let b:NERDTreeType = "window"
call b:NERDTree.render() call b:NERDTree.render()
@ -115,8 +113,8 @@ function! s:Creator.createWindowTree(dir)
endfunction endfunction
" FUNCTION: s:Creator._createNERDTree(path) {{{1 " FUNCTION: s:Creator._createNERDTree(path) {{{1
function! s:Creator._createNERDTree(path) function! s:Creator._createNERDTree(path, type)
let b:NERDTree = g:NERDTree.New(a:path) let b:NERDTree = g:NERDTree.New(a:path, a:type)
"TODO: This is kept for compatability only since many things use "TODO: This is kept for compatability only since many things use
"b:NERDTreeRoot instead of the new NERDTree.root "b:NERDTreeRoot instead of the new NERDTree.root
"Remove this one day "Remove this one day

View File

@ -105,6 +105,16 @@ function! s:NERDTree.IsOpen()
return s:NERDTree.GetWinNum() != -1 return s:NERDTree.GetWinNum() != -1
endfunction endfunction
"FUNCTION: s:NERDTree.isTabTree() {{{1
function! s:NERDTree.isTabTree()
return self._type == "tab"
endfunction
"FUNCTION: s:NERDTree.isWinTree() {{{1
function! s:NERDTree.isWinTree()
return self._type == "window"
endfunction
"FUNCTION: s:NERDTree.MustBeOpen() {{{1 "FUNCTION: s:NERDTree.MustBeOpen() {{{1
function! s:NERDTree.MustBeOpen() function! s:NERDTree.MustBeOpen()
if !s:NERDTree.IsOpen() if !s:NERDTree.IsOpen()
@ -113,10 +123,11 @@ function! s:NERDTree.MustBeOpen()
endfunction endfunction
"FUNCTION: s:NERDTree.New() {{{1 "FUNCTION: s:NERDTree.New() {{{1
function! s:NERDTree.New(path) function! s:NERDTree.New(path, type)
let newObj = copy(self) let newObj = copy(self)
let newObj.ui = g:NERDTreeUI.New(newObj) let newObj.ui = g:NERDTreeUI.New(newObj)
let newObj.root = g:NERDTreeDirNode.New(a:path) let newObj.root = g:NERDTreeDirNode.New(a:path)
let newObj._type = a:type
return newObj return newObj
endfunction endfunction

View File

@ -64,7 +64,7 @@ endfunction
"FUNCTION: Opener._gotoTargetWin() {{{1 "FUNCTION: Opener._gotoTargetWin() {{{1
function! s:Opener._gotoTargetWin() function! s:Opener._gotoTargetWin()
if b:NERDTreeType ==# "window" if b:NERDTree.isWinTree()
if self._where == 'v' if self._where == 'v'
vsplit vsplit
elseif self._where == 'h' elseif self._where == 'h'
@ -149,7 +149,7 @@ function! s:Opener.New(path, opts)
let newObj._keepopen = nerdtree#has_opt(a:opts, 'keepopen') let newObj._keepopen = nerdtree#has_opt(a:opts, 'keepopen')
let newObj._where = has_key(a:opts, 'where') ? a:opts['where'] : '' let newObj._where = has_key(a:opts, 'where') ? a:opts['where'] : ''
let newObj._treetype = b:NERDTreeType let newObj._nerdtree = b:NERDTree
call newObj._saveCursorPos() call newObj._saveCursorPos()
return newObj return newObj
@ -248,7 +248,7 @@ function! s:Opener._openFile()
call self._gotoTargetWin() call self._gotoTargetWin()
if self._treetype ==# "window" if self._nerdtree.isWinTree()
call self._path.edit() call self._path.edit()
else else
call self._path.edit() call self._path.edit()
@ -262,7 +262,7 @@ endfunction
"FUNCTION: Opener._openDirectory(node) {{{1 "FUNCTION: Opener._openDirectory(node) {{{1
function! s:Opener._openDirectory(node) function! s:Opener._openDirectory(node)
if self._treetype ==# "window" if self._nerdtree.isWinTree()
call self._gotoTargetWin() call self._gotoTargetWin()
call g:NERDTreeCreator.CreateWindow(a:node.path.str()) call g:NERDTreeCreator.CreateWindow(a:node.path.str())
else else

View File

@ -27,12 +27,12 @@ function! s:UI._dumpHelp()
let @h=@h."\" File node mappings~\n" let @h=@h."\" File node mappings~\n"
let @h=@h."\" ". (g:NERDTreeMouseMode ==# 3 ? "single" : "double") ."-click,\n" let @h=@h."\" ". (g:NERDTreeMouseMode ==# 3 ? "single" : "double") ."-click,\n"
let @h=@h."\" <CR>,\n" let @h=@h."\" <CR>,\n"
if b:NERDTreeType ==# "tab" if b:NERDTree.isTabTree()
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n" let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n"
else else
let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n" let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n"
endif endif
if b:NERDTreeType ==# "tab" if b:NERDTree.isTabTree()
let @h=@h."\" ". g:NERDTreeMapPreview .": preview\n" let @h=@h."\" ". g:NERDTreeMapPreview .": preview\n"
endif endif
let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n" let @h=@h."\" ". g:NERDTreeMapOpenInTab.": open in new tab\n"