您如何在 Eclipse 中向编辑器上下文菜单提供命令

2022-01-16 00:00:00 eclipse-plugin 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>

相关文章