Using ring menus / MENU interaction blocks |
The COMMAND [KEY(key-name)] "option-name" clause defines a menu action handler with a set of instructions to be executed when an action is invoked. The option text (option-name), converted to lowercase letters, defines the name of the action.
COMMAND "Hello"The name of the action will be "hello" (not "Hello" with a capital H).
When used with the KEY() clause, the command specifies both accelerator keys and an option text. For backward compatibility, a coma-separated key list is supported in the KEY() specification. Consider using a single key for new developments, or prefer accelerator definition with action defaults.
Action defaults will be applied by using the action name defined by the option text (converted to lower case).
Explicit action views defined in the form (BUTTON in layout, TOPMENU or TOOLBAR items) will get all action defaults associated to the menu command, while default action views (i.e. buttons in the action frame) will be decorated with the menu option text and comment specified in the program (i.e. the TEXT and COMMENT attributes of the corresponding action defaults entry are not used for the default action views), however, other attributes such as the IMAGE will also be applied to default action views.
COMMAND "Hello" "This is the Hello option"The name of the action will become "hello", the default action view button text will be "Hello", and the button hint will be "This is the Hello option", even if an action default defines a different text or comment for the "hello" action. If the corresponding action default defines a IMAGE icon, it will display in the default action view button.
The KEY() clause can specify up to four accelerator attributes for the action. The keys defined in the program will take precedence over accelerators defined with action defaults.
MENU COMMAND "Start" DISPLAY "Start" COMMAND "Stop" DISPLAY "Stop" COMMAND "Quit" EXIT MENU END MENU
In this example, when pressing S on the keyboard, the focus will toggle between "Start" and "Stop"buttons, and the current option can be selected with the Return or Space key. When pressing Q, the "Quit" action will be fired.
To write abstract code without decoration in your programs, use the ON ACTION clause instead of COMMAND [KEY], except if the action view must get the focus.
Note that if you use an ampersand (&) in the command name, some front-ends consider the letter following & as an Alt-key accelerator, and the letter will be underscored. However the ampersand forms part of the action name. For example, COMMAND "&Save" will create an action with the name "&save".
In TUI mode, actions created with COMMAND [KEY] do not get accelerators from action defaults; Only actions defined with ON ACTION will get accelerators of action defaults.