2014-10-29 109 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 
} 

乾杯