【发布时间】:2014-07-07 17:04:50
【问题描述】:
是否可以将编辑器与项目 natureId 关联?我有一个项目,其中包含具有不同文件扩展名的文件,但它们使用相同的编辑器进行编辑。
我试图通过将扩展类型留空来将内容类型与 natureId 和编辑器匹配。不幸的是它不起作用或者我做得不对:(
如果可能的话,也可以覆盖项目的默认编辑器!?
到目前为止我已经尝试过:
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
describer="test.FOPContentDescriber"
id="test.content.type"
name="FO Files"
priority="high">
</content-type>
</extension>
<extension
point="org.eclipse.ui.editors">
<editor
class="test.editors.FOEditor"
contributorClass="test.editors.FOEditorContributor"
default="false"
icon="icons/fo_editor_16.png"
id="test.editors.FOEditor"
name="%editor.name">
<contentTypeBinding
contentTypeId="test.content.type">
</contentTypeBinding>
</editor>
内容描述器类:
package test.fop;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.content.IContentDescriber;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.content.ITextContentDescriber;
public class FOPContentDescriber implements IContentDescriber {
public FOPContentDescriber() {
System.out.println("init content describer");
}
@Override
public int describe(InputStream contents, IContentDescription description) throws IOException {
System.out.println("Call describer");
return ITextContentDescriber.VALID;
}
@Override
public QualifiedName[] getSupportedOptions() {
return IContentDescription.ALL;
}
}
【问题讨论】:
-
使用的编辑器由文件内容类型决定,如果没有定义内容类型,则由扩展名决定。项目没有默认编辑器。
-
每个文件都包含我可以识别的格式...文件内容有扩展点吗?
标签: java eclipse eclipse-plugin editor