简体   繁体   English

Eclipse编辑器中的上下文相关菜单

[英]Context sensitive menu in eclipse editor

If I use eclipse and right click on a part of Java source code, the context menu depends on the syntactic element the user clicks on (like: a method, a variable,...). 如果使用eclipse并右键单击Java源代码的一部分,则上下文菜单取决于用户单击的语法元素(例如:方法,变量等)。

How can I implement this kind of behaviour in my own eclipse plugin, eg add an item to the context menu only if the user clicks on a method in Java source code. 如何在自己的eclipse插件中实现这种行为,例如,仅当用户单击Java源代码中的方法时,才将项目添加到上下文菜单。 Furthermore, the plugin needs to know which method the user clicks on. 此外,该插件需要知道用户单击哪种方法。

I guess I have to relate the clicking position to the abstract syntax tree that eclipse builds but I have no idea how to do that. 我想我必须将单击位置与eclipse构建的抽象语法树相关联,但是我不知道该怎么做。

You do this with Eclipse Commands and you can enable them and change their visibility in many ways, depending on selection, global state, etc. 您可以使用Eclipse命令执行此操作,并且可以根据选择,全局状态等以多种方式启用它们并更改其可见性。

I guess I have to relate the clicking position to the abstract syntax tree that eclipse builds but I have no idea how to do that. 我想我必须将单击位置与eclipse构建的抽象语法树相关联,但是我不知道该怎么做。

The good news is you (generally) don't have to do that, Eclipse has done all that heavy lifting for you. 好消息是您(通常)不必这样做,Eclipse已经为您完成了所有繁重的工作。

It is quite a broad subject, so I suggest working through some tutorials on Commands first: 这是一个广泛的主题,因此,我建议先完成一些有关Commands的教程:

  1. Adding menus, toolbar and popup menus to the Eclipse IDE - Tutorial 将菜单,工具栏和弹出菜单添加到Eclipse IDE-教程
  2. Eclipse Commands Advanced - Tutorial Eclipse Commands Advanced-教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM