使IClassifier与自定义内容类型一起使用 [英] Getting IClassifier to work with custom content type

查看:124
本文介绍了使IClassifier与自定义内容类型一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为基于文本的自定义内容类型添加语法突出显示

I am trying to add syntax highlighting for a custom content type based on text e.g.

static class RTextContentType
{
    public const string ContentTypeName = Constants.CONTENT_TYPE;
    [Export, Name(ContentTypeName), BaseDefinition("text")]
    internal static ContentTypeDefinition ContentTypeDefinition = null; // set via MEF
}

然后,分类器提供程序就这样声明,

Then the classifier provider is declared like this,

[Export(typeof(IClassifierProvider)), ContentType(Constants.CONTENT_TYPE)]
class RTextClassifierProvider : IClassifierProvider
{
   ...
}

问题是,从未为我指定的扩展调用提供者的构造函数.请注意,在这里,我提供了编辑器工厂,并且文件扩展名与工厂相关联.我可以看到工厂通过调试来初始化所有关联的文件.

The problem is, that the constructor of the provider is never get called for my specified extensions. Note here, that I provide the editor factories and the file extensions are associated with the factory. I can see the factory getting initialized through debugging for all associated files.

如果将内容类型更改为"text",则会调用构造函数.

If I change the content type to "text" the constructor gets called.

问题是,如何将自定义内容类型映射到文件扩展名?

So the question is, how can one map a custom content type to a file extension ?

第二个注释,使用不是一个选项,因为它不允许很多功能.

is not an option, as this does not allow a lot of features..

感谢您的帮助:)

推荐答案

您的 FileExtensionToContentTypeDefinitionAttribute的特殊支持. 作为不需要某些更高级功能(例如,用于多种内容类型的投影缓冲区)的用户的简单扩展机制.

Your implementation of IVsEditorFactory is responsible for setting the content type of the text displayed in the editor. The default implementation of this interface includes special support for FileExtensionToContentTypeDefinitionAttribute as a simple extension mechanism for users that don't require some of the more advanced features (e.g. projection buffers for multiple content types).

DjangoEditorFactory 类包含一个名为TextBufferEventListener的嵌套类,该类显示了一个示例,说明编辑器工厂如何将内容类型分配给显示在编辑器窗口中的缓冲区.

The DjangoEditorFactory class includes a nested class named TextBufferEventListener, which shows one example for how an editor factory might assign the content types to the buffers displayed in an editor window.

这篇关于使IClassifier与自定义内容类型一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆