|
WikiDoc |
The [menuItem] commandCommands.MenuItemCommand HistoryHide minor edits - Show changes to markup October 24, 2009, at 07:43 AM
by - Unified -mark and -unimark
Changed lines 134-135 from:
to:
October 24, 2009, at 07:42 AM
by - Unified -mark and -unimark
Changed line 50 from:
with the -mark switch. to:
with the -mark option. Changed lines 134-135 from:
to:
Deleted lines 167-168:
October 23, 2009, at 03:08 PM
by - 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 - Documenting the -unimark option
Changed lines 134-135 from:
to:
Added lines 168-169:
September 30, 2009, at 09:02 AM
by - Removed experimental
Changed line 2 from:
to:
December 02, 2007, at 06:57 PM
by - 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:
March 27, 2007, at 07:32 AM
by - 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:
March 27, 2007, at 07:30 AM
by - 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] subcommandThis 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:
If no matching style option is specified, the default is -glob. The other options have the following signifcation:
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 - 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 - More info about menu indices
Deleted line 0:
Changed line 99 from:
Both the to:
Both the March 18, 2007, at 11:15 AM
by - 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 indicesThe 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 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 optionsto:
Added line 115:
Added line 165:
Changed line 167 from:
Menu item shortcutsto:
Changed line 181 from:
Examplesto:
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 - 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 - Options of the [appen] and [insert] subcmds
Added line 1:
Changed lines 3-4 from:
to:
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 optionsThe [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:
Added line 107:
Changed lines 109-111 from:
to:
Added line 113:
Added line 115:
Added line 123:
Added line 125:
Added lines 127-129:
Added line 131:
Added line 143:
Added line 145:
Deleted lines 146-164:
Menu item attributesThe [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:
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 - 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 - 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 - 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 - New [menuItem index] subcommand
Changed lines 10-14 from:
to:
Changed lines 58-61 from:
The [insert] subcommandThis 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] subcommandThis 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] subcommandThis 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] subcommandto:
Changed line 121 from:
Menu item attributesto:
Menu item attributesChanged line 140 from:
Menu item shortcutsto:
Menu item shortcutsChanged line 154 from:
Examplesto:
ExamplesFebruary 20, 2007, at 09:45 AM
by - 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:
included in command-key matching unless the -dynamic attribute is set.
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:
Changed lines 121-122 from:
selectable. to:
February 16, 2007, at 01:32 PM
by - Modified syntax after removal of [action] command
Changed line 3 from:
to:
Changed line 76 from:
to:
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:
to:
included in command-key matching unless the -dynamic attribute is set.
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:
to:
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 - 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 - 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 - 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:
included in command-key matching unless the -dynamic attribute is set.
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:
Changed lines 120-121 from:
selectable. to:
February 06, 2007, at 01:19 PM
by - Updated for 8.1a5d4
Deleted line 2:
Deleted line 76:
Deleted line 78:
Changed lines 106-107 from:
to:
February 06, 2007, at 01:13 PM
by - 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:
to:
Changed line 81 from:
to:
Changed line 83 from:
to:
Changed lines 87-90 from:
to:
Added lines 89-98:
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 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:
to:
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:
to:
included in command-key matching unless the -dynamic attribute is set.
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:
to:
selectable. Deleted lines 131-132:
Changed lines 134-218 from:
Menu item glyphsHere is a table of the decimal constants which can be used with the [menuItem set -glyph] command.
Modifier key constantsSpecify 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.
Character codes vs. virtual keycodesA 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 shortcutsStarting 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:
ExamplesHere 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:
ExamplesHere 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 - 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:
to:
Changed line 104 from:
to:
Changed lines 120-121 from:
to:
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 - 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 - Virtual keycodes table
Changed lines 112-120 from:
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:
January 13, 2007, at 11:16 AM
by - Virtual keycodes table
Added lines 213-248:
Here is a list of the main virtual keycodes with the value of the corresponding glyph:
January 12, 2007, at 07:31 AM
by - Transfered the [count] and [items] subcommands
Added line 3:
Changed lines 10-19 from:
to:
Changed lines 53-54 from:
to:
The [delete] subcommandThis 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] subcommandThis subcommand deletes an item from a menu. The syntax is:
menuItem delete menu index
Changed line 60 from:
The [insert] subcommandto:
The [insert] subcommandChanged lines 68-70 from:
The [list] subcommandThis subcommand returns a list of all the items currently present in the menu, in the index order. The syntax is: to:
The [set] subcommandThis 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] subcommandThis 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 attributesto:
Menu item attributesChanged line 124 from:
Menu item glyphsto:
Menu item glyphsChanged line 186 from:
Modifier key constantsto:
Modifier key constantsChanged line 199 from:
to:
Character codes vs. virtual keycodesChanged line 213 from:
to:
ExamplesChanged 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 - Experimental menuItem command
Changed lines 1-2 from:
to:
(:title The [menuItem] command:) January 11, 2007, at 07:58 PM
by - Experimental menuItem command
Added lines 1-357:
IntroductionThe [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. SynopsisThe 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] subcommandThis 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] subcommandThis 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] subcommandThis subcommand returns the number of menu items in a menu. The syntax is:
menuItem count menu
The [delete] subcommandThis 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] subcommandThis 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] subcommandThis 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] subcommandThis 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:
Not all combinations are supported by the Menu Manager or by the System font.
Menu item attributesThe [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:
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 glyphsHere is a table of the decimal constants which can be used with the [menuItem set -glyph] command.
Modifier key constantsSpecify 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.
Character codes vs. virtual keycodesA 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. ExamplesHere 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...) |
|
Edit -
History -
Print -
Recent Changes -
Search
Page last modified on October 24, 2009, at 07:43 AM
|
Hosted on
|