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

Ita*_*man 5 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>
Run Code Online (Sandbox Code Playgroud)

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

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

绝望地,你的.

-Itay

更新

VonC的解决方案非常正确,除了您不能指定org.eclipse.core.resources.problemmarker为标记的超类型.它只有当我用工作org.eclipse.core.resources.textmarker作为唯一的超类型.

Von*_*onC 4

请参阅bug 260909 “markerImageProviders 扩展点不起作用”(阅读此线程后发现)

托德·克雷西 2009-01-21 07:32:38 美国东部时间

我们从来没有推动过这个 API,因为它有一些不灵活性,使得它通常不可使用 - 它是在早期编写的,以便为我们使用的 3 个严重性启用第一个标记视图,因此没有被标记支持使用这不是 API。

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

[伊泰编辑]

按照冯克的指示,我最终成功地让这件事成功了。这是我的相关片段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>
Run Code Online (Sandbox Code Playgroud)

陷阱

  • 标记的超级类型必须设置为org.eclipse.core.resources.textmarker。任何其他值都将阻止使用您的自定义图标。
  • 当您在代码中创建标记时,请确保其严重性与扩展点markerSeverity属性中指定的严重性值相匹配org.eclipse.ui.editors.annotationTypes1表示警告等。
  • 确保在 build.properties 文件(或插件编辑器的“build”选项卡)中指定了图标文件夹
  • 上面的声明只会指定一个自定义图标。如果您想自定义其他属性(概览标尺上的指示颜色等),请遵循解决方案所基于的示例。