add proof of concept for path flags API and add git modified flags

This commit is contained in:
Martin Grenfell
2014-07-05 00:29:45 +01:00
parent d162c08fd7
commit a7428eba38
6 changed files with 124 additions and 5 deletions

View File

@@ -56,17 +56,17 @@ function! s:Creator.createPrimary(name)
unlet t:NERDTreeBufName
endif
call self._createTreeWin()
let newRoot = g:NERDTreeDirNode.New(path)
let b:NERDTreeRoot = newRoot
let b:NERDTreeType = "primary"
call newRoot.open()
call self._createTreeWin()
let b:treeShowHelp = 0
let b:NERDTreeIgnoreEnabled = 1
let b:NERDTreeShowFiles = g:NERDTreeShowFiles
let b:NERDTreeShowHidden = g:NERDTreeShowHidden
let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks
let b:NERDTreeRoot = newRoot
let b:NERDTreeType = "primary"
call nerdtree#renderView()
call b:NERDTreeRoot.putCursorHere(0, 0)

View File

@@ -24,6 +24,13 @@ function! s:Path.AbsolutePathFor(str)
return toReturn
endfunction
"FUNCTION: Path.addFlag(flag) {{{1
function! s:Path.addFlag(flag)
if index(self._flags, a:flag) == -1
call add(self._flags, a:flag)
endif
endfunction
"FUNCTION: Path.bookmarkNames() {{{1
function! s:Path.bookmarkNames()
if !exists("self._bookmarkNames")
@@ -33,8 +40,10 @@ function! s:Path.bookmarkNames()
endfunction
"FUNCTION: Path.cacheDisplayString() {{{1
function! s:Path.cacheDisplayString()
let self.cachedDisplayString = self.getLastPathComponent(1)
function! s:Path.cacheDisplayString() abort
let self.cachedDisplayString = self._flagString()
let self.cachedDisplayString .= self.getLastPathComponent(1)
if self.isExecutable
let self.cachedDisplayString = self.cachedDisplayString . '*'
@@ -350,6 +359,15 @@ function! s:Path.getSortOrderIndex()
return s:NERDTreeSortStarIndex
endfunction
"FUNCTION: Path._flagString() {{{1
function! s:Path._flagString()
if empty(self._flags)
return ""
endif
return '[' . join(self._flags, ',') . ']'
endfunction
"FUNCTION: Path.isUnixHiddenFile() {{{1
"check for unix hidden files
function! s:Path.isUnixHiddenFile()
@@ -460,6 +478,7 @@ function! s:Path.New(path)
call newPath.readInfoFromDisk(s:Path.AbsolutePathFor(a:path))
let newPath.cachedDisplayString = ""
let newPath._flags = []
return newPath
endfunction
@@ -480,6 +499,14 @@ function! s:Path.Resolve(path)
return tmp =~# '.\+/$' ? substitute(tmp, '/$', '', '') : tmp
endfunction
"FUNCTION: Path.removeFlag(flag) {{{1
function! s:Path.removeFlag(flag)
let i = index(self._flags, a:flag)
if i >= 0
call remove(self._flags, i)
endif
endfunction
"FUNCTION: Path.readInfoFromDisk(fullpath) {{{1
"
"
@@ -537,6 +564,7 @@ endfunction
"FUNCTION: Path.refresh() {{{1
function! s:Path.refresh()
call self.readInfoFromDisk(self.str())
call g:NERDTreeRefreshNotifier.NotifyListeners(self)
call self.cacheDisplayString()
endfunction

View File

@@ -0,0 +1,21 @@
"CLASS: RefreshNotifier
"============================================================
let s:RefreshNotifier = {}
let g:NERDTreeRefreshNotifier = s:RefreshNotifier
function! s:RefreshNotifier.AddListener(funcname)
call add(s:RefreshNotifier.GetListeners(), a:funcname)
endfunction
function! s:RefreshNotifier.NotifyListeners(refreshedPath)
for listener in s:RefreshNotifier.GetListeners()
call {listener}(a:refreshedPath)
endfor
endfunction
function! s:RefreshNotifier.GetListeners()
if !exists("s:refreshListeners")
let s:refreshListeners = []
endif
return s:refreshListeners
endfunction

View File

@@ -252,6 +252,7 @@ function! s:TreeDirNode._initChildren(silent)
try
let path = g:NERDTreePath.New(i)
call self.createChild(path, 0)
call g:NERDTreeRefreshNotifier.NotifyListeners(path)
catch /^NERDTree.\(InvalidArguments\|InvalidFiletype\)Error/
let invalidFilesFound += 1
endtry