Use popup for confirmations (note these have to be async)
This commit is contained in:
parent
48076ba2ef
commit
68edda842a
5 changed files with 129 additions and 33 deletions
|
|
@ -80,6 +80,28 @@ function! vimspector#internal#neopopup#HideSplash( id ) abort
|
|||
unlet s:db[ a:id ]
|
||||
endfunction
|
||||
|
||||
function! vimspector#internal#neopopup#Confirm( confirm_id,
|
||||
\ text,
|
||||
\ default_value ) abort
|
||||
let result = confirm( a:text, '&Yes &No &Default', 3 )
|
||||
|
||||
" Map the results to what popup_menu_filter would return (ok s:ConfirmCallback
|
||||
" in popup.vim)
|
||||
if result == 2
|
||||
" No is represented as 0
|
||||
let result = 0
|
||||
elseif result == 0
|
||||
" User pressed ESC/ctrl-c
|
||||
let result = -1
|
||||
elseif result == 3
|
||||
" Default
|
||||
let result = a:default_value
|
||||
endif
|
||||
|
||||
py3 __import__( 'vimspector', fromlist = [ 'utils' ] ).utils.ConfirmCallback(
|
||||
\ int( vim.eval( 'a:confirm_id' ) ),
|
||||
\ int( vim.eval( 'result' ) ) )
|
||||
endfunction
|
||||
" Boilerplate {{{
|
||||
let &cpoptions=s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
|
|
|||
|
|
@ -32,6 +32,37 @@ function! vimspector#internal#popup#HideSplash( id ) abort
|
|||
call popup_hide( a:id )
|
||||
endfunction
|
||||
|
||||
function! s:YesNoDefaultFilter( default_value, id, key ) abort
|
||||
if a:key ==# "\<CR>" || a:key ==# 'D' || a:key ==# 'd'
|
||||
call popup_close( a:id, a:default_value )
|
||||
endif
|
||||
|
||||
return popup_filter_yesno( a:id, a:key )
|
||||
endfunction
|
||||
|
||||
function! s:ConfirmCallback( confirm_id, id, result ) abort
|
||||
py3 __import__( 'vimspector', fromlist = [ 'utils' ] ).utils.ConfirmCallback(
|
||||
\ int( vim.eval( 'a:confirm_id' ) ),
|
||||
\ int( vim.eval( 'a:result' ) ) )
|
||||
endfunction
|
||||
|
||||
function! vimspector#internal#popup#Confirm(
|
||||
\ confirm_id,
|
||||
\ text,
|
||||
\ default_value ) abort
|
||||
let text = a:text
|
||||
if type( a:text ) != v:t_list
|
||||
let text = [ a:text ]
|
||||
endif
|
||||
|
||||
call extend( text, [ '', '(Y)es (N)o (D)efault' ] )
|
||||
|
||||
return popup_dialog( text, {
|
||||
\ 'callback': function( 's:ConfirmCallback', [ a:confirm_id ] ),
|
||||
\ 'filter': function( 's:YesNoDefaultFilter', [ a:default_value ] )
|
||||
\ } )
|
||||
endfunction
|
||||
|
||||
" Boilerplate {{{
|
||||
let &cpoptions=s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue