2014-08-03 18:02:51 -04:00
|
|
|
"CLASS: Notifier
|
|
|
|
"============================================================
|
|
|
|
let s:Notifier = {}
|
|
|
|
|
|
|
|
function! s:Notifier.AddListener(event, funcname)
|
|
|
|
let listeners = s:Notifier.GetListenersForEvent(a:event)
|
|
|
|
if listeners == []
|
|
|
|
let listenersMap = s:Notifier.GetListenersMap()
|
|
|
|
let listenersMap[a:event] = listeners
|
|
|
|
endif
|
|
|
|
call add(listeners, a:funcname)
|
|
|
|
endfunction
|
|
|
|
|
2015-12-08 08:20:04 -05:00
|
|
|
function! s:Notifier.NotifyListeners(event, path, nerdtree, params)
|
|
|
|
let event = g:NERDTreeEvent.New(a:nerdtree, a:path, a:event, a:params)
|
2014-08-03 18:02:51 -04:00
|
|
|
|
|
|
|
for listener in s:Notifier.GetListenersForEvent(a:event)
|
|
|
|
call {listener}(event)
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Notifier.GetListenersMap()
|
|
|
|
if !exists("s:refreshListenersMap")
|
|
|
|
let s:refreshListenersMap = {}
|
|
|
|
endif
|
|
|
|
return s:refreshListenersMap
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Notifier.GetListenersForEvent(name)
|
|
|
|
let listenersMap = s:Notifier.GetListenersMap()
|
|
|
|
return get(listenersMap, a:name, [])
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:NERDTreePathNotifier = deepcopy(s:Notifier)
|
|
|
|
|