在 Eclipse 插件中成功显示 IMarkers
我是插件开发的新手,所以我可能犯了一个愚蠢的错误。我正在尝试开发一个基本插件,它将根据外部输入突出显示选定的行。现在,我只是想突出显示任何线条。我尝试在操作中使用以下代码实现文本标记:
IWorkbenchPage page = window.getActivePage();
IEditorPart editor = page.getActiveEditor();
IResource resource = null;
if (editor != null){
resource = extractResource(editor);
}
try {
IMarker marker = createMarker((IFile) resource, 3);
} catch (CoreException e) {}
createMarker()
创建 IMarker 并设置严重性、行号和消息。
plugin.xml
将选定的 MARKER_TYPE 定义为 org.eclipse.core.resources.textmarker
类型并持久存在。我尝试四处搜索,但我不知道如何对标记进行设置,以在设置后进行一些可见的 UI 更改。什么也没有出现。
I'm a complete newbie to Plugin Development, so I might have made a stupid mistake. I'm trying to develop a basic plugin that'll highlight selected lines based on outside input. For now, I'm just trying to get any lines to highlight at all. I've tried implementing a textmarker with the following code in an action:
IWorkbenchPage page = window.getActivePage();
IEditorPart editor = page.getActiveEditor();
IResource resource = null;
if (editor != null){
resource = extractResource(editor);
}
try {
IMarker marker = createMarker((IFile) resource, 3);
} catch (CoreException e) {}
The createMarker()
creates the IMarker and sets severity, line number, and message.
The plugin.xml
defines the selected MARKER_TYPE as of type org.eclipse.core.resources.textmarker
and persistent. I've tried searching around but I can't figure out what to do to the marker to make some visible UI change after setting it. Nothing appears.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要突出显示错误,那么您还应该将 org.eclipse.core.resources.problemmarker 添加到生成器超级类型中,这样编辑器就可以突出显示它,而无需额外的工作。
否则,您应该使用 org.eclipse.ui.editors.annotationTypes 扩展点为您的标记类型(实际显示在编辑器中)和 org.eclipse 定义新的注释类型。 ui.editors.markerAnnotationSpecification 扩展点,用于自定义该注释的默认视觉表示。
If you are highlighting errors, then you should also add
org.eclipse.core.resources.problemmarker
to maker super types, so it will be highlighter by the editor without additional efforts.Otherwise, you should use
org.eclipse.ui.editors.annotationTypes
extension point to define the new annotation type for your marker type (which is actually displayed in the editor) andorg.eclipse.ui.editors.markerAnnotationSpecification
extension point to customize default visual representation of that annotation.