Reputation: 11
I created a MEF editor extension (VSIX) for VS2012 using the information from: http://msdn.microsoft.com/en-us/library/dd885242(v=vs.110).aspx
Syntax highlighting, statement completion, signature help, and outlining features are working fine.
The way the editor extension links the file extensions with the content is as follow: http://msdn.microsoft.com/en-us/library/ee372313(v=vs.110).aspx
[Export]
[FileExtension(".hid")]
[ContentType("hid")]
internal static FileExtensionToContentTypeDefinition hiddenFileExtensionDefinition;
I cannot find a way to link a few specific extensionless files to the content type. How can I do this?
Thanks for reading my question.
Upvotes: 0
Views: 320
Reputation: 11
Thanks to Chris Eelmaa suggestion I found the solution to this issue. It might not be the best way to do it, but at least I solved the problem.
So, here is, I created a new class as follows:
[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
}
Cheers
Upvotes: 1