解决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编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

Goland debug失效详细解决步骤(合集)

《Golanddebug失效详细解决步骤(合集)》今天用Goland开发时,打断点,以debug方式运行,发现程序并没有断住,程序跳过了断点,直接运行结束,网上搜寻了大量文章,最后得以解决,特此在这... 目录Bug:Goland debug失效详细解决步骤【合集】情况一:Go或Goland架构不对情况二:

解决jupyterLab打开后出现Config option `template_path`not recognized by `ExporterCollapsibleHeadings`问题

《解决jupyterLab打开后出现Configoption`template_path`notrecognizedby`ExporterCollapsibleHeadings`问题》在Ju... 目录jupyterLab打开后出现“templandroidate_path”相关问题这是 tensorflo

如何解决Pycharm编辑内容时有光标的问题

《如何解决Pycharm编辑内容时有光标的问题》文章介绍了如何在PyCharm中配置VimEmulator插件,包括检查插件是否已安装、下载插件以及安装IdeaVim插件的步骤... 目录Pycharm编辑内容时有光标1.如果Vim Emulator前面有对勾2.www.chinasem.cn如果tools工

Java多线程父线程向子线程传值问题及解决

《Java多线程父线程向子线程传值问题及解决》文章总结了5种解决父子之间数据传递困扰的解决方案,包括ThreadLocal+TaskDecorator、UserUtils、CustomTaskDeco... 目录1 背景2 ThreadLocal+TaskDecorator3 RequestContextH

SpringBoot+MyBatis-Flex配置ProxySQL的实现步骤

《SpringBoot+MyBatis-Flex配置ProxySQL的实现步骤》本文主要介绍了SpringBoot+MyBatis-Flex配置ProxySQL的实现步骤,文中通过示例代码介绍的非常详... 目录 目标 步骤 1:确保 ProxySQL 和 mysql 主从同步已正确配置ProxySQL 的

解决JavaWeb-file.isDirectory()遇到的坑问题

《解决JavaWeb-file.isDirectory()遇到的坑问题》JavaWeb开发中,使用`file.isDirectory()`判断路径是否为文件夹时,需要特别注意:该方法只能判断已存在的文... 目录Jahttp://www.chinasem.cnvaWeb-file.isDirectory()遇

Spring Boot整合log4j2日志配置的详细教程

《SpringBoot整合log4j2日志配置的详细教程》:本文主要介绍SpringBoot项目中整合Log4j2日志框架的步骤和配置,包括常用日志框架的比较、配置参数介绍、Log4j2配置详解... 目录前言一、常用日志框架二、配置参数介绍1. 日志级别2. 输出形式3. 日志格式3.1 PatternL