[英]Add custom markers to java editor in eclipse
我一直在尝试将自定义标记添加到eclipse编辑器中很多小时(几天),但是我无法使其正常工作。
通过在我自己的plugin.xml
上扩展问题标记,可以很好地添加问题标记,而不会出现任何问题。 除了标记的图标,它可以完成我想要的所有操作。 我想要一个不同的图标。 这是我所拥有的:
plugin.xml
<extension
point="org.eclipse.ui.editors.annotationTypes">
<type
markerType="Plugin.MyMarker"
name="Plugin.MyMarker"/>
</extension>
<extension
id="MyMarker"
point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.textmarker" />
<!-- <super type="org.eclipse.core.resources.problemmarker" /> --><!-- if I remove this comment, all works... But I don't want that icon-->
<persistent value="true"/>
</extension>
<extension
id="Plugin.markerAnnotationSpecifications"
point="org.eclipse.ui.editors.markerAnnotationSpecification">
<specification
annotationType="Plugin.MyMarker"
colorPreferenceKey="Plugin.markerColor"
colorPreferenceValue="100,100,100"
contributesToHeader="false"
highlightPreferenceKey="Plugin.markerHighlight"
highlightPreferenceValue="true"
includeOnPreferencePage="true"
icon="icons/icon_mine.gif"
label="My beautiful label"
overviewRulerPreferenceKey="Plugin.markerOverview"
overviewRulerPreferenceValue="true"
presentationLayer="0"
symbolicIcon="warning"
textPreferenceKey="Plugin.tarkerText"
textPreferenceValue="true"
textStylePreferenceKey="Plugin.textStyle"
textStylePreferenceValue="BOX"
verticalRulerPreferenceKey="Plugin.markerRuler"
verticalRulerPreferenceValue="true" />
MyPlugin.java
IMarker myMarker = file.createMarker("Plugin.MyMarker");
if(!myMarker.exists()){
Activator.myLog.log(new Status(Status.ERROR, LOG_PLUGIN_NAME, 15, "There's no marker!", null));
}
myMarker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
myMarker.setAttribute(IMarker.MESSAGE, "Txt:\nabc");
myMarker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
myMarker.setAttribute(IMarker.LINE_NUMBER, line);
myMarker.setAttribute(IMarker.CHAR_START, searchStart);
myMarker.setAttribute(IMarker.CHAR_END, searchEnd);
标记图片在这里: icon="icons/icon_mine.gif"
如果我使用上面的代码,则注释会出现在菜单中的注释( General>Editors>TextEditors>Annotations
)选项下,并带有正确的图像和我期望的正确选项。
如果我只是更改在XML中注释的行(请参阅XML注释),则我在代码中放置的其他日志消息将确认该代码与结果的执行效果相同。
但是,仍然看不到任何东西告诉我标记是实际上是在应用还是错误(或在日志或控制台中的任何内容)。 好像我什么都没设置,什么也没发生。
欢迎任何帮助
请检查每个<extension>
的ID是否以与项目包相同的子字符串开头。 我看到您使用Plugin
作为软件包,并且软件包通常以小写字母开头。
请尝试将ID的前缀重命名为plugin.
(小写),而不是Plugin
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.