Merge pull request #717 from scrooloose/dev
Define the "TreeDirNode._glob()" method.
This commit is contained in:
commit
7ed79c00c1
@ -1,13 +1,17 @@
|
|||||||
"CLASS: TreeDirNode
|
" ============================================================================
|
||||||
"A subclass of NERDTreeFileNode.
|
" CLASS: TreeDirNode
|
||||||
"
|
"
|
||||||
"The 'composite' part of the file/dir composite.
|
" A subclass of NERDTreeFileNode.
|
||||||
"============================================================
|
"
|
||||||
|
" The 'composite' part of the file/dir composite.
|
||||||
|
" ============================================================================
|
||||||
|
|
||||||
|
|
||||||
let s:TreeDirNode = copy(g:NERDTreeFileNode)
|
let s:TreeDirNode = copy(g:NERDTreeFileNode)
|
||||||
let g:NERDTreeDirNode = s:TreeDirNode
|
let g:NERDTreeDirNode = s:TreeDirNode
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.AbsoluteTreeRoot(){{{1
|
" FUNCTION: TreeDirNode.AbsoluteTreeRoot(){{{1
|
||||||
"class method that returns the highest cached ancestor of the current root
|
" Class method that returns the highest cached ancestor of the current root.
|
||||||
function! s:TreeDirNode.AbsoluteTreeRoot()
|
function! s:TreeDirNode.AbsoluteTreeRoot()
|
||||||
let currentNode = b:NERDTree.root
|
let currentNode = b:NERDTree.root
|
||||||
while currentNode.parent != {}
|
while currentNode.parent != {}
|
||||||
@ -16,7 +20,7 @@ function! s:TreeDirNode.AbsoluteTreeRoot()
|
|||||||
return currentNode
|
return currentNode
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.activate([options]) {{{1
|
" FUNCTION: TreeDirNode.activate([options]) {{{1
|
||||||
unlet s:TreeDirNode.activate
|
unlet s:TreeDirNode.activate
|
||||||
function! s:TreeDirNode.activate(...)
|
function! s:TreeDirNode.activate(...)
|
||||||
let opts = a:0 ? a:1 : {}
|
let opts = a:0 ? a:1 : {}
|
||||||
@ -25,12 +29,12 @@ function! s:TreeDirNode.activate(...)
|
|||||||
call self.putCursorHere(0, 0)
|
call self.putCursorHere(0, 0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.addChild(treenode, inOrder) {{{1
|
" FUNCTION: TreeDirNode.addChild(treenode, inOrder) {{{1
|
||||||
"Adds the given treenode to the list of children for this node
|
" Adds the given treenode to the list of children for this node
|
||||||
"
|
"
|
||||||
"Args:
|
" Args:
|
||||||
"-treenode: the node to add
|
" -treenode: the node to add
|
||||||
"-inOrder: 1 if the new node should be inserted in sorted order
|
" -inOrder: 1 if the new node should be inserted in sorted order
|
||||||
function! s:TreeDirNode.addChild(treenode, inOrder)
|
function! s:TreeDirNode.addChild(treenode, inOrder)
|
||||||
call add(self.children, a:treenode)
|
call add(self.children, a:treenode)
|
||||||
let a:treenode.parent = self
|
let a:treenode.parent = self
|
||||||
@ -40,14 +44,14 @@ function! s:TreeDirNode.addChild(treenode, inOrder)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.close() {{{1
|
" FUNCTION: TreeDirNode.close() {{{1
|
||||||
"Closes this directory
|
" Closes this directory
|
||||||
function! s:TreeDirNode.close()
|
function! s:TreeDirNode.close()
|
||||||
let self.isOpen = 0
|
let self.isOpen = 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.closeChildren() {{{1
|
" FUNCTION: TreeDirNode.closeChildren() {{{1
|
||||||
"Closes all the child dir nodes of this node
|
" Closes all the child dir nodes of this node
|
||||||
function! s:TreeDirNode.closeChildren()
|
function! s:TreeDirNode.closeChildren()
|
||||||
for i in self.children
|
for i in self.children
|
||||||
if i.path.isDirectory
|
if i.path.isDirectory
|
||||||
@ -57,23 +61,23 @@ function! s:TreeDirNode.closeChildren()
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.createChild(path, inOrder) {{{1
|
" FUNCTION: TreeDirNode.createChild(path, inOrder) {{{1
|
||||||
"Instantiates a new child node for this node with the given path. The new
|
" Instantiates a new child node for this node with the given path. The new
|
||||||
"nodes parent is set to this node.
|
" nodes parent is set to this node.
|
||||||
"
|
"
|
||||||
"Args:
|
" Args:
|
||||||
"path: a Path object that this node will represent/contain
|
" path: a Path object that this node will represent/contain
|
||||||
"inOrder: 1 if the new node should be inserted in sorted order
|
" inOrder: 1 if the new node should be inserted in sorted order
|
||||||
"
|
"
|
||||||
"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, self.getNerdtree())
|
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
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.displayString() {{{1
|
" FUNCTION: TreeDirNode.displayString() {{{1
|
||||||
unlet s:TreeDirNode.displayString
|
unlet s:TreeDirNode.displayString
|
||||||
function! s:TreeDirNode.displayString()
|
function! s:TreeDirNode.displayString()
|
||||||
let cascade = self.getCascade()
|
let cascade = self.getCascade()
|
||||||
@ -89,11 +93,11 @@ function! s:TreeDirNode.displayString()
|
|||||||
return sym . ' ' . flags . rv
|
return sym . ' ' . flags . rv
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.findNode(path) {{{1
|
" FUNCTION: TreeDirNode.findNode(path) {{{1
|
||||||
"Will find one of the children (recursively) that has the given path
|
" Will find one of the children (recursively) that has the given path
|
||||||
"
|
"
|
||||||
"Args:
|
" Args:
|
||||||
"path: a path object
|
" path: a path object
|
||||||
unlet s:TreeDirNode.findNode
|
unlet s:TreeDirNode.findNode
|
||||||
function! s:TreeDirNode.findNode(path)
|
function! s:TreeDirNode.findNode(path)
|
||||||
if a:path.equals(self.path)
|
if a:path.equals(self.path)
|
||||||
@ -114,8 +118,8 @@ function! s:TreeDirNode.findNode(path)
|
|||||||
return {}
|
return {}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getCascade() {{{1
|
" FUNCTION: TreeDirNode.getCascade() {{{1
|
||||||
"Return an array of dir nodes (starting from self) that can be cascade opened.
|
" Return an array of dir nodes (starting from self) that can be cascade opened.
|
||||||
function! s:TreeDirNode.getCascade()
|
function! s:TreeDirNode.getCascade()
|
||||||
if !self.isCascadable()
|
if !self.isCascadable()
|
||||||
return [self]
|
return [self]
|
||||||
@ -127,20 +131,20 @@ function! s:TreeDirNode.getCascade()
|
|||||||
return [self] + visChild.getCascade()
|
return [self] + visChild.getCascade()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getChildCount() {{{1
|
" FUNCTION: TreeDirNode.getChildCount() {{{1
|
||||||
"Returns the number of children this node has
|
" Returns the number of children this node has
|
||||||
function! s:TreeDirNode.getChildCount()
|
function! s:TreeDirNode.getChildCount()
|
||||||
return len(self.children)
|
return len(self.children)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getChild(path) {{{1
|
" FUNCTION: TreeDirNode.getChild(path) {{{1
|
||||||
"Returns child node of this node that has the given path or {} if no such node
|
" Returns child node of this node that has the given path or {} if no such node
|
||||||
"exists.
|
" exists.
|
||||||
"
|
"
|
||||||
"This function doesnt not recurse into child dir nodes
|
" This function doesnt not recurse into child dir nodes
|
||||||
"
|
"
|
||||||
"Args:
|
" Args:
|
||||||
"path: a path object
|
" path: a path object
|
||||||
function! s:TreeDirNode.getChild(path)
|
function! s:TreeDirNode.getChild(path)
|
||||||
if stridx(a:path.str(), self.path.str(), 0) ==# -1
|
if stridx(a:path.str(), self.path.str(), 0) ==# -1
|
||||||
return {}
|
return {}
|
||||||
@ -155,12 +159,13 @@ function! s:TreeDirNode.getChild(path)
|
|||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getChildByIndex(indx, visible) {{{1
|
" FUNCTION: TreeDirNode.getChildByIndex(indx, visible) {{{1
|
||||||
"returns the child at the given index
|
" returns the child at the given index
|
||||||
"Args:
|
"
|
||||||
"indx: the index to get the child from
|
" Args:
|
||||||
"visible: 1 if only the visible children array should be used, 0 if all the
|
" indx: the index to get the child from
|
||||||
"children should be searched.
|
" visible: 1 if only the visible children array should be used, 0 if all the
|
||||||
|
" children should be searched.
|
||||||
function! s:TreeDirNode.getChildByIndex(indx, visible)
|
function! s:TreeDirNode.getChildByIndex(indx, visible)
|
||||||
let array_to_search = a:visible? self.getVisibleChildren() : self.children
|
let array_to_search = a:visible? self.getVisibleChildren() : self.children
|
||||||
if a:indx > len(array_to_search)
|
if a:indx > len(array_to_search)
|
||||||
@ -169,14 +174,14 @@ function! s:TreeDirNode.getChildByIndex(indx, visible)
|
|||||||
return array_to_search[a:indx]
|
return array_to_search[a:indx]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getChildIndex(path) {{{1
|
" FUNCTION: TreeDirNode.getChildIndex(path) {{{1
|
||||||
"Returns the index of the child node of this node that has the given path or
|
" Returns the index of the child node of this node that has the given path or
|
||||||
"-1 if no such node exists.
|
" -1 if no such node exists.
|
||||||
"
|
"
|
||||||
"This function doesnt not recurse into child dir nodes
|
" This function doesnt not recurse into child dir nodes
|
||||||
"
|
"
|
||||||
"Args:
|
" Args:
|
||||||
"path: a path object
|
" path: a path object
|
||||||
function! s:TreeDirNode.getChildIndex(path)
|
function! s:TreeDirNode.getChildIndex(path)
|
||||||
if stridx(a:path.str(), self.path.str(), 0) ==# -1
|
if stridx(a:path.str(), self.path.str(), 0) ==# -1
|
||||||
return -1
|
return -1
|
||||||
@ -200,34 +205,86 @@ function! s:TreeDirNode.getChildIndex(path)
|
|||||||
return -1
|
return -1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getDirChildren() {{{1
|
" FUNCTION: TreeDirNode.getDirChildren() {{{1
|
||||||
"Get all children that are directories
|
" Return a list of all child nodes from "self.children" that are of type
|
||||||
|
" TreeDirNode.
|
||||||
function! s:TreeDirNode.getDirChildren()
|
function! s:TreeDirNode.getDirChildren()
|
||||||
return filter(self.children, 'v:val.path.isDirectory == 1')
|
return filter(self.children, 'v:val.path.isDirectory == 1')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode._getGlobDir() {{{1
|
" FUNCTION: TreeDirNode._glob(pattern, all) {{{1
|
||||||
"Return a string giving the pathname related to this TreeDirNode. The returned
|
" Return a list of strings naming the descendants of the directory in this
|
||||||
"pathname is in a glob-friendly format and is relative to the current working
|
" TreeDirNode object that match the specified glob pattern.
|
||||||
"directory, if this TreeDirNode's path is under the current working directory.
|
"
|
||||||
function! s:TreeDirNode._getGlobDir()
|
" Args:
|
||||||
" Gets a relative path, if possible. This ensures that 'wildignore' rules
|
" pattern: (string) the glob pattern to apply
|
||||||
" for relative paths will be obeyed.
|
" all: (0 or 1) if 1, include "." and ".." if they match "pattern"; if 0,
|
||||||
let l:globDir = fnamemodify(self.path.str({'format': 'Glob'}), ':.')
|
" always exclude them
|
||||||
|
"
|
||||||
|
" Note: If the pathnames in the result list are below the working directory,
|
||||||
|
" they are returned as pathnames relative to that directory. This is because
|
||||||
|
" this function, internally, attempts to obey 'wildignore' rules that use
|
||||||
|
" relative paths.
|
||||||
|
function! s:TreeDirNode._glob(pattern, all)
|
||||||
|
|
||||||
" Calling fnamemodify() with ':.' on Windows systems strips the leading
|
" Construct a path specification such that "globpath()" will return
|
||||||
" drive letter from paths that aren't under the working directory. Here,
|
" relative pathnames, if possible.
|
||||||
" the drive letter is added back to the pathname.
|
if self.path.str() == getcwd()
|
||||||
if nerdtree#runningWindows() && l:globDir[0] == '\'
|
let l:pathSpec = ','
|
||||||
let l:globDir = self.path.drive . l:globDir
|
else
|
||||||
|
let l:pathSpec = fnamemodify(self.path.str({'format': 'Glob'}), ':.')
|
||||||
|
|
||||||
|
" On Windows, the drive letter may be removed by "fnamemodify()".
|
||||||
|
if nerdtree#runningWindows() && l:pathSpec[0] == '\'
|
||||||
|
let l:pathSpec = self.path.drive . l:pathSpec
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return l:globDir
|
let l:globList = []
|
||||||
|
|
||||||
|
" See ":h version7.txt" for the details of the progression of the "glob()"
|
||||||
|
" and "globpath()" functions.
|
||||||
|
if v:version >= 704
|
||||||
|
let l:globList = globpath(l:pathSpec, a:pattern, !g:NERDTreeRespectWildIgnore, 1)
|
||||||
|
elseif v:version >= 703
|
||||||
|
let l:globString = globpath(l:pathSpec, a:pattern, !g:NERDTreeRespectWildIgnore)
|
||||||
|
let l:globList = split(l:globString, "\n")
|
||||||
|
else
|
||||||
|
let l:globString = globpath(l:pathSpec, a:pattern)
|
||||||
|
let l:globList = split(l:globString, "\n")
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If "a:all" is false, filter "." and ".." from the output.
|
||||||
|
if !a:all
|
||||||
|
let l:toRemove = []
|
||||||
|
|
||||||
|
for l:file in l:globList
|
||||||
|
let l:tail = fnamemodify(l:file, ':t')
|
||||||
|
|
||||||
|
" Double the modifier if only a separator was stripped.
|
||||||
|
if l:tail == ''
|
||||||
|
let l:tail = fnamemodify(l:file, ':t:t')
|
||||||
|
endif
|
||||||
|
|
||||||
|
if l:tail == '.' || l:tail == '..'
|
||||||
|
call add(l:toRemove, l:file)
|
||||||
|
if len(l:toRemove) == 2
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
for l:file in l:toRemove
|
||||||
|
call remove(l:globList, index(l:globList, l:file))
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
|
||||||
|
return l:globList
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.GetSelected() {{{1
|
" FUNCTION: TreeDirNode.GetSelected() {{{1
|
||||||
"Returns the current node if it is a dir node, or else returns the current
|
" Returns the current node if it is a dir node, or else returns the current
|
||||||
"nodes parent
|
" nodes parent
|
||||||
unlet s:TreeDirNode.GetSelected
|
unlet s:TreeDirNode.GetSelected
|
||||||
function! s:TreeDirNode.GetSelected()
|
function! s:TreeDirNode.GetSelected()
|
||||||
let currentDir = g:NERDTreeFileNode.GetSelected()
|
let currentDir = g:NERDTreeFileNode.GetSelected()
|
||||||
@ -239,17 +296,17 @@ function! s:TreeDirNode.GetSelected()
|
|||||||
return currentDir
|
return currentDir
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getVisibleChildCount() {{{1
|
" FUNCTION: TreeDirNode.getVisibleChildCount() {{{1
|
||||||
"Returns the number of visible children this node has
|
" Returns the number of visible children this node has
|
||||||
function! s:TreeDirNode.getVisibleChildCount()
|
function! s:TreeDirNode.getVisibleChildCount()
|
||||||
return len(self.getVisibleChildren())
|
return len(self.getVisibleChildren())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.getVisibleChildren() {{{1
|
" FUNCTION: TreeDirNode.getVisibleChildren() {{{1
|
||||||
"Returns a list of children to display for this node, in the correct order
|
" Returns a list of children to display for this node, in the correct order
|
||||||
"
|
"
|
||||||
"Return:
|
" Return:
|
||||||
"an array of treenodes
|
" an array of treenodes
|
||||||
function! s:TreeDirNode.getVisibleChildren()
|
function! s:TreeDirNode.getVisibleChildren()
|
||||||
let toReturn = []
|
let toReturn = []
|
||||||
for i in self.children
|
for i in self.children
|
||||||
@ -260,14 +317,14 @@ function! s:TreeDirNode.getVisibleChildren()
|
|||||||
return toReturn
|
return toReturn
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.hasVisibleChildren() {{{1
|
" FUNCTION: TreeDirNode.hasVisibleChildren() {{{1
|
||||||
"returns 1 if this node has any childre, 0 otherwise..
|
" returns 1 if this node has any childre, 0 otherwise..
|
||||||
function! s:TreeDirNode.hasVisibleChildren()
|
function! s:TreeDirNode.hasVisibleChildren()
|
||||||
return self.getVisibleChildCount() != 0
|
return self.getVisibleChildCount() != 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.isCascadable() {{{1
|
" FUNCTION: TreeDirNode.isCascadable() {{{1
|
||||||
"true if this dir has only one visible child - which is also a dir
|
" true if this dir has only one visible child - which is also a dir
|
||||||
function! s:TreeDirNode.isCascadable()
|
function! s:TreeDirNode.isCascadable()
|
||||||
if g:NERDTreeCascadeSingleChildDir == 0
|
if g:NERDTreeCascadeSingleChildDir == 0
|
||||||
return 0
|
return 0
|
||||||
@ -277,28 +334,19 @@ function! s:TreeDirNode.isCascadable()
|
|||||||
return len(c) == 1 && c[0].path.isDirectory
|
return len(c) == 1 && c[0].path.isDirectory
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode._initChildren() {{{1
|
" FUNCTION: TreeDirNode._initChildren() {{{1
|
||||||
"Removes all childen from this node and re-reads them
|
" Removes all childen from this node and re-reads them
|
||||||
"
|
"
|
||||||
"Args:
|
" Args:
|
||||||
"silent: 1 if the function should not echo any "please wait" messages for
|
" silent: 1 if the function should not echo any "please wait" messages for
|
||||||
"large directories
|
" large directories
|
||||||
"
|
"
|
||||||
"Return: the number of child nodes read
|
" Return: the number of child nodes read
|
||||||
function! s:TreeDirNode._initChildren(silent)
|
function! s:TreeDirNode._initChildren(silent)
|
||||||
"remove all the current child nodes
|
"remove all the current child nodes
|
||||||
let self.children = []
|
let self.children = []
|
||||||
|
|
||||||
"get an array of all the files in the nodes dir
|
let files = self._glob('*', 1) + self._glob('.*', 0)
|
||||||
let globDir = self._getGlobDir()
|
|
||||||
|
|
||||||
if version >= 703
|
|
||||||
let filesStr = globpath(globDir, '*', !g:NERDTreeRespectWildIgnore) . "\n" . globpath(globDir, '.*', !g:NERDTreeRespectWildIgnore)
|
|
||||||
else
|
|
||||||
let filesStr = globpath(globDir, '*') . "\n" . globpath(globDir, '.*')
|
|
||||||
endif
|
|
||||||
|
|
||||||
let files = split(filesStr, "\n")
|
|
||||||
|
|
||||||
if !a:silent && len(files) > g:NERDTreeNotificationThreshold
|
if !a:silent && len(files) > g:NERDTreeNotificationThreshold
|
||||||
call nerdtree#echo("Please wait, caching a large dir ...")
|
call nerdtree#echo("Please wait, caching a large dir ...")
|
||||||
@ -306,13 +354,6 @@ function! s:TreeDirNode._initChildren(silent)
|
|||||||
|
|
||||||
let invalidFilesFound = 0
|
let invalidFilesFound = 0
|
||||||
for i in files
|
for i in files
|
||||||
|
|
||||||
"filter out the .. and . directories
|
|
||||||
"Note: we must match .. AND ../ since sometimes the globpath returns
|
|
||||||
"../ for path with strange chars (eg $)
|
|
||||||
if i[len(i)-3:2] != ".." && i[len(i)-2:2] != ".." &&
|
|
||||||
\ i[len(i)-2:1] != "." && i[len(i)-1] != "."
|
|
||||||
"put the next file in a new node and attach it
|
|
||||||
try
|
try
|
||||||
let path = g:NERDTreePath.New(i)
|
let path = g:NERDTreePath.New(i)
|
||||||
call self.createChild(path, 0)
|
call self.createChild(path, 0)
|
||||||
@ -320,7 +361,6 @@ function! s:TreeDirNode._initChildren(silent)
|
|||||||
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
|
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
|
||||||
let invalidFilesFound += 1
|
let invalidFilesFound += 1
|
||||||
endtry
|
endtry
|
||||||
endif
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call self.sortChildren()
|
call self.sortChildren()
|
||||||
@ -335,12 +375,12 @@ function! s:TreeDirNode._initChildren(silent)
|
|||||||
return self.getChildCount()
|
return self.getChildCount()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.New(path, nerdtree) {{{1
|
" FUNCTION: TreeDirNode.New(path, nerdtree) {{{1
|
||||||
"Returns a new TreeNode object with the given path and parent
|
" Return a new TreeDirNode object with the given path and parent.
|
||||||
"
|
"
|
||||||
"Args:
|
" Args:
|
||||||
"path: dir that the node represents
|
" path: dir that the node represents
|
||||||
"nerdtree: the tree the node belongs to
|
" nerdtree: the tree the node belongs to
|
||||||
function! s:TreeDirNode.New(path, nerdtree)
|
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."
|
||||||
@ -358,10 +398,10 @@ function! s:TreeDirNode.New(path, nerdtree)
|
|||||||
return newTreeNode
|
return newTreeNode
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.open([opts]) {{{1
|
" FUNCTION: TreeDirNode.open([opts]) {{{1
|
||||||
"Open the dir in the current tree or in a new tree elsewhere.
|
" Open the dir in the current tree or in a new tree elsewhere.
|
||||||
"
|
"
|
||||||
"If opening in the current tree, return the number of cached nodes.
|
" If opening in the current tree, return the number of cached nodes.
|
||||||
unlet s:TreeDirNode.open
|
unlet s:TreeDirNode.open
|
||||||
function! s:TreeDirNode.open(...)
|
function! s:TreeDirNode.open(...)
|
||||||
let opts = a:0 ? a:1 : {}
|
let opts = a:0 ? a:1 : {}
|
||||||
@ -379,10 +419,10 @@ function! s:TreeDirNode.open(...)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.openAlong([opts]) {{{1
|
" FUNCTION: TreeDirNode.openAlong([opts]) {{{1
|
||||||
"recursive open the dir if it has only one directory child.
|
" recursive open the dir if it has only one directory child.
|
||||||
"
|
"
|
||||||
"return the level of opened directories.
|
" return the level of opened directories.
|
||||||
function! s:TreeDirNode.openAlong(...)
|
function! s:TreeDirNode.openAlong(...)
|
||||||
let opts = a:0 ? a:1 : {}
|
let opts = a:0 ? a:1 : {}
|
||||||
let level = 0
|
let level = 0
|
||||||
@ -401,42 +441,42 @@ function! s:TreeDirNode.openAlong(...)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: TreeDirNode.openExplorer() {{{1
|
" FUNCTION: TreeDirNode.openExplorer() {{{1
|
||||||
" opens an explorer window for this node in the previous window (could be a
|
" Open an explorer window for this node in the previous window. The explorer
|
||||||
" nerd tree or a netrw)
|
" can be a NERDTree window or a netrw window.
|
||||||
function! s:TreeDirNode.openExplorer()
|
function! s:TreeDirNode.openExplorer()
|
||||||
call self.open({'where': 'p'})
|
call self.open({'where': 'p'})
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.openInNewTab(options) {{{1
|
" FUNCTION: TreeDirNode.openInNewTab(options) {{{1
|
||||||
unlet s:TreeDirNode.openInNewTab
|
unlet s:TreeDirNode.openInNewTab
|
||||||
function! s:TreeDirNode.openInNewTab(options)
|
function! s:TreeDirNode.openInNewTab(options)
|
||||||
call nerdtree#deprecated('TreeDirNode.openInNewTab', 'is deprecated, use open() instead')
|
call nerdtree#deprecated('TreeDirNode.openInNewTab', 'is deprecated, use open() instead')
|
||||||
call self.open({'where': 't'})
|
call self.open({'where': 't'})
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode._openInNewTab() {{{1
|
" FUNCTION: TreeDirNode._openInNewTab() {{{1
|
||||||
function! s:TreeDirNode._openInNewTab()
|
function! s:TreeDirNode._openInNewTab()
|
||||||
tabnew
|
tabnew
|
||||||
call g:NERDTreeCreator.CreateTabTree(self.path.str())
|
call g:NERDTreeCreator.CreateTabTree(self.path.str())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.openRecursively() {{{1
|
" FUNCTION: TreeDirNode.openRecursively() {{{1
|
||||||
"Opens this treenode and all of its children whose paths arent 'ignored'
|
" Opens this treenode and all of its children whose paths arent 'ignored'
|
||||||
"because of the file filters.
|
" because of the file filters.
|
||||||
"
|
"
|
||||||
"This method is actually a wrapper for the OpenRecursively2 method which does
|
" This method is actually a wrapper for the OpenRecursively2 method which does
|
||||||
"the work.
|
" the work.
|
||||||
function! s:TreeDirNode.openRecursively()
|
function! s:TreeDirNode.openRecursively()
|
||||||
call self._openRecursively2(1)
|
call self._openRecursively2(1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode._openRecursively2() {{{1
|
" FUNCTION: TreeDirNode._openRecursively2() {{{1
|
||||||
"Opens this all children of this treenode recursively if either:
|
" Opens this all children of this treenode recursively if either:
|
||||||
" *they arent filtered by file filters
|
" *they arent filtered by file filters
|
||||||
" *a:forceOpen is 1
|
" *a:forceOpen is 1
|
||||||
"
|
"
|
||||||
"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(self.getNerdtree()) ==# 0 || a:forceOpen
|
if self.path.ignore(self.getNerdtree()) ==# 0 || a:forceOpen
|
||||||
let self.isOpen = 1
|
let self.isOpen = 1
|
||||||
@ -452,29 +492,16 @@ function! s:TreeDirNode._openRecursively2(forceOpen)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.refresh() {{{1
|
" FUNCTION: TreeDirNode.refresh() {{{1
|
||||||
unlet s:TreeDirNode.refresh
|
|
||||||
function! s:TreeDirNode.refresh()
|
function! s:TreeDirNode.refresh()
|
||||||
call self.path.refresh(self.getNerdtree())
|
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)
|
||||||
"go thru all the files/dirs under this node
|
let files = self._glob('*', 1) + self._glob('.*', 0)
|
||||||
let newChildNodes = []
|
let newChildNodes = []
|
||||||
let invalidFilesFound = 0
|
let invalidFilesFound = 0
|
||||||
let globDir = self._getGlobDir()
|
|
||||||
let filesStr = globpath(globDir, '*') . "\n" . globpath(globDir, '.*')
|
|
||||||
let files = split(filesStr, "\n")
|
|
||||||
for i in files
|
for i in files
|
||||||
"filter out the .. and . directories
|
|
||||||
"Note: we must match .. AND ../ cos sometimes the globpath returns
|
|
||||||
"../ for path with strange chars (eg $)
|
|
||||||
"if i !~# '\/\.\.\/\?$' && i !~# '\/\.\/\?$'
|
|
||||||
|
|
||||||
" Regular expression is too expensive. Use simply string comparison
|
|
||||||
" instead
|
|
||||||
if i[len(i)-3:2] != ".." && i[len(i)-2:2] != ".." &&
|
|
||||||
\ i[len(i)-2:1] != "." && i[len(i)-1] != "."
|
|
||||||
try
|
try
|
||||||
"create a new path and see if it exists in this nodes children
|
"create a new path and see if it exists in this nodes children
|
||||||
let path = g:NERDTreePath.New(i)
|
let path = g:NERDTreePath.New(i)
|
||||||
@ -489,12 +516,9 @@ function! s:TreeDirNode.refresh()
|
|||||||
let newNode.parent = self
|
let newNode.parent = self
|
||||||
call add(newChildNodes, newNode)
|
call add(newChildNodes, newNode)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
|
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
|
||||||
let invalidFilesFound = 1
|
let invalidFilesFound = 1
|
||||||
endtry
|
endtry
|
||||||
endif
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
"swap this nodes children out for the children we just read/refreshed
|
"swap this nodes children out for the children we just read/refreshed
|
||||||
@ -507,7 +531,7 @@ function! s:TreeDirNode.refresh()
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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(self.getNerdtree())
|
call self.path.refreshFlags(self.getNerdtree())
|
||||||
@ -516,15 +540,15 @@ function! s:TreeDirNode.refreshFlags()
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.refreshDirFlags() {{{1
|
" FUNCTION: TreeDirNode.refreshDirFlags() {{{1
|
||||||
function! s:TreeDirNode.refreshDirFlags()
|
function! s:TreeDirNode.refreshDirFlags()
|
||||||
call self.path.refreshFlags(self.getNerdtree())
|
call self.path.refreshFlags(self.getNerdtree())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.reveal(path) {{{1
|
" FUNCTION: TreeDirNode.reveal(path) {{{1
|
||||||
"reveal the given path, i.e. cache and open all treenodes needed to display it
|
" reveal the given path, i.e. cache and open all treenodes needed to display it
|
||||||
"in the UI
|
" in the UI
|
||||||
"Returns the revealed node
|
" Returns the revealed node
|
||||||
function! s:TreeDirNode.reveal(path, ...)
|
function! s:TreeDirNode.reveal(path, ...)
|
||||||
let opts = a:0 ? a:1 : {}
|
let opts = a:0 ? a:1 : {}
|
||||||
|
|
||||||
@ -551,14 +575,12 @@ function! s:TreeDirNode.reveal(path, ...)
|
|||||||
return n.reveal(a:path, opts)
|
return n.reveal(a:path, opts)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.removeChild(treenode) {{{1
|
" FUNCTION: TreeDirNode.removeChild(treenode) {{{1
|
||||||
|
" Remove the given treenode from "self.children".
|
||||||
|
" Throws "NERDTree.ChildNotFoundError" if the node is not found.
|
||||||
"
|
"
|
||||||
"Removes the given treenode from this nodes set of children
|
" Args:
|
||||||
"
|
" treenode: the node object to remove
|
||||||
"Args:
|
|
||||||
"treenode: the node to remove
|
|
||||||
"
|
|
||||||
"Throws a NERDTree.ChildNotFoundError if the given treenode is not found
|
|
||||||
function! s:TreeDirNode.removeChild(treenode)
|
function! s:TreeDirNode.removeChild(treenode)
|
||||||
for i in range(0, self.getChildCount()-1)
|
for i in range(0, self.getChildCount()-1)
|
||||||
if self.children[i].equals(a:treenode)
|
if self.children[i].equals(a:treenode)
|
||||||
@ -570,18 +592,15 @@ function! s:TreeDirNode.removeChild(treenode)
|
|||||||
throw "NERDTree.ChildNotFoundError: child node was not found"
|
throw "NERDTree.ChildNotFoundError: child node was not found"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.sortChildren() {{{1
|
" FUNCTION: TreeDirNode.sortChildren() {{{1
|
||||||
"
|
" Sort "self.children" by alphabetical order and directory priority.
|
||||||
"Sorts the children of this node according to alphabetical order and the
|
|
||||||
"directory priority.
|
|
||||||
"
|
|
||||||
function! s:TreeDirNode.sortChildren()
|
function! s:TreeDirNode.sortChildren()
|
||||||
let CompareFunc = function("nerdtree#compareNodesBySortKey")
|
let CompareFunc = function("nerdtree#compareNodesBySortKey")
|
||||||
call sort(self.children, CompareFunc)
|
call sort(self.children, CompareFunc)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.toggleOpen([options]) {{{1
|
" FUNCTION: TreeDirNode.toggleOpen([options]) {{{1
|
||||||
"Opens this directory if it is closed and vice versa
|
" Opens this directory if it is closed and vice versa
|
||||||
function! s:TreeDirNode.toggleOpen(...)
|
function! s:TreeDirNode.toggleOpen(...)
|
||||||
let opts = a:0 ? a:1 : {}
|
let opts = a:0 ? a:1 : {}
|
||||||
if self.isOpen ==# 1
|
if self.isOpen ==# 1
|
||||||
@ -595,13 +614,13 @@ function! s:TreeDirNode.toggleOpen(...)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: TreeDirNode.transplantChild(newNode) {{{1
|
" FUNCTION: TreeDirNode.transplantChild(newNode) {{{1
|
||||||
"Replaces the child of this with the given node (where the child node's full
|
" Replaces the child of this with the given node (where the child node's full
|
||||||
"path matches a:newNode's fullpath). The search for the matching node is
|
" path matches a:newNode's fullpath). The search for the matching node is
|
||||||
"non-recursive
|
" non-recursive
|
||||||
"
|
"
|
||||||
"Arg:
|
" Arg:
|
||||||
"newNode: the node to graft into the tree
|
" newNode: the node to graft into the tree
|
||||||
function! s:TreeDirNode.transplantChild(newNode)
|
function! s:TreeDirNode.transplantChild(newNode)
|
||||||
for i in range(0, self.getChildCount()-1)
|
for i in range(0, self.getChildCount()-1)
|
||||||
if self.children[i].equals(a:newNode)
|
if self.children[i].equals(a:newNode)
|
||||||
|
Loading…
Reference in New Issue
Block a user