@interface name="KitMenubars" alias="$ENV">
Extension point for defining kit menubars/toolbars
(c) SAP AG 2003-2006. All rights reserved.
+
? # The menubar category# The menubar description# Indicates whether the menubar can
be edited by the user
*
ExampleSTANDARDStandardtrue
function defineMenubar(id, category, description, editable, icon) {
var mnu=[];
mnu.findPos = _findMenuPos;
mnu.getItem = _getMenuItem;
mnu.append = _appendMenuItem;
mnu.insert = _insertMenuItem;
mnu.remove = _removeMenuItem;
mnu.clear = _clearMenuItems;
if (!id) return mnu;
if (!isValidId(id)) return raiseKitError('Invalid namespace specification of Id:'+ id + " in kit :" + _currentPackage);
id = UPPER(id);
if (id in _kitMenubars) return raiseKitError('Menubar "'+id+'" is already defined');
mnu.id = id;
mnu.category = category;
mnu.text = mnu.description = description || '';
mnu.icon = icon || '';
mnu.editable = BOOL(editable);
_kitMenubars[id] = mnu;
delete _usrMenubars[id];
if (editable && typeof $CTL != 'undefined') {
$CTL.addVar(id, 'str', '', 'user');
}
return mnu;
}
<@method name="getMenubar">
Returns the kit-default version of a specified menubar
The menubar id
The requested menubar
function getMenubar(id) {
return _kitMenubars[UPPER(id)] || null;
}
<@method name="getMenubarsTable">
Returns the complete menubars table (kit-default versions)
Table of menubar objects, indexed by menubar id
Menuber id's are stored in uppercase. Use @lib:Basic!UPPER macro to convert the menubar id to uppercase
before using it as the index in this table.
function getMenubarsTable() {
return _kitMenubars;
}
<@method name="getUserMenubar">
Returns the user-tailored version of a specified menubar
The menubar id
The tailored menubar
function getUserMenubar(id) {
id = UPPER(id);
// all the items that are defined in the framework.
var sysmenu = _kitMenubars[id] || null;
// all the customized user defined items .
var usrmenu = _usrMenubars[id] || null;
/* the items that are saved on the server, per user.
this is used for initialize the usrmenu items. */
var usrdata = GETVAR(id);
if (!sysmenu || !sysmenu.editable) return sysmenu;
if (usrmenu) return usrmenu;
if (!usrdata) return sysmenu;
usrmenu = [];
usrmenu.id = sysmenu.id;
usrmenu.category = sysmenu.category;
usrmenu.editable = sysmenu.editable;
var items = VAL(usrdata)||[];
for (var i=0, len=items.length; i
Returns the complete table of user-tailored menubars
Table of menubar objects, indexed by menubar id
Menuber id's are stored in uppercase. Use @lib:Basic!UPPER macro to convert the menubar id to uppercase
before using it as the index in this table.
function getUserMenubarsTable() {
return _usrMenubars;
}
<@method name="setUserMenubar">
Tailors a specified menubar for the current user
The menubar Id
The tailored menubar items array
function setUserMenubar(id, items) {
id = UPPER(id);
if (!(id in _kitMenubars)) return;
delete _usrMenubars[id];
SETVAR(id, STR(items||[]));
}
<@method name="removeMenubar">
Removes a specified menubar definition
The menubar id
function removeMenubar(id) {
id = UPPER(id);
delete _kitMenubars[id];
delete _usrMenubars[id];
}
<@method name="resetMenubar">
Resets a specified menubar to kit defaults
The menubar Id
function resetMenubar(id) {
id = UPPER(id);
SETVAR(id, '');
delete _usrMenubars[id];
}
// INTERNAL: appends a menu item to this menubar
function _appendMenuItem(item, after) {
if (after) {
this.splice(MIN(this.findPos(after)+1, this.length), 0, _expandMenuItem(item));
} else {
this.push(_expandMenuItem(item));
}
}
// INTERNAL: gets the position of a specified menu item
function _findMenuPos(id) {
if (!id) return 0;
if (typeof id == 'number') return MAX(0, MIN(this.length, id));
id = UPPER(id);
for (var i=0, len=this.length; i
Parses the given menubar node and returns a string which represents its details
Menubar node to parse
function parseMenubar(menubarNode) {
var map = getNodeProps(menubarNode);
var res="", size=0;
for (var k in map) size++; // get the map's size
if (size==0) return "var menubar = $ENV.defineMenubar();";
var id = map['id'];
var category = map['category'];
var desc = map['description'];
var edit = map['editable'];
if (!id || !category || !desc || ! edit) return res;
res+="var menubar = $ENV.defineMenubar(" + STR(id) + "," + STR(category) + "," + STR(desc) + "," + edit + ");";
res = parseItems(res, menubarNode);
return res;
}
// INTERNAL: parses the items in the given menubar, and returns their details
function parseItems(res, menubarNode) {
var items = menubarNode && menubarNode.childNodes|| [];
for (var i=0;i
Represents a %STUDIO% menubar or toolbar definition
The MENU_BAR structure is made of:
Name | Type | Description
id | QName | Menubar Id - must be prefixed with namespace e.g. com.sap.mypackage:id
category | String | The menubar category
description | String | The menubar description
editable | Boolean | Indicates whether the menubar can be edited by the user
0..n | @MENU_ITEM | The menubar items, indexed by display order
In addition, the structure has the following methods:
menubar.append(menuitem, after)
Appends a menu item just after another item in the menubar, where:
Parameter | Type | Description
menuitem | @MENU_ITEM | The menu item to append
after | QName | Optional. The id of the menu item after which the new item will be appended
If ~after is omitted or not found, the new menu item will be appended at the end of the menubar.
menuitem = menubar.getItem(id)
Gets a specified menu item by Id or by position, where:
Parameter | Type | Description
id | QName/Number | The menu item id or ordinal position
menuitem | @MENU_ITEM | The requested menu item
menubar.insert(menuitem, before)
Inserts a menu item just before another item in the menubar, where:
Parameter | Type | Description
menuitem | @MENU_ITEM | The menu item to insert
before | QName | Optional. The id of the menu item before which the new item will be inserted
If ~before is omitted, the new menu item will be inserted at the beginning of the menubar.
If ~before is not found, the new menu item will be inserted at the end of the menubar.
menubar.remove(id)
Removes a menu item from the menubar, where:
Parameter | Type | Description
id | QName | The Id of the menu item to remove
menubar.clear()
Clears all items from the menubar
<@struct name="MENU_ITEM">
A union representing a menubar/toolbar item
The MenuItem is a union of the following menu item structure types:
Menu Button
Name | Type | Description
button | QName | Id of command to invoke when this menu button is clicked (can be omitted if the signal and the text/icon properties are provided)
signal | String | Menu button signal (overrides corresponding property on associated command)
text | String | Menu button label (overrides corresponding property on associated command)
icon | String | Menu button icon (overrides corresponding property on associated command)
key | String | Shortcut key mnemonic (overrides corresponding property on associated command)
check | Boolean | A predicate indicating whether to display the button as a checkbox.
radio | Boolean | A predicate indicating whether to display the button as a radio button.
toggle | Boolean | A predicate indicating whether to display the button as a toggle icon.
disable | Boolean | A predicate indicating whether to display the button as disabled.
Alternatively, if the MenuItem is a plain string it will be interpreted as a command button identifier,
and the rest of the structure members will be filled automatically from the correspondig command definition.
Menu Input
Name | Type | Description
input | QName | Id of command to invoke when this menu input is changed (can be omitted if the signal and the text/icon properties are provided)
signal | String | Menu input signal (overrides corresponding property on associated command)
text | String | Menu input label (overrides corresponding property on associated command)
Menu Group
Name | Type | Description
group | String | Menu group Id (can be omitted)
text | String | Menu group label
show | Boolean | Indicates whether the group should be initially expanded
Menu Dropdown
Name | Type | Description
menu | QName | Id of submenu to open when this menu dropdown is clicked
text | String | Menu display label
icon | String | Menu display icon
Menu Separator
A ~null or empty object