问题描述
我想制作一个 Eclipse插件
(文本编辑器)。我会阅读光标下的文本,并显示取决于文本的动态生成的悬停。现在我有一个问题,我不知道我如何阅读文本和添加的悬停。
I would like to make a Eclipse plugin
(text editor). I would "read" the text under the cursor and show a dynamical generated hover that depends on the text. Now I have the problem that I don't know how I can read the text and "add" the hover.
这是我的第一个 Eclipse插件
所以我很高兴为每一个提示我可以得到。
It's my first Eclipse Plugin
so I am happy for each tip I can get.
编辑:
我想将它集成到默认的 Eclipse
Java
编辑器中。我试图用编辑器模板创建一个新的插件
,但我认为这是错误的方式。
I'd like to integrate it into the default Eclipse
Java
editor. I have tried to create a new plugin
with a editor template but I think it is the wrong way.
最后编辑:
来自PKeidel的答案正是我正在寻找的:)
The answer from PKeidel is exactly what I'm looking for :)
感谢PKeidel
推荐答案
您的错误是您创建了一个完整的新编辑器,而不是现有Java编辑器的插件。插件将通过扩展点
激活。在你的情况下,你必须使用 org.eclipse.jdt.ui.javaEditorTextHovers
。
Your fault is that you created a completly new Editor instead of a plugin for the existing Java Editor. Plugins will be activated via extension points
. In your case you have to use org.eclipse.jdt.ui.javaEditorTextHovers
more....
<plugin>
<extension
point="org.eclipse.jdt.ui.javaEditorTextHovers">
<hover
activate="true"
class="path.to_your.hoverclass"
id="id.path.to_your.hoverclass">
</hover>
</extension>
</plugin>
类参数包含您的Class的路径,实现IJavaEditorTextHover
。
public class LangHover implements IJavaEditorTextHover
{
@Override
public String getHoverInfo(ITextViewer textviewer, IRegion region)
{
if(youWantToShowAOwnHover)
return "Your own hover Text goes here"";
return null; // Shows the default Hover (Java Docs)
}
}
应该这样做; - )
That should do it ;-)
这篇关于创建一个带有文本悬停的eclipse插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!