NB. provides jpick form
NB. built from project: ~Source\classes\pick\pick
NB. provides jpick form
NB.
NB. methods:
NB.   create
NB.   destroy
NB.
NB. on exit calls return verb in creator locale,
NB. with argument of selection or '' if none
NB.
NB. y. is a boxed list of at 4 elements:
NB.   0  boxed list of choices
NB.   1  initial selections
NB.   2  title
NB.   3  return verb
NB.   4  options
NB.    0  0 = fixed, 1 = proportional font
NB.    1  tabstop

coclass 'jpick'


RETURN=: ''

todelim=: ; @: ((EAV&,) @ (,&EAV) @ , @ ": &.>)

NB. =========================================================
NB.*create v create pick form
create=: jpick_run

NB. =========================================================
NB.*destroy v destroy pick form
destroy=: 3 : 0
wd 'pclose'
codestroy''
)

NB. pick

NB. =========================================================
JPICK=: 0 : 0
pc jpick nomin owner;
xywh 0 0 160 146;cc lb listbox ws_vscroll rightmove bottommove;
pas 0 0;pcenter;ptop;
rem form end;
)

NB. =========================================================
jpick_run=: 3 : 0
'sel init title return opts'=. 5 {. y.
'font tab'=. 2 {. opts, 0
RETURN=: (return -.' '),'__COCREATOR'
wd JPICK
wd 'pn *',title
wd 'setfont lb ',font pick FIXFONT;PROFONT
if. tab  do.
  wd 'settabstops lb ',": tab
end.
wd 'set lb ',todelim sel
if. #init do.
  wd 'setselect lb ',":init
end.
wd 'setfocus lb'
wd 'pshow'
)

NB. =========================================================
jpick_enter=: jpick_close=: jpick_lb_button=: jpickdo bind 1
jpick_cancel=: jpickdo bind 0

NB. =========================================================
NB. jpickdo 0 = cancel, 1 = success
NB. calls pick_result
jpickdo=: 3 : 0
res=. ''
if. y. do.
  sel=. lb_select
  if. #sel do.
    res=. {. 0 ". sel
  end.
end.
destroy''
try. RETURN~ res catch. end.
)
