Fab*_*anB 5 java eclipse eclipse-plugin
我正在开发一个eclipse插件,它将某个Editor与特定的文件扩展名相关联,比如".abc".
问题是我想将.abc文件与该编辑器关联,仅用于我自己的项目.就像现在一样,无论在哪个项目中,它都将始终使用该编辑器打开.abc文件.
如果".abc"文件属于我自己的项目,我该如何打开自己的编辑器呢?
您需要content-type使用org.eclipse.core.contenttype扩展点定义a .然后,您需要将编辑器与特定内容类型(而不是文件扩展名)相关联.
接下来,您需要将项目性质与刚刚定义的内容类型相关联.
在具有特定性质的项目之外时,您可能还需要创建应该用于文件的第二种内容类型.
这是我们在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>
Run Code Online (Sandbox Code Playgroud)
在这里,我们定义groovySource了常规项目和groovyText非常规项目.另请注意,内容类型的优先级不同.
然后,在其他地方,我们将GroovyEditor与groovySource内容类型相关联.