GET_MENU_ITEM_POS ​
Gets the position of a specific menu item.
Syntax ​
leo-grammar
CC "Application" GET_MENU_ITEM_POS component:strValue item:strValue
#--> RESULT ecode:intValue pos:intValue .
Parameters ​
component
(strValue) - The Name of the component. Must be one of"acquisition"
,"modeling"
,"analysis"
,"simulation"
,"evaluation"
or"importexport"
.item
(strValue) - The complete path of the menu item whose position to retrieve.
Returns ​
ecode
(intValue) - Contains the error code or0
in case of success. Will be2
if the menu bar could not be retrieved for the component. Will be1
if any part from theitem
is missing.pos
(intValue) - The absolute position of the item, starting at0
. Will be-1
if the item doesn't exist.
Details ​
The value of item
should be the complete path to the menu item, with parts separated by \t
, like in "Model\tOpen..."
.
It is not possible to specify "all"
for the component
(like it is for INSERT_MENU_ITEM).
This command crashes the entire platform when any part from item
is empty! This is for example the case when a menu or sub-menu has been newly created. See examples section for how to deal with these cases.
Examples ​
Get the position of the menu item "Open..." in the menu "Model" of the "modeling" component:
asc
# Get menu item position.
CC "Application" GET_MENU_ITEM_POS component:("modeling")
item:("Model\tOpen...")
Handle creating menus and sub-menus should they be missing:
asc
# Create the menu, sub-menu and menu items if they are missing.
# Using GET_MENU_ITEM_POS with more than one item in the path that is empty (e.g. newly created) crashes the platform. So we have to keep track of what is new.
SETL bMenuAlreadyAvailable:(0) # Was the menu available from the start?
SETL bSubMenuAlreadyAvailable:(0) # Was the sub-menu available from the start?
# Check if the menu is missing and if so create it.
CC "Application" GET_MENU_ITEM_POS component:("modeling") item:("MainMenu")
SETL iPos:(pos)
IF (iPos < 0) {
CC "Application" INSERT_MENU_ITEM component:("modeling") item:("MainMenu") pos:before:"Extras"
# The menu is still empty at this point.
} ELSE {
SETL bMenuAlreadyAvailable:(1) # Yes, it was available.
}
# Check if the sub-menu is missing and if so create it.
SETL iPos:(-1) # We set it to -1 to indicate that the sub-menu might be missing.
IF (bMenuAlreadyAvailable) {
CC "Application" GET_MENU_ITEM_POS component:("modeling") item:("MainMenu\tSubMenu")
SETL iPos:(pos)
}
IF (iPos < 0) {
CC "Application" INSERT_MENU_ITEM component:("modeling") item:("MainMenu\tSubMenu")
# The sub-menu is still empty on this point.
} ELSE {
SETL bSubMenuAlreadyAvailable:(1) # Yes, it was available.
}
# Check if the fist menu item is missing and if so create it.
SETL iPos:(-1) # We set it to -1 to indicate that the menu item might be missing.
IF (bSubMenuAlreadyAvailable) {
CC "Application" GET_MENU_ITEM_POS component:("modeling") item:("MainMenu\tSubMenu\tMenu item 1")
SETL iPos:(pos)
}
IF (iPos < 0) {
CC "Application" raw INSERT_MENU_ITEM component:("modeling") item:("MainMenu\tSubMenu\tMenu item 1") {
# ... Code to execute when clicking the menu item
}
} ELSE {
# Menu item already exists ... what should we do?
}
# At this point the sub-menu has at least one item, so things get easier.
# Check if the second menu item is missing and if so create it.
CC "Application" GET_MENU_ITEM_POS component:("modeling") item:("MainMenu\tSubMenu\tMenu item 2")
IF (pos < 0) {
CC "Application" raw INSERT_MENU_ITEM component:("modeling") item:("MainMenu\tSubMenu\tMenu item 2") {
# ... Code to execute when clicking the menu item
}
} ELSE {
# Menu item already exists ... what should we do?
}
#...
See Also ​
Versions and Changes ​
Available since ADOxx 1.8