/* InputOutput Editor - DMS - march 98 - by Sylvain HUET */
/* Rev. 1.2 - Sep. '98 - by Marc BARILLEY */
/* Rev - Apr 99 - by Sebastien DENEUX*/

typeof bannerll = ObjText;;
typeof ll=ObjList;;
typeof addll = ObjButton;;
typeof delll = ObjButton;;
typeof links=[S r1];;
typeof editWin=ObjWin;;

fun updatel2(s,b)=
 _ADDlist ll 1000 s;;

fun updatel()=
 _RSTlist ll;
 apply_on_list links @updatel2 0;;

fun addr(s)=
 if (s==nil) || (!strcmpi s "in") then nil
 else
 (set links=listcat links s::nil;
  updatel);;

fun _add(a,b)=
/* loc( iniEnterBox _channel editWin nil nil "New Event" @addr "Enter a new event name" ;; ) */
 iniEnterBox _channel editWin nil nil (_locEditor "250-IOEDIT-newevent" nil) @addr (_locEditor "251-IOEDIT-enteranewe" nil) ;;

fun _rem(x,b)=
 let _GETlist ll ->[i _] in
 let nth_list links i -> a in
 if a==nil then nil else
 (set links=remove_from_list links a;
  updatel);;

fun fdlink(a,b)=
 if (strcmp hd a "eventC") || (!strcmp hd tl a "in") then 0
 else (set links=listcat links (hd tl a)::nil; 0);;

/* SCS editor */
fun suppevent(l)=
  if l==nil then nil
  else let l->[a n] in ("eventC"::a::nil)::suppevent n;;

fun save (filename, n)=
  ("event"::"log"::"log"::nil)::
  ("eventC"::"in"::"in"::nil)::
  ("action"::"start"::"start"::nil)::
  ("action"::"openUrl"::nil)::
  ("action"::"gotoUrl"::nil)::
  ("action"::"activeX"::nil)::
  ("action"::"openUser"::nil)::
  ("rule"::"1"::"In/Out"::"0"::"Log"::"1"::"log"::nil)::
  suppevent links;;

fun load (l)=
  set links=nil;
  apply_on_list l @fdlink 0;
  updatel;;

fun rflSizeEditWin (wn, blurp, w, h)=
  _SIZEtext bannerll w-10 15 5 10;
  _SIZElist ll w-10 h-60 5 30;
  _SIZEbutton addll 45 20 5 h-25;
  _SIZEbutton delll 45 20 70 h-25;;

fun IniEditor (s)=
  let [315 125] -> [w h] in
  let startEditor
    _channel nil nil nil w h WN_NORMAL EDITOR_NORMAL
    s "Dms/CommTools/Io/io.dmc" nil nil
    @load @save nil
  -> ed in
  (
    set editWin = getEditWin ed; 
    
    _CBwinSize editWin @rflSizeEditWin 0;
  
/* loc(    set bannerll = _CRtext _channel editWin 5 10 w-10 15 ET_ALIGN_CENTER "ActiveX events :"; ) */
    set bannerll = _CRtext _channel editWin 5 10 w-10 15 ET_ALIGN_CENTER (_locEditor "770-IOEDIT-activexeve" nil);
    set ll=_CRlist _channel editWin 5 30 w-10 h-60 LB_DOWN+LB_VSCROLL;
/* loc(    set addll = _CBbutton _CRbutton _channel editWin 5 h-25 45 20 0 "Add" @_add 0; ) */
    set addll = _CBbutton _CRbutton _channel editWin 5 h-25 45 20 0 (_locEditor "790-IOEDIT-add" nil) @_add 0;
/* loc(    set delll = _CBbutton _CRbutton _channel editWin 70 h-25 45 20 0 "Remove" @_rem 0; ) */
    set delll = _CBbutton _CRbutton _channel editWin 70 h-25 45 20 0 (_locEditor "800-IOEDIT-remove" nil) @_rem 0;
  
    if s==nil then nil else openDMI ed
  );
0;;