home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / workbench / appmenuitem.e < prev    next >
Text File  |  1977-12-31  |  3KB  |  69 lines

  1. -> appmenuitem.e -- Show use of an AppMenuItem
  2.  
  3. OPT OSVERSION=37
  4.  
  5. MODULE 'wb',
  6.        'dos/dostags',
  7.        'workbench/startup',
  8.        'workbench/workbench'
  9.  
  10. ENUM ERR_NONE, ERR_APPMENU, ERR_LIB, ERR_PORT
  11.  
  12. RAISE ERR_APPMENU IF AddAppMenuItemA()=NIL,
  13.       ERR_LIB     IF OpenLibrary()=NIL,
  14.       ERR_PORT    IF CreateMsgPort()=NIL
  15.  
  16. PROC main() HANDLE
  17.   DEF myport=NIL, appitem=NIL,
  18.       appmsg=NIL:PTR TO appmessage, result, x, count=0, file
  19.   workbenchbase:=OpenLibrary('workbench.library', 37)
  20.   -> The CreateMsgPort() function is in Exec version 37 and later only
  21.   myport:=CreateMsgPort()
  22.   -> Add our own AppMenuItem to the Workbench Tools Menu
  23.   appitem:=AddAppMenuItemA(0,                   -> Our ID# for item
  24.                           'SYS:Utilities/More', -> Our UserData
  25.                           'Browse Files',       -> MenuItem Text
  26.                            myport, NIL)         -> MsgPort, no tags
  27.  
  28.   WriteF('Select Workbench Tools demo menuitem "Browse Files"\n')
  29.  
  30.   -> For this example, we allow the AppMenuItem to be selected only once,
  31.   -> then we remove it and exit
  32.   WaitPort(myport)
  33.   WHILE (appmsg:=GetMsg(myport)) AND (count<1)
  34.     -> Handle messages from the AppMenuItem - we have only one item so we don't
  35.     -> have to check its appmsg.id number.  We'll System() the command string
  36.     -> that we passed as userdata when we added the menu item.  We find our
  37.     -> userdata pointer in appmsg.userdata
  38.  
  39.     WriteF('User picked AppMenuItem with \d icons selected\n', appmsg.numargs)
  40.     FOR x:=0 TO appmsg.numargs-1
  41.       WriteF('  #\d name="\s"\n', x+1, appmsg.arglist[x].name)
  42.     ENDFOR
  43.  
  44.     INC count
  45.     IF file:=Open('CON:0/40/640/150/AppMenu Example/auto/close/wait', OLDFILE)
  46.       result:=SystemTagList(appmsg.userdata, [SYS_INPUT,  file,
  47.                                               SYS_OUTPUT, NIL,
  48.                                               SYS_ASYNCH, TRUE, NIL])
  49.       -> If Asynch System() itself fails, we must close file
  50.       IF result=-1 THEN Close(file)
  51.     ENDIF
  52.     ReplyMsg(appmsg)
  53.   ENDWHILE
  54.  
  55. EXCEPT DO
  56.   IF appitem THEN RemoveAppMenuItem(appitem)
  57.   IF myport
  58.     -> Clear away any messages that arrived at the last moment
  59.     -> and let Workbench know we're done with the messages
  60.     WHILE appmsg:=GetMsg(myport) DO ReplyMsg(appmsg)
  61.     DeleteMsgPort(myport)
  62.   ENDIF
  63.   IF workbenchbase THEN CloseLibrary(workbenchbase)
  64.   SELECT exception
  65.   CASE ERR_APPMENU; WriteF('Error: Could not attach AppMenuItem to Workbench\n')
  66.   CASE ERR_LIB;     WriteF('Error: Could not open workbench.library\n')
  67.   CASE ERR_PORT;    WriteF('Error: Could not create port\n')
  68.   ENDSELECT
  69. ENDPROC