Define Dynamic Menus

You can dynamically control the content of a drop-down or pop-up menus using ProcScript. First define a menu containing a menu item of type Dynamic Menu, then build the dynamic menu in the preDisplay trigger, and handle the use selection of an item in the option trigger.

Create a menu that will contain the dynamic menu. For more information, seeDefine and Use Menus.

  1. Insert a menu item of type Dynamic Menu at the desired location in the menu.

    This acts as a placeholder for the dynamic menu and provides a location for the ProcScript required to generate the menu options and program their behavior.

  2. Edit the preDisplay trigger of the dynamic menu placeholder.

    Generate a nested associative list with the contents of the dynamic menu and insert it using the $inlinemenu ProcScript function.

    For example:

    1. Define the first menu item by building a list of properties. For more information, see $inlinemenu.
    2. Add the menu item to the list of options for the dynamic menu. Each menu option must have an identifier, which can be used in the option trigger to define its behavior. In this case, it is A.
    3. Build a list of properties for the second menu item.
    4. Add the second item to the list of options for the dynamic menu as B.
    ; trigger preDisplay ; of dynamic menu placeholder
    variables
      string vMenuItem
    endvariables
    
    ; Callout 1 Define a dynamic menu item               
    putitem/id vMenuItem, "TYPE", "Option"
    putitem/id vMenuItem, "TEXT", "Option % A"
    putitem/id vMenuItem, "IMAGE","@ball.png"
    
    ; Callout 2 Add it to the dynamic menu 	           
    putitem/id $inlinemenu, "A", vMenuItem    
    
    ; Callout 3 Define another menu item                
    putitem/id vMenuItem, "TYPE", "Option"
    putitem/id vMenuItem, "TEXT", "Option B"
    putitem/id vMenuItem, "CHECKED", "T"
    
    ; Callout 4 Add it to the dynamic menu 
    putitem/id $inlinemenu, "B", vMenuItem    
    
    end; predisplay
  3. Edit the option trigger of the dynamic menu placeholder.

    Add ProcScript to determine which menu item was selected by the user and to perform the corresponding action.

    For example, the following code displays a message indicating which menu item has been selected:

    ;trigger option
    ;Input parameter contains the identifier of the selected menu item
    params
       string strId : IN
    endparams
    
    ;Obtain the id of selected menu item and perform the associated action 
    selectcase strId
       case "A"
            message/info "Option A selected"
       case "B"
            message/info "Option B selected"
    endselectcase
    end; select
  4. Compile the menu.

Related Topics