예제 #1
0
        public MonoDevelopCodeLensPresenterStyle()
        {
            var blackBrush = new SolidColorBrush(Colors.Black);
            var whiteBrush = new SolidColorBrush(Colors.White);

            var typeface = new Typeface("Calibri");
            var size     = 8.0 * 96.0 / 72.0;

            var textRunProperties = TextFormattingRunProperties.CreateTextFormattingRunProperties(
                foreground: blackBrush,
                background: null,
                typeface: typeface,
                size: size,
                textDecorations: null,
                textEffects: null,
                hintingSize: null,
                cultureInfo: null);

            this.IndicatorTextRunProperties         = textRunProperties;
            this.IndicatorHoveredTextRunProperties  = textRunProperties;
            this.IndicatorDisabledTextRunProperties = textRunProperties;
            this.IndicatorSeparatorBrush            = blackBrush;
            this.PopupBackgroundBrush = whiteBrush;
            this.PopupTextBrush       = blackBrush;
            this.PopupBorderBrush     = blackBrush;
        }
예제 #2
0
        public static TextFormattingRunProperties Create(ResourceDictionary dict)
        {
            var      foreground      = GetBrush(dict, EditorFormatDefinition.ForegroundBrushId, EditorFormatDefinition.ForegroundColorId, ClassificationFormatDefinition.ForegroundOpacityId, null, SystemColors.WindowTextBrush);
            var      background      = GetBrush(dict, EditorFormatDefinition.BackgroundBrushId, EditorFormatDefinition.BackgroundColorId, ClassificationFormatDefinition.BackgroundOpacityId, ClassificationFormatDefinition.DefaultBackgroundOpacity, null);
            Typeface typeface        = GetTypeface(dict);
            double?  size            = dict[ClassificationFormatDefinition.FontRenderingSizeId] as double? ?? 16;
            double?  hintingSize     = dict[ClassificationFormatDefinition.FontHintingSizeId] as double?;
            var      textDecorations = dict[ClassificationFormatDefinition.TextDecorationsId] as TextDecorationCollection;
            var      textEffects     = dict[ClassificationFormatDefinition.TextEffectsId] as TextEffectCollection;
            var      cultureInfo     = dict[ClassificationFormatDefinition.CultureInfoId] as CultureInfo;
            var      textRunProps    = TextFormattingRunProperties.CreateTextFormattingRunProperties(foreground, background, typeface, size, hintingSize, textDecorations, textEffects, cultureInfo);
            var      isItalic        = dict[ClassificationFormatDefinition.IsItalicId] as bool?;

            if (isItalic is not null)
            {
                textRunProps = textRunProps.SetItalic(isItalic.Value);
            }
            var isBold = dict[ClassificationFormatDefinition.IsBoldId] as bool?;

            if (isBold is not null)
            {
                textRunProps = textRunProps.SetBold(isBold.Value);
            }
            double?opacity;

            if (foreground is null && (opacity = dict[ClassificationFormatDefinition.ForegroundOpacityId] as double?) is not null)
            {
                textRunProps = textRunProps.SetForegroundOpacity(opacity.Value);
            }
            if (background is null && (opacity = dict[ClassificationFormatDefinition.BackgroundOpacityId] as double?) is not null)
            {
                textRunProps = textRunProps.SetBackgroundOpacity(opacity.Value);
            }
            return(textRunProps);
        }
예제 #3
0
        /// <summary>
        /// Create an ITextViewHost instance for the active ITextBuffer
        /// </summary>
        private IWpfTextViewHost CreateTextViewHost()
        {
            var textViewRoleSet = _vimComponentHost.TextEditorFactoryService.CreateTextViewRoleSet(
                PredefinedTextViewRoles.PrimaryDocument,
                PredefinedTextViewRoles.Document,
                PredefinedTextViewRoles.Editable,
                PredefinedTextViewRoles.Interactive,
                PredefinedTextViewRoles.Structured,
                PredefinedTextViewRoles.Analyzable);
            var textView = _vimComponentHost.TextEditorFactoryService.CreateTextView(
                _textBuffer,
                textViewRoleSet);

            textView.Options.SetOptionValue(DefaultTextViewOptions.UseVisibleWhitespaceId, true);
            var textViewHost = _vimComponentHost.TextEditorFactoryService.CreateTextViewHost(textView, true);

            var classificationFormatMap = _classificationFormatMapService.GetClassificationFormatMap(textViewHost.TextView);

            classificationFormatMap.DefaultTextProperties = TextFormattingRunProperties.CreateTextFormattingRunProperties(
                new Typeface(new FontFamily("Consolas"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
                14,
                Colors.Black);

            return(textViewHost);
        }
        private void ApplyFormatting(SettingsItem item, IClassificationFormatMap formatMap)
        {
            if (!item.IsActive)
            {
                return;
            }

            var classificationType = ClassificationRegistry.GetClassificationType(item.ClassificationId);

            if (classificationType == null)
            {
                return;
            }
            var oldFormatting   = formatMap.GetTextProperties(classificationType);
            var foregroundBrush = item.ForegroundColor == Colors.Transparent ? null : new SolidColorBrush(item.ForegroundColor);
            var backgroundBrush = item.BackgroundColor == Colors.Transparent ? null : new SolidColorBrush(item.BackgroundColor);
            var formatting      = TextFormattingRunProperties.CreateTextFormattingRunProperties(foregroundBrush, backgroundBrush, oldFormatting.Typeface, null, null, oldFormatting.TextDecorations, oldFormatting.TextEffects, oldFormatting.CultureInfo);

            formatting = Settings.Settings.Instance.UpdateProperties(item, formatting);
            var identifierPosition = formatMap.CurrentPriorityOrder.IndexOf(classificationType);

            if (identifierPosition < 0)
            {
                return;
            }
            var afterIdentifierClassification = formatMap.CurrentPriorityOrder[identifierPosition /* + 1*/];

            // formatMap.AddExplicitTextProperties(classificationType, formatting, afterIdentifierClassification);
            formatMap.AddExplicitTextProperties(classificationType, formatting, afterIdentifierClassification);
        }
예제 #5
0
        private TextFormattingRunProperties CreateTextProperties(CategoryItemDecorationSettings colorSetting)
        {
            TextFormattingRunProperties textFormatting = TextFormattingRunProperties.CreateTextFormattingRunProperties();

            textFormatting = textFormatting.SetBackground(colorSetting.BackgroundColor);
            textFormatting = textFormatting.SetForeground(colorSetting.ForegroundColor);
            textFormatting = textFormatting.SetBold(colorSetting.IsBold);
            textFormatting = textFormatting.SetItalic(colorSetting.IsItalic);

            if (colorSetting.HasStrikethrough || colorSetting.IsUnderlined)
            {
                TextDecorationCollection decorationsCollection = new TextDecorationCollection();
                TextDecorationCollection decorations           = textFormatting.TextDecorations.Clone();

                if (colorSetting.IsUnderlined)
                {
                    decorations.Add(TextDecorations.Underline);
                }
                if (colorSetting.HasStrikethrough)
                {
                    decorations.Add(TextDecorations.Strikethrough);
                }

                decorationsCollection.Add(decorations);
                textFormatting = textFormatting.SetTextDecorations(decorationsCollection);
            }

            return(textFormatting);
        }
예제 #6
0
        private TextFormattingRunProperties CreateTextProperties(CategoryItemDecorationSettings colorSetting)
        {
            TextFormattingRunProperties textFormatting = TextFormattingRunProperties.CreateTextFormattingRunProperties();

            textFormatting = textFormatting.SetBackground(colorSetting.BackgroundColor);
            textFormatting = textFormatting.SetForeground(colorSetting.ForegroundColor);

            return(textFormatting);
        }
예제 #7
0
 private void UpdateOptions()
 {
     this.EditorCommands.ConvertTabsToSpace = this.editorSpecificOptionsModel.ConvertTabsToSpace;
     this.textView.TabSize = this.editorSpecificOptionsModel.TabSize;
     this.fontName         = this.editorSpecificOptionsModel.FontFamily;
     this.fontSize         = this.editorSpecificOptionsModel.FontSize;
     this.lineNumberMargin.LineNumberFont = TextFormattingRunProperties.CreateTextFormattingRunProperties(new Typeface(this.fontName), this.fontSize * 4 / 3, Color.FromRgb(0, 128, 128));
     this.textViewHost.WordWrapStyle      = (this.editorSpecificOptionsModel.WordWrap ? WordWrapStyles.WordWrap : WordWrapStyles.None);
     this.SetDefaultClassifications();
 }
예제 #8
0
        public TextFormattingRunProperties GetTextProperties(IClassificationType classificationType)
        {
            Color color = Colors.Black;

            if (classificationType.Classification != "text")
            {
                color = Colors.Blue;
            }

            return(TextFormattingRunProperties.CreateTextFormattingRunProperties(
                       new Typeface("Consolas"), 12, color));
        }
        private static void UpdateFormatMap(IClassificationFormatMap formatMap, IClassificationTypeRegistryService typeRegistryService, string type, Color color)
        {
            var classificationType = typeRegistryService.GetClassificationType(type);
            var oldProp            = formatMap.GetTextProperties(classificationType);

            var backgroundBrush = new SolidColorBrush(color);

            var newProp = TextFormattingRunProperties.CreateTextFormattingRunProperties(
                oldProp.ForegroundBrush, backgroundBrush, oldProp.Typeface, null, null, oldProp.TextDecorations,
                oldProp.TextEffects, oldProp.CultureInfo);

            formatMap.SetTextProperties(classificationType, newProp);
        }
예제 #10
0
        private static TextFormattingRunProperties GetFormat(Color?foreground, Color?background)
        {
            TextFormattingRunProperties fmt = TextFormattingRunProperties.CreateTextFormattingRunProperties();

            if (foreground != null)
            {
                fmt = fmt.SetForeground(foreground.Value);
            }
            if (background != null)
            {
                fmt = fmt.SetBackground(background.Value);
            }
            return(fmt);
        }
예제 #11
0
        /// <summary>
        /// Create an ITextViewHost instance for the active ITextBuffer
        /// </summary>
        internal IWpfTextViewHost CreateTextViewHost(IWpfTextView textView)
        {
            textView.Options.SetOptionValue(DefaultTextViewOptions.UseVisibleWhitespaceId, true);
            var textViewHost = _vimComponentHost.EditorHost.TextEditorFactoryService.CreateTextViewHost(textView, setFocus: true);

            var classificationFormatMap = _classificationFormatMapService.GetClassificationFormatMap(textViewHost.TextView);

            classificationFormatMap.DefaultTextProperties = TextFormattingRunProperties.CreateTextFormattingRunProperties(
                new Typeface(Constants.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
                Constants.FontSize,
                Colors.Black);

            return(textViewHost);
        }
        private void UpdateColors()
        {
            var theme = themeEngine.GetCurrentTheme();

            // Did theme change?
            if (theme != currentTheme)
            {
                currentTheme = theme;

                var colors    = themeColors[theme];
                var formatMap = classificationFormatMapService.GetClassificationFormatMap(ClassificationCategory);

                // TODO: It seems this approach doesn't update Fonts & Colors settings
                try
                {
                    formatMap.BeginBatchUpdate();
                    foreach (var pair in colors)
                    {
                        string type  = pair.Key;
                        var    color = pair.Value;

                        var classificationType = classificationTypeRegistry.GetClassificationType(type);
                        var oldProp            = formatMap.GetTextProperties(classificationType);

                        var foregroundBrush =
                            color.ForegroundColor == null
                                ? null
                                : new SolidColorBrush(color.ForegroundColor.Value);

                        var backgroundBrush =
                            color.BackgroundColor == null
                                ? null
                                : new SolidColorBrush(color.BackgroundColor.Value);

                        var newProp = TextFormattingRunProperties.CreateTextFormattingRunProperties(
                            foregroundBrush, backgroundBrush, oldProp.Typeface, null, null, oldProp.TextDecorations,
                            oldProp.TextEffects, oldProp.CultureInfo);

                        formatMap.SetTextProperties(classificationType, newProp);
                    }
                }
                finally
                {
                    formatMap.EndBatchUpdate();
                }
            }
        }
예제 #13
0
        protected virtual void Create(params string[] lines)
        {
            _textView                = CreateTextView(lines);
            _textBuffer              = _textView.TextBuffer;
            _controlCharUtil         = new ControlCharUtil();
            _classificationFormatMap = new Mock <IClassificationFormatMap>(MockBehavior.Strict);
            var typeface = SystemFonts.CaptionFontFamily.GetTypefaces().First();
            var textFormattingProperties = TextFormattingRunProperties.CreateTextFormattingRunProperties(typeface, 10.0, Colors.Black);

            _classificationFormatMap.SetupGet(x => x.DefaultTextProperties).Returns(textFormattingProperties);
            _source = new CharDisplayTaggerSource(
                _textView,
                new Mock <IEditorFormatMap>(MockBehavior.Loose).Object,
                _controlCharUtil,
                _classificationFormatMap.Object);
            _basicTaggerSource = _source;
        }
        public void UpdateColors()
        {
            var newTheme = _themeManager.GetCurrentTheme();

            if (newTheme != VisualStudioTheme.Unknown && newTheme != _currentTheme)
            {
                _currentTheme = newTheme;

                var colors    = newTheme == VisualStudioTheme.Dark ? DarkColors : LightAndBlueColors;
                var formatMap = _classificationFormatMapService.GetClassificationFormatMap(category: "text");

                try
                {
                    formatMap.BeginBatchUpdate();
                    foreach (var pair in colors)
                    {
                        string    type  = pair.Key;
                        FontColor color = pair.Value;

                        var classificationType = _classificationTypeRegistry.GetClassificationType(type);
                        var oldProp            = formatMap.GetTextProperties(classificationType);

                        var foregroundBrush =
                            color.Foreground == null
                                ? null
                                : new SolidColorBrush(color.Foreground.Value);

                        var backgroundBrush =
                            color.Background == null
                                ? null
                                : new SolidColorBrush(color.Background.Value);

                        var newProp = TextFormattingRunProperties.CreateTextFormattingRunProperties(
                            foregroundBrush, backgroundBrush, oldProp.Typeface, null, null, oldProp.TextDecorations,
                            oldProp.TextEffects, oldProp.CultureInfo);

                        formatMap.SetTextProperties(classificationType, newProp);
                    }
                }
                finally
                {
                    formatMap.EndBatchUpdate();
                }
            }
        }
예제 #15
0
        public TextFormattingRunProperties GetExplicitTextProperties(IClassificationType classificationType)
        {
            if (classificationType is null)
            {
                throw new ArgumentNullException(nameof(classificationType));
            }
            var info = TryGetClassificationInfo(classificationType, canCreate: false);

            if (info is null)
            {
                return(TextFormattingRunProperties.CreateTextFormattingRunProperties());
            }
            if (info.ExplicitTextProperties is null)
            {
                CreateExplicitTextProperties(info);
            }
            Debug.Assert(!(info.ExplicitTextProperties is null));
            return(info.ExplicitTextProperties);
        }
예제 #16
0
        private void UpdateClassificationColors(IClassificationFormatMap formatMap)
        {
            try
            {
                formatMap.BeginBatchUpdate();
                foreach (var pair in ThemeColors.Colors)
                {
                    var type  = pair.Key;
                    var color = pair.Value;

                    var classificationType = _classificationTypeRegistry.GetClassificationType(type);
                    if (classificationType == null)
                    {
                        Error.LogError($"Cannot find classification type related to {type}", Module);
                        continue;
                    }

                    var oldProp = formatMap.GetTextProperties(classificationType);

                    var foregroundBrush = color.Foreground == null
                        ? null
                        : new SolidColorBrush(color.Foreground.Value);

                    var backgroundBrush = color.Background == null
                            ? null
                            : new SolidColorBrush(color.Background.Value);

                    var newProp = TextFormattingRunProperties.CreateTextFormattingRunProperties(
                        foregroundBrush, backgroundBrush, oldProp.Typeface, null, null, oldProp.TextDecorations,
                        oldProp.TextEffects, oldProp.CultureInfo);

                    formatMap.SetTextProperties(classificationType, newProp);
                }
            }
            finally
            {
                formatMap.EndBatchUpdate();
            }
        }
        public void UpdateColors()
        {
            var currentTheme = _themeManager.GetCurrentTheme();

            if (currentTheme == VisualStudioTheme.Unknown || currentTheme == _lastTheme)
            {
                return;
            }

            _lastTheme = currentTheme;

            var colors    = _themeColors[currentTheme];
            var formatMap = _classificationFormatMapService.GetClassificationFormatMap(category: "text");

            try
            {
                formatMap.BeginBatchUpdate();
                foreach (var pair in colors)
                {
                    var type  = pair.Key;
                    var color = pair.Value;

                    var classificationType = _classificationTypeRegistryService.GetClassificationType(type);
                    var oldProp            = formatMap.GetTextProperties(classificationType);

                    var brush = new SolidColorBrush(color);

                    var newProp = TextFormattingRunProperties.CreateTextFormattingRunProperties(
                        brush, null, oldProp.Typeface, null, null, oldProp.TextDecorations,
                        oldProp.TextEffects, oldProp.CultureInfo);

                    formatMap.SetTextProperties(classificationType, newProp);
                }
            }
            finally
            {
                formatMap.EndBatchUpdate();
            }
        }
예제 #18
0
        /// <returns>
        /// Classifications are grouped by language
        /// </returns>
        public static IReadOnlyDictionary <string, ICollection <IClassificationType> > GetClassifications()
        {
            if (_classifications != null)
            {
                return(_classifications);
            }

            _classifications = new Dictionary <string, ICollection <IClassificationType> >();

            var registryService  = ServicesProvider.Instance.RegistryService;
            var formatMapService = ServicesProvider.Instance.FormatMapService;

            var formatMap          = formatMapService.GetClassificationFormatMap(category: "text");
            var identifierPosition = GetClassificationPosition(registryService, formatMap, PredefinedClassificationTypeNames.Identifier);

            formatMap.BeginBatchUpdate();
            foreach (var(language, names) in Names.All)
            {
                var languageClassifications = new List <IClassificationType>();
                foreach (var name in names)
                {
                    var classificationPosition = identifierPosition;
                    if (NonIdentifierClassifications.TryGetValue(name, out var relevantClassification))
                    {
                        classificationPosition = GetClassificationPosition(registryService, formatMap, relevantClassification);
                    }

                    var classificationType = registryService.GetClassificationType(name);
                    if (classificationType != null)
                    {
                        // TODO: need to carefully test this case
                        if (classificationPosition > 0)
                        {
                            // NOTE: Set priority of classification next to the relevant classification
                            SetPriority(formatMap, classificationType, classificationPosition);
                        }
                    }
                    else
                    {
                        classificationType = registryService.CreateClassificationType(name, new IClassificationType[0]);
                        var formatting = TextFormattingRunProperties.CreateTextFormattingRunProperties();
                        if (classificationPosition > 0)
                        {
                            // NOTE: Set priority of classification next to the relevant classification
                            var afterClassification = formatMap.CurrentPriorityOrder[classificationPosition + 1];
                            formatMap.AddExplicitTextProperties(classificationType, formatting, afterClassification);
                        }
                        else
                        {
                            // NOTE: Set the last priority
                            formatMap.AddExplicitTextProperties(classificationType, formatting);
                        }
                    }

                    languageClassifications.Add(classificationType);
                }
                _classifications.Add(language, languageClassifications);
            }
            formatMap.EndBatchUpdate();

            return(_classifications);
        }
예제 #19
0
 public TextFormattingRunProperties GetTooltipFormatting()
 => _lazyTooltipFormatMap.Value?.DefaultTextProperties ?? TextFormattingRunProperties.CreateTextFormattingRunProperties();
예제 #20
0
        private void SetDefaultClassifications()
        {
            List <KeyValuePair <string, Color> > list = new List <KeyValuePair <string, Color> >();

            if (this.codeOptionsModel.GetEditorType(this.TextBuffer) == EditorType.XamlEditor)
            {
                list.Add(new KeyValuePair <string, Color>(XamlTokens.Tag.Classification, Colors.Blue));
                list.Add(new KeyValuePair <string, Color>(XamlTokens.QuotedString.Classification, Colors.Blue));
                list.Add(new KeyValuePair <string, Color>(XamlTokens.CommentDelimiter.Classification, Colors.Blue));
                list.Add(new KeyValuePair <string, Color>(XamlTokens.ElementName.Classification, Colors.DarkRed));
                list.Add(new KeyValuePair <string, Color>(XamlTokens.Comment.Classification, Colors.Green));
                list.Add(new KeyValuePair <string, Color>(XamlTokens.Attribute.Classification, Colors.Red));
                list.Add(new KeyValuePair <string, Color>(XamlTokens.Text.Classification, Colors.Black));
                list.Add(new KeyValuePair <string, Color>(XamlTokens.Quote.Classification, Colors.Black));
                list.Add(new KeyValuePair <string, Color>(XamlTokens.MarkupExtension.Classification, Colors.DarkGoldenrod));
            }
            else
            {
                list.Add(new KeyValuePair <string, Color>(CodeClassifications.Comment.Classification, Color.FromRgb((byte)0, (byte)127, (byte)0)));
                list.Add(new KeyValuePair <string, Color>(CodeClassifications.Quote.Classification, Color.FromRgb((byte)143, (byte)0, (byte)0)));
                list.Add(new KeyValuePair <string, Color>(CodeClassifications.Keyword.Classification, Color.FromRgb((byte)0, (byte)0, byte.MaxValue)));
                list.Add(new KeyValuePair <string, Color>(CodeClassifications.Type.Classification, Color.FromRgb((byte)0, (byte)63, (byte)127)));
            }
            this.classificationFormatMap.SetTextProperties(this.classificationRegistry.GetClassificationType("text"), TextFormattingRunProperties.CreateTextFormattingRunProperties(new Typeface(this.fontName), this.fontSize * 4.0 / 3.0, Colors.Black));
            foreach (KeyValuePair <string, Color> keyValuePair in list)
            {
                this.classificationFormatMap.SetTextProperties(TokenClassificationStore.GetTokenType(keyValuePair.Key), TextFormattingRunProperties.CreateTextFormattingRunProperties(new Typeface(this.fontName), this.fontSize * 4.0 / 3.0, keyValuePair.Value));
            }
        }
        public TextFormattingRunProperties GetTooltipFormatting()
        {
            IClassificationFormatMap formatMap = _lazyFormatMap.Value;

            return(formatMap != null ? formatMap.DefaultTextProperties : TextFormattingRunProperties.CreateTextFormattingRunProperties());
        }