mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-08 11:23:48 -05:00
refactor the Refresh() method for tree nodes
create a oFileTreeNode#Refresh() and make sure that Refresh() is always called for dir nodes
This commit is contained in:
@@ -348,6 +348,10 @@ function! s:oTreeFileNode.New(path) dict
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: oTreeFileNode.Refresh {{{3
|
||||||
|
function! s:oTreeFileNode.Refresh() dict
|
||||||
|
call self.path.Refresh()
|
||||||
|
endfunction
|
||||||
"FUNCTION: oTreeFileNode.Rename {{{3
|
"FUNCTION: oTreeFileNode.Rename {{{3
|
||||||
"Calls the rename method for this nodes path obj
|
"Calls the rename method for this nodes path obj
|
||||||
function! s:oTreeFileNode.Rename(newName) dict
|
function! s:oTreeFileNode.Rename(newName) dict
|
||||||
@@ -701,55 +705,50 @@ function! s:oTreeDirNode.OpenRecursively2(forceOpen) dict
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: oTreeDirNode.Refresh {{{3
|
"FUNCTION: oTreeDirNode.Refresh {{{3
|
||||||
|
unlet s:oTreeDirNode.Refresh
|
||||||
function! s:oTreeDirNode.Refresh() dict
|
function! s:oTreeDirNode.Refresh() dict
|
||||||
let newChildNodes = []
|
call self.path.Refresh()
|
||||||
let invalidFilesFound = 0
|
|
||||||
|
|
||||||
"go thru all the files/dirs under this node
|
"if this node was ever opened, refresh its children
|
||||||
let dir = self.path
|
if self.isOpen || !empty(self.children)
|
||||||
let filesStr = globpath(dir.StrForGlob(), '*') . "\n" . globpath(dir.StrForGlob(), '.*')
|
"go thru all the files/dirs under this node
|
||||||
let files = split(filesStr, "\n")
|
let newChildNodes = []
|
||||||
for i in files
|
let invalidFilesFound = 0
|
||||||
if i !~ '\.\.$' && i !~ '\.$'
|
let dir = self.path
|
||||||
|
let filesStr = globpath(dir.StrForGlob(), '*') . "\n" . globpath(dir.StrForGlob(), '.*')
|
||||||
|
let files = split(filesStr, "\n")
|
||||||
|
for i in files
|
||||||
|
if i !~ '\.\.$' && i !~ '\.$'
|
||||||
|
|
||||||
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 = s:oPath.New(i)
|
let path = s:oPath.New(i)
|
||||||
let newNode = self.GetChild(path)
|
let newNode = self.GetChild(path)
|
||||||
if newNode != {}
|
if newNode != {}
|
||||||
|
|
||||||
"if the existing node is a dir can be refreshed then
|
|
||||||
"refresh it
|
|
||||||
if newNode.path.isDirectory && (!empty(newNode.children) || newNode.isOpen == 1)
|
|
||||||
call newNode.Refresh()
|
call newNode.Refresh()
|
||||||
|
call add(newChildNodes, newNode)
|
||||||
|
|
||||||
"if we have a filenode then refresh the path
|
"the node doesnt exist so create it
|
||||||
elseif newNode.path.isDirectory == 0
|
else
|
||||||
call newNode.path.Refresh()
|
let newNode = s:oTreeFileNode.New(path)
|
||||||
|
let newNode.parent = self
|
||||||
|
call add(newChildNodes, newNode)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call add(newChildNodes, newNode)
|
|
||||||
|
|
||||||
"the node doesnt exist so create it
|
catch /^NERDTree.InvalidArguments/
|
||||||
else
|
let invalidFilesFound = 1
|
||||||
let newNode = s:oTreeFileNode.New(path)
|
endtry
|
||||||
let newNode.parent = self
|
endif
|
||||||
call add(newChildNodes, newNode)
|
endfor
|
||||||
endif
|
|
||||||
|
|
||||||
|
"swap this nodes children out for the children we just read/refreshed
|
||||||
|
let self.children = newChildNodes
|
||||||
|
call self.SortChildren()
|
||||||
|
|
||||||
catch /^NERDTree.InvalidArguments/
|
if invalidFilesFound
|
||||||
let invalidFilesFound = 1
|
call s:EchoWarning("some files could not be loaded into the NERD tree")
|
||||||
endtry
|
|
||||||
endif
|
endif
|
||||||
endfor
|
|
||||||
|
|
||||||
"swap this nodes children out for the children we just read/refreshed
|
|
||||||
let self.children = newChildNodes
|
|
||||||
call self.SortChildren()
|
|
||||||
|
|
||||||
if invalidFilesFound
|
|
||||||
call s:EchoWarning("some files could not be loaded into the NERD tree")
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user