2

我有一个以 xml 文件作为输入的流程图编辑器。在 plugin.xml 中,我已将扩展名指定为我的编辑器的 xml,但它在默认的 xml 编辑器中打开。是什么让文件在我的编辑器中打开?我想在我的插件开发中这样做。在我启动我的插件后,没有偏好或使用上下文菜单打开。我想将我的编辑器保留为 xml 文件的默认值

4

2 回答 2

2

检查文件的打开方式上下文菜单,以及文件关联首选项页面上的默认值。

于 2012-09-26T03:01:42.583 回答
2

Eclipse 提供了一种机制,可以根据文件的实际内容以编程方式识别文件类型。组织。蚀。核。内容类型。contentTypes 扩展点可用于定义由“描述器”描述的内容类型,描述器是能够识别给定输入流的特定类型内容的类。设计用于处理特定内容类型的编辑器可以绑定到它而不是文件扩展名。

我们需要在 plugin.xml 中指定内容类型,如下所示

<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type base-type="org.eclipse.core.runtime.xml"
             file-extensions="xml"
             id="ca.ecliptical.examples.contenttype.apples"
             name="Apples File"
             priority="normal">
  <describer class="org.eclipse.core.runtime.content
                    .XMLRootElementContentDescriber">
     <parameter name="element"
                value="apples">
     </parameter>
  </describer>
</content-type>

下面是参考,它工作正常

http://www.developer.com/java/data/article.php/3648736/Eclipse-Tip-Define-Custom-Content-Types-to-Identify-Your-Data-Files.htm

于 2012-09-27T09:57:35.977 回答