弹出菜单的定义保存在配置文件editor-commons.xml中,在mxDefaultPopupMenu节下,增加的方法与Toolbar基本一样。出了使用add增加action外,还可以使用<separator/>增加分隔线。如果增加子菜单,可以在add标签中增加子菜单项,比如:
<add as="shape" if="cell">
<add as="group" action="group" icon="Lib/mxGraph/editors/images/group.gif" if="ncells"/>
<add as="ungroup" action="ungroup" icon="Lib/mxGraph/editors/images/ungroup.gif" if="cell"/>
<separator/>
<add as="removeFromParent" action="removeFromParent" if="cell"/>
<separator/>
<add as="collapse" action="collapse" icon="Lib/mxGraph/editors/images/collapse.gif" if="expandable"/>
<add as="expand" action="expand" icon="Lib/mxGraph/editors/images/expand.gif" if="collapsable"/>
<separator/>
<add as="toFront" action="toFront" icon="Lib/mxGraph/editors/images/tofront.gif" if="cell"/>
<add as="toBack" action="toBack" icon="Lib/mxGraph/editors/images/toback.gif" if="cell"/>
<separator/>
<add as="editStyle" action="editStyle" if="cell"/>
</add>
add标签中可以使用if属性,将菜单指定为特定的对象,比如 if="cell"。在action中增加对菜单动作的响应,比如我们增加自定义属性菜单:
<add as="myproperties" action="myProperties" icon="Lib/mxGraph/editors/images/properties.gif"/>
对应的菜单action为:
<add as="myProperties">
<![CDATA[
function (editor,cell)
{
alert(cell.value);
}
]]>
</add>
菜单项的文字在资源文件中定义,我们在resources/app_zh.txt中增加:
myproperties=附加属性
访问页面,在图元上按右键弹出菜单:
图片.png