Specifies a command that is run when the specified menu-bar item or sub- item is selected.
| Note: | This parameter is valid only in an Editor window. |
Scope: Document
Syntax
set submenuinit.Menu_id [drop] Command
query popupinit
Options
Menu_id |
The id of an existing menu-bar item or sub-item. For predefined Editor window items, this is the predefined Editor window name as described in menuactive parameter. For user-defined items, this id can be obtained by querying the actionbarid parameter. |
Command |
A command that is run when the specified menu-bar item or sub-item is selected. |
drop |
Remove the specified command from the callback list of the specified menu-bar item or sub-item. |
Description
You can use the submenuinit parameter to specify a callback routine or command, to be run between the time you request a menu-bar item or sub-item, and the time it appears. The callback routine can use any of the Editor window commands, including the set and query commands, to work with items of interest. A typical callback routine might modify the contents of a sub-menu, depending on the state of the document being edited when the sub-menu is requested.
A menu item or sub-item can have multiple callback routines, which are called in LIFO order. If one of the callback routines returns a non- zero value, no further callbacks will be called.
A callback routine can be removed from the callback list by using the drop argument with the submenuinit parameter. If a callback routine is not explicitly dropped, it remains active until the document is closed.
Examples
set submenuinit.LP_OPTIONS msg Options menu item selected!
set submenuinit.LP_OPTIONS drop msg Options menu item selected!
query submenuinit.LP_OPTIONS
The example assumes that the My tools menu-bar item has been created with the following command:
set actionbar.My_tools.Query_version query version
and that the id attached to this menu item, as returned by querying the actionbarid parameter, is 6008.
The primary callback routine used to create the menu choice in the My tools pull-down menu is shown below:
/* Macro file "del_emp.lx" */
/* Enable pull-down menu item if empty lines are found at the top of a file */
'mark set predel' /* Save the cursor position for later use */
'top' /* Move cursor to first line in the file */
'extract content' /* Get contents of first line */
/* A pair of Editor commands will be run if the pull-down menu item is */
/* selected - 1. run the macro called delemp.lx */
/* - 2. remove the menu item from the pull-down menu when done */
/* These commands are assigned to a variable for easier reading in */
/* the next section where the pull-down menu item is actually created. */
run_cmd = "mult ;macro delemp ;set actionbar.My_tools.Delete_leading_empty_lines"
/* Check line and add pull-down menu item if first line is empty */
if (content = "") then do /* line is empty */
/* Create a pull-down menu item that runs commands to first delete empty */
/* leading lines, and then removes itself from the pull-down menu. */
'set popupmenu.Delete_leading_empty_lines 'run_cmd
end
'mark find predel' /* Restore original cursor position if still existing */
'mark clear predel' /* Clear the mark saving the original cursor position */
exit 0
This callback routine calls another macro called delemp.lx that actually removes the leading empty lines from the file.
/* Macro file "delemp.lx" */
/* Find and remove leading empty lines */
'mark set predel' /* Save the cursor position for later use */
'top' /* move cursor to first line in file */
'extract content' /* get contents of first line */
do while (content="") /* loop while empty lines found */
'block mark element' /* highlight empty lines */
'next element' /* move cursor to next line */
'extract content' /* get contents of next line */
end
'block delete' /* delete marked block */
'mark find predel' /* Restore cursor position if still existing */
'mark clear predel' /* Clear mark saving the cursor position */
exit 0
set submenuinit.6008 del_emp.lx
set submenuinit.6008 drop del_emp.lx
API Return Code
None.
![]()
menuactive Parameter
menucheck Parameter
