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:
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?

View File

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

View File

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

View File

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

View File

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

View File

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