<?xml version="1.0" encoding="utf-8"?> <gui:RCPModule xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:gui="cn.smartinvoke.gui.*" xmlns:rcp="cn.smartinvoke.rcp.*" layout="vertical" creationComplete="init()"> <mx:Script> <![CDATA[ import cn.smartinvoke.smartrcp.util.CWorkbenchActions; import cn.smartinvoke.smartrcp.gui.control.CActionManager; import cn.smartinvoke.smartrcp.gui.control.CAppMenuBarManager; import cn.smartinvoke.smartrcp.gui.module.CActionEvent; import cn.smartinvoke.rcp.CAction; import org.eclipse.swt.CEventType; import org.eclipse.swt.widgets.Display; function init():void{ var actionManager:CActionManager=CActionManager.Instance; for(var i:int=0;i<this.cActions1.length;i++){ actionManager.addAction(this.cActions1[i]); } actionManager.addListener('a1',function (evt:CActionEvent):void{ this.infoLabel.text=evt.actionId+" "+evt.path; },this); } //设置菜单条 function onSetMenuBarClick():void{ var menuFile:CMenuRelation=new CMenuRelation("文件"); menuFile.actions=["a5","-","a1",CWorkbenchActions.ID_QUIT]; var menuEdit:CMenuRelation=new CMenuRelation("编辑"); menuEdit.actions=["a2"]; var menuSearch:CMenuRelation=new CMenuRelation("查找"); menuSearch.actions=["a3"]; CAppMenuBarManager.Instance.initMenuBar([menuFile,menuEdit,menuSearch]); } function onAddMenuClick():void{ //添加菜单\ CAppMenuBarManager.Instance.setMenu(menuRelation); } function onDelMenuClick():void{ //删除菜单 CAppMenuBarManager.Instance.removeMenu(menuRelation.label); } function onRemoveAll():void{ //清除所有菜单 CAppMenuBarManager.Instance.removeAll(); } function addMenuItem():void{ var action:CAction=new CAction("file_save","保存文件","/icons/help.gif","保存当前文件"); //action.actionId CActionManager.Instance.addAction(action); CAppMenuBarManager.Instance.addMenuItem(action.actionId,"文件"); } function removeMenuItem():void{ CAppMenuBarManager.Instance.removeMenuItem("file_save","文件"); } var isEnable:Boolean=false; function changeState():void{ CActionManager.Instance.updateEnable("file_save",isEnable=!isEnable); } ]]> </mx:Script> <rcp:CMenuRelation id="menuRelation" label="添加的菜单"> <rcp:actions> <mx:String>a1</mx:String> <mx:String>a2</mx:String> <rcp:CMenuRelation label="子菜单"> <rcp:actions> <mx:String>a3</mx:String> <mx:String>a4</mx:String> <rcp:CMenuRelation label="子菜单1"> <rcp:actions> <mx:String>a5</mx:String> </rcp:actions> </rcp:CMenuRelation> </rcp:actions> </rcp:CMenuRelation> </rcp:actions> </rcp:CMenuRelation> <mx:Array id="cActions1"> <rcp:CAction actionId="a1" enable="false" type="{CAction.AS_RADIO_BUTTON}" text="测试2" toolTip="toolTipTest1..."/> <rcp:CAction actionId="a2" type="{CAction.AS_RADIO_BUTTON}" text="测试3" toolTip="toolTipTest2..."/> <rcp:CAction actionId="a3" type="{CAction.AS_RADIO_BUTTON}" text="测试4" toolTip="toolTipTest3..."/> <rcp:CAction actionId="a4" type="{CAction.AS_RADIO_BUTTON}" text="a4" toolTip="toolTipTest3..."/> <rcp:CAction actionId="a5" type="{CAction.AS_RADIO_BUTTON}" text="a5" toolTip="toolTipTest3..."/> </mx:Array> <mx:Panel title="本模块实现了应用程序菜单的修改功能,点击下面的菜单就会发现菜单的变化" cornerRadius="0" styleName="opaquePanel" width="100%" height="100%"> <mx:Label id="infoLabel"/> <mx:ControlBar horizontalAlign="right"> <mx:Button label="设置菜单条" click="onSetMenuBarClick()"/> <mx:Button label="添加Menu" click="onAddMenuClick()"/> <mx:Button label="删除Menu" click="onDelMenuClick()"/> <mx:Button label="添加文件保存菜单项" click="addMenuItem()"/> <mx:Button label="删除文件保存菜单项" click="removeMenuItem()"/> <mx:Button label="改变文件菜单状态" click="changeState()"/> <mx:Button label="清除所有菜单" click="onRemoveAll()"/> </mx:ControlBar> </mx:Panel> </gui:RCPModule>
smartrcp菜单栏的实现
最新推荐文章于 2013-02-19 09:34:01 发布