Progress
Language Tutorial
for Character


Assigning Triggers to Menu Items

To associate functionality with menu items, you use triggers. As with buttons, the key event to attach a trigger to is CHOOSE. Typically, the content of a trigger for a menu item is a RUN statement calling an internal or external procedure, as shown in the example below:

/**********  DEFINE TRIGGERS  **********/
ON CHOOSE OF MENU-ITEM mi-Labels IN MENU sm-Reports
DO:
    RUN Display-Labels.
END. 

Another typical function found on a menu is the Exit command. Throughout the tutorial, you’ve used a button labeled “Exit” and used the CHOOSE event of the Exit button as the condition that satisfies the WAIT-FOR statement. When the user chooses Exit, the flow of control goes past the WAIT-FOR. If the WAIT-FOR is the last statement in the procedure, the procedure ends.

You can easily replace this functionality with an Exit command on the menu bar. By convention, the Exit command is always the last menu item on the first submenu of a menu bar. If you add this menu item to your menu bar, then you could use the following WAIT-FOR statement to block the application:

/**********  MAIN LOGIC  *********/
WAIT FOR CHOOSE OF MENU-ITEM mi-Exit IN MENU mbar.  

In reality, closing down an application often requires some clean up. While still using the CHOOSE event of the Exit command as your WAIT-FOR condition, you can write a trigger for the same event to do your clean-up. Then, as a last step, you could close the window and end the application, as shown in the following example:

/**********  DEFINE TRIGGERS  *********/
ON CHOOSE OF MENU-ITEM mi-Exit IN MENU mbar
DO:
    /* Clean up Code */
    APPLY "CLOSE-WINDOW" TO DEFAULT-WINDOW.
END. 

CLOSE WINDOW is a Progress event function that executes for any event that equates to dismissing a window.

For a complete discussion of triggers and trigger programming techniques, see the Progress Programming Handbook .

Referencing Menus

Each menu and submenu must have a unique name. To reference the menu or submenu, precede the reference with the keyword MENU. To reference a menu item, precede the reference with the keyword MENU-ITEM. Menu items do not have to have unique names. In situations where ambiguity arises, you must extend the menu item reference to include the IN MENU option.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095