Frame definition files

Creating a dynamic menu

Now let us take a look at some more complex menus. This example shows how to pass parameters from one frame to another and how to create a menu dynamically. The example application will allow users to edit menu, form, and text frame definition files stored in the same directory. The application displays a ``top menu'' from which the user can select the type of frame definition file to edit:

   menu="Edit Files"

name="Menu Files" action=open Menu.dynamic Menu

name="Form Files" action=open Menu.dynamic Form

name="Text Files" action=open Menu.dynamic Text

name="Exit" action=exit

Menu.edit: an example of a dynamically created menu

This menu definition file creates the following menu:

Menu.edit: screen output

From this menu a user can choose to see a menu of menu frame definition files, form definition files, or text frame definition files. The action defined for all three menu items results in the same frame definition file being opened: Menu.dynamic. The last argument to the open command is a parameter that is passed to Menu.dynamic. ``Menu.dynamic: an example of a dynamically created menu'' shows the contents of Menu.dynamic:

   menu="$ARG1 Files"

`ls | regex '^('$ARG1'.*)$0$' '

name="$m0" action=`run '$EDITOR' "$m0"`' nop`

Menu.dynamic: an example of a dynamically created menu

Menu.dynamic is a dynamically built menu that uses regex. The parameter passed to Menu.dynamic by the open command is used to build a unique title for the new menu. The items on this menu are created by a stand-alone backquoted expression. Recall that stand-alone backquoted expressions are evaluated when the frame definition file is opened, reread, or updated. That means that when Menu.dynamic is opened in this case, the ls command is run in the current directory, and its output is piped to the FMLI built-in utility regex.

The regex utility is used for pattern matching. Since this single regex pattern matches only files that begin with $ARG1, only files in the directory that have the name defined by the parameter, followed by a literal dot (.), then by any other characters, are included in the list of menu items. The menu definition file Menu.dynamic will create one of the three menus, based on the parameter that is passed to it. The items in the menu it creates are based on the files whose names match the pattern being searched for by the regex utility. The menu item template defined in this menu definition file provides that the name descriptor has the value $m0, which evaluates to the pattern enclosed in parentheses (a filename) in the regex expression. The template provides that the action descriptor will invoke the defined editor on the file. All filenames matched by the regex utility are passed to this menu item template, FMLI determines the size and shape of the menu frame based on the total number of items produced, and the menu frame is posted.

For example, when Menu Files is selected from the menu titled Edit Files, Menu.dynamic receives the parameter Menu, regex searches for filenames beginning with Menu. (``menu dot''), and displays the following second menu:

Menu.edit: screen output when menu files is selected

By selecting the appropriate item from the Menu Files menu, the user is able to edit any of the menu, form, or text frame definition files in the directory. If one of these types of frame definition files is not present in the directory, the corresponding menu is not created.

Next topic: Form frame descriptors
Previous topic: screen output

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004