如何为“开放声明”定义自定义操作Eclipse 中的(快捷键 F3)

发布于 08-14 10:09 字数 432 浏览 10 评论 0原文

如何在插件中为“开放声明”(又名 F3)注册附加处理程序/操作/命令?

我想在 Java 代码中的字符串文字上使用 F3 来导航到声明资源包键的文件。我已经准备好了一个上下文菜单操作来完成这项工作。所缺少的只是一种将其绑定到用户习惯的密钥的方法。

完整的扩展点带注释列表的额外奖励。我厌倦了必须花半天时间才能找到我必须用于某个功能的扩展点。我所说的“带注释”的意思不仅仅是

Identifier: org.eclipse.ui.workbench.texteditor.quickdiffReferenceProvider
Description: Allows contributors to add reference providers for the quick diff display.

How do I register an additional handler/action/command for "Open Declaration" (aka F3) in a plugin?

I want to use F3 on String literals in Java code to navigate to the files declaring resource bundle keys. I already have a context menu action ready that does the job. All that's missing is a way to bind it to the key that users are used to.

Extra credit for a complete annotated list of extension points. I'm getting tired of having to spend half a day to find the extension point I have to use for a feature. And by "annotated" I mean more than

Identifier: org.eclipse.ui.workbench.texteditor.quickdiffReferenceProvider
Description: Allows contributors to add reference providers for the quick diff display.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初与友歌2024-08-21 10:09:10

有关如何实现的详细说明,请参阅 Eclipse 命令教程中有关键绑定的部分命令处理程序并将它们绑定到按键、菜单和工具栏。

有一个 Eclipse 帮助中提供了完整的扩展点列表,但您必须深入了解才能获得完整的描述和代码示例。插件编辑器中还有一个“添加扩展点”向导,其中显示了简要说明、完整帮助的链接,对于某些扩展点甚至有预定义的模板。

See section on keybindings in Eclipse Commands tutorial for detailed instructions how to implement command handlers and bind them to keys, menus and toolbars.

There is a full list of extension points provided in Eclipse help, though you have to drill down to get the full description and code samples. There is also an "Add extension point" wizard in plugin editor, which shows a brief description, link to the full help and for some extension points even have predefined templates.

爱冒险2024-08-21 10:09:10

也许您知道这一点,但尽管 F3 键盘快捷键不会将您带到声明资源包键,但有两个类似的操作可以起作用:

  • 将鼠标悬停在字符串上将显示转换后的字符串。
  • 按住 Control 键单击该字符串将跳转到声明资源包密钥。

显然,这些都需要使用鼠标;如果您是只使用键盘的人,您可能会对这些不满意。

这并不能直接回答您的问题,但希望对您有所帮助。

Perhaps you know this, but although the F3 keyboard shortcut won't take you to the declaring resource bundle key, there are two similar things that do work:

  • Hovering over the string with the mouse will show you the converted string.
  • Control-clicking the string will jump you to the declaring resource bundle key.

Obviously, these both require use of the mouse; if you are a keyboard-only kind of person, you might not be happy with these.

This doesn't directly answer your question, but I hope it helps.

冷︶言冷语的世界2024-08-21 10:09:10

不幸的是,没有扩展点可供您扩展此功能。我建议您停止尝试使用 Eclipse 命令框架。 JavaEditor 不使用该框架来注册其命令,而是在打开编辑器时注册命令。第三方没有简单的方法来扩展/改变这一点。

按下 F3 时运行的操作是 org.eclipse.jdt.ui.actions.OpenAction。

尽管没有简单的方法来扩展或更改 JavaEditor,但有一些方法可以做到这一点。我针对您的情况推荐的一种方法是通过 Equinox Aspects (http://www.eclipse.org/equinox/incubator/aspects/)。这允许您使用 AspectJ 融入 Eclipse 并根据需要进行更改。

这就是 AJDT (http://eclipse.org/ajdt) 能够改变 JDT 工作方式的方式。

在您的特定情况下,我建议创建一个针对 OpenAction 类实例化的切入点,并将其替换为您创建的实现。它通常委托给 JDT 的实现,或者在您需要时运行您的命令。

如果这就是您正在寻找的解决方案,那么我可以详细说明如何做到这一点。

Unfortunately, there is no extension point for you to extend for this functionality. I recommend that you stop trying to muck around with the Eclipse Command Framework. The JavaEditor does not use that framework to register its commands, and instead, registers commands when the editor is opened. And there is no easy way for third parties to extend/change this.

The action that gets run when F3 is pressed is the org.eclipse.jdt.ui.actions.OpenAction.

Although there is no easy way to extend or change the JavaEditor, there are ways to do this. The one way that I recommend for your situation is through Equinox Aspects (http://www.eclipse.org/equinox/incubator/aspects/). This allows you to use AspectJ to weave into Eclipse and make changes where you require.

This is how AJDT (http://eclipse.org/ajdt) is able to alter the way JDT works.

In your particular situation, I'd recommend creating a pointcut that targets the instantiation of the OpenAction class and replace it with an implementation that you create. It delegates to JDT's implementation normally, or it runs your command when you require it.

If this is the kind of solution that you are looking for, then I can expand on exactly how to do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文