Recent Changes - Search:

WikiDoc

Categories

The [menuItem] command

Commands.MenuItemCommand History

Hide minor edits - Show changes to markup

October 24, 2009, at 07:43 AM by bd - Unified -mark and -unimark
Changed lines 134-135 from:
  • the -mark option lets you specify a symbol to use as a mark before the menu item: this symbol can be any Unicode character. It can be specified as a string if it is a simple MacRoman character or using the \u escape sequence for any code-point in the BMP (between 0x0000 and 0xFFFF): for instance, "*" and \u2022 are equivalent. To insert or remove a check mark, one can also use the [menuItem check] command directly.
to:
  • the -mark option lets you specify a symbol to use as a mark before the menu item: this symbol can be any Unicode character. It can be specified as a string if it is a simple MacRoman character or using the \u escape sequence for any code-point in the BMP (between 0x0000 and 0xFFFF): for instance, for a bullet "*" and \u2022 are equivalent. To insert or remove a check mark, one can also use the [menuItem check] command directly.
October 24, 2009, at 07:42 AM by bd - Unified -mark and -unimark
Changed line 50 from:

with the -mark switch.

to:

with the -mark option.

Changed lines 134-135 from:
  • the -mark option lets you specify a symbol to use as a mark before the menu item: the symbol is any character in MacRoman encoding. If you want to insert a Unicode character, use the -unimark option instead. To insert or remove a check mark, one can also use the [menuItem check] command directly.
to:
  • the -mark option lets you specify a symbol to use as a mark before the menu item: this symbol can be any Unicode character. It can be specified as a string if it is a simple MacRoman character or using the \u escape sequence for any code-point in the BMP (between 0x0000 and 0xFFFF): for instance, "*" and \u2022 are equivalent. To insert or remove a check mark, one can also use the [menuItem check] command directly.
Deleted lines 167-168:
  • the -unimark option lets you specify a symbol to use as a mark before the menu item: this symbol can be any Unicode character designated with the \u escape sequence. The -mark and the -unimark options are mutually exclusive: the -unimark option has precedence over the -mark option.
October 23, 2009, at 03:08 PM by bd - Example of -unimark
Changed lines 221-223 from:
     menuItem set $iconMenu 1 -mark *
to:
     # Put a Unicode mark: 03A3 is the code-point of the Greek capital 
     # letter sigma.
     menuItem set $iconMenu 1 -unimark \u03A3
October 23, 2009, at 03:03 PM by bd - Documenting the -unimark option
Changed lines 134-135 from:
  • the -mark option lets you specify a symbol to use as a mark before the menu item. To insert or remove a check mark, one can also use the [menuItem check] command directly.
to:
  • the -mark option lets you specify a symbol to use as a mark before the menu item: the symbol is any character in MacRoman encoding. If you want to insert a Unicode character, use the -unimark option instead. To insert or remove a check mark, one can also use the [menuItem check] command directly.
Added lines 168-169:
  • the -unimark option lets you specify a symbol to use as a mark before the menu item: this symbol can be any Unicode character designated with the \u escape sequence. The -mark and the -unimark options are mutually exclusive: the -unimark option has precedence over the -mark option.
September 30, 2009, at 09:02 AM by bd - Removed experimental
Changed line 2 from:
This file documents the new [menuItem] command in version 8.2a1d4 of AlphaX. This is an experimental command proposed as a part of the bindings reform. It is open to discussion.
to:
This file documents the new [menuItem] command in version 8.2a1d4 of AlphaX.
December 02, 2007, at 06:57 PM by bd - menuItem index now has -nocase option
Changed line 60 from:
     menuItem index menu text ?-(exact|glob|regexp)? ?-all? ?-inline? ?-not?
to:
     menuItem index menu text ?-(exact|glob|regexp)? ?-all? ?-inline? ?-nocase? ?-not?
Added line 70:
-nocase
Causes comparisons to be handled in a case-insensitive manner.
March 27, 2007, at 07:32 AM by bd - Added options ?-(exact|glob|regexp)? ?-inline? ?-not? to [menuItem index]
Changed lines 56-58 from:

If you specify 0 or an index number greater than the last item in the menu, the command does not delete any item from the menu. This subcommand returns the index of a menu item. The first item is at index 0. The syntax is:

to:

If you specify 0 or an index number greater than the last item in the menu, the command does not delete any item from the menu.

The [index] subcommand

This subcommand returns the index of a menu item. The first item is at index 0. The syntax is:

March 27, 2007, at 07:30 AM by bd - Added options ?-(exact|glob|regexp)? ?-inline? ?-not? to [menuItem index]
Changed lines 56-60 from:

If you specify 0 or an index number greater than the last item in the menu, the command does not delete any item from the menu.

The [index] subcommand

This subcommand returns the index of a menu item specified by its text. The first item is at index 0. The syntax is:

to:

If you specify 0 or an index number greater than the last item in the menu, the command does not delete any item from the menu. This subcommand returns the index of a menu item. The first item is at index 0. The syntax is:

Changed line 58 from:
     menuItem index menu text ?-all? 
to:
     menuItem index menu text ?-(exact|glob|regexp)? ?-all? ?-inline? ?-not?
Changed lines 60-67 from:

In a properly designed menu, all the items should be different. It is possible though that, in some circumstances, several items have the same text: this could happen when the menu is built at runtime out of a list of arbitrary data which are not necessarily unique. In that case, one can specify the -all option in order to get a list of all the matching indices.

If the item is not found, the command raises an error.

to:

The -exact, -glob, and -regexp options let you specify how the text is to be matched against the menu items:

-exact
The text argument is a literal string that is compared for exact equality against each menu item.
-glob
The text argument is a glob-style pattern which is matched against each menu item using the same rules as the [string match] Tcl command.
-regexp
The text argument is treated as a regular expression.

If no matching style option is specified, the default is -glob.

The other options have the following signifcation:

-all
Return a list of all the matches rather than only the first one.
-inline
The matching value is returned instead of its index (or an empty string if no value matches.) If -all is also specified, then the result of the command is the list of all values that matched.
-not
This negates the sense of the match, returning the index of the first non-matching value in the list.

If no matching item is found, the command returns the value -1 if the option -all is not specified, or an empty list otherwise.

March 19, 2007, at 02:22 PM by bd - Fixed obsolete option in example
Changed line 207 from:
     menuItem append $iconMenu "item 5" -disabled 1
to:
     menuItem append $iconMenu "item 5" -enabled 0
Changed line 242 from:
     menuItem set $iconMenu 10 -indent 1
to:
     menuItem set $iconMenu 11 -indent 1
March 18, 2007, at 11:17 AM by bd - More info about menu indices
Deleted line 0:
Changed line 99 from:

Both the integer(]integer)? and the end([integer)?

to:

Both the integer((+|-)integer)? and the end((+|-)integer)?

March 18, 2007, at 11:15 AM by bd - More info about menu indices
Added line 1:
Changed lines 13-15 from:
to:
Changed line 61 from:

by its text. The first item is at index 1. The syntax is:

to:

by its text. The first item is at index 0. The syntax is:

Changed line 76 from:

item is inserted at the end of the menu. The first item is at index 1. The syntax is:

to:

item is inserted at the end of the menu. The first item is at index 0. The syntax is:

Added lines 92-107:

Menu item indices

The menu item indices are 0-based: the first item is at index 0 and the last item is at index count-1 where count is the number of items in the menu.

In the subcommands accepting an index argument ([check], [delete], [insert], and [set]), this argument can be expressed either as an integer or using the end keyword to designate the last item of the menu, as with the usual Tcl list commands. Both the integer(]integer)? and the end([integer)? formats are supported for the index argument.

Be aware, when using the end keyword, that this designates the last element of the complete list of items, that is to say the list returned by the [menuRef items] command, and it is not necessarily the one you see displayed when opening the menu since some items can be hidden or dynamic.

Changed line 109 from:

Menu item options

to:

Menu item options

Added line 115:
Added line 165:
Changed line 167 from:

Menu item shortcuts

to:

Menu item shortcuts

Changed line 181 from:

Examples

to:

Examples

Changed lines 216-218 from:
     menuItem set $iconMenu 1 -style 1
     menuItem set $iconMenu 2 -mark *
     menuItem set $iconMenu 3 -icon "ques"
to:
     menuItem set $iconMenu 0 -style 1
     menuItem set $iconMenu 1 -mark *
     menuItem set $iconMenu 2 -icon "ques"
Changed line 230 from:
     menuItem set $iconMenu 4 -enabled 0
to:
     menuItem set $iconMenu 3 -enabled 0
Changed line 243 from:
     menuItem set $iconMenu 11 -indent 1
to:
     menuItem set $iconMenu 10 -indent 1
Changed lines 245-246 from:
     # Hide the second item
     menuItem set $iconMenu 2 -hidden 1
to:
     # Hide the second item (its index is 1)
     menuItem set $iconMenu 1 -hidden 1
Changed line 249 from:
     menuItem set $iconMenu 2 -hidden 0
to:
     menuItem set $iconMenu 1 -hidden 0
Changed line 253 from:
     menuItem insert $iconMenu 1 "-40 degrees F" -ignoreMeta 1
to:
     menuItem insert $iconMenu 0 "-40 degrees F" -ignoreMeta 1
Changed line 256 from:
     menuItem delete $iconMenu 1
to:
     menuItem delete $iconMenu 0
Changed line 259 from:
     menuItem check $iconMenu 4 1
to:
     menuItem check $iconMenu 3 1
Changed line 262 from:
     menuItem set $iconMenu 4 -style 2
to:
     menuItem set $iconMenu 3 -style 2
Changed line 284 from:
     menuItem set $iconMenu 2 -submenu $testSubmenu
to:
     menuItem set $iconMenu 1 -submenu $testSubmenu
Changed line 287 from:
     menuItem set $iconMenu 2 -parentChoosable 1
to:
     menuItem set $iconMenu 1 -parentChoosable 1
Changed line 290 from:
     menuItem set $iconMenu 2 -submenu ""
to:
     menuItem set $iconMenu 1 -submenu ""
Changed line 306 from:

(add your comments here...)

to:

(add your comments here...)

March 18, 2007, at 07:41 AM by bd - Corrected syntax for [menuItem check]
Deleted line 0:
Changed line 46 from:
     menuItem check menu
to:
     menuItem check menu index (0|1)
March 17, 2007, at 01:02 PM by bd - Options of the [appen] and [insert] subcmds
Added line 1:
Changed lines 3-4 from:
This file documents the new [menuItem] command introduced in version 8.2a1d1 of AlphaX. This is an experimental command proposed as a part of the bindings reform. It is open to discussion.
to:
This file documents the new [menuItem] command in version 8.2a1d4 of AlphaX. This is an experimental command proposed as a part of the bindings reform. It is open to discussion.
Changed line 13 from:
to:
Changed line 41 from:
     menuItem append menu text ?attribute (0|1)...?
to:
     menuItem append menu text ?option value...?
Changed line 43 from:

The possible attributes are described in the Menu item attributes section below.

to:

The possible options are described in the Menu item options section below.

Changed line 62 from:
     menuItem index menu text ?-all?
to:
     menuItem index menu text ?-all? 
Changed line 68 from:

specify the -all option in order to get the list of all the

to:

specify the -all option in order to get a list of all the

Changed line 77 from:
     menuItem insert menu index text ?attribute (0|1)...?
to:
     menuItem insert menu index text ?option value...?
Changed line 79 from:

The possible attributes are described in the Menu item attributes section below.

to:

The possible options are described in the Menu item options section below.

Changed lines 90-97 from:

Here is the list of the available options:

to:

The possible options are described in the Menu item options section below.

Menu item options

The [menuItem append], [menuItem insert] and '''[menuItem set]''' commands accept many options to set their attributes and parameters. All these properties are specified by an option starting with a dash. Here is the list of the menu item options:

Added line 99:
Added line 101:
Added lines 103-105:
  • the -header option takes the values 0 or 1. When it is set to 1, any text in the item is ignored.
Added line 107:
Changed lines 109-111 from:
  • the -ignoreMeta option lets you set or unset the ignoreMeta attribute. See the Menu item attributes section below.
to:
  • the -ignoreMeta option lets you set or unset the ignoreMeta attribute. Set its value to 1 to ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)
Added line 113:
Added line 115:
Added line 123:
Added line 125:
Added lines 127-129:
  • the -separator option takes the values 0 or 1. If it is set to 1, the item is a horizontal separator. Note that, by convention, if the text of a menu item is a single dash, the item is automatically drawn as a separator: this is another way of creating a menu separator.
Added line 131:
Added line 143:
Added line 145:
Deleted lines 146-164:

Menu item attributes

The [menuItem append] and [menuItem insert] commands accept some attributes. All these attributes are specified by an option (starting with a dash) and followed by 0 or 1: they are set to zero by default.

Here is the list of the available attributes and their signification when the value is set to 1:

-disabled
This menu item is disabled
-dynamic
This menu item changes dynamically based on the state of the modifier keys.
-hidden
The menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the -dynamic attribute is set.
-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)
-notAlternate
This item is not part of the same dynamic group as the previous item.
-header
The menu item is a menu section header: this item is disabled and not selectable.
-separator
The menu item is a separator: any text in the item is ignored.
-parentChoosable
The user can select the parent item of a submenu.

Some of these attributes can be modified later using the [menuItem set] command.

Changed lines 191-196 from:
     set idx [menuItem append $iconMenu "dynamic 1" -dynamic 1]
     set idx [menuItem append $iconMenu "dynamic 2" -dynamic 1]
     menuItem set $iconMenu $idx -modifiers "o"
     set idx [menuItem append $iconMenu "dynamic 3" -notAlternate 1 -dynamic 1]
     set idx [menuItem append $iconMenu "dynamic 4" -dynamic 1]
     menuItem set $iconMenu $idx -modifiers "z"
to:
     menuItem append $iconMenu "dynamic 1" -dynamic 1
     menuItem append $iconMenu "dynamic 2" -dynamic 1 -modifiers "o"
     menuItem append $iconMenu "dynamic 3" -notAlternate 1 -dynamic 1
     menuItem append $iconMenu "dynamic 4" -dynamic 1 -modifiers "z"
March 03, 2007, at 02:31 PM by bd - New [menuItem index] subcommand
Added lines 70-71:

If the item is not found, the command raises an error.

March 03, 2007, at 02:17 PM by bd - Moved the ?-all? option
Changed line 62 from:
     menuItem index menu ?-all? text ?-all?
to:
     menuItem index menu text ?-all?
March 03, 2007, at 02:16 PM by bd - Moved the ?-all? option
Changed line 62 from:
     menuItem index menu ?-all? text 
to:
     menuItem index menu ?-all? text ?-all?
March 03, 2007, at 08:30 AM by bd - New [menuItem index] subcommand
Changed lines 10-14 from:
to:
Changed lines 58-61 from:

The [insert] subcommand

This subcommand lets you insert a new menu item with text at a specified index. If the index is greater than the number of items in the menu, the item is inserted at the end of the menu. The first item is at index 1. The syntax is:

to:

The [index] subcommand

This subcommand returns the index of a menu item specified by its text. The first item is at index 1. The syntax is:

Changed line 62 from:
     menuItem insert menu index text ?attribute (0|1)...?
to:
     menuItem index menu ?-all? text 
Added lines 64-76:

In a properly designed menu, all the items should be different. It is possible though that, in some circumstances, several items have the same text: this could happen when the menu is built at runtime out of a list of arbitrary data which are not necessarily unique. In that case, one can specify the -all option in order to get the list of all the matching indices.

The [insert] subcommand

This subcommand lets you insert a new menu item with text at a specified index. If the index is greater than the number of items in the menu, the item is inserted at the end of the menu. The first item is at index 1. The syntax is:

 
     menuItem insert menu index text ?attribute (0|1)...?

Changed line 78 from:

The [set] subcommand

to:

The [set] subcommand

Changed line 121 from:

Menu item attributes

to:

Menu item attributes

Changed line 140 from:

Menu item shortcuts

to:

Menu item shortcuts

Changed line 154 from:

Examples

to:

Examples

February 20, 2007, at 09:45 AM by bd - Formatting glitches
Changed line 90 from:
 Note that this option does not concern menu shortcuts: menu item key equivalents are defined through the bindings mechanism (see the BindingCommand page). 
to:

Note that this option does not concern menu shortcuts: menu item key equivalents are defined through the bindings mechanism (see the BindingCommand page).

Changed line 104 from:
 Note that not all combinations are supported by the Menu Manager or by the System font. 
to:

Note that not all combinations are supported by the Menu Manager or by the System font.

Added line 113:
Changed lines 118-123 from:
-hidden
The menu item is not drawn when displaying the menu. The item is also not

included in command-key matching unless the -dynamic attribute is set.

-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the

beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)

to:
-hidden
The menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the -dynamic attribute is set.
-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)
Changed lines 121-122 from:
-header
The menu item is a menu section header: this item is disabled and not

selectable.

to:
-header
The menu item is a menu section header: this item is disabled and not selectable.
February 16, 2007, at 01:32 PM by bd - Modified syntax after removal of [action] command
Changed line 3 from:
This file documents the new [menuItem] command introduced in version 8.1 of AlphaX. This is an experimental command proposed as a part of the bindings reform. It is open to discussion.
to:
This file documents the new [menuItem] command introduced in version 8.2a1d1 of AlphaX. This is an experimental command proposed as a part of the bindings reform. It is open to discussion.
Changed line 76 from:
  • the -action option lets you specify an action attached to the menu item. The value of this option is a token previously obtained with the [action create] command (see the ActionCommand page on this wiki). When the menu item will be selected, this action will be executed rather than the proc attached to the menu itself. If no action has been specified, the menu proc is executed instead.
to:
  • the -command option lets you specify a Tcl proc attached to the menu item. The value of this option is a Tcl proc or a Tcl code snippet. When the menu item is selected, this code will be executed rather than the proc attached to the menu itself. If no command has been specified, the menu proc is executed instead.
Changed line 90 from:

Note that this option does not concern menu shortcuts: menu item key equivalents are defined through the bindings and actions mechanism (see the ActionCommand and BindingCommand pages).

to:
 Note that this option does not concern menu shortcuts: menu item key equivalents are defined through the bindings mechanism (see the BindingCommand page). 
Changed line 104 from:

Note that not all combinations are supported by the Menu Manager or by the System font.

to:
 Note that not all combinations are supported by the Menu Manager or by the System font. 
Changed lines 117-118 from:
-hidden
The menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the -dynamic attribute is set.
-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)
to:
-hidden
The menu item is not drawn when displaying the menu. The item is also not

included in command-key matching unless the -dynamic attribute is set.

-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the

beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)

Changed lines 124-125 from:
-header
The menu item is a menu section header: this item is disabled and not selectable.
to:
-header
The menu item is a menu section header: this item is disabled and not

selectable.

Changed lines 128-129 from:

Some of these attributes can be modified later using the [menuItem set] command.

to:

Some of these attributes can be modified later using the [menuItem set] command.

Changed line 132 from:

Starting with version 8.1a5d4, key shortcuts (if they exist) are

to:

Starting with version 8.2a1d1, keyboard shortcuts (if they exist) are

Changed line 135 from:

Key shortcuts can be defined with the new [binding] command

to:

Keyboard shortcuts can be defined with the new [binding] command

Changed lines 137-143 from:

associated with an action defined with the [action] command (see ActionCommand). If the action is also attached to a menu item (with [menuItem set -action]), then the binding is displayed in the menu as the menu item equivalent.

The automatic attachment of bindings to menu items can be disabled:

to:

associated with a Tcl proc. If the same Tcl proc is also attached to a menu item (using [menuItem set -command]), then the binding is displayed in the menu as the menu item key equivalent.

If necessary, the automatic attachment of bindings to menu items can be disabled:

Added line 144:

Added lines 268-270:

More sample instructions concerning menu shortcuts can be found on the Binding Command page on this wiki.

February 06, 2007, at 01:51 PM by bd - Updated for 8.1a5d4
Changed line 172 from:
     menuItem set $iconMenu $idx -modifiers 2
to:
     menuItem set $iconMenu $idx -modifiers "o"
Changed line 175 from:
     menuItem set $iconMenu $idx -modifiers 4
to:
     menuItem set $iconMenu $idx -modifiers "z"
February 06, 2007, at 01:22 PM by bd - Updated for 8.1a5d4
Changed line 90 from:
 Note that this option does not concern menu shortcuts: menu item key equivalents are defined through the bindings and actions mechanism (see the ActionCommand and BindingCommand pages). 
to:

Note that this option does not concern menu shortcuts: menu item key equivalents are defined through the bindings and actions mechanism (see the ActionCommand and BindingCommand pages).

Changed lines 123-124 from:

Some of these attributes can be modified later using the [menuItem set] command.

to:

Some of these attributes can be modified later using the [menuItem set] command.

February 06, 2007, at 01:21 PM by bd - Updated for 8.1a5d4
Changed line 104 from:
 Note that not all combinations are supported by the Menu Manager or by the System font. 
to:

Note that not all combinations are supported by the Menu Manager or by the System font.

Changed lines 117-122 from:
-hidden
The menu item is not drawn when displaying the menu. The item is also not

included in command-key matching unless the -dynamic attribute is set.

-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the

beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)

to:
-hidden
The menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the -dynamic attribute is set.
-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)
Changed lines 120-121 from:
-header
The menu item is a menu section header: this item is disabled and not

selectable.

to:
-header
The menu item is a menu section header: this item is disabled and not selectable.
February 06, 2007, at 01:19 PM by bd - Updated for 8.1a5d4
Deleted line 2:
Deleted line 76:
  • the -commandKey option lets you specify a keyboard equivalent !! !! for the menu item. By default the key is used in association with the !! !! Command key but this can be modified with the -modifiers option. !! !! The command key can also be interpreted either as a character code (this is !! !! the default behavior), or as a virtual key code (see the -virtual !! !! option).
Deleted line 78:
  • the -glyph option lets you specify a glyph to represent a !! !! particular key from the keyboard when it corresponds to a key shortcut and !! !! is not a single letter. The value of this option is a decimal number: see !! !! the Menu item glyphs section below for the possible !! !! values.
Changed lines 106-107 from:
  • the -text option lets you specify the text of the menu item. The command does not perform any transformation on the text (such as prettifying, menu forms).
  • the -virtual option tells whether a keyboard shortcut !! !! attached to a menu item is to be interpreted as a character code or a !! !! virtual key code (the values for this option are 0 and 1 respectively).
to:
  • the -text option lets you specify the text of the menu item. The command does not perform any transformation on the text (such as prettifying, menu forms).
February 06, 2007, at 01:13 PM by bd - Updated for 8.1a5d4
Changed lines 14-17 from:
to:
Changed lines 26-27 from:

menuItem subcommand ?options?

to:

menuItem subcommand ?options?

Changed line 41 from:
	 menuItem append menu text ?attribute (0|1)...?
to:
     menuItem append menu text ?attribute (0|1)...?
Changed line 47 from:
	 menuItem check menu
to:
     menuItem check menu
Changed line 54 from:
	 menuItem delete menu index
to:
     menuItem delete menu index
Changed line 63 from:
	 menuItem insert menu index text ?attribute (0|1)...?
to:
     menuItem insert menu index text ?attribute (0|1)...?
Changed lines 70-71 from:
	 menuItem set menu index option
	 menuItem set menu index option value ?option value...?
to:
     menuItem set menu index option
     menuItem set menu index option value ?option value...?
Changed lines 77-78 from:
  • the -commandKey option lets you specify a keyboard equivalent for the menu item. By default the key is used in association with the Command key but this can be modified with the -modifiers option. The command key can also be interpreted either as a character code (this is the default behavior), or as a virtual key code (see the -virtual option).
  • the -dynamic option lets you specify whether the menu item is a dynamic item. A dynamic item changes dynamically based on the state of the modifier keys. For example, holding down the command key might change the menu item from Close to Close all. When a menu item has alternate dynamic states, you should group them together sequentially in the menu and assign them the same command key (but it is also possible to have dynamic items without a command key equivalent). Each item of a dynamic group must be assigned a key modifier (see the -modifiers option). See also the -notAlternate option to start a new dynamic group.
to:
  • the -action option lets you specify an action attached to the menu item. The value of this option is a token previously obtained with the [action create] command (see the ActionCommand page on this wiki). When the menu item will be selected, this action will be executed rather than the proc attached to the menu itself. If no action has been specified, the menu proc is executed instead.
  • the -commandKey option lets you specify a keyboard equivalent !! !! for the menu item. By default the key is used in association with the !! !! Command key but this can be modified with the -modifiers option. !! !! The command key can also be interpreted either as a character code (this is !! !! the default behavior), or as a virtual key code (see the -virtual !! !! option).
  • the -dynamic option lets you specify whether the menu item is a dynamic item. A dynamic item changes dynamically based on the state of the modifier keys. For example, holding down the command key might change the menu item from Close to Close all. When a menu item has alternate dynamic states, you should group them together sequentially in the menu. Usually one assigns them the same command key but it is also possible to have dynamic items without a command key equivalent. Each item of a dynamic group must be assigned a key modifier (see the -modifiers option). See also the -notAlternate option to start a new dynamic group.
Changed line 81 from:
  • the -glyph option lets you specify a glyph to represent a particular key from the keyboard when it corresponds to a key shortcut and is not a single letter. The value of this option is a decimal number: see the Menu item glyphs section below for the possible values.
to:
  • the -glyph option lets you specify a glyph to represent a !! !! particular key from the keyboard when it corresponds to a key shortcut and !! !! is not a single letter. The value of this option is a decimal number: see !! !! the Menu item glyphs section below for the possible !! !! values.
Changed line 83 from:
  • the -icon option lets you specify an icon to attach to the menu item. Its value is a four character code corresponding to a registered icon reference: see the IconrefCommand documentation on this wiki.
to:
  • the -icon option lets you specify an icon to attach to the menu item. Its value is a four character code corresponding to a registered icon reference: see the IconrefCommand documentation on this wiki. One can also find a list of predefined icons in the Icon codes section of the Toolbar Command page.
Changed lines 87-90 from:
  • the -modifiers option lets you specify the modifier keys associated with a menu shortcut. The value of this option is an additive value made of the following base-2 constants: see the Modifier key constants section below.
  • the -notAlternate option lets you specify that the menu item is not part of the same dynamic group as the previous item (see the -dynamic option). You should set this flag for the first menu item in a new dynamic group.
  • the -parentChoosable option lets you specify whether the menu item is selectable or not when a submenu is attached to it. The values for this option are 0 or 1. By default it is not selectable (value 0).
  • the -style option lets you specify the style of the menu item. Its value is an additive value combining the following base-2 numbers:
to:
  • the -modifiers option lets you specify the modifier keys associated with dynamic items: it defines the modifier keys which must be used to select items in a group of dynamic items. The value of this option uses the same syntax as the [binding] command. It is a combination of the c, o, s and z letters:
Added lines 89-98:
"c"corresponds to the Command key
"s"corresponds to the Shift key
"o"corresponds to the Option key
"z"corresponds to the Control key
 Note that this option does not concern menu shortcuts: menu item key equivalents are defined through the bindings and actions mechanism (see the ActionCommand and BindingCommand pages). 
  • the -notAlternate option lets you specify that the menu item is not part of the same dynamic group as the previous item (see the -dynamic option). You should set this flag for the first menu item in a new dynamic group.
  • the -parentChoosable option lets you specify whether the menu item is selectable or not when a submenu is attached to it. The values for this option are 0 or 1. By default it is not selectable (value 0).
  • the -showKey option tells whether a keyboard shortcut attached to a menu item should be displayed or not. See the Menu Item Shortcuts section for more on this subject.
  • the -style option lets you specify the style of the menu item. Its value is an additive value combining the following base-2 numbers:
Changed line 107 from:
 Not all combinations are supported by the Menu Manager or by the System font. 
to:
 Note that not all combinations are supported by the Menu Manager or by the System font. 
Changed line 110 from:
  • the -virtual option tells whether a keyboard shortcut attached to a menu item is to be interpreted as a charaacter code or a virtual key code (the values for this option are 0 and 1 respectively).
to:
  • the -virtual option tells whether a keyboard shortcut !! !! attached to a menu item is to be interpreted as a character code or a !! !! virtual key code (the values for this option are 0 and 1 respectively).
Changed lines 117-118 from:

Here is the list of the available attributes and their signification:

to:

Here is the list of the available attributes and their signification when the value is set to 1:

Changed lines 121-122 from:
-hidden
The menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the -dynamic attribute is set.
-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)
to:
-hidden
The menu item is not drawn when displaying the menu. The item is also not

included in command-key matching unless the -dynamic attribute is set.

-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the

beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)

Changed lines 128-129 from:
-header
The menu item is a menu section header: this item is disabled and not selectable.
to:
-header
The menu item is a menu section header: this item is disabled and not

selectable.

Deleted lines 131-132:
-virtual
When comparing this item's keyboard equivalent against a keyboard event, use the item's virtual keycode equivalent rather than its character code equivalent.
Changed lines 134-218 from:

Menu item glyphs

Here is a table of the decimal constants which can be used with the [menuItem set -glyph] command.

NameDec valueDescription
AppleLogoFilled20The filled Apple logo.
AppleLogoOutline108The outlined Apple logo.
Blank97The blank key.
CapsLock99The Caps Lock key.
Checkmark18The Check mark key.
Clear28The Clear key.
Command17The Command key.
ContextualMenu109The contextual menu key
Control6The Control key.
ControlISO138The ISO standard control key.
DeleteLeft23The Delete-to-the-left key.
DeleteRight10The Delete-to-the-right key. Used in right-to-left script systems.
Diamond19The diamond mark.
DownArrow106The down arrow key.
DownwardArrowDashed16The downward dashed arrow key.
Eject140The Eject key (available in Mac OS X v10.2 and later).
Enter4The Enter key.
Escape27The Escape key.
F1111The F1 key.
F2112The F2 key.
F3113The F3 key.
F4114The F4 key.
F5115The F5 key.
F6116The F6 key.
F7117The F7 key.
F8118The F8 key.
F9119The F9 key.
F10120The F10 key.
F11121The F11 key.
F12122The F12 key.
F13135The F13 key.
F14136The F14 key.
F15137The F15 key.
Help103The Help key.
LeftArrow100The left arrow key.
LeftArrowDashed24The dashed left arrow key.
NonmarkingReturn13The nonmarking Return key. Note that this glyph has no visible representation (that is, nothing appears in the menu).
NorthwestArrow102The northwest arrow key
Null0The null character. Note that this glyph has no visible representation (that is, nothing appears in the menu).
Option7The Option key.
PageDown107The Page Down key.
PageUp98The Page Up key.
Pencil15The Pencil key.
Power110The power key (that is, the startup key).
Return11The Return key for left-to-right script systems.
ReturnR2L12The Return key for right-to-left script systems.
RightArrow101The right arrow key.
RightArrowDashed26The dashed right arrow key.
Shift5The Shift key.
SoutheastArrow105The southeast arrow key.
Space9The Space bar. Note that this glyph has no visible representation (that is, nothing appears in the menu).
TabLeft3The Tab-to-the-left key. Used in right to left script systems.
TabRight2The Tab-to-the-right key. Used in left to right script systems.
UpArrow104The up arrow key.
UpArrowDashed25The dashed up arrow key.

Modifier key constants

Specify modifier keys used with menu item selections. You can use one or more of these mask constants to determine which modifier key(s) must be pressed along with a character key to create a keyboard equivalent for selecting a menu item. You set and obtain these constants by calling the [menuItem set -modifiers] command.

No modifiers0If no bit is set, only the Command key is used in the keyboard equivalent
Shift modifier1If this bit (bit 0) is set, the Shift key is used in the keyboard equivalent
Option modifier2If this bit (bit 1) is set, the Option key is used in the keyboard equivalent
Control modifier4If this bit (bit 2) is set, the Control key is used in the keyboard equivalent
No Command modifier8If this bit (bit 3) is set, the Command key is not used in the keyboard equivalent

Character codes vs. virtual keycodes

A menu item's keyboard equivalent may be either a character code or a virtual keycode. An item's character code and virtual keycode are stored separately and may contain different values, but only one is used by the Menu Manager at any given time. The character code is always used to draw the item's keyboard equivalent in the menu, but either may be used for keyboard equivalent matching, depending on whether the -virtual item attribute is set. To make the menu item stop using the virtual keycode equivalent and use the character code equivalent instead, use

to:

Menu item shortcuts

Starting with version 8.1a5d4, key shortcuts (if they exist) are automatically attached to menu items.

Key shortcuts can be defined with the new [binding] command (see the BindingCommand page on this wiki): a key binding is associated with an action defined with the [action] command (see ActionCommand). If the action is also attached to a menu item (with [menuItem set -action]), then the binding is displayed in the menu as the menu item equivalent.

The automatic attachment of bindings to menu items can be disabled:

  • for an entire menu with the -keyMatching option, by setting its value to 0 via the [menuRef set] command
  • for a particular menu item with the -showKey option, by setting its value to 0 via the [menuItem set] command

Examples

Here are a few basic examples which can be executed one by one in the Tcl shell in AlphaX:

Changed lines 154-271 from:
	 menuItem set menu index -virtual 0
to:
     proc testMenuRefProc {menu item} {
     	alertnote "Item $item of menu $menu was selected!"
     }

     # Create a menu
     set testMenu [menuRef create -title Test -command testMenuRefProc]

     # Create a menu with the Burning Icon
     set iconMenu [menuRef create -icon "burn" -command testMenuRefProc]

     # Get the list of newly created menus
     menuRef list
     # Result: menu1 menu2 etc.

     # Insert the menus
     menuRef insert $testMenu
     menuRef insert $iconMenu

     # Populate the "Icon" menu
     menuItem append $iconMenu "item 1"
     menuItem append $iconMenu "item 2"
     menuItem append $iconMenu "item 3"
     menuItem append $iconMenu "item 4"
     menuItem append $iconMenu "item 5" -disabled 1
     # Create dynamic items
     set idx [menuItem append $iconMenu "dynamic 1" -dynamic 1]
     set idx [menuItem append $iconMenu "dynamic 2" -dynamic 1]
     menuItem set $iconMenu $idx -modifiers 2
     set idx [menuItem append $iconMenu "dynamic 3" -notAlternate 1 -dynamic 1]
     set idx [menuItem append $iconMenu "dynamic 4" -dynamic 1]
     menuItem set $iconMenu $idx -modifiers 4

     # Change some properties (1=bold)
     menuItem set $iconMenu 1 -style 1
     menuItem set $iconMenu 2 -mark *
     menuItem set $iconMenu 3 -icon "ques"

     # Query properties
     menuItem set $iconMenu 6 -dynamic

     # Populate the "Test" menu
     menuItem append $testMenu "test item 1"
     menuItem append $testMenu "test item 2"
     menuItem append $testMenu "test item 3"
     menuItem append $testMenu "test item 4"

     # Disable an item
     menuItem set $iconMenu 4 -enabled 0

     # Add a separator and a section header
     menuItem append $iconMenu "" -separator 1
     menuItem append $iconMenu "Section header" -header 1

     # Get the list of items
     menuItem list $iconMenu

     # Count the items
     menuItem count $iconMenu

     # Indent the section header item
     menuItem set $iconMenu 11 -indent 1

     # Hide the second item
     menuItem set $iconMenu 2 -hidden 1

     # Show it again
     menuItem set $iconMenu 2 -hidden 0

     # Insert an item at the top of the menu (the -ignoreMeta option causes the
     # dash not to generate a separator)
     menuItem insert $iconMenu 1 "-40 degrees F" -ignoreMeta 1

     # Delete this first item
     menuItem delete $iconMenu 1

     # Put a checkmark in front of an item
     menuItem check $iconMenu 4 1

     # Change the style (2=italic)
     menuItem set $iconMenu 4 -style 2

     # Hilite the test menu
     menuRef hilite $testMenu 1
     # Unhilite it
     menuRef hilite $testMenu 0

     # Remove the test menu
     menuRef remove $testMenu
     # Re-insert it before the icon menu
     menuRef insert $testMenu -before $iconMenu

     # Create a new menu which will be later used as a submenu
     set testSubmenu [menuRef create -title TestSub -command testMenuRefProc]

     # Populate the "Test" menu
     menuItem append $testSubmenu "subitem 1"
     menuItem append $testSubmenu "subitem 2"
     menuItem append $testSubmenu "subitem 3"
     menuItem append $testSubmenu "subitem 4"

     # Make it a submenu of the second item in the icon menu
     menuItem set $iconMenu 2 -submenu $testSubmenu

     # Make the submenu title itself selectable
     menuItem set $iconMenu 2 -parentChoosable 1

     # Detach the submenu from the menu item
     menuItem set $iconMenu 2 -submenu ""

     # Suppose you have an icon file named Kandinsky.icns in the Application
     # Support folder. First register the icon (under the KAND type for
     # instance). and then apply it to the menu.
     set icnsFile [file join $SUPPORT(user) Images Kandinsky.icns]
     iconref register -file $icnsFile KAND
     menuRef set $iconMenu -icon KAND

     # Delete the Test menu
     menuRef delete $testMenu    
Deleted lines 272-442:

to clear the -virtual item attribute. Note that zero is a valid virtual keycode.

Here is a list of the main virtual keycodes with the value of the corresponding glyph:

DescriptionKeycodeGlyph
Arrow Down125106
Arrow Left123100
Arrow Right124101
Arrow Up126104
Del5123
End119105
Enter764
F1122111
F2120112
F399113
F4118114
F596115
F697116
F798117
F8100118
F9101119
F10109120
F11103121
F12111122
F13105135
F14107136
F15113137
Forward Del11710
Help114103
Home115102
Num Lock7128
Page Down121107
Page Up11698
Return3611
Tab482

Examples

Here are a few basic examples which can be executed one by one in the Tcl shell in AlphaX:

 
	 proc testMenuRefProc {menu item} {
		alertnote "Item $item of menu $menu was selected!"
	 }

	 # Create a menu
	 set testMenu [menuRef create -title Test -command testMenuRefProc]

	 # Create a menu with the Burning Icon
	 set iconMenu [menuRef create -icon "burn" -command testMenuRefProc]

	 # Get the list of newly created menus
	 menuRef list
	 # Result: menu1 menu2 etc.

	 # Insert the menus
	 menuRef insert $testMenu
	 menuRef insert $iconMenu

	 # Populate the "Icon" menu
	 menuItem append $iconMenu "item 1"
	 menuItem append $iconMenu "item 2"
	 menuItem append $iconMenu "item 3"
	 menuItem append $iconMenu "item 4"
	 menuItem append $iconMenu "item 5" -disabled 1
	 # Create dynamic items
	 set idx [menuItem append $iconMenu "dynamic 1" -dynamic 1]
	 menuItem set $iconMenu $idx
	 set idx [menuItem append $iconMenu "dynamic 2" -dynamic 1]
	 menuItem set $iconMenu $idx -modifiers 2
	 set idx [menuItem append $iconMenu "dynamic 3" -notAlternate 1 -dynamic 1]
	 menuItem set $iconMenu $idx -commandKey 66
	 set idx [menuItem append $iconMenu "dynamic 4" -dynamic 1]
	 menuItem set $iconMenu $idx -modifiers 4 -commandKey 66

	 # Change some properties (1=bold)
	 menuItem set $iconMenu 1 -style 1
	 menuItem set $iconMenu 2 -mark *
	 menuItem set $iconMenu 3 -icon Beet

	 # Query properties
	 menuItem set $iconMenu 6 -dynamic

	 # Populate the "Test" menu
	 menuItem append $testMenu "test item 1"
	 menuItem append $testMenu "test item 2"
	 menuItem append $testMenu "test item 3"
	 menuItem append $testMenu "test item 4"

	 # 104 is the up arrow key
	 menuItem set $iconMenu 4 -enabled 0 -glyph 104

	 # Add a separator and a section header
	 menuItem append $iconMenu "" -separator 1
	 menuItem append $iconMenu "Section header" -header 1

	 # Get the list of items
	 menuItem list $iconMenu

	 # Count the items
	 menuItem count $iconMenu

	 # Indent the section header item
	 menuItem set $iconMenu 11 -indent 1

	 # Hide the second item
	 menuItem set $iconMenu 2 -hidden 1

	 # Show it again
	 menuItem set $iconMenu 2 -hidden 0

	 # Insert an item at the top of the menu (the -ignoreMeta option causes the
	 # dash not to generate a separator)
	 menuItem insert $iconMenu 1 "-40 degrees F" -ignoreMeta 1

	 # Delete this first item
	 menuItem delete $iconMenu 1

	 # Put a checkmark in front of an item
	 menuItem check $iconMenu 4 1

	 # Change the style (2=italic)
	 menuItem set $iconMenu 4 -style 2

	 # Hilite the test menu
	 menuRef hilite $testMenu 1
	 # Unhilite it
	 menuRef hilite $testMenu 0

	 # Remove the test menu
	 menuRef remove $testMenu
	 # Re-insert it before the icon menu
	 menuRef insert $testMenu -before $iconMenu

	 # Create a new menu which will be later used as a submenu
	 set testSubmenu [menuRef create -title TestSub -command testMenuRefProc]

	 # Populate the "Test" menu
	 menuItem append $testSubmenu "subitem 1"
	 menuItem append $testSubmenu "subitem 2"
	 menuItem append $testSubmenu "subitem 3"
	 menuItem append $testSubmenu "subitem 4"

	 # Make it a submenu of the second item in the icon menu
	 menuItem set $iconMenu 2 -submenu $testSubmenu

	 # Make the submenu title itself selectable
	 menuItem set $iconMenu 2 -parentChoosable 1

	 # Detach the submenu from the menu item
	 menuItem set $iconMenu 2 -submenu ""

	 # Bind the first item to ctrl-opt-cmd-a
	 menuItem set $testMenu 1 -virtual 0 -commandKey 65 -modifiers 6

	 # Bind the second item to opt-cmd-F5
	 #    virtual keycode for F5 is 96
	 #    glyph for F5 is 115
	 menuItem set $testMenu 2 -virtual 1 -commandKey 96 -glyph 115 -modifiers 2

	 # Suppose you have an icon file named Kandinsky.icns in the Application
	 # Support folder. First register the icon (under the KAND type for
	 # instance). and then apply it to the menu.
	 set icnsFile [file join $SUPPORT(user) Images Kandinsky.icns]
	 iconref register -file $icnsFile KAND
	 menuRef set $iconMenu -icon KAND

	 # Delete the Test menu
	 menuRef delete $testMenu    

Changed line 274 from:

(add your comments here...)

to:

(add your comments here...)

January 24, 2007, at 06:33 AM by bd - Renamed -virtualKey as -virtual
Changed line 43 from:
     menuItem append menu text ?attribute (0|1)...?
to:
	 menuItem append menu text ?attribute (0|1)...?
Changed line 49 from:
     menuItem check menu
to:
	 menuItem check menu
Changed line 56 from:
     menuItem delete menu index
to:
	 menuItem delete menu index
Changed line 65 from:
     menuItem insert menu index text ?attribute (0|1)...?
to:
	 menuItem insert menu index text ?attribute (0|1)...?
Changed lines 72-73 from:
     menuItem set menu index option
     menuItem set menu index option value ?option value...?
to:
	 menuItem set menu index option
	 menuItem set menu index option value ?option value...?
Changed line 79 from:
  • the -commandKey option lets you specify a keyboard equivalent for the menu item. By default the key is used in association with the Command key but this can be modified with the -modifiers option. The command key can also be interpreted either as a character code (this is the default behavior), or as a virtual key code (see the -virtualKey option).
to:
  • the -commandKey option lets you specify a keyboard equivalent for the menu item. By default the key is used in association with the Command key but this can be modified with the -modifiers option. The command key can also be interpreted either as a character code (this is the default behavior), or as a virtual key code (see the -virtual option).
Changed line 104 from:
  • the -virtualKey option tells whether a keyboard shortcut attached to a menu item is to be interpreted as a charaacter code or a virtual key code (the values for this option are 0 and 1 respectively).
to:
  • the -virtual option tells whether a keyboard shortcut attached to a menu item is to be interpreted as a charaacter code or a virtual key code (the values for this option are 0 and 1 respectively).
Changed lines 120-121 from:
-virtualKey
When comparing this item's keyboard equivalent against a keyboard event, use the item's virtual keycode equivalent rather than its character code equivalent.
to:
-virtual
When comparing this item's keyboard equivalent against a keyboard event, use the item's virtual keycode equivalent rather than its character code equivalent.
Changed line 206 from:

keyboard equivalent matching, depending on whether the -virtualKey

to:

keyboard equivalent matching, depending on whether the -virtual

Changed line 210 from:
     menuItem set menu index -virtualKey 0
to:
	 menuItem set menu index -virtual 0
Changed line 212 from:

to clear the -virtualKey item attribute.

to:

to clear the -virtual item attribute.

Changed lines 254-319 from:
     proc testMenuRefProc {menu item} {
     	alertnote "Item $item of menu $menu was selected!"
     }

     # Create a menu
     set testMenu [menuRef create -title Test -command testMenuRefProc]

     # Create a menu with the Burning Icon
     set iconMenu [menuRef create -icon "burn" -command testMenuRefProc]

     # Get the list of newly created menus
     menuRef list
     # Result: menu1 menu2 etc.

     # Insert the menus
     menuRef insert $testMenu
     menuRef insert $iconMenu

     # Populate the "Icon" menu
     menuItem append $iconMenu "item 1"
     menuItem append $iconMenu "item 2"
     menuItem append $iconMenu "item 3"
     menuItem append $iconMenu "item 4"
     menuItem append $iconMenu "item 5" -disabled 1
     # Create dynamic items
     set idx [menuItem append $iconMenu "dynamic 1" -dynamic 1]
     menuItem set $iconMenu $idx
     set idx [menuItem append $iconMenu "dynamic 2" -dynamic 1]
     menuItem set $iconMenu $idx -modifiers 2
     set idx [menuItem append $iconMenu "dynamic 3" -notAlternate 1 -dynamic 1]
     menuItem set $iconMenu $idx -commandKey 66
     set idx [menuItem append $iconMenu "dynamic 4" -dynamic 1]
     menuItem set $iconMenu $idx -modifiers 4 -commandKey 66

     # Change some properties (1=bold)
     menuItem set $iconMenu 1 -style 1
     menuItem set $iconMenu 2 -mark *
     menuItem set $iconMenu 3 -icon Beet

     # Query properties
     menuItem set $iconMenu 6 -dynamic

     # Populate the "Test" menu
     menuItem append $testMenu "test item 1"
     menuItem append $testMenu "test item 2"
     menuItem append $testMenu "test item 3"
     menuItem append $testMenu "test item 4"

     # 104 is the up arrow key
     menuItem set $iconMenu 4 -enabled 0 -glyph 104

     # Add a separator and a section header
     menuItem append $iconMenu "" -separator 1
     menuItem append $iconMenu "Section header" -header 1

     # Get the list of items
     menuItem list $iconMenu

     # Count the items
     menuItem count $iconMenu

     # Indent the section header item
     menuItem set $iconMenu 11 -indent 1

     # Hide the second item
     menuItem set $iconMenu 2 -hidden 1
to:
	 proc testMenuRefProc {menu item} {
		alertnote "Item $item of menu $menu was selected!"
	 }

	 # Create a menu
	 set testMenu [menuRef create -title Test -command testMenuRefProc]

	 # Create a menu with the Burning Icon
	 set iconMenu [menuRef create -icon "burn" -command testMenuRefProc]

	 # Get the list of newly created menus
	 menuRef list
	 # Result: menu1 menu2 etc.

	 # Insert the menus
	 menuRef insert $testMenu
	 menuRef insert $iconMenu

	 # Populate the "Icon" menu
	 menuItem append $iconMenu "item 1"
	 menuItem append $iconMenu "item 2"
	 menuItem append $iconMenu "item 3"
	 menuItem append $iconMenu "item 4"
	 menuItem append $iconMenu "item 5" -disabled 1
	 # Create dynamic items
	 set idx [menuItem append $iconMenu "dynamic 1" -dynamic 1]
	 menuItem set $iconMenu $idx
	 set idx [menuItem append $iconMenu "dynamic 2" -dynamic 1]
	 menuItem set $iconMenu $idx -modifiers 2
	 set idx [menuItem append $iconMenu "dynamic 3" -notAlternate 1 -dynamic 1]
	 menuItem set $iconMenu $idx -commandKey 66
	 set idx [menuItem append $iconMenu "dynamic 4" -dynamic 1]
	 menuItem set $iconMenu $idx -modifiers 4 -commandKey 66

	 # Change some properties (1=bold)
	 menuItem set $iconMenu 1 -style 1
	 menuItem set $iconMenu 2 -mark *
	 menuItem set $iconMenu 3 -icon Beet

	 # Query properties
	 menuItem set $iconMenu 6 -dynamic

	 # Populate the "Test" menu
	 menuItem append $testMenu "test item 1"
	 menuItem append $testMenu "test item 2"
	 menuItem append $testMenu "test item 3"
	 menuItem append $testMenu "test item 4"

	 # 104 is the up arrow key
	 menuItem set $iconMenu 4 -enabled 0 -glyph 104

	 # Add a separator and a section header
	 menuItem append $iconMenu "" -separator 1
	 menuItem append $iconMenu "Section header" -header 1

	 # Get the list of items
	 menuItem list $iconMenu

	 # Count the items
	 menuItem count $iconMenu

	 # Indent the section header item
	 menuItem set $iconMenu 11 -indent 1

	 # Hide the second item
	 menuItem set $iconMenu 2 -hidden 1
Changed lines 321-357 from:
     # Show it again
     menuItem set $iconMenu 2 -hidden 0

     # Insert an item at the top of the menu (the -ignoreMeta option causes the
     # dash not to generate a separator)
     menuItem insert $iconMenu 1 "-40 degrees F" -ignoreMeta 1

     # Delete this first item
     menuItem delete $iconMenu 1

     # Put a checkmark in front of an item
     menuItem check $iconMenu 4 1

     # Change the style (2=italic)
     menuItem set $iconMenu 4 -style 2

     # Hilite the test menu
     menuRef hilite $testMenu 1
     # Unhilite it
     menuRef hilite $testMenu 0

     # Remove the test menu
     menuRef remove $testMenu
     # Re-insert it before the icon menu
     menuRef insert $testMenu -before $iconMenu

     # Create a new menu which will be later used as a submenu
     set testSubmenu [menuRef create -title TestSub -command testMenuRefProc]

     # Populate the "Test" menu
     menuItem append $testSubmenu "subitem 1"
     menuItem append $testSubmenu "subitem 2"
     menuItem append $testSubmenu "subitem 3"
     menuItem append $testSubmenu "subitem 4"

     # Make it a submenu of the second item in the icon menu
     menuItem set $iconMenu 2 -submenu $testSubmenu
to:
	 # Show it again
	 menuItem set $iconMenu 2 -hidden 0

	 # Insert an item at the top of the menu (the -ignoreMeta option causes the
	 # dash not to generate a separator)
	 menuItem insert $iconMenu 1 "-40 degrees F" -ignoreMeta 1

	 # Delete this first item
	 menuItem delete $iconMenu 1

	 # Put a checkmark in front of an item
	 menuItem check $iconMenu 4 1

	 # Change the style (2=italic)
	 menuItem set $iconMenu 4 -style 2

	 # Hilite the test menu
	 menuRef hilite $testMenu 1
	 # Unhilite it
	 menuRef hilite $testMenu 0

	 # Remove the test menu
	 menuRef remove $testMenu
	 # Re-insert it before the icon menu
	 menuRef insert $testMenu -before $iconMenu

	 # Create a new menu which will be later used as a submenu
	 set testSubmenu [menuRef create -title TestSub -command testMenuRefProc]

	 # Populate the "Test" menu
	 menuItem append $testSubmenu "subitem 1"
	 menuItem append $testSubmenu "subitem 2"
	 menuItem append $testSubmenu "subitem 3"
	 menuItem append $testSubmenu "subitem 4"

	 # Make it a submenu of the second item in the icon menu
	 menuItem set $iconMenu 2 -submenu $testSubmenu
Changed lines 359-381 from:
     # Make the submenu title itself selectable
     menuItem set $iconMenu 2 -parentChoosable 1

     # Detach the submenu from the menu item
     menuItem set $iconMenu 2 -submenu ""

     # Bind the first item to ctrl-opt-cmd-a
     menuItem set $testMenu 1 -virtualKey 0 -commandKey 65 -modifiers 6

     # Bind the second item to opt-cmd-F5
     #    virtual keycode for F5 is 96
     #    glyph for F5 is 115
     menuItem set $testMenu 2 -virtualKey 1 -commandKey 96 -glyph 115 -modifiers 2

     # Suppose you have an icon file named Kandinsky.icns in the Application
     # Support folder. First register the icon (under the KAND type for
     # instance). and then apply it to the menu.
     set icnsFile [file join $SUPPORT(user) Images Kandinsky.icns]
     iconref register -file $icnsFile KAND
     menuRef set $iconMenu -icon KAND

     # Delete the Test menu
     menuRef delete $testMenu    
to:
	 # Make the submenu title itself selectable
	 menuItem set $iconMenu 2 -parentChoosable 1

	 # Detach the submenu from the menu item
	 menuItem set $iconMenu 2 -submenu ""

	 # Bind the first item to ctrl-opt-cmd-a
	 menuItem set $testMenu 1 -virtual 0 -commandKey 65 -modifiers 6

	 # Bind the second item to opt-cmd-F5
	 #    virtual keycode for F5 is 96
	 #    glyph for F5 is 115
	 menuItem set $testMenu 2 -virtual 1 -commandKey 96 -glyph 115 -modifiers 2

	 # Suppose you have an icon file named Kandinsky.icns in the Application
	 # Support folder. First register the icon (under the KAND type for
	 # instance). and then apply it to the menu.
	 set icnsFile [file join $SUPPORT(user) Images Kandinsky.icns]
	 iconref register -file $icnsFile KAND
	 menuRef set $iconMenu -icon KAND

	 # Delete the Test menu
	 menuRef delete $testMenu    
January 18, 2007, at 03:18 PM by bd - More key equiv
Changed line 266 from:
     # Result: menu2000 menu2001 etc.
to:
     # Result: menu1 menu2 etc.
Added lines 364-366:
     # Bind the first item to ctrl-opt-cmd-a
     menuItem set $testMenu 1 -virtualKey 0 -commandKey 65 -modifiers 6
Changed lines 368-371 from:
     # 106 (0x6a) is the F16 key
     menuItem set $testMenu 1 -virtualKey 1
     menuItem set $testMenu 1 -commandKey 96  
to:
     # Bind the second item to opt-cmd-F5
     #    virtual keycode for F5 is 96
     #    glyph for F5 is 115
     menuItem set $testMenu 2 -virtualKey 1 -commandKey 96 -glyph 115 -modifiers 2
January 13, 2007, at 11:27 AM by bd - Virtual keycodes table
Changed lines 112-120 from:
-disabled This menu item is disabled. l
t)) ((lt -dynamic This menu item changes dynamically based on the state of the modifier keys. l

t)) ((lt -hidden The menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the -dynamic attribute is set. l t)) ((lt -ignoreMeta Ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.) l t)) ((lt -notAlternate This item is not part of the same dynamic group as the previous item. l t)) ((lt -header The menu item is a menu section header: this item is disabled and not selectable. l t)) ((lt -separator The menu item is a separator: any text in the item is ignored. l t)) ((lt -parentChoosable The user can select the parent item of a submenu. l t)) ((lt -virtualKey When comparing this item's keyboard equivalent against a keyboard event, use the item's virtual keycode equivalent rather than its character code equivalent. l t))

to:
-disabled
This menu item is disabled
-dynamic
This menu item changes dynamically based on the state of the modifier keys.
-hidden
The menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the -dynamic attribute is set.
-ignoreMeta
Ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.)
-notAlternate
This item is not part of the same dynamic group as the previous item.
-header
The menu item is a menu section header: this item is disabled and not selectable.
-separator
The menu item is a separator: any text in the item is ignored.
-parentChoosable
The user can select the parent item of a submenu.
-virtualKey
When comparing this item's keyboard equivalent against a keyboard event, use the item's virtual keycode equivalent rather than its character code equivalent.
January 13, 2007, at 11:16 AM by bd - Virtual keycodes table
Added lines 213-248:

Here is a list of the main virtual keycodes with the value of the corresponding glyph:

DescriptionKeycodeGlyph
Arrow Down125106
Arrow Left123100
Arrow Right124101
Arrow Up126104
Del5123
End119105
Enter764
F1122111
F2120112
F399113
F4118114
F596115
F697116
F798117
F8100118
F9101119
F10109120
F11103121
F12111122
F13105135
F14107136
F15113137
Forward Del11710
Help114103
Home115102
Num Lock7128
Page Down121107
Page Up11698
Return3611
Tab482
January 12, 2007, at 07:31 AM by bd - Transfered the [count] and [items] subcommands
Added line 3:
Changed lines 10-19 from:
to:
Changed lines 53-54 from:

The [count] subcommand

This subcommand returns the number of menu items in a menu. The syntax is:

to:

The [delete] subcommand

This subcommand deletes an item from a menu. The syntax is:

Changed line 56 from:
     menuItem count menu
to:
     menuItem delete menu index
Deleted lines 57-61:

The [delete] subcommand

This subcommand deletes an item from a menu. The syntax is:

 
     menuItem delete menu index

Changed line 60 from:

The [insert] subcommand

to:

The [insert] subcommand

Changed lines 68-70 from:

The [list] subcommand

This subcommand returns a list of all the items currently present in the menu, in the index order. The syntax is:

to:

The [set] subcommand

This subcommand lets you get or set several properties attached to a menu item. The syntax can take two forms:

Changed lines 72-73 from:
     menuItem list menu
to:
     menuItem set menu index option
     menuItem set menu index option value ?option value...?
Deleted lines 74-82:

This command should not be confused with the [menuRef list] command which returns the current list of menus.

The [set] subcommand

This subcommand lets you get or set several properties attached to a menu item. The syntax can take two forms:

 
     menuItem set menu index option
     menuItem set menu index option value ?option value...?

Changed line 106 from:

Menu item attributes

to:

Menu item attributes

Changed line 124 from:

Menu item glyphs

to:

Menu item glyphs

Changed line 186 from:

Modifier key constants

to:

Modifier key constants

Changed line 199 from:

Character codes vs. virtual keycodes

to:

Character codes vs. virtual keycodes

Changed line 213 from:

Examples

to:

Examples

Changed lines 338-340 from:
 	# Delete the Test menu
 	menuRef delete $testMenu    
to:
     # Delete the Test menu
     menuRef delete $testMenu    
Deleted line 343:
January 11, 2007, at 08:00 PM by bd - Experimental menuItem command
Changed lines 1-2 from:
to:

(:title The [menuItem] command:)

January 11, 2007, at 07:58 PM by bd - Experimental menuItem command
Added lines 1-357:
This file documents the new [menuItem] command introduced in version 8.1 of AlphaX. This is an experimental command proposed as a part of the bindings reform. It is open to discussion.


Introduction

The [menuItem] command lets you manipulate menu items in Alpha's menus. Menus can be created and manipulated using the new [menuRef] command (see the MenuRefCommand page on this wiki). Both commands could constitute a replacement for the old [Menu] command.

Synopsis

The formal syntax of the [menuItem] command is:

menuItem subcommand ?options?

The possible subcommands are described below. Depending on the subcommand, various options can be additionnally specified. In all these subcommands, the menu argument designates a unique menu token generated by Alpha each time a menu is created: such a token is typically obtained from the [menuRef create] command, but note that, for backward compatibility, tokens are also generated when menus are created with the old [Menu] command. As a consequence, the [menuItem] command also applies to menu items in menus which where not created with the [menuRef create] command, provided you know the associated token.

The [append] subcommand

This subcommand lets you append a new menu item. It returns the index of the item in the menu items list. The syntax is:

 
     menuItem append menu text ?attribute (0|1)...?

The possible attributes are described in the Menu item attributes section below.

The [check] subcommand

This subcommand lets you add or remove a check mark from a menu item. The syntax is:

 
     menuItem check menu

You can also add or remove a check mark using the [menuItem set] command with the -mark switch.

The [count] subcommand

This subcommand returns the number of menu items in a menu. The syntax is:

 
     menuItem count menu

The [delete] subcommand

This subcommand deletes an item from a menu. The syntax is:

 
     menuItem delete menu index

If you specify 0 or an index number greater than the last item in the menu, the command does not delete any item from the menu.

The [insert] subcommand

This subcommand lets you insert a new menu item with text at a specified index. If the index is greater than the number of items in the menu, the item is inserted at the end of the menu. The first item is at index 1. The syntax is:

 
     menuItem insert menu index text ?attribute (0|1)...?

The possible attributes are described in the Menu item attributes section below.

The [list] subcommand

This subcommand returns a list of all the items currently present in the menu, in the index order. The syntax is:

 
     menuItem list menu

This command should not be confused with the [menuRef list] command which returns the current list of menus.

The [set] subcommand

This subcommand lets you get or set several properties attached to a menu item. The syntax can take two forms:

 
     menuItem set menu index option
     menuItem set menu index option value ?option value...?

In the first form the command returns the current value of the specified option. In the second form, it lets you set the value of one or several options. Here is the list of the available options:

  • the -commandKey option lets you specify a keyboard equivalent for the menu item. By default the key is used in association with the Command key but this can be modified with the -modifiers option. The command key can also be interpreted either as a character code (this is the default behavior), or as a virtual key code (see the -virtualKey option).
  • the -dynamic option lets you specify whether the menu item is a dynamic item. A dynamic item changes dynamically based on the state of the modifier keys. For example, holding down the command key might change the menu item from Close to Close all. When a menu item has alternate dynamic states, you should group them together sequentially in the menu and assign them the same command key (but it is also possible to have dynamic items without a command key equivalent). Each item of a dynamic group must be assigned a key modifier (see the -modifiers option). See also the -notAlternate option to start a new dynamic group.
  • the -enabled option takes the values 0 or 1 to respectively disable or enable the menu item
  • the -glyph option lets you specify a glyph to represent a particular key from the keyboard when it corresponds to a key shortcut and is not a single letter. The value of this option is a decimal number: see the Menu item glyphs section below for the possible values.
  • the -hidden option takes the values 0 or 1 to respectively show or hide the menu item
  • the -icon option lets you specify an icon to attach to the menu item. Its value is a four character code corresponding to a registered icon reference: see the IconrefCommand documentation on this wiki.
  • the -ignoreMeta option lets you set or unset the ignoreMeta attribute. See the Menu item attributes section below.
  • the -indent option lets you specify an indentation for the menu item: the value is an integer indicating the level of indentation (0 means no indentation).
  • the -mark option lets you specify a symbol to use as a mark before the menu item. To insert or remove a check mark, one can also use the [menuItem check] command directly.
  • the -modifiers option lets you specify the modifier keys associated with a menu shortcut. The value of this option is an additive value made of the following base-2 constants: see the Modifier key constants section below.
  • the -notAlternate option lets you specify that the menu item is not part of the same dynamic group as the previous item (see the -dynamic option). You should set this flag for the first menu item in a new dynamic group.
  • the -parentChoosable option lets you specify whether the menu item is selectable or not when a submenu is attached to it. The values for this option are 0 or 1. By default it is not selectable (value 0).
  • the -style option lets you specify the style of the menu item. Its value is an additive value combining the following base-2 numbers:
normal0
bold1
italic2
underline4
outline8
shadow16
condense32
extend64
 Not all combinations are supported by the Menu Manager or by the System font. 
  • the -submenu option lets you specify a submenu attached to the menu item. Its value is a menu token designating a menu previously created with the [menuRef create] option.
  • the -text option lets you specify the text of the menu item. The command does not perform any transformation on the text (such as prettifying, menu forms).
  • the -virtualKey option tells whether a keyboard shortcut attached to a menu item is to be interpreted as a charaacter code or a virtual key code (the values for this option are 0 and 1 respectively).

Menu item attributes

The [menuItem append] and [menuItem insert] commands accept some attributes. All these attributes are specified by an option (starting with a dash) and followed by 0 or 1: they are set to zero by default. Here is the list of the available attributes and their signification:

-disabled This menu item is disabled. l
t)) ((lt -dynamic This menu item changes dynamically based on the state of the modifier keys. l

t)) ((lt -hidden The menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the -dynamic attribute is set. l t)) ((lt -ignoreMeta Ignore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read -40 degrees F.) l t)) ((lt -notAlternate This item is not part of the same dynamic group as the previous item. l t)) ((lt -header The menu item is a menu section header: this item is disabled and not selectable. l t)) ((lt -separator The menu item is a separator: any text in the item is ignored. l t)) ((lt -parentChoosable The user can select the parent item of a submenu. l t)) ((lt -virtualKey When comparing this item's keyboard equivalent against a keyboard event, use the item's virtual keycode equivalent rather than its character code equivalent. l t)) Some of these attributes can be modified later using the [menuItem set] command.

Menu item glyphs

Here is a table of the decimal constants which can be used with the [menuItem set -glyph] command.

NameDec valueDescription
AppleLogoFilled20The filled Apple logo.
AppleLogoOutline108The outlined Apple logo.
Blank97The blank key.
CapsLock99The Caps Lock key.
Checkmark18The Check mark key.
Clear28The Clear key.
Command17The Command key.
ContextualMenu109The contextual menu key
Control6The Control key.
ControlISO138The ISO standard control key.
DeleteLeft23The Delete-to-the-left key.
DeleteRight10The Delete-to-the-right key. Used in right-to-left script systems.
Diamond19The diamond mark.
DownArrow106The down arrow key.
DownwardArrowDashed16The downward dashed arrow key.
Eject140The Eject key (available in Mac OS X v10.2 and later).
Enter4The Enter key.
Escape27The Escape key.
F1111The F1 key.
F2112The F2 key.
F3113The F3 key.
F4114The F4 key.
F5115The F5 key.
F6116The F6 key.
F7117The F7 key.
F8118The F8 key.
F9119The F9 key.
F10120The F10 key.
F11121The F11 key.
F12122The F12 key.
F13135The F13 key.
F14136The F14 key.
F15137The F15 key.
Help103The Help key.
LeftArrow100The left arrow key.
LeftArrowDashed24The dashed left arrow key.
NonmarkingReturn13The nonmarking Return key. Note that this glyph has no visible representation (that is, nothing appears in the menu).
NorthwestArrow102The northwest arrow key
Null0The null character. Note that this glyph has no visible representation (that is, nothing appears in the menu).
Option7The Option key.
PageDown107The Page Down key.
PageUp98The Page Up key.
Pencil15The Pencil key.
Power110The power key (that is, the startup key).
Return11The Return key for left-to-right script systems.
ReturnR2L12The Return key for right-to-left script systems.
RightArrow101The right arrow key.
RightArrowDashed26The dashed right arrow key.
Shift5The Shift key.
SoutheastArrow105The southeast arrow key.
Space9The Space bar. Note that this glyph has no visible representation (that is, nothing appears in the menu).
TabLeft3The Tab-to-the-left key. Used in right to left script systems.
TabRight2The Tab-to-the-right key. Used in left to right script systems.
UpArrow104The up arrow key.
UpArrowDashed25The dashed up arrow key.

Modifier key constants

Specify modifier keys used with menu item selections. You can use one or more of these mask constants to determine which modifier key(s) must be pressed along with a character key to create a keyboard equivalent for selecting a menu item. You set and obtain these constants by calling the [menuItem set -modifiers] command.

No modifiers0If no bit is set, only the Command key is used in the keyboard equivalent
Shift modifier1If this bit (bit 0) is set, the Shift key is used in the keyboard equivalent
Option modifier2If this bit (bit 1) is set, the Option key is used in the keyboard equivalent
Control modifier4If this bit (bit 2) is set, the Control key is used in the keyboard equivalent
No Command modifier8If this bit (bit 3) is set, the Command key is not used in the keyboard equivalent

Character codes vs. virtual keycodes

A menu item's keyboard equivalent may be either a character code or a virtual keycode. An item's character code and virtual keycode are stored separately and may contain different values, but only one is used by the Menu Manager at any given time. The character code is always used to draw the item's keyboard equivalent in the menu, but either may be used for keyboard equivalent matching, depending on whether the -virtualKey item attribute is set. To make the menu item stop using the virtual keycode equivalent and use the character code equivalent instead, use

 
     menuItem set menu index -virtualKey 0

to clear the -virtualKey item attribute. Note that zero is a valid virtual keycode.

Examples

Here are a few basic examples which can be executed one by one in the Tcl shell in AlphaX:

 
     proc testMenuRefProc {menu item} {
     	alertnote "Item $item of menu $menu was selected!"
     }

     # Create a menu
     set testMenu [menuRef create -title Test -command testMenuRefProc]

     # Create a menu with the Burning Icon
     set iconMenu [menuRef create -icon "burn" -command testMenuRefProc]

     # Get the list of newly created menus
     menuRef list
     # Result: menu2000 menu2001 etc.

     # Insert the menus
     menuRef insert $testMenu
     menuRef insert $iconMenu

     # Populate the "Icon" menu
     menuItem append $iconMenu "item 1"
     menuItem append $iconMenu "item 2"
     menuItem append $iconMenu "item 3"
     menuItem append $iconMenu "item 4"
     menuItem append $iconMenu "item 5" -disabled 1
     # Create dynamic items
     set idx [menuItem append $iconMenu "dynamic 1" -dynamic 1]
     menuItem set $iconMenu $idx
     set idx [menuItem append $iconMenu "dynamic 2" -dynamic 1]
     menuItem set $iconMenu $idx -modifiers 2
     set idx [menuItem append $iconMenu "dynamic 3" -notAlternate 1 -dynamic 1]
     menuItem set $iconMenu $idx -commandKey 66
     set idx [menuItem append $iconMenu "dynamic 4" -dynamic 1]
     menuItem set $iconMenu $idx -modifiers 4 -commandKey 66

     # Change some properties (1=bold)
     menuItem set $iconMenu 1 -style 1
     menuItem set $iconMenu 2 -mark *
     menuItem set $iconMenu 3 -icon Beet

     # Query properties
     menuItem set $iconMenu 6 -dynamic

     # Populate the "Test" menu
     menuItem append $testMenu "test item 1"
     menuItem append $testMenu "test item 2"
     menuItem append $testMenu "test item 3"
     menuItem append $testMenu "test item 4"

     # 104 is the up arrow key
     menuItem set $iconMenu 4 -enabled 0 -glyph 104

     # Add a separator and a section header
     menuItem append $iconMenu "" -separator 1
     menuItem append $iconMenu "Section header" -header 1

     # Get the list of items
     menuItem list $iconMenu

     # Count the items
     menuItem count $iconMenu

     # Indent the section header item
     menuItem set $iconMenu 11 -indent 1

     # Hide the second item
     menuItem set $iconMenu 2 -hidden 1

     # Show it again
     menuItem set $iconMenu 2 -hidden 0

     # Insert an item at the top of the menu (the -ignoreMeta option causes the
     # dash not to generate a separator)
     menuItem insert $iconMenu 1 "-40 degrees F" -ignoreMeta 1

     # Delete this first item
     menuItem delete $iconMenu 1

     # Put a checkmark in front of an item
     menuItem check $iconMenu 4 1

     # Change the style (2=italic)
     menuItem set $iconMenu 4 -style 2

     # Hilite the test menu
     menuRef hilite $testMenu 1
     # Unhilite it
     menuRef hilite $testMenu 0

     # Remove the test menu
     menuRef remove $testMenu
     # Re-insert it before the icon menu
     menuRef insert $testMenu -before $iconMenu

     # Create a new menu which will be later used as a submenu
     set testSubmenu [menuRef create -title TestSub -command testMenuRefProc]

     # Populate the "Test" menu
     menuItem append $testSubmenu "subitem 1"
     menuItem append $testSubmenu "subitem 2"
     menuItem append $testSubmenu "subitem 3"
     menuItem append $testSubmenu "subitem 4"

     # Make it a submenu of the second item in the icon menu
     menuItem set $iconMenu 2 -submenu $testSubmenu

     # Make the submenu title itself selectable
     menuItem set $iconMenu 2 -parentChoosable 1

     # Detach the submenu from the menu item
     menuItem set $iconMenu 2 -submenu ""

     # 106 (0x6a) is the F16 key
     menuItem set $testMenu 1 -virtualKey 1
     menuItem set $testMenu 1 -commandKey 96  

     # Suppose you have an icon file named Kandinsky.icns in the Application
     # Support folder. First register the icon (under the KAND type for
     # instance). and then apply it to the menu.
     set icnsFile [file join $SUPPORT(user) Images Kandinsky.icns]
     iconref register -file $icnsFile KAND
     menuRef set $iconMenu -icon KAND

 	# Delete the Test menu
 	menuRef delete $testMenu    


(add your comments here...)

Page last modified on October 24, 2009, at 07:43 AM
Hosted on SourceForge.net Logo