国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

解決RCP中CNF(navigator)配置后delete/copy/past快捷鍵失效

2019-11-11 07:29:56
字體:
供稿:網(wǎng)友

這兩天在配置一個(gè)CNF導(dǎo)航視圖時(shí)候發(fā)現(xiàn)快捷鍵delete、past、copy等都失效了,折騰良久,搞清楚了;

1.快捷鍵要想能在菜單右邊顯示出來:

deleteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE);2.要想生效必須綁定handler:

@Override	public void fillActionBars(final IActionBars actionBars) {		if (textActionHandler == null) {			textActionHandler = new TextActionHandler(actionBars); // hook																	// handlers		}		textActionHandler.setCopyAction(copyAction);		textActionHandler.setPasteAction(pasteAction);		textActionHandler.setDeleteAction(deleteAction);		// renameAction.setTextActionHandler(textActionHandler);		updateActionBars();		textActionHandler.updateActionBars();	}
public void updateActionBars() {		actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(),                textCutAction);		actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),                textCopyAction);actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),                textPasteAction);		actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),                textSelectAllAction);		actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),                textDeleteAction);	}setGlobalActionHandler把id和action綁定到一塊;

這里你發(fā)現(xiàn)綁定的action并不是自己那個(gè)action,是texthandler中的action;

如果想強(qiáng)制生效可以直接把這個(gè)action換成我們那個(gè)action;

3.推薦的解決方法:

之所以不生效,是因?yàn)橄到y(tǒng)找不到action對(duì)應(yīng)的commandid,我們可以綁定:

PRotected void makeActions() {		clipboard = new Clipboard(shell.getDisplay());		...		deleteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE);		initActionCommandMappingService();	}	/**	 * 快捷鍵綁定actionBars.setGlobalActionHandler();	 * 這里使用了textActionHandler.updateActionBars();所以綁定的是textActionHandler中text*Action,而不是這里的action;	 * 方法一:重新設(shè)置setGlobalActionHandler為這里的action;	 * 方法二:ActionCommandMappingService中添加這里的action映射WorkbenchCommandConstants.EDIT_*	 */	private void initActionCommandMappingService() {		final IActionCommandMappingService actionCommandMappingService = (IActionCommandMappingService) CommonUIPlugin.getDefault().getWorkbench()				.getActiveWorkbenchWindow().getService(IActionCommandMappingService.class);		final String idDelete = actionCommandMappingService.getCommandId(ActionFactory.DELETE.getId());		if (idDelete == null) {			actionCommandMappingService.map(ActionFactory.DELETE.getId(), IWorkbenchCommandConstants.EDIT_DELETE);		}		final String idCopy = actionCommandMappingService.getCommandId(ActionFactory.COPY.getId());		if (idCopy == null) {			actionCommandMappingService.map(ActionFactory.COPY.getId(), IWorkbenchCommandConstants.EDIT_COPY);		}		final String idPast = actionCommandMappingService.getCommandId(ActionFactory.PASTE.getId());		if (idPast == null) {			actionCommandMappingService.map(ActionFactory.PASTE.getId(), IWorkbenchCommandConstants.EDIT_PASTE);		}	}這樣問題就解決了


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 白城市| 磐安县| 梁河县| 洛扎县| 勐海县| 洛扎县| 砚山县| 芜湖县| 明星| 赫章县| 新昌县| 贵阳市| 海丰县| 林口县| 元谋县| 九龙县| 界首市| 乐山市| 新龙县| 久治县| 山阴县| 库车县| 买车| 阳东县| 富川| 会东县| 太保市| 新乡县| 漳平市| 容城县| 兴山县| 靖边县| 宁化县| 蒲城县| 海淀区| 吴江市| 二连浩特市| 汕尾市| 兴化市| 贵港市| 泰州市|