2014-10-29 107 views
0

我使用从信息创建了VS2012一个MEF编辑器扩展(VSIX): http://msdn.microsoft.com/en-us/library/dd885242(v=vs.110).aspx如何扩展名的文件添加到VSIX MEF编辑器扩展

语法高亮,语句完成,签名的帮助,并概述功能工作正常。

编辑器扩展与内容链接的文件扩展名的方法是如下: http://msdn.microsoft.com/en-us/library/ee372313(v=vs.110).aspx

[Export] 
[FileExtension(".hid")] 
[ContentType("hid")] 
internal static FileExtensionToContentTypeDefinition hiddenFileExtensionDefinition; 

我无法找到一个方法来几个特定扩展名的文件链接到内容类型。我怎样才能做到这一点?

感谢您阅读我的问题。

+0

不要指定文件exgtension和你textViewCreationListener内,做一个如果,检查是否有IDocument.FilePath没有扩展名,然后使用SetContrntType或者什么? – 2014-11-06 09:05:19

回答

1

感谢Chris Eelmaa的建议,我找到了解决这个问题的方法。这可能不是最好的办法,但至少我解决了这个问题。

所以,这里,我创建了一个新的类,如下所示:

[Export(typeof(IWpfTextViewCreationListener))] 
[ContentType("text")] 
[TextViewRole(PredefinedTextViewRoles.Document)] 
class ExtensionlessViewCreationListener : IWpfTextViewCreationListener 
{ 
    [Import] 
    internal IEditorFormatMapService FormatMapService = null; 

    [Import] 
    internal IContentTypeRegistryService ContentTypeRegistryService = null; 

    [Import] 
    internal SVsServiceProvider ServiceProvider = null; 

    #region IWpfTextViewCreationListener Members 

    void IWpfTextViewCreationListener.TextViewCreated(IWpfTextView textView) 
    { 
     DTE dte = (DTE)ServiceProvider.GetService(typeof(DTE)); 
     string docName = dte.Documents.Item(dte.Documents.Count).Name; 
     if (docName.ToLower() == EditorConstants.DICTIONARY_FILE_NAME) 
     { 
      var contentType = ContentTypeRegistryService.GetContentType(EditorConstants.LANGUAGE_TYPE); 
      textView.TextBuffer.ChangeContentType(contentType, null); 
     } 
    } 

    #endregion 
} 

干杯