您如何在 Eclipse 中向编辑器上下文菜单提供命令 [英] How do you contribute a command to an editor context menu in Eclipse

查看:14
本文介绍了您如何在 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 中向编辑器上下文菜单提供命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆