【问题标题】:How to add extensionless files to VSIX MEF editor extension如何将无扩展名文件添加到 VSIX MEF 编辑器扩展名
【发布时间】:2014-10-29 19:52:54
【问题描述】:

我使用以下信息为 VS2012 创建了一个 MEF 编辑器扩展 (VSIX): http://msdn.microsoft.com/en-us/library/dd885242(v=vs.110).aspx

语法高亮、语句完成、签名帮助和大纲功能运行良好。

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

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

我找不到将一些特定的无扩展名文件链接到内容类型的方法。我该怎么做?

感谢您阅读我的问题。

【问题讨论】:

  • 不要指定文件扩展名并在你的 textViewCreationListener 中,如果 IDocument.FilePath 没有扩展名,做一个 if-check,然后使用 SetContrntType 什么的?

标签: c# visual-studio-2012 mef visual-studio-extensions vsix


【解决方案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
}

干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2023-03-09
    • 2018-09-11
    • 1970-01-01
    • 2016-09-06
    相关资源
    最近更新 更多