How do you contribute a command to an editor context menu in Eclipse(您如何在 Eclipse 中向编辑器上下文菜单提供命令)
问题描述
我想在选择文本时向任何文本编辑器的上下文菜单提供一个命令.在过去"中,我会使用 objectContribution 和带有enablesFor='+'"的嵌套操作来完成此操作.
I want to contribute a command to the context menu of any text editor when text is selected. In "the old days", I would have done this using objectContribution and a nested action with "enablesFor='+'".
如何使用命令而不是操作来做到这一点?
How does one do this using commands instead of actions?
推荐答案
我阅读了有关命令表达式中可用变量的更多信息,我接近自己想弄清楚它,但失败了.然后我在 eclipse 新闻组上问了一个类似的问题,并被引导到正确的方向.下面是一个示例,说明如何主要做我正在寻找的事情:
I read more about the variables available in command expressions, and I came close to figuring it out on my own, but failed. I then asked a similar question on the eclipse newsgroup and was led in the right direction. Here's an example of how to do mostly what I was looking for:
<command
commandId="org.marcesher.blogcodeformatter.commands.wikiFormatterCommand"
tooltip="Format And Copy to Clipboard"
id="org.marcesher.blogcodeformatter.popup.wikiFormatterCommand">
<visibleWhen>
<with variable="selection">
<instanceof value="org.eclipse.jface.text.ITextSelection"/>
</with>
</visibleWhen>
这篇关于您如何在 Eclipse 中向编辑器上下文菜单提供命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您如何在 Eclipse 中向编辑器上下文菜单提供命令


基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01