解决RCP中CNF(navigator)配置后delete\copy\past快捷键失效

2023-12-14 17:32

本文主要是介绍解决RCP中CNF(navigator)配置后delete\copy\past快捷键失效,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这两天在配置一个CNF导航视图时候发现快捷键delete、past、copy等都失效了,折腾良久,搞清楚了;


1.快捷键要想能在菜单右边显示出来:

deleteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE);

2.要想生效必须绑定handler:

@Overridepublic 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绑定到一块;

这里你发现绑定的action并不是自己那个action,是texthandler中的action;

如果想强制生效可以直接把这个action换成我们那个action;


3.推荐的解决方法:

之所以不生效,是因为系统找不到action对应的commandid,我们可以绑定:

protected void makeActions() {clipboard = new Clipboard(shell.getDisplay());...deleteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE);initActionCommandMappingService();}/*** 快捷键绑定actionBars.setGlobalActionHandler();* 这里使用了textActionHandler.updateActionBars();所以绑定的是textActionHandler中text*Action,而不是这里的action;* 方法一:重新设置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);}}

这样问题就解决了






这篇关于解决RCP中CNF(navigator)配置后delete\copy\past快捷键失效的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/493413

相关文章

解决IDEA报错:编码GBK的不可映射字符问题

《解决IDEA报错:编码GBK的不可映射字符问题》:本文主要介绍解决IDEA报错:编码GBK的不可映射字符问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录IDEA报错:编码GBK的不可映射字符终端软件问题描述原因分析解决方案方法1:将命令改为方法2:右下jav

MyBatis模糊查询报错:ParserException: not supported.pos 问题解决

《MyBatis模糊查询报错:ParserException:notsupported.pos问题解决》本文主要介绍了MyBatis模糊查询报错:ParserException:notsuppo... 目录问题描述问题根源错误SQL解析逻辑深层原因分析三种解决方案方案一:使用CONCAT函数(推荐)方案二:

SpringBoot3.4配置校验新特性的用法详解

《SpringBoot3.4配置校验新特性的用法详解》SpringBoot3.4对配置校验支持进行了全面升级,这篇文章为大家详细介绍了一下它们的具体使用,文中的示例代码讲解详细,感兴趣的小伙伴可以参考... 目录基本用法示例定义配置类配置 application.yml注入使用嵌套对象与集合元素深度校验开发

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊

SpringBoot基于配置实现短信服务策略的动态切换

《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾

关于MongoDB图片URL存储异常问题以及解决

《关于MongoDB图片URL存储异常问题以及解决》:本文主要介绍关于MongoDB图片URL存储异常问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录MongoDB图片URL存储异常问题项目场景问题描述原因分析解决方案预防措施js总结MongoDB图

SpringBoot项目中报错The field screenShot exceeds its maximum permitted size of 1048576 bytes.的问题及解决

《SpringBoot项目中报错ThefieldscreenShotexceedsitsmaximumpermittedsizeof1048576bytes.的问题及解决》这篇文章... 目录项目场景问题描述原因分析解决方案总结项目场景javascript提示:项目相关背景:项目场景:基于Spring

解决Maven项目idea找不到本地仓库jar包问题以及使用mvn install:install-file

《解决Maven项目idea找不到本地仓库jar包问题以及使用mvninstall:install-file》:本文主要介绍解决Maven项目idea找不到本地仓库jar包问题以及使用mvnin... 目录Maven项目idea找不到本地仓库jar包以及使用mvn install:install-file基

如何为Yarn配置国内源的详细教程

《如何为Yarn配置国内源的详细教程》在使用Yarn进行项目开发时,由于网络原因,直接使用官方源可能会导致下载速度慢或连接失败,配置国内源可以显著提高包的下载速度和稳定性,本文将详细介绍如何为Yarn... 目录一、查询当前使用的镜像源二、设置国内源1. 设置为淘宝镜像源2. 设置为其他国内源三、还原为官方