! menu maintenance
! 
! 
POSTDISPLAY:
OPEN (HFN,IOL=*)"*launch/tasks.dat"
FL_TRX=LFO
! 
OPEN (HFN,IOL=*)"*launch/menu.dat"
FL_MNU=LFO
! 
MNULIST_LOAD$=""
MNULIST_TBL$=""
! 
TRXLIST_LOAD$=""
! 
SELECT * FROM FL_TRX BEGIN ""
! 
IF TRXTYPE$="M" THEN BITMAP$="!File_copy"; MNULIST_LOAD$+=TRXNAME$+" - "+TRXDESC$+$00$; MNULIST_TBL$+=TRXRID$+$00$ ELSE BITMAP$="!+Process"
! 
IF MID(TRXNAME$,1,1)="*" THEN CONTINUE
! 
L$=TRXNAME$+SEP+BITMAP$+SEP+TRXDESC$+SEP+TRXRID$+SEP
! 
TRXLIST_LOAD$+=L$+$00$
! 
NEXT RECORD 
! 
LIST_BOX LOAD MNULIST.CTL,MNULIST_LOAD$
MNULIST.CTL'TBLWIDTH=0
MNULIST.CTL'TBL$=MNULIST_TBL$
! 
LIST_BOX LOAD TRXLIST.CTL,TRXLIST_LOAD$
! 
MNULIST$=""
LIST_BOX FIND MNULIST.CTL,1,MNULIST$,ERR=*NEXT
! 
IF MNULIST$<>"" THEN GOSUB LOAD_MNU
! 
MENU_CHGED=0
RETURN 
! 
WRAPUP:
GOSUB CHECK_CHANGE
RETURN 
! 
CHANGE_MNU:
GOSUB CHECK_CHANGE
GOSUB LOAD_MNU
! 
RETURN 
! 
RESET_MNU:
GOSUB LOAD_MNU
! 
RETURN 
! 
LOAD_MNU:
IF CURMNUTRXRID$<>"" AND CURMNUTRXRID$<>MNULIST$ THEN BACKLIST$=CURMNUTRXRID$+SEP+BACKLIST$
! 
MNUTRX_LOAD$=""
CURMNUTRXRID$=MNULIST$
! 
SELECT * FROM FL_MNU BEGIN CURMNUTRXRID$ END CURMNUTRXRID$:"9999"
READ (FL_TRX,KEY=TRXRID$,KNO="Refid",DOM=*NEXT)
! 
IF TRXTYPE$="M" THEN BITMAP$="!File_copy" ELSE BITMAP$="!+Process"
! 
MNUTRX_LOAD$+=TRXNAME$+SEP+BITMAP$+SEP+TRXDESC$+SEP+TRXRID$+SEP+$00$
NEXT RECORD 
! 
LIST_BOX LOAD MNUTRX.CTL,MNUTRX_LOAD$
MNUTRX$=""
! 
MENU_CHGED=0
RETURN 
! 
CHECK_CHANGE:
IF MENU_CHGED=0 THEN RETURN 
! 
MSGBOX "Record has been altered.  Do you wish to record the changes","Record Changed","?,YesNoCancel",_YESNO$
IF _YESNO$="CANCEL" THEN MNULIST$=CURMNUTRXRID$; IGNORE_EXIT=1; EXIT 
! 
IF _YESNO$="YES" THEN GOSUB SAVE_MENU
! 
RETURN 
! 
SAVE_MENU:
LIST_BOX FIND MNUTRX.CTL,0,X$
! 
MNUSEQ=0
MNUTRXRID$=CURMNUTRXRID$
! 
WHILE X$
O=POS($00$=X$)
READ DATA FROM X$(1,O-1) TO TRXNAME$,BITMAP$,*,TRXRID$
X$=X$(O+1)
! 
MNUSEQ++
MNUSEQ$=STR(MNUSEQ:"00")
! 
WRITE (FL_MNU)
WEND 
! 
WHILE 1
MNUSEQ++
MNUSEQ$=STR(MNUSEQ:"00")
REMOVE (FL_MNU,KEY=MNUTRXRID$:MNUSEQ$,DOM=*BREAK)
WEND 
! 
MENU_CHGED=0
RETURN 
! 
SELECT_TRX:
IF _EOM$<>$0D$ AND _EOM$<>$02$ THEN RETURN 
! 
X=MNUTRX.CTL'CURRENTITEM
IF X>0 THEN X++
! 
GOTO ADD_TRX
! 
DROP_TRX:
X=MNUTRX.CTL'DROPPEDON
! 
ADD_TRX:
READ DATA FROM TRXLIST$ TO *,*,*,TRXRID$
GOSUB CHECK_CONFLICT
! 
LIST_BOX LOAD MNUTRX.CTL,X,TRXLIST$
MENU_CHGED++
! 
RETURN 
! 
SELECT_MNU:
IF _EOM$<>$0D$ AND _EOM$<>$02$ THEN RETURN 
SELECT_MENU_DO:
X$=ARG(MNUTRX$,1)
IF X$="" THEN RETURN 
! 
READ (FL_TRX,KEY=X$,KNO=0,DOM=*RETURN)
IF TRXTYPE$<>"M" THEN RETURN 
! 
DROP_BOX WRITE MNULIST.CTL,TRXRID$,ERR=*RETURN
MNULIST$=TRXRID$
GOSUB CHECK_CHANGE
GOSUB LOAD_MNU
RETURN 
! 
DO_BACK:
O=POS(SEP=BACKLIST$)
IF O=0 THEN RETURN 
! 
B$=BACKLIST$(O+1)
MNULIST$=BACKLIST$(1,O-1)
! 
GOSUB CHECK_CHANGE
GOSUB LOAD_MNU
! 
BACKLIST$=B$
RETURN 
! 
DELETE_MNU:
X=MNUTRX.CTL'CURRENTITEM
IF X<>0 THEN LIST_BOX LOAD MNUTRX.CTL,X,*
! 
MNUTRX$=""
MENU_CHGED++
RETURN 
! 
MOVE_TRX:
FROM=MNUTRX.CTL'CURRENTITEM
TO=MNUTRX.CTL'DROPPEDON
! 
IF FROM=TO THEN RETURN 
! 
LIST_BOX FIND MNUTRX.CTL,FROM,L$
LIST_BOX LOAD MNUTRX.CTL,FROM,*
! 
IF FROM<TO THEN TO--
! 
LIST_BOX LOAD MNUTRX.CTL,TO,L$
! 
MENU_CHGED++
RETURN 
CHECK_CONFLICT:
LOCAL CHKNAME$
LOCAL CHKDESC$
! 
READ (FL_TRX,KEY=TRXRID$,KNO="RefId",DOM=*RETURN)
IF TRXTYPE$<>"M" THEN RETURN 
! 
IF TRXRID$=CURMNUTRXRID$ THEN MSGBOX "Cannot add menu to itself","Rejected","!"; EXIT 
! 
CHKNAME$=TRXNAME$
CHKDESC$=TRXDESC$
! 
GOSUB CHECK_SUBMENUS
! 
RETURN 
! 
CHECK_SUBMENUS:
LOCAL MNUSEQ
LOCAL CHKRID$=TRXRID$
LOCAL CURNAME$=TRXNAME$
! 
WHILE 1
MNUSEQ++
MNUSEQ$=STR(MNUSEQ:"00")
! 
READ (FL_MNU,KEY=CHKRID$:MNUSEQ$,KNO=0,DOM=*BREAK)
IF TRXRID$=CURMNUTRXRID$ THEN MSGBOX "Cannot add '"+CHKNAME$+"' because the sub-menu "+CURNAME$+" includes this menu and would result in recursive loop.","Rejected","!"; EXIT 
! 
READ (FL_TRX,KEY=TRXRID$,KNO="Refid",DOM=*CONTINUE)
IF TRXTYPE$="M" THEN GOSUB CHECK_SUBMENUS
! 
WEND 
RETURN 
