This file documents the new [menuRef] command in version 8.2a1d5 of AlphaX.
The [menuRef] command lets you create and manipulate menus in
Alpha. Menu items can be manipulated using the new [menuItem]
command (see the MenuItemCommand page on this wiki). Both
commands could constitute a replacement for the old [Menu] command.
The formal syntax of the [menuRef] command is:
menuRef subcommand ?options?
The possible subcommands are described below. Depending on the subcommand,
various options can be additionnally specified.
The [clear] subcommand
This subcommand removes all the items from a menu. The syntax is:
menuItem clear token
To remove only one item from a menu list, use the [menuRef delete] command.
The [count] subcommand
This subcommand returns the number of menu items in a menu. The syntax is:
menuItem count token
The [create] subcommand
This subcommand creates a new menu. It accepts
a few options. The complete syntax is:
menuRef create ?-attributes val? ?(-icon code|-title name)? ?-command name?
The [menuRef create] command returns a token used in the other
subcommands (as well as with the [menuItem] command) to uniquely
identify the menu.
Here is the description of the various options:
- the -attributes option lets you specify some attributes for the menu. The default value is 0. The value passed in the -attributes option is additive. It is the sum of base-2 constants. The only values of interest could be:
|1||ExcludesMarkColumn||No column space is allocated for the mark character when this menu is drawn.|
|4||AutoDisable||The menu title is automatically disabled when all items are disabled.|
|16||Hidden||The menu title is not drawn in the menubar, even when the menu is inserted in the menubar. Useful for adding command keys that don't correspond to a visible menu item; menu items with the desired command keys can be added to the menu and inserted in the menubar without making the menu visible.|
|32||CondenseSeparators||If menu item separators are present at the beginning or end of the menu, or if multiple contiguous separators are present, the extra separator items are marked as hidden to avoid extra blank space in the menu. The menu is examined for extra separators whenever the menu size is recalculated.|
- the -command option lets you specify the name of the Tcl proc to execute when an item is selected in this menu. Alpha will invoke this command with two arguments: the token of the menu and the index of the selected item (to get the text of the item use the [menuItem set -text] command).
- the -icon option lets you specify a four character code corresponding to a registered icon reference in order to set the title of the menu to be an icon: see the IconrefCommand documentation on this wiki. The -icon and the -title options are mutually exclusive.
- the -keyMatching option lets you enable or disable key matching for the entire menu. By default, this option is set to 1 and key matching is performed when the menu is opened: this means that, for each menu item, Alpha will check if there is a binding associated with the action attached to the menu item. To speed things up, you can disable key matching in menus where you do not want items to have a keyboard shortcut, or if you know that no items have a shortcut (for instance, in the menus representing a fileset).
- the -name option lets you change the name of the menu. This option is provided only for compatibility reasons: the previous menu syntax identified menus by name. By default, the name field of a menu created with the new syntax contains the menu token. Under some circumstances, one might want to modify the name of the menu to ensure that a menu created with the new syntax can be found by procs using the old syntax.
- the -title option lets you specify the title of the menu. The -icon and the -title options are mutually exclusive.
- the -updateProc option lets you specify a Tcl procedure to evaluate before a menu is opened. This can be useful when the contents of a menu has to be adjusted before it is displayed: depending on the context, one might want to enable or disable some items, add or remove items, or even rebuild the menu entirely. When the procedure declared by this option is invoked, the token of the menu is appended to its list of arguments. Note that the procedure is only invoked once per menu tracking session for a given menu, even if that menu is closed and opened multiple times by the user. In order to remove such a procedure, use the [menuRef set] command and pass an empty string for this option.
The [delete] subcommand
This subcommand lets you delete a menu. The syntax is:
menuRef delete token
The token associated with this menu is not valid anymore and is removed from
the list returned by the [menuRef list] command.
The [hilite] subcommand
This subcommand lets you hilite/unhilite a menu. The syntax is:
menuRef hilite token (0|1)
The [insert] subcommand
This subcommand lets you insert a menu in the menu bar. The syntax is:
menuRef insert token ?-before token?
The -before option lets you specify the token of another menu
before which the menu must be inserted in the menu bar. If unspecified, the
menu is appended at the right of the menu bar (yet before the Help menu).
The [items] subcommand
This subcommand returns a list of all the items currently present in the
menu, in the index order. The syntax is:
menuRef items token
This command should not be confused with the [menuRef list] command which
returns the current list of menus.
The [list] subcommand
This subcommand returns a list of the tokens corresponding to the currently
existing menus. Each time a new menu is created, its
token is appended at the end of the list, so this list is ordered from the
oldest to the newest menu. The syntax is:
The [remove] subcommand
This subcommand lets you remove a menu from the menu bar. The syntax is:
menuRef remove token
The menu is removed but not deleted: its token remains valid.
The [set] subcommand
This subcommand lets you get or set some properties of a menu. The syntax can take two forms:
menuRef set token option
menuRef set token option value ?option value...?
In the first form the command returns the current value of the specified
In the second form, it lets you set the value of one or several options.
The available options are exactly the same as with the [menuRef create] command.
There are two special menus provided by the system: the application menu
(which starts with the About Alpha item) and the help menu. Both
menus can be targetted by the [menuRef] and [menuItem] commands using the
"application" and "help" symbolic names in place of the
token. For instance:
menuRef count help
The application also provides a symbolic token "contextual" to
designate the contextual menu which is displayed when the user
control-clicks on a document window (see the ContextualModules page on this wiki).
These menus cannot be deleted or removed using the [menuRef delete] and
[menuRef remove] commands.
See a series of sample instructions on the
page on this wiki.
(add your comments here...)