Eclipse plugin: Custom icon for a Marker

前端 未结 1 1418
梦如初夏
梦如初夏 2021-02-09 23:58

I want to specify a custom icon for a marker. Sadly, the icon that I chose is not displayed.

Here\'s the relevant parts of the plugin.xml file (the project id \"x\"):

相关标签:
1条回答
  • 2021-02-10 00:51

    See bug 260909 "markerImageProviders extension point does not work" (found after reading this thread)

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

    We have never had the push to make this API because it has some inflexibility that made it generally not consumable - it was written early on to enable the first marker views for the 3 severities we use and as a result was not used by the markerSupport as it was not API.

    It is confusing that we have an internal extension point (we don't generally do that) but removing it would likely break someone without warning.

    [EDIT by Itay]

    Following on Vonc's pointers, I eventually managed to make this thing work. Here are the relevant fragments from my plugin.xml (assuming the plugin name is 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>
    

    Pitfalls

    • The super type of the marker must be set to org.eclipse.core.resources.textmarker. Any other value will prevent your custom icon from being used.
    • When you create a marker in your code make sure its severity matches the severity value specified in the markerSeverity attribute at the org.eclipse.ui.editors.annotationTypes extension point. 1 means warning, etc.
    • Make sure the icons folder is specified in your build.properties file (or the "build" tab at the plugin editor)
    • The declaration above will only specify a custom icon. If you want to customize other attributes (color of indication at the overview ruler, etc.) follow the sample from here on which this solution is based.
    0 讨论(0)
提交回复
热议问题