如果写成: Menu menu = popupMenuManager.createContextMenu([b]this.sourceViewer.getControl()[/b]);
[b] this.sourceViewer.getControl()[/b].setMenu(menu);
则无法弹出菜单!
正确写法:
protected void initializeHookContextMenu()
{
//创建菜单管理对象
MenuManager popupMenuManager = new MenuManager();
//add copy action
popupMenuManager.add(ActionManager.INSTANCE.getAction(CopyAction.ACTION_ID));
//add paste action
popupMenuManager.add(ActionManager.INSTANCE.getAction(PasteAction.ACTION_ID));
//add delete action
popupMenuManager.add(ActionManager.INSTANCE.getAction(DeleteAction.ACTION_ID));
popupMenuManager.add(new Separator());
//add refresh action
popupMenuManager.add(ActionManager.INSTANCE.getAction(RefreshAction.ACTION_ID));
//为project树对象创建上下文菜单
Menu menu = popupMenuManager.createContextMenu([b]this.sourceViewer.getTextWidget()[/b]);
//设置菜单
[b]this.sourceViewer.getTextWidget()[/b].setMenu(menu);
}
[b] this.sourceViewer.getControl()[/b].setMenu(menu);
则无法弹出菜单!
正确写法:
protected void initializeHookContextMenu()
{
//创建菜单管理对象
MenuManager popupMenuManager = new MenuManager();
//add copy action
popupMenuManager.add(ActionManager.INSTANCE.getAction(CopyAction.ACTION_ID));
//add paste action
popupMenuManager.add(ActionManager.INSTANCE.getAction(PasteAction.ACTION_ID));
//add delete action
popupMenuManager.add(ActionManager.INSTANCE.getAction(DeleteAction.ACTION_ID));
popupMenuManager.add(new Separator());
//add refresh action
popupMenuManager.add(ActionManager.INSTANCE.getAction(RefreshAction.ACTION_ID));
//为project树对象创建上下文菜单
Menu menu = popupMenuManager.createContextMenu([b]this.sourceViewer.getTextWidget()[/b]);
//设置菜单
[b]this.sourceViewer.getTextWidget()[/b].setMenu(menu);
}