Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

Overriding font in custom Visual Studio editor

$
0
0
The problem is in making custom editor inside VS extension look differently than the current theme dictates. The editor is hosted inside a dialog and should have the same font the hosting dialog defines.

The content type of the editor is defined like this: 
    [Export]
    [Name("MyContent")]
    [BaseDefinition("code")]
    public static readonly ContentTypeDefinition ExportContentTypeDefinition = null;
And there is a classification type definition:
    [Export]
    [Name("MyContentText")]
    [BaseDefinition("text")]
    public static readonly ClassificationTypeDefinition MyTextDefinition = null;
The classifier provider is defined as below:
    [Export(typeof(IClassifierProvider))]
    [ContentType("MyContent")]
    public class ClassifierProvider : IClassifierProvider
    {
        [Import]
        public IClassificationTypeRegistryService ClassificationTypesRegistry { get; set; }

        public IClassifier GetClassifier(ITextBuffer textBuffer)
        {
            return new Classifier(
                ClassificationTypesRegistry.GetClassificationType("MyContentText"));
        }
    }
While the classifier just provides the same format for any snapshot:
    public class Classifier : IClassifier
    {
        private readonly IClassificationType _classificationType;

        public Classifier(IClassificationType classificationType)
        {
            _classificationType = classificationType;
        }

        public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            return new [] { new ClassificationSpan(span, _classificationType)};
        }

        public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
    }
Now, in code, while creating the editor, I'm trying to override the properties of the matchingIClassificationFormatMap:
    var contentType = contentTypeRegistryService.GetContentType("MyContent");
    var textBuffer = textBufferFactoryService.CreateTextBuffer(initialText, contentType);
    var textView = textEditorFactoryService.CreateTextView(textBuffer);

    ...

    var formatMap = classificationFomatMapService
        .GetClassificationFormatMap("MyContentText");

    formatMap.DefaultTextProperties = formatMap.DefaultTextProperties
        .SetFontRenderingEmSize(dialog.FontSize)
        .SetTypeface(
            new Typeface(
                dialog.FontFamily,
                dialog.FontStyle,
                dialog.FontWeight,
                dialog.FontStretch));
However, the change doesn't affect my editor instance.

Moreover, the format map returned from the classificationFomatMapService.GetClassificationFormatMap(ITextView) overload is different from the one returned from the overload I use above. And changing this another instance of format also affects all the code editors in the running Visual Studio instance, so I have to conclude that despite my efforts thetextView somehow maps to the default editor's classification.

My question is: what should I do in order to control text appearance of a custom editor designated for a custom content type?

Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>