【问题标题】:issues with eclipse plugin decoratoreclipse插件装饰器的问题
【发布时间】:2015-05-12 23:02:51
【问题描述】:

我正在为一些噱头调整我当前的 eclipse 插件,并为文件和文件夹制作了我自己的装饰器。当前文件装饰器如下所示:

<decorator
  lightweight="true"
  id="com.tdm.eclipse.plugin.decorators.readonly"
  label="readOnly file decorator"
  icon="icons/readonly.ico"
  state="true"
  location="TOP_LEFT"
  adaptable="true">
  <description>
    readOnly file decorator
  </description>
  <enablement>
     <and>
     <objectClass name="org.eclipse.core.resources.IFile"/>
     <objectState name ="readOnly" value="true"/> 
     </and>
  </enablement>
</decorator>

当前问题:

I.) 如果文件权限更改为可写,则文件装饰器不会更改,除非您再次重新加载项目(有时会出现文件不同步错误)。

II.) 我只想对特定文件使用装饰器(目前所有只读文件都被装饰)。尝试使用 nameFilter,但不允许在装饰器或 objectState/objectName 内使用。

任何线索如何解决我的问题? 谢谢

【问题讨论】:

    标签: xml eclipse plugins decorator readonly


    【解决方案1】:

    您必须编写一个装饰器类(指定class 属性)而不是使用icon 属性。

    ILightweightLabelDecorator

    public void decorate(Object element, IDecoration decoration)
    

    方法将传递 IFile 作为元素,因此您可以对其进行过滤。

    要处理文件只读属性更改,您必须使用IResourceChangeListener 来监听资源更改。

    当您检测到属性更改时,您可以告诉装饰器管理器进行更新:

    IDecoratorManager decoratorMgr = PlatformUI.getWorkbench().getDecoratorManager();
    
    decoratorMgr.update("your decorator id");
    

    你可以使用

    <objectState name ="extension" value="file extension"/> 
    

    在扩展点按文件扩展名过滤。

    【讨论】:

    • 感谢您的快速响应。已经篡改了装饰器类,但认为在 plugin.xml 中这样做会更短。特定文件的图标是否至少仅适用于 xml?
    • 编辑已经太晚了,所以我不得不再次发布:另一个潜在的问题可能是文件权限更改不是在 Eclipse 中完成的,而是来自外部脚本。 IResourceChangeListener 会注意到它吗??
    • Eclipse 在刷新工作空间或指定“使用本机挂钩或轮询刷新”首选项之前根本看不到外部更改。
    • 您可以按文件扩展名过滤 - 查看更新的答案
    • 非常感谢我正在寻找的信息,但似乎“使用本机挂钩或轮询刷新”并没有更新装饰。也许它只适用于您建议的 IResourceChangeListenener
    猜你喜欢
    • 2011-01-23
    • 2011-11-17
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 2011-07-01
    • 2013-01-11
    • 2012-01-27
    相关资源
    最近更新 更多