如何将无扩展名文件添加到VSIXMEF编辑器扩展名中
本文关键字:扩展名 VSIXMEF 编辑器 添加 文件 | 更新日期: 2023-09-27 18:28:24
我使用以下信息为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;
我找不到将一些特定的无扩展名文件链接到内容类型的方法。我该怎么做?
谢谢你阅读我的问题。
感谢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
}
干杯