Eclipse插件:标记的自定义图标 [英] Eclipse plugin: Custom icon for a Marker

查看:144
本文介绍了Eclipse插件:标记的自定义图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为标记指定一个自定义图标。不幸的是,我选择的图标不显示。



这是plugin.xml文件(项目编号x)的相关部分:

 < extension 
id =xmlProblem
name =XML问题
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 作为 超类型

解决方案

请参阅 bug 260909 markerImageProviders扩展点不起作用(阅读这个线程


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



我们从未有过这样的API,因为它有一些不灵活性,使得它通常不是可消费的 - 早期写的是为我们使用的3个严重性的第一个标记视图,因此没有使用markerSupport,因为它不是API。



令人困惑的是,我们有一个内部扩展点(我们通常不会
)但删除它可能会打破某人的威胁


[由Itay编辑]



随着Vonc的指点,我终于设法使这个事情发挥作用。
这是我的 plugin.xml 中的相关片段(假设插件名称为 abc

 < 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 =abcmyMarker
name =abcmyAnnotation
markerSeverity = 1/>
< / extension>

< extension point =org.eclipse.ui.editors.markerAnnotationSpecification>
< specification
annotationType =abcmyAnnotation
icon =icons / marker.png
verticalRulerPreferenceKey =myMarkerIndicationInVerticalRuler
verticalRulerPreferenceValue =true/> ;
< / extension>

陷阱




  • 标记的超级类型必须设置为 org.eclipse.core.resources.textmarker 。任何其他值将阻止您使用自定义图标。

  • 在代码中创建标记时,请确保其严重性与 markerSeverity 属性在 org.eclipse.ui.editors.annotationTypes 扩展点。 1 表示警告等。

  • 确保您的build.properties文件(或构建)选项卡中指定了图标文件夹在插件编辑器上)

  • 上面的声明只会指定一个自定义图标。如果要自定义其他属性(概览标尺的指示颜色等),请从这里


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"):

<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>

I also tried specifying a class (implementing IMarkerImageProvider) instead of an icon, but that getImagePath() method of the class does not get called.

Any thoughts on how to make custom marker icons work?

Desperately, yours.

-Itay

Update

VonC's solution is pretty much correct, except that you must not specify org.eclipse.core.resources.problemmarker as a supertype of your marker. It worked only when I used org.eclipse.core.resources.textmarker as the only supertype.

解决方案

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.

这篇关于Eclipse插件:标记的自定义图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆