123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- let s:cpo_save=&cpo
- set cpo&vim
-
-
-
-
-
- let s:LHdialog = {}
-
-
-
-
- function! lh#buffer#dialog#verbose(level)
- let s:verbose = a:level
- endfunction
-
- function! s:Verbose(expr)
- if exists('s:verbose') && s:verbose
- echomsg a:expr
- endif
- endfunction
-
- function! lh#buffer#dialog#debug(expr)
- return eval(a:expr)
- endfunction
-
-
-
-
-
- function! s:Mappings(abuffer)
-
- exe "nnoremap <silent> <buffer> <esc> :silent call ".a:abuffer.action."(-1, ".a:abuffer.id.")<cr>"
- exe "nnoremap <silent> <buffer> q :call lh#buffer#dialog#select(-1, ".a:abuffer.id.")<cr>"
- exe "nnoremap <silent> <buffer> <cr> :call lh#buffer#dialog#select(line('.'), ".a:abuffer.id.")<cr>"
- " nnoremap <silent> <buffer> <2-LeftMouse> :silent call <sid>GrepEditFileLine(line(".
-
-
-
- if a:abuffer.support_tagging
- nnoremap <silent> <buffer> t :silent call <sid>ToggleTag(line("."))<cr>
- nnoremap <silent> <buffer> <space> :silent call <sid>ToggleTag(line("."))<cr>
- endif
- nnoremap <silent> <buffer> <tab> :silent call <sid>NextChoice('')<cr>
- nnoremap <silent> <buffer> <S-tab> :silent call <sid>NextChoice('b')<cr>
- exe "nnoremap <silent> <buffer> h :silent call <sid>ToggleHelp(".a:abuffer.id.")<cr>"
- endfunction
-
-
-
- function! s:ToggleTag(lineNum)
- if a:lineNum > s:Help_NbL()
-
- if (getline(a:lineNum)[0] == '*')
- let b:NbTags = b:NbTags - 1
- silent exe a:lineNum.'s/^\* / /e'
- else
- let b:NbTags = b:NbTags + 1
- silent exe a:lineNum.'s/^ /* /e'
- endif
-
-
- silent! normal! 3|
- call s:NextChoice('')
- endif
- endfunction
-
-
- function! s:Help_NbL()
-
- return 2 + len(b:dialog['help_'.b:dialog.help_type])
- endfunction
-
-
- function! s:NextChoice(direction)
- " echomsg "next!
- call search('^[ *]\s*\zs\S\+', a:direction)
- endfunction
-
-
-
-
- function! s:RedisplayHelp(dialog)
- silent! 2,$g/^@/d_
- normal! gg
- for help in a:dialog['help_'.a:dialog.help_type]
- silent put=help
- endfor
- endfunction
-
- function! lh#buffer#dialog#update(dialog)
- set noro
- exe (s:Help_NbL()+1).',$d_'
- for choice in a:dialog.choices
- silent $put=' '.choice
- endfor
- set ro
- endfunction
-
- function! s:Display(dialog, atitle)
- set noro
- 0 put = a:atitle
- call s:RedisplayHelp(a:dialog)
- for choice in a:dialog.choices
- silent $put=' '.choice
- endfor
- set ro
- exe s:Help_NbL()+1
- endfunction
-
- function! s:ToggleHelp(bufferId)
- call lh#buffer#find(a:bufferId)
- call b:dialog.toggle_help()
- endfunction
-
- function! lh#buffer#dialog#toggle_help() dict
- let self.help_type
- \ = (self.help_type == 'short')
- \ ? 'long'
- \ : 'short'
- call s:RedisplayHelp(self)
- endfunction
-
- function! lh#buffer#dialog#new(bname, title, where, support_tagging, action, choices)
-
- let res = {}
- let where_it_started = getpos('.')
- let where_it_started[0] = bufnr('%')
- let res.where_it_started = where_it_started
-
- try
- call lh#buffer#scratch(a:bname, a:where)
- catch /.*/
- echoerr v:exception
- return res
- endtry
- let res.id = bufnr('%')
- let b:NbTags = 0
- let b:dialog = res
- let s:LHdialog[res.id] = res
- let res.help_long = []
- let res.help_short = []
- let res.help_type = 'short'
- let res.support_tagging = a:support_tagging
- let res.action = a:action
- let res.choices = a:choices
-
-
- call lh#buffer#dialog#add_help(res, '@| <cr>, <double-click> : select this', 'long')
- call lh#buffer#dialog#add_help(res, '@| <esc>, q : Abort', 'long')
- if a:support_tagging
- call lh#buffer#dialog#add_help(res, '@| <t>, <space> : Tag/Untag the current item', 'long')
- endif
- call lh#buffer#dialog#add_help(res, '@| <up>/<down>, <tab>, +/- : Move between entries', 'long')
- call lh#buffer#dialog#add_help(res, '@|', 'long')
-
- call lh#buffer#dialog#add_help(res, '@+'.repeat('-', winwidth(bufwinnr(res.id))-3), 'long')
-
-
- call lh#buffer#dialog#add_help(res, '@+'.repeat('-', winwidth(bufwinnr(res.id))-3), 'short')
-
- let res.toggle_help = function("lh#buffer#dialog#toggle_help")
- let title = '@ ' . a:title
- let helpstr = '| Toggle (h)elp'
- let title = title
- \ . repeat(' ', winwidth(bufwinnr(res.id))-lh#encoding#strlen(title)-lh#encoding#strlen(helpstr)-1)
- \ . helpstr
- call s:Display(res, title)
-
- call s:Mappings(res)
- return res
- endfunction
-
- function! lh#buffer#dialog#add_help(abuffer, text, help_type)
- call add(a:abuffer['help_'.a:help_type],a:text)
- endfunction
-
-
- function! lh#buffer#dialog#quit()
- let bufferId = b:dialog.where_it_started[0]
- echohl WarningMsg
- echo "Abort"
- echohl None
- quit
- call lh#buffer#find(bufferId)
- endfunction
-
-
- function! lh#buffer#dialog#select(line, bufferId, ...)
- if a:line == -1
- call lh#buffer#dialog#quit()
- return
-
- elseif a:line <= s:Help_NbL()
- echoerr "Unselectable item"
- return
- else
- let dialog = s:LHdialog[a:bufferId]
- let results = { 'dialog' : dialog, 'selection' : [] }
-
- if b:NbTags == 0
-
-
- let results.selection = [ a:line - s:Help_NbL() - 1 ]
- else
- silent g/^* /call add(results.selection, line('.')-s:Help_NbL()-1)
- endif
- endif
-
- if a:0 > 0
- exe 'call '.dialog.action.'(results, a:000)'
- else
- exe 'call '.dialog.action.'(results)'
- endif
- endfunction
- function! lh#buffer#dialog#Select(line, bufferId, ...)
- echomsg "lh#buffer#dialog#Select() is deprecated, use lh#buffer#dialog#select() instead"
- if a:0 > 0
- exe 'call lh#buffer#dialog#select(a:line, a:bufferId, a:1)'
- else
- exe 'call lh#buffer#dialog#select(a:line, a:bufferId)'
- endif
- endfunction
-
- function! Action(results)
- let dialog = a:results.dialog
- let choices = dialog.choices
- for r in a:results.selection
- echomsg '-> '.choices[r]
- endfor
- endfunction
-
-
-
- let &cpo=s:cpo_save
-
|