Use org.eclipse cut/copy/paste in custom RCP application(在自定义 RCP 应用程序中使用 org.eclipse 剪切/复制/粘贴)
问题描述
我正在开发一个 RCP 应用程序,我需要在这个应用程序中剪切/复制/粘贴.由于已经有 eclipse 提供的命令(org.eclipse.ui.edit.copy,...)我想在编辑器中使用它们(我已经将它们添加到工具栏,例如).我玩了一点,但我不明白我如何对复制/粘贴命令做出反应.例如.如果某些内容被复制或粘贴,我如何在编辑器中获得通知?
I am developing a RCP application and I need cut/copy/paste in this app. As there are already commands which are delivered by eclipse (org.eclipse.ui.edit.copy, ...) I want to use them (I already added them to the toolbar, e.g.) in an editor. I played around a little, but I don't get it how I can react to the copy/paste command. E.g. how do I get informed in an editor if something was copied or pasted?
有没有一种简单的方法来使用像保存命令这样的命令.在那里我只需要实现 ISaveablePart,然后调用 doSave() 或 doSaveAs() 方法......我真的很喜欢这个,但我没有找到 ICopyablePart,......接口;)
Is there an easy way to use the commands like the Save Command. There I just have to implement the ISaveablePart and then the doSave() or doSaveAs() methods are called...I really like this, but I didn't find ICopyablePart,... interfaces ;)
推荐答案
如果您需要在编辑器或视图中复制(或任何命令)特定行为,您可以为其激活处理程序.通常在您的 createPartControl(Composite)
方法中:
If you need specific behaviour to copy (or any command) within your editor or view, you would activate a handler for it. Usually in your createPartControl(Composite)
method:
IHandlerService serv = (IHandlerService) getSite().getService(IHandlerService.class);
MyCopyHandler cp = new MyCopyHandler(this);
serv.activateHandler(org.eclipse.ui.IWorkbenchCommandConstants.EDIT_COPY, cp);
另一种常见的方式是通过你的 plugin.xml 提供一个处理程序:
The other common way is to provide a handler through your plugin.xml:
<handler commandId="org.eclipse.ui.edit.copy"
handler="com.example.app.MyCopyHandler">
<activeWhen>
<with variable="activePartId">
<equals value="com.example.app.MyEditorId"/>
</with>
</activeWhen>
</handler>
然后在您的处理程序中,您将获得活动部分并在其上调用您的复制实现.例如:
Then in your handler, you would get the active part and call your copy implementation on it. ex:
IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part instanceof MyEditor) {
((MyEditor)part).copy();
}
这篇关于在自定义 RCP 应用程序中使用 org.eclipse 剪切/复制/粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在自定义 RCP 应用程序中使用 org.eclipse 剪切/复制/粘贴


基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01