Skip to content

Commit

Permalink
add event support
Browse files Browse the repository at this point in the history
  • Loading branch information
prabirshrestha committed Sep 19, 2020
1 parent f3268bf commit 9fe3c45
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions autoload/vital/__vital__/Experimental/UI/Popup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function! s:create(opt) abort
\ })
endif
let s:_popups[id] = data
call s:_notify(id, {}, 'create')
return id
endfunction

Expand All @@ -58,11 +59,19 @@ function! s:close(id) abort
else
silent! call popup_close(a:id)
endif
call s:_notify(a:id, {}, 'close')
call remove(s:_popups, a:id)
endif
endfunction

function! s:_set(data, opt) abort
" copy all callbacks to data
for [key, Cb] in items(a:opt)
if stridx(key, 'on_') == 0
let a:data[key] = Cb
endif
endfor

" try to set values from a:opt, if not set from a:data, if not default
let a:data['w'] = get(a:opt, 'w', get(a:data, 'w', 5))
let a:data['h'] = get(a:opt, 'h', get(a:data, 'h', 5))
Expand Down Expand Up @@ -103,6 +112,16 @@ function! s:_set(data, opt) abort
endif
endfunction

function! s:_notify(id, data, event) abort
if has_key(s:_popups[a:id], 'on_event')
call s:_popups[a:id]['on_event'](a:id, a:data, a:event)
endif
let eventhandler = 'on_' . a:event
if has_key(s:_popups[a:id], eventhandler)
call s:_popups[a:id][eventhandler](a:id, a:data, a:event)
endif
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
"vim: sts=2 sw=2 smarttab et ai textwidth=0 fdm=marker

0 comments on commit 9fe3c45

Please sign in to comment.