Eclipse插件:标记的自定义图标

时间:2010-05-22 13:14:14

标签: java eclipse eclipse-plugin

我想为标记指定自定义图标。可悲的是,我没有显示我选择的图标。

这是plugin.xml文件的相关部分(项目ID“x”):

<extension
      id="xmlProblem"
      name="XML Problem"
      point="org.eclipse.core.resources.markers">
   <super type="org.eclipse.core.resources.problemmarker"/>
   <persistent
         value="true">
   </persistent>
</extension>

<extension
      point="org.eclipse.ui.ide.markerImageProviders">
   <imageprovider
         markertype="x.xmlProblem"
         icon="icons/marker.png"
         id="xmlProblemImageProvider">
   </imageprovider>
</extension>

我还尝试指定一个类(实现IMarkerImageProvider)而不是图标,但是不会调用该类的getImagePath()方法。

有关如何制作自定义标记图标的任何想法?

绝望地,你的。

-Itay

更新

VonC的解决方案非常正确,只是您必须指定org.eclipse.core.resources.problemmarker作为标记的超类型。仅当我使用org.eclipse.core.resources.textmarker作为超类型时才有效。

1 个答案:

答案 0 :(得分:4)

请参阅bug 260909“markerImageProviders扩展点不起作用”(在阅读this thread后找到)

  

Tod Creasey 2009-01-21 07:32:38 EST

     

我们从来没有努力制作这个API,因为它有一些不灵活性,使它通常不会消耗 - 它是早期写的,为我们使用的3个严重性启用第一个标记视图,因此没有被使用markerSupport,因为它不是API。

     

令人困惑的是,我们有一个内部扩展点(我们通常不这样做   但是,删除它可能会在没有警告的情况下打破某人。

[由Itay编辑]

根据Vonc的指示,我最终成功地完成了这项工作。 以下是我plugin.xml的相关片段(假设插件名称为a.b.c

  <extension point="org.eclipse.core.resources.markers"   
        id="myMarker">
     <super type="org.eclipse.core.resources.textmarker"/>         
     <persistent value="true"/>
  </extension>

  <extension point="org.eclipse.ui.editors.annotationTypes">
     <type
        super="org.eclipse.ui.workbench.texteditor.warning"
        markerType="a.b.c.myMarker"
        name="a.b.c.myAnnotation"
        markerSeverity="1"/>
  </extension>

  <extension point="org.eclipse.ui.editors.markerAnnotationSpecification">
     <specification
        annotationType="a.b.c.myAnnotation"
        icon="icons/marker.png"
        verticalRulerPreferenceKey="myMarkerIndicationInVerticalRuler"
        verticalRulerPreferenceValue="true"/>
  </extension>

<强>陷阱

  • 标记的超级类型必须设置为org.eclipse.core.resources.textmarker。任何其他值都将阻止您使用自定义图标。
  • 在代码中创建标记时,请确保其严重性与markerSeverity扩展点的org.eclipse.ui.editors.annotationTypes属性中指定的严重性值相匹配。 1表示警告等。
  • 确保在build.properties文件(或插件编辑器中的“构建”标签)中指定了icons文件夹。
  • 上述声明仅指定自定义图标。如果要自定义其他属性(概览标尺上的指示颜色等),请按照此解决方案所基于的here示例进行操作。