GRIDPLUS2 - Menu
Home Reference Manpage Examples Download License Contact

GRIDPLUS Menu

In order to simplify creation of screen layouts, GRIDPLUS provides a GRIDPLUS menu command mode. This uses a simple syntax to create a menubar and cascaded menus.

This command mode is also used to create menus for the menubutton command mode -and- the right-click pop-up menus for tablelist and tree command modes.

If the name parameter supplied to the a menu command mode identifies a toplevel window a menubar is created, otherwise a "named" (cascadable) menu is created.

GRIDPLUS Menu Layout

The menu layout defines a list of menu options. The layout list consists of pairs of items, which can have either of the following formats:-

Menu Accelerator Keys

GRIDPLUS provides a simple method to define menu accelerator keys.

The key to be used as the accelerator key should be prefixed with an underline character.

Example:

gridplus menu . {
   Menu_1 {
      {"Option _One"}
      {"Option _Two"}
   }
   Menu_2 {
      {"Option _Three"}
      {"Option _Four"}
   }
}

Pressing the "Alt" key will display...

Pressing the "1" key will display...

To invoke menu "Option Two" - Press the "t" key.

GRIDPLUS Menu Item Options

.name
The name of the command to be invoked (Optional).

~name
The name of the command to be invoked (Optional). This is the preferred method as it is consistant with Widget Grid.

:icon
The name of the icon to be used for the menu item. (Example: :filesave16).

%group
The name of the group to which menu option belongs (Example: %mygroup1).

<
Create widget with disabled state. Overrides -state option.

>
Create widget with normal state. Overrides -state option.

!
Specifies that entry validations are to be perfomed (for the window containing the menu) prior to evaluating the command.

-
Specifies that a separator line is displayed.

=
Specifies that a separator line is displayed. This is the preferred method as it is consistant with Widget Grid/Layout.

@name
Specifies menu name will cascade from this entry (Example: @mymenu).

Example

This section contains an example which illustrates the main GRIDPLUS menu command mode features.

The following example assumes that the reader is familiar with the contents of the Grid/Layout page. Information given on that page will not be duplicated here.

Note: The example assumes that the gridplus package has already been "required" and the commands imported.


Menu Example

Window:

With "Menu1" selected...

With "Menu2" selected...

Source Code:

gridplus menu .mymenu {
   ~ {"Cascade Option 1"}
   ~ {"Cascade Option 2" ~mycascade2}
}

gridplus menu . {
   Menu1 {
      {Option1}
      {Option2}
   }

   Menu2 {
      {Option3 ~myoption3 :filesave16}
      {Option4 ~myoption4 :edit16}
   }

   Menu3 {
      {"Option Five"}
      {"Option Six" @mymenu}
      =
      {"Option Seven"}
   }

   ~ {"Menu4" ~menu_four}
}

gridplus grid .text -padding 35 -wtitle "Menu Example" {
   {"^This is a Window with a four option menubar"}
}

pack .text

Comments:

When using the GRIDPLUS menu command mode each Menu consists of a menu name followed by a list of menu options.

By default, When a menu option is selected a command is invoked which as a name based on the name of the menubar, the menu name and the option label text. The menu name and the option label text are converted to lowercase and spaces are replaced by underscores.

For Example: When "Option Five" is select from "Menu3", the name of the command invoked will be "menubar:menu3,option_five".

It is also possible to invoke a specific command by specifying a "~" prefixed command name.

For Example: When "Option3" is select from "Menu2", the name of the command invoked will be "myoption3".

"Menu3" demontrates that menu option labels containg spaces must be enclosed in quotes.

Specifying an "equal" symbol ("=") instead of a menu option displays a dividing line in the menu:-


Copyright © 2008 Adrian Davis.