Creates popupmenus for mouse events. This object holds an XML node which is a description of the popup menu to be created. In createMenu, the configuration is applied to the context and the resulting menu items are added to the menu dynamically. See createMenu for a description of the configuration format.
This class does not create the DOM nodes required for the popup menu, it only parses an XML description to invoke the respective methods on an mxPopupMenu each time the menu is displayed.
This class uses the mxDefaultPopupMenuCodec to read configuration data into an existing instance, however, the actual parsing is done by this class during program execution, so the format is described below.
mxDefaultPopupMenu | Creates popupmenus for mouse events. |
Functions | |
mxDefaultPopupMenu | Constructs a new popupmenu-factory based on given configuration. |
Variables | |
imageBasePath | Base path for all icon attributes in the config. |
config | XML node used as the description of new menu items. |
Functions | |
createMenu | This function is called from mxEditor to add items to the given menu based on config. |
addItems | Recursively adds the given items and all of its children into the given menu. |
addAction | Helper method to bind an action to a new menu item. |
createConditions | Evaluates the default conditions for the given context. |
mxDefaultPopupMenu.prototype.config
XML node used as the description of new menu items. This node is used in createMenu to dynamically create the menu items if their respective conditions evaluate to true for the given arguments.
mxDefaultPopupMenu.prototype.createMenu = function( editor, menu, cell, evt )
This function is called from mxEditor to add items to the given menu based on config. The config is a sequence of the following nodes and attributes.
add | Adds a new menu item. See below for attributes. |
separator | Adds a separator. No attributes. |
condition | Adds a custom condition. Name attribute. |
The add-node may have a child node that defines a function to be invoked before the action is executed (or instead of an action to be executed).
as | Resource key for the label (needs entry in property file). |
action | Name of the action to execute in enclosing editor. |
icon | Optional icon (relative/absolute URL). |
iconCls | Optional CSS class for the icon. |
if | Optional name of condition that must be true(see below). |
name | Name of custom condition. Only for condition nodes. |
nocell | No cell under the mouse. |
ncells | More than one cell selected. |
notRoot | Drilling position is other than home. |
cell | Cell under the mouse. |
notEmpty | Exactly one cell with children under mouse. |
expandable | Exactly one expandable cell under mouse. |
collapsable | Exactly one collapsable cell under mouse. |
validRoot | Exactly one cell which is a possible root under mouse. |
swimlane | Exactly one cell which is a swimlane under mouse. |
<mxDefaultPopupMenu as="popupHandler"> <add as="delete" action="delete" icon="images/delete.gif" if="cell"/> </mxDefaultPopupMenu>
<mxDefaultPopupMenu as="popupHandler"> <add as="action1"><![CDATA[ function (editor, cell, evt) { editor.execute('action1', cell, 'myArg'); } ]]></add> </mxDefaultPopupMenu>
The above example invokes action1 with an additional third argument via the editor instance. The third argument is passed to the function that defines action1. If the add-node has no action-attribute, then only the function defined in the text content is executed, otherwise first the function and then the action defined in the action-attribute is executed. The function in the text content has 3 arguments, namely the mxEditor instance, the mxCell instance under the mouse, and the native mouse event.
<condition name="condition1"><![CDATA[ function (editor, cell, evt) { return cell != null; } ]]></condition>
<add as="action1" action="action1" icon="action1.gif" if="condition1"/>
The order in which the items and conditions appear is not significant as all connditions are evaluated before any items are created.
editor | Enclosing mxEditor instance. |
menu | mxPopupMenu that is used for adding items and separators. |
cell | Optional mxCell which is under the mousepointer. |
evt | Optional mouse event which triggered the menu. |
mxDefaultPopupMenu.prototype.addItems = function( editor, menu, cell, evt, conditions, item, parent )
Recursively adds the given items and all of its children into the given menu.
editor | Enclosing mxEditor instance. |
menu | mxPopupMenu that is used for adding items and separators. |
cell | Optional mxCell which is under the mousepointer. |
evt | Optional mouse event which triggered the menu. |
conditions | Array of names boolean conditions. |
item | XML node that represents the current menu item. |
parent | DOM node that represents the parent menu item. |
mxDefaultPopupMenu.prototype.addAction = function( menu, editor, lab, icon, funct, action, cell, parent, iconCls )
Helper method to bind an action to a new menu item.
menu | mxPopupMenu that is used for adding items and separators. |
editor | Enclosing mxEditor instance. |
lab | String that represents the label of the menu item. |
icon | Optional URL that represents the icon of the menu item. |
action | Optional name of the action to execute in the given editor. |
funct | Optional function to execute before the optional action. The function takes an mxEditor, the mxCell under the mouse and the mouse event that triggered the call. |
cell | Optional mxCell to use as an argument for the action. |
parent | DOM node that represents the parent menu item. |
iconCls | Optional CSS class for the menu icon. |
Constructs a new popupmenu-factory based on given configuration.
function mxDefaultPopupMenu( config )
Base path for all icon attributes in the config.
mxDefaultPopupMenu.prototype.imageBasePath
XML node used as the description of new menu items.
mxDefaultPopupMenu.prototype.config
This function is called from mxEditor to add items to the given menu based on config.
mxDefaultPopupMenu.prototype.createMenu = function( editor, menu, cell, evt )
Recursively adds the given items and all of its children into the given menu.
mxDefaultPopupMenu.prototype.addItems = function( editor, menu, cell, evt, conditions, item, parent )
Helper method to bind an action to a new menu item.
mxDefaultPopupMenu.prototype.addAction = function( menu, editor, lab, icon, funct, action, cell, parent, iconCls )
Evaluates the default conditions for the given context.
mxDefaultPopupMenu.prototype.createConditions = function( editor, cell, evt )