remove dependency on b:NERDTree from classes that dont need it

Inject it where needed.
This commit is contained in:
Martin Grenfell 2015-11-20 01:44:12 +00:00
parent a0de028688
commit 665f326577
9 changed files with 86 additions and 83 deletions

View File

@ -105,7 +105,7 @@ endfunction
"FUNCTION: s:activateBookmark() {{{1 "FUNCTION: s:activateBookmark() {{{1
"handle the user activating a bookmark "handle the user activating a bookmark
function! s:activateBookmark(bm) function! s:activateBookmark(bm)
call a:bm.activate(!a:bm.path.isDirectory ? {'where': 'p'} : {}) call a:bm.activate(b:NERDTree, !a:bm.path.isDirectory ? {'where': 'p'} : {})
endfunction endfunction
" FUNCTION: nerdtree#ui_glue#bookmarkNode(name) {{{1 " FUNCTION: nerdtree#ui_glue#bookmarkNode(name) {{{1
@ -155,7 +155,7 @@ function! nerdtree#ui_glue#chRootCwd()
if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str() if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str()
return return
endif endif
call s:chRoot(g:NERDTreeDirNode.New(cwd)) call s:chRoot(g:NERDTreeDirNode.New(cwd, b:NERDTree))
endfunction endfunction
" FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1 " FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1
@ -171,6 +171,7 @@ function! nerdtree#ui_glue#clearBookmarks(bookmarks)
call bookmark.delete() call bookmark.delete()
endfor endfor
endif endif
call b:NERDTree.root.refresh()
call b:NERDTree.render() call b:NERDTree.render()
endfunction endfunction
@ -225,6 +226,7 @@ function! s:deleteBookmark(bm)
if nr2char(getchar()) ==# 'y' if nr2char(getchar()) ==# 'y'
try try
call a:bm.delete() call a:bm.delete()
call b:NERDTree.root.refresh()
call b:NERDTree.render() call b:NERDTree.render()
redraw redraw
catch /^NERDTree/ catch /^NERDTree/
@ -279,7 +281,7 @@ function! s:findAndRevealPath()
call g:NERDTree.CursorToTreeWin() call g:NERDTree.CursorToTreeWin()
endif endif
call b:NERDTree.setShowHidden(g:NERDTreeShowHidden) call b:NERDTree.setShowHidden(g:NERDTreeShowHidden)
call s:chRoot(g:NERDTreeDirNode.New(p.getParent())) call s:chRoot(g:NERDTreeDirNode.New(p.getParent(), b:NERDTree))
else else
if !g:NERDTree.IsOpen() if !g:NERDTree.IsOpen()
call g:NERDTreeCreator.ToggleTabTree("") call g:NERDTreeCreator.ToggleTabTree("")
@ -442,13 +444,13 @@ endfunction
" put the cursor on the given bookmark and, if its a file, open it " put the cursor on the given bookmark and, if its a file, open it
function! nerdtree#ui_glue#openBookmark(name) function! nerdtree#ui_glue#openBookmark(name)
try try
let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0) let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0, b:NERDTree)
call targetNode.putCursorHere(0, 1) call targetNode.putCursorHere(0, 1)
redraw! redraw!
catch /^NERDTree.BookmarkedNodeNotFoundError/ catch /^NERDTree.BookmarkedNodeNotFoundError/
call nerdtree#echo("note - target node is not cached") call nerdtree#echo("note - target node is not cached")
let bookmark = g:NERDTreeBookmark.BookmarkFor(a:name) let bookmark = g:NERDTreeBookmark.BookmarkFor(a:name)
let targetNode = g:NERDTreeFileNode.New(bookmark.path) let targetNode = g:NERDTreeFileNode.New(bookmark.path, b:NERDTree)
endtry endtry
if targetNode.path.isDirectory if targetNode.path.isDirectory
call targetNode.openExplorer() call targetNode.openExplorer()
@ -510,7 +512,7 @@ endfunction
" put the cursor on the node associate with the given name " put the cursor on the node associate with the given name
function! nerdtree#ui_glue#revealBookmark(name) function! nerdtree#ui_glue#revealBookmark(name)
try try
let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0) let targetNode = g:NERDTreeBookmark.GetNodeForName(a:name, 0, b:NERDTree)
call targetNode.putCursorHere(0, 1) call targetNode.putCursorHere(0, 1)
catch /^NERDTree.BookmarkNotFoundError/ catch /^NERDTree.BookmarkNotFoundError/
call nerdtree#echo("Bookmark isnt cached under the current root") call nerdtree#echo("Bookmark isnt cached under the current root")
@ -614,7 +616,7 @@ function! nerdtree#ui_glue#upDir(keepState)
if empty(b:NERDTree.root.parent) if empty(b:NERDTree.root.parent)
let path = b:NERDTree.root.path.getParent() let path = b:NERDTree.root.path.getParent()
let newRoot = g:NERDTreeDirNode.New(path) let newRoot = g:NERDTreeDirNode.New(path, b:NERDTree)
call newRoot.open() call newRoot.open()
call newRoot.transplantChild(b:NERDTree.root) call newRoot.transplantChild(b:NERDTree.root)
let b:NERDTree.root = newRoot let b:NERDTree.root = newRoot

View File

@ -3,9 +3,9 @@
let s:Bookmark = {} let s:Bookmark = {}
let g:NERDTreeBookmark = s:Bookmark let g:NERDTreeBookmark = s:Bookmark
" FUNCTION: Bookmark.activate() {{{1 " FUNCTION: Bookmark.activate(nerdtree) {{{1
function! s:Bookmark.activate(...) function! s:Bookmark.activate(nerdtree, ...)
call self.open(a:0 ? a:1 : {}) call self.open(a:nerdtree, a:0 ? a:1 : {})
endfunction endfunction
" FUNCTION: Bookmark.AddBookmark(name, path) {{{1 " FUNCTION: Bookmark.AddBookmark(name, path) {{{1
@ -128,26 +128,18 @@ endfunction
" Delete this bookmark. If the node for this bookmark is under the current " Delete this bookmark. If the node for this bookmark is under the current
" root, then recache bookmarks for its Path object " root, then recache bookmarks for its Path object
function! s:Bookmark.delete() function! s:Bookmark.delete()
let node = {}
try
let node = self.getNode(1)
catch /^NERDTree.BookmarkedNodeNotFoundError/
endtry
call remove(s:Bookmark.Bookmarks(), index(s:Bookmark.Bookmarks(), self)) call remove(s:Bookmark.Bookmarks(), index(s:Bookmark.Bookmarks(), self))
if !empty(node)
call node.path.cacheDisplayString()
endif
call s:Bookmark.Write() call s:Bookmark.Write()
endfunction endfunction
" FUNCTION: Bookmark.getNode(searchFromAbsoluteRoot) {{{1 " FUNCTION: Bookmark.getNode(nerdtree, searchFromAbsoluteRoot) {{{1
" Gets the treenode for this bookmark " Gets the treenode for this bookmark
" "
" Args: " Args:
" searchFromAbsoluteRoot: specifies whether we should search from the current " searchFromAbsoluteRoot: specifies whether we should search from the current
" tree root, or the highest cached node " tree root, or the highest cached node
function! s:Bookmark.getNode(searchFromAbsoluteRoot) function! s:Bookmark.getNode(nerdtree, searchFromAbsoluteRoot)
let searchRoot = a:searchFromAbsoluteRoot ? g:NERDTreeDirNode.AbsoluteTreeRoot() : b:NERDTree.root let searchRoot = a:searchFromAbsoluteRoot ? a:nerdtree.root.AbsoluteTreeRoot() : a:nerdtree.root
let targetNode = searchRoot.findNode(self.path) let targetNode = searchRoot.findNode(self.path)
if empty(targetNode) if empty(targetNode)
throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name
@ -155,12 +147,12 @@ function! s:Bookmark.getNode(searchFromAbsoluteRoot)
return targetNode return targetNode
endfunction endfunction
" FUNCTION: Bookmark.GetNodeForName(name, searchFromAbsoluteRoot) {{{1 " FUNCTION: Bookmark.GetNodeForName(name, searchFromAbsoluteRoot, nerdtree) {{{1
" Class method that finds the bookmark with the given name and returns the " Class method that finds the bookmark with the given name and returns the
" treenode for it. " treenode for it.
function! s:Bookmark.GetNodeForName(name, searchFromAbsoluteRoot) function! s:Bookmark.GetNodeForName(name, searchFromAbsoluteRoot, nerdtree)
let bookmark = s:Bookmark.BookmarkFor(a:name) let bookmark = s:Bookmark.BookmarkFor(a:name)
return bookmark.getNode(a:searchFromAbsoluteRoot) return bookmark.getNode(nerdtree, a:searchFromAbsoluteRoot)
endfunction endfunction
" FUNCTION: Bookmark.GetSelected() {{{1 " FUNCTION: Bookmark.GetSelected() {{{1
@ -210,8 +202,11 @@ function! s:Bookmark.New(name, path)
return newBookmark return newBookmark
endfunction endfunction
" FUNCTION: Bookmark.open([options]) {{{1 " FUNCTION: Bookmark.open(nerdtree, [options]) {{{1
"Args: "Args:
"
"nerdtree: the tree to load open the bookmark in
"
"A dictionary containing the following keys (all optional): "A dictionary containing the following keys (all optional):
" 'where': Specifies whether the node should be opened in new split/tab or in " 'where': Specifies whether the node should be opened in new split/tab or in
" the previous window. Can be either 'v' (vertical split), 'h' " the previous window. Can be either 'v' (vertical split), 'h'
@ -220,11 +215,11 @@ endfunction
" 'keepopen': dont close the tree window " 'keepopen': dont close the tree window
" 'stay': open the file, but keep the cursor in the tree win " 'stay': open the file, but keep the cursor in the tree win
" "
function! s:Bookmark.open(...) function! s:Bookmark.open(nerdtree, ...)
let opts = a:0 ? a:1 : {} let opts = a:0 ? a:1 : {}
if self.path.isDirectory && !has_key(opts, 'where') if self.path.isDirectory && !has_key(opts, 'where')
call self.toRoot() call self.toRoot(a:nerdtree)
else else
let opener = g:NERDTreeOpener.New(self.path, opts) let opener = g:NERDTreeOpener.New(self.path, opts)
call opener.open(self) call opener.open(self)
@ -266,24 +261,24 @@ function! s:Bookmark.str()
return '>' . self.name . ' ' . pathStr return '>' . self.name . ' ' . pathStr
endfunction endfunction
" FUNCTION: Bookmark.toRoot() {{{1 " FUNCTION: Bookmark.toRoot(nerdtree) {{{1
" Make the node for this bookmark the new tree root " Make the node for this bookmark the new tree root
function! s:Bookmark.toRoot() function! s:Bookmark.toRoot(nerdtree)
if self.validate() if self.validate()
try try
let targetNode = self.getNode(1) let targetNode = self.getNode(a:nerdtree, 1)
catch /^NERDTree.BookmarkedNodeNotFoundError/ catch /^NERDTree.BookmarkedNodeNotFoundError/
let targetNode = g:NERDTreeFileNode.New(s:Bookmark.BookmarkFor(self.name).path) let targetNode = g:NERDTreeFileNode.New(s:Bookmark.BookmarkFor(self.name).path, a:nerdtree)
endtry endtry
call b:NERDTree.changeRoot(targetNode) call a:nerdtree.changeRoot(targetNode)
endif endif
endfunction endfunction
" FUNCTION: Bookmark.ToRoot(name) {{{1 " FUNCTION: Bookmark.ToRoot(name, nerdtree) {{{1
" Make the node for this bookmark the new tree root " Make the node for this bookmark the new tree root
function! s:Bookmark.ToRoot(name) function! s:Bookmark.ToRoot(name, nerdtree)
let bookmark = s:Bookmark.BookmarkFor(a:name) let bookmark = s:Bookmark.BookmarkFor(a:name)
call bookmark.toRoot() call bookmark.toRoot(a:nerdtree)
endfunction endfunction
" FUNCTION: Bookmark.validate() {{{1 " FUNCTION: Bookmark.validate() {{{1
@ -292,7 +287,6 @@ function! s:Bookmark.validate()
return 1 return 1
else else
call s:Bookmark.CacheBookmarks(1) call s:Bookmark.CacheBookmarks(1)
call b:NERDTree.render()
call nerdtree#echo(self.name . "now points to an invalid location. See :help NERDTreeInvalidBookmarks for info.") call nerdtree#echo(self.name . "now points to an invalid location. See :help NERDTreeInvalidBookmarks for info.")
return 0 return 0
endif endif

View File

@ -16,7 +16,7 @@ function! s:Creator._bindMappings()
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 RevealBookmark :call nerdtree#ui_glue#revealBookmark('<args>') command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 RevealBookmark :call nerdtree#ui_glue#revealBookmark('<args>')
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark :call nerdtree#ui_glue#openBookmark('<args>') command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=1 OpenBookmark :call nerdtree#ui_glue#openBookmark('<args>')
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=* ClearBookmarks call nerdtree#ui_glue#clearBookmarks('<args>') command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=* ClearBookmarks call nerdtree#ui_glue#clearBookmarks('<args>')
command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=+ BookmarkToRoot call g:NERDTreeBookmark.ToRoot('<args>') command! -buffer -complete=customlist,nerdtree#completeBookmarks -nargs=+ BookmarkToRoot call g:NERDTreeBookmark.ToRoot('<args>', b:NERDTree)
command! -buffer -nargs=0 ClearAllBookmarks call g:NERDTreeBookmark.ClearAll() <bar> call b:NERDTree.render() command! -buffer -nargs=0 ClearAllBookmarks call g:NERDTreeBookmark.ClearAll() <bar> call b:NERDTree.render()
command! -buffer -nargs=0 ReadBookmarks call g:NERDTreeBookmark.CacheBookmarks(0) <bar> call b:NERDTree.render() command! -buffer -nargs=0 ReadBookmarks call g:NERDTreeBookmark.CacheBookmarks(0) <bar> call b:NERDTree.render()
command! -buffer -nargs=0 WriteBookmarks call g:NERDTreeBookmark.Write() command! -buffer -nargs=0 WriteBookmarks call g:NERDTreeBookmark.Write()

View File

@ -148,7 +148,7 @@ endfunction
function! s:NERDTree.New(path, type) 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, newObj)
let newObj._type = a:type let newObj._type = a:type
return newObj return newObj
endfunction endfunction

View File

@ -11,8 +11,8 @@ function! s:Notifier.AddListener(event, funcname)
call add(listeners, a:funcname) call add(listeners, a:funcname)
endfunction endfunction
function! s:Notifier.NotifyListeners(event, path, params) function! s:Notifier.NotifyListeners(event, path, nerdtree, params)
let event = g:NERDTreeEvent.New(b:NERDTree, a:path, a:event, a:params) let event = g:NERDTreeEvent.New(a:nerdtree, a:path, a:event, a:params)
for listener in s:Notifier.GetListenersForEvent(a:event) for listener in s:Notifier.GetListenersForEvent(a:event)
call {listener}(event) call {listener}(event)

View File

@ -406,11 +406,11 @@ function! s:Path.isUnixHiddenPath()
endif endif
endfunction endfunction
"FUNCTION: Path.ignore() {{{1 "FUNCTION: Path.ignore(nerdtree) {{{1
"returns true if this path should be ignored "returns true if this path should be ignored
function! s:Path.ignore() function! s:Path.ignore(nerdtree)
"filter out the user specified paths to ignore "filter out the user specified paths to ignore
if b:NERDTree.ui.isIgnoreFilterEnabled() if a:nerdtree.ui.isIgnoreFilterEnabled()
for i in g:NERDTreeIgnore for i in g:NERDTreeIgnore
if self._ignorePatternMatches(i) if self._ignorePatternMatches(i)
return 1 return 1
@ -418,18 +418,18 @@ function! s:Path.ignore()
endfor endfor
for callback in g:NERDTree.PathFilters() for callback in g:NERDTree.PathFilters()
if {callback}({'path': self, 'nerdtree': b:NERDTree}) if {callback}({'path': self, 'nerdtree': a:nerdtree})
return 1 return 1
endif endif
endfor endfor
endif endif
"dont show hidden files unless instructed to "dont show hidden files unless instructed to
if !b:NERDTree.ui.getShowHidden() && self.isUnixHiddenFile() if !a:nerdtree.ui.getShowHidden() && self.isUnixHiddenFile()
return 1 return 1
endif endif
if b:NERDTree.ui.getShowFiles() ==# 0 && self.isDirectory ==# 0 if a:nerdtree.ui.getShowFiles() ==# 0 && self.isDirectory ==# 0
return 1 return 1
endif endif
@ -572,16 +572,16 @@ function! s:Path.readInfoFromDisk(fullpath)
endif endif
endfunction endfunction
"FUNCTION: Path.refresh() {{{1 "FUNCTION: Path.refresh(nerdtree) {{{1
function! s:Path.refresh() function! s:Path.refresh(nerdtree)
call self.readInfoFromDisk(self.str()) call self.readInfoFromDisk(self.str())
call g:NERDTreePathNotifier.NotifyListeners('refresh', self, {}) call g:NERDTreePathNotifier.NotifyListeners('refresh', self, a:nerdtree, {})
call self.cacheDisplayString() call self.cacheDisplayString()
endfunction endfunction
"FUNCTION: Path.refreshFlags() {{{1 "FUNCTION: Path.refreshFlags(nerdtree) {{{1
function! s:Path.refreshFlags() function! s:Path.refreshFlags(nerdtree)
call g:NERDTreePathNotifier.NotifyListeners('refreshFlags', self, {}) call g:NERDTreePathNotifier.NotifyListeners('refreshFlags', self, a:nerdtree, {})
call self.cacheDisplayString() call self.cacheDisplayString()
endfunction endfunction

View File

@ -21,7 +21,7 @@ unlet s:TreeDirNode.activate
function! s:TreeDirNode.activate(...) function! s:TreeDirNode.activate(...)
let opts = a:0 ? a:1 : {} let opts = a:0 ? a:1 : {}
call self.toggleOpen(opts) call self.toggleOpen(opts)
call b:NERDTree.render() call self.getNerdtree().render()
call self.putCursorHere(0, 0) call self.putCursorHere(0, 0)
endfunction endfunction
@ -68,7 +68,7 @@ endfunction
"Returns: "Returns:
"the newly created node "the newly created node
function! s:TreeDirNode.createChild(path, inOrder) function! s:TreeDirNode.createChild(path, inOrder)
let newTreeNode = g:NERDTreeFileNode.New(a:path) let newTreeNode = g:NERDTreeFileNode.New(a:path, self.getNerdtree())
call self.addChild(newTreeNode, a:inOrder) call self.addChild(newTreeNode, a:inOrder)
return newTreeNode return newTreeNode
endfunction endfunction
@ -205,7 +205,7 @@ endfunction
function! s:TreeDirNode.getVisibleChildren() function! s:TreeDirNode.getVisibleChildren()
let toReturn = [] let toReturn = []
for i in self.children for i in self.children
if i.path.ignore() ==# 0 if i.path.ignore(self.getNerdtree()) ==# 0
call add(toReturn, i) call add(toReturn, i)
endif endif
endfor endfor
@ -258,7 +258,7 @@ function! s:TreeDirNode._initChildren(silent)
try try
let path = g:NERDTreePath.New(i) let path = g:NERDTreePath.New(i)
call self.createChild(path, 0) call self.createChild(path, 0)
call g:NERDTreePathNotifier.NotifyListeners('init', path, {}) call g:NERDTreePathNotifier.NotifyListeners('init', path, self.getNerdtree(), {})
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/ catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
let invalidFilesFound += 1 let invalidFilesFound += 1
endtry endtry
@ -277,13 +277,13 @@ function! s:TreeDirNode._initChildren(silent)
return self.getChildCount() return self.getChildCount()
endfunction endfunction
"FUNCTION: TreeDirNode.New(path) {{{1 "FUNCTION: TreeDirNode.New(path, nerdtree) {{{1
"Returns a new TreeNode object with the given path and parent "Returns a new TreeNode object with the given path and parent
" "
"Args: "Args:
"path: a path object representing the full filesystem path to the file/dir that the node represents "path: dir that the node represents
unlet s:TreeDirNode.New "nerdtree: the tree the node belongs to
function! s:TreeDirNode.New(path) function! s:TreeDirNode.New(path, nerdtree)
if a:path.isDirectory != 1 if a:path.isDirectory != 1
throw "NERDTree.InvalidArgumentsError: A TreeDirNode object must be instantiated with a directory Path object." throw "NERDTree.InvalidArgumentsError: A TreeDirNode object must be instantiated with a directory Path object."
endif endif
@ -295,6 +295,7 @@ function! s:TreeDirNode.New(path)
let newTreeNode.children = [] let newTreeNode.children = []
let newTreeNode.parent = {} let newTreeNode.parent = {}
let newTreeNode._nerdtree = a:nerdtree
return newTreeNode return newTreeNode
endfunction endfunction
@ -379,7 +380,7 @@ endfunction
"Args: "Args:
"forceOpen: 1 if this node should be opened regardless of file filters "forceOpen: 1 if this node should be opened regardless of file filters
function! s:TreeDirNode._openRecursively2(forceOpen) function! s:TreeDirNode._openRecursively2(forceOpen)
if self.path.ignore() ==# 0 || a:forceOpen if self.path.ignore(self.getNerdtree()) ==# 0 || a:forceOpen
let self.isOpen = 1 let self.isOpen = 1
if self.children ==# [] if self.children ==# []
call self._initChildren(1) call self._initChildren(1)
@ -396,7 +397,7 @@ endfunction
"FUNCTION: TreeDirNode.refresh() {{{1 "FUNCTION: TreeDirNode.refresh() {{{1
unlet s:TreeDirNode.refresh unlet s:TreeDirNode.refresh
function! s:TreeDirNode.refresh() function! s:TreeDirNode.refresh()
call self.path.refresh() call self.path.refresh(self.getNerdtree())
"if this node was ever opened, refresh its children "if this node was ever opened, refresh its children
if self.isOpen || !empty(self.children) if self.isOpen || !empty(self.children)
@ -427,7 +428,7 @@ function! s:TreeDirNode.refresh()
"the node doesnt exist so create it "the node doesnt exist so create it
else else
let newNode = g:NERDTreeFileNode.New(path) let newNode = g:NERDTreeFileNode.New(path, self.getNerdtree())
let newNode.parent = self let newNode.parent = self
call add(newChildNodes, newNode) call add(newChildNodes, newNode)
endif endif
@ -452,7 +453,7 @@ endfunction
"FUNCTION: TreeDirNode.refreshFlags() {{{1 "FUNCTION: TreeDirNode.refreshFlags() {{{1
unlet s:TreeDirNode.refreshFlags unlet s:TreeDirNode.refreshFlags
function! s:TreeDirNode.refreshFlags() function! s:TreeDirNode.refreshFlags()
call self.path.refreshFlags() call self.path.refreshFlags(self.getNerdtree())
for i in self.children for i in self.children
call i.refreshFlags() call i.refreshFlags()
endfor endfor
@ -460,7 +461,7 @@ endfunction
"FUNCTION: TreeDirNode.refreshDirFlags() {{{1 "FUNCTION: TreeDirNode.refreshDirFlags() {{{1
function! s:TreeDirNode.refreshDirFlags() function! s:TreeDirNode.refreshDirFlags()
call self.path.refreshFlags() call self.path.refreshFlags(self.getNerdtree())
endfunction endfunction
"FUNCTION: TreeDirNode.reveal(path) {{{1 "FUNCTION: TreeDirNode.reveal(path) {{{1

View File

@ -19,7 +19,7 @@ function! s:TreeFileNode.bookmark(name)
"it so we can update its display string "it so we can update its display string
let oldMarkedNode = {} let oldMarkedNode = {}
try try
let oldMarkedNode = g:NERDTreeBookmark.GetNodeForName(a:name, 1) let oldMarkedNode = g:NERDTreeBookmark.GetNodeForName(a:name, 1, self.getNerdtree())
catch /^NERDTree.BookmarkNotFoundError/ catch /^NERDTree.BookmarkNotFoundError/
catch /^NERDTree.BookmarkedNodeNotFoundError/ catch /^NERDTree.BookmarkedNodeNotFoundError/
endtry endtry
@ -41,7 +41,7 @@ function! s:TreeFileNode.cacheParent()
if parentPath.equals(self.path) if parentPath.equals(self.path)
throw "NERDTree.CannotCacheParentError: already at root" throw "NERDTree.CannotCacheParentError: already at root"
endif endif
let self.parent = s:TreeFileNode.New(parentPath) let self.parent = s:TreeFileNode.New(parentPath, self.getNerdtree())
endif endif
endfunction endfunction
@ -59,7 +59,7 @@ endfunction
function! s:TreeFileNode.copy(dest) function! s:TreeFileNode.copy(dest)
call self.path.copy(a:dest) call self.path.copy(a:dest)
let newPath = g:NERDTreePath.New(a:dest) let newPath = g:NERDTreePath.New(a:dest)
let parent = b:NERDTree.root.findNode(newPath.getParent()) let parent = self.getNerdtree().root.findNode(newPath.getParent())
if !empty(parent) if !empty(parent)
call parent.refresh() call parent.refresh()
return parent.findNode(newPath) return parent.findNode(newPath)
@ -165,7 +165,7 @@ function! s:TreeFileNode.findSibling(direction)
"if the next node is not an ignored node (i.e. wont show up in the "if the next node is not an ignored node (i.e. wont show up in the
"view) then return it "view) then return it
if self.parent.children[siblingIndx].path.ignore() ==# 0 if self.parent.children[siblingIndx].path.ignore(self.getNerdtree()) ==# 0
return self.parent.children[siblingIndx] return self.parent.children[siblingIndx]
endif endif
@ -178,6 +178,11 @@ function! s:TreeFileNode.findSibling(direction)
return {} return {}
endfunction endfunction
"FUNCTION: TreeFileNode.getNerdtree(){{{1
function! s:TreeFileNode.getNerdtree()
return self._nerdtree
endfunction
"FUNCTION: TreeFileNode.GetRootForTab(){{{1 "FUNCTION: TreeFileNode.GetRootForTab(){{{1
"get the root node for this tab "get the root node for this tab
function! s:TreeFileNode.GetRootForTab() function! s:TreeFileNode.GetRootForTab()
@ -205,31 +210,32 @@ endfunction
"returns 1 if this node should be visible according to the tree filters and "returns 1 if this node should be visible according to the tree filters and
"hidden file filters (and their on/off status) "hidden file filters (and their on/off status)
function! s:TreeFileNode.isVisible() function! s:TreeFileNode.isVisible()
return !self.path.ignore() return !self.path.ignore(self.getNerdtree())
endfunction endfunction
"FUNCTION: TreeFileNode.isRoot() {{{1 "FUNCTION: TreeFileNode.isRoot() {{{1
"returns 1 if this node is b:NERDTree.root
function! s:TreeFileNode.isRoot() function! s:TreeFileNode.isRoot()
if !g:NERDTree.ExistsForBuf() if !g:NERDTree.ExistsForBuf()
throw "NERDTree.NoTreeError: No tree exists for the current buffer" throw "NERDTree.NoTreeError: No tree exists for the current buffer"
endif endif
return self.equals(b:NERDTree.root) return self.equals(self.getNerdtree().root)
endfunction endfunction
"FUNCTION: TreeFileNode.New(path) {{{1 "FUNCTION: TreeFileNode.New(path, nerdtree) {{{1
"Returns a new TreeNode object with the given path and parent "Returns a new TreeNode object with the given path and parent
" "
"Args: "Args:
"path: a path object representing the full filesystem path to the file/dir that the node represents "path: file/dir that the node represents
function! s:TreeFileNode.New(path) "nerdtree: the tree the node belongs to
function! s:TreeFileNode.New(path, nerdtree)
if a:path.isDirectory if a:path.isDirectory
return g:NERDTreeDirNode.New(a:path) return g:NERDTreeDirNode.New(a:path, a:nerdtree)
else else
let newTreeNode = copy(self) let newTreeNode = copy(self)
let newTreeNode.path = a:path let newTreeNode.path = a:path
let newTreeNode.parent = {} let newTreeNode.parent = {}
let newTreeNode._nerdtree = a:nerdtree
return newTreeNode return newTreeNode
endif endif
endfunction endfunction
@ -269,7 +275,7 @@ endfunction
"recurseUpward: try to put the cursor on the parent if the this node isnt "recurseUpward: try to put the cursor on the parent if the this node isnt
"visible "visible
function! s:TreeFileNode.putCursorHere(isJump, recurseUpward) function! s:TreeFileNode.putCursorHere(isJump, recurseUpward)
let ln = b:NERDTree.ui.getLineNum(self) let ln = self.getNerdtree().ui.getLineNum(self)
if ln != -1 if ln != -1
if a:isJump if a:isJump
mark ' mark '
@ -278,11 +284,11 @@ function! s:TreeFileNode.putCursorHere(isJump, recurseUpward)
else else
if a:recurseUpward if a:recurseUpward
let node = self let node = self
while node != {} && b:NERDTree.ui.getLineNum(node) ==# -1 while node != {} && self.getNerdtree().ui.getLineNum(node) ==# -1
let node = node.parent let node = node.parent
call node.open() call node.open()
endwhile endwhile
call b:NERDTree.render() call self.getNerdtree().render()
call node.putCursorHere(a:isJump, 0) call node.putCursorHere(a:isJump, 0)
endif endif
endif endif
@ -290,12 +296,12 @@ endfunction
"FUNCTION: TreeFileNode.refresh() {{{1 "FUNCTION: TreeFileNode.refresh() {{{1
function! s:TreeFileNode.refresh() function! s:TreeFileNode.refresh()
call self.path.refresh() call self.path.refresh(self.getNerdtree())
endfunction endfunction
"FUNCTION: TreeFileNode.refreshFlags() {{{1 "FUNCTION: TreeFileNode.refreshFlags() {{{1
function! s:TreeFileNode.refreshFlags() function! s:TreeFileNode.refreshFlags()
call self.path.refreshFlags() call self.path.refreshFlags(self.getNerdtree())
endfunction endfunction
"FUNCTION: TreeFileNode.rename() {{{1 "FUNCTION: TreeFileNode.rename() {{{1
@ -306,7 +312,7 @@ function! s:TreeFileNode.rename(newName)
call self.parent.removeChild(self) call self.parent.removeChild(self)
let parentPath = self.path.getParent() let parentPath = self.path.getParent()
let newParent = b:NERDTree.root.findNode(parentPath) let newParent = self.getNerdtree().root.findNode(parentPath)
if newParent != {} if newParent != {}
call newParent.createChild(self.path, 1) call newParent.createChild(self.path, 1)

View File

@ -107,7 +107,7 @@ function! NERDTreeAddNode()
let newPath = g:NERDTreePath.Create(newNodeName) let newPath = g:NERDTreePath.Create(newNodeName)
let parentNode = b:NERDTree.root.findNode(newPath.getParent()) let parentNode = b:NERDTree.root.findNode(newPath.getParent())
let newTreeNode = g:NERDTreeFileNode.New(newPath) let newTreeNode = g:NERDTreeFileNode.New(newPath, b:NERDTree)
if empty(parentNode) if empty(parentNode)
call b:NERDTree.root.refresh() call b:NERDTree.root.refresh()
call b:NERDTree.render() call b:NERDTree.render()