【问题标题】:Eclipse Plugin Development, associating different editors to same file extensionEclipse 插件开发,将不同的编辑器关联到相同的文件扩展名
【发布时间】:2011-02-10 01:56:58
【问题描述】:

我正在开发一个 Eclipse 插件,它将某个编辑器关联到一个特定的文件扩展名,比如“.abc”。

问题是我只想将 .abc 文件与该编辑器相关联,仅用于我自己的项目和我自己的性质。 就像现在一样,无论在哪个项目中,它都将始终使用该编辑器打开 .abc 文件。

如果“.abc”文件位于具有我自己性质的项目中,我如何才能打开我自己的编辑器?

【问题讨论】:

    标签: java eclipse eclipse-plugin


    【解决方案1】:

    您需要使用org.eclipse.core.contenttype 扩展点定义content-type。然后您需要将您的编辑器与特定的内容类型(而不是文件扩展名)相关联。

    接下来,您需要将您的项目性质与您刚刚定义的内容类型相关联。

    您可能还需要创建第二种内容类型,当您在具有特定性质的项目之外时,该内容类型应该用于您的文件。

    这是我们在 Groovy-Eclipse 中使用的示例,因此 *.groovy 文件在 groovy 项目中默认使用 groovy 编辑器打开,但在 groovy 项目之外使用文本编辑器打开:

     <extension point="org.eclipse.core.contenttype.contentTypes">
        <content-type
           base-type="org.eclipse.jdt.core.javaSource"
           file-extensions="groovy"
           id="groovySource"
           name="Groovy Source File (for Groovy projects)"
           priority="high"/>
    
        <content-type
           base-type="org.eclipse.core.runtime.text"
           file-extensions="groovy"
           id="groovyText"
           name="Groovy Text File (for non-Groovy projects)"
           priority="low"/>
    </extension>
    
    <extension
         id="groovyNature"
         name="Groovy Nature"
         point="org.eclipse.core.resources.natures">
      <runtime>
         <run class="org.codehaus.jdt.groovy.model.GroovyNature"/>
      </runtime>
      <requires-nature id="org.eclipse.jdt.core.javanature"/>
      <content-type
            id="org.eclipse.jdt.groovy.core.groovySource">
      </content-type>
    

    在这里,我们为 groovy 项目定义 groovySource,为非 groovy 项目定义 groovyText。另请注意,内容类型的优先级不同。

    然后,在其他地方,我们将GroovyEditor 与 groovySource 内容类型相关联。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      相关资源
      最近更新 更多