public static void UpdateTextProperties(IClassificationTypeRegistryService registryService, IClassificationFormatMap formatMap, Settings settings) { var classificationType = registryService.GetClassificationType(ClassifierKey); var textProperties = formatMap.GetTextProperties(classificationType); if (settings.Background.HasValue) { formatMap.SetTextProperties(classificationType, textProperties.SetBackground(settings.Background.Value)); } else { formatMap.SetTextProperties(classificationType, textProperties.ClearBackgroundBrush()); } }
public static void UpdateTextProperties(IClassificationTypeRegistryService registryService, IClassificationFormatMap formatMap, Settings settings) { var classificationType = registryService.GetClassificationType(ClassifierKey); var textProperties = formatMap.GetTextProperties(classificationType); if (settings.Size.HasValue) { formatMap.SetTextProperties(classificationType, textProperties.SetFontRenderingEmSize(settings.Size.Value)); } else { formatMap.SetTextProperties(classificationType, textProperties.ClearFontRenderingEmSize()); } }
private void SetItalics(IClassificationType classifierType, bool enable) { var tp = formatMap.GetTextProperties(classifierType); tp = tp.SetItalic(enable); formatMap.SetTextProperties(classifierType, tp); }
public void UpdateClassifications(IClassificationFormatMap formatMap) { if (_updating || formatMap.IsInBatchUpdate) { return; } try { _updating = true; foreach (var identifier in _colorizerCache.Values) { if (!identifier.IsDirty) { continue; } if (!formatMap.IsInBatchUpdate) { formatMap.BeginBatchUpdate(); } var textProperties = formatMap.GetTextProperties(identifier.Classification); textProperties = textProperties.SetForeground(identifier.Color.ToColor()); formatMap.SetTextProperties(identifier.Classification, textProperties); identifier.IsDirty = false; } } finally { if (formatMap.IsInBatchUpdate) { formatMap.EndBatchUpdate(); } _updating = false; } }
private void SetProperties(IClassificationType classificationType) { //? Might need to benchmark this function for performance. var properties = formatMap.GetTextProperties(classificationType); var settings = FontSettingsManager.CurrentSettings; var fontSize = GetEditorTextSize() + settings.Size; if (!string.IsNullOrWhiteSpace(FontSettingsManager.CurrentSettings.Font)) { properties = properties.SetTypeface(new Typeface(settings.Font)); } if (Math.Abs(fontSize - properties.FontRenderingEmSize) > 0) { properties = properties.SetFontRenderingEmSize(fontSize); } if (properties.Italic != settings.Italic) { properties = properties.SetItalic(settings.Italic); } if (settings.Opacity >= 0.1 && settings.Opacity <= 1) { properties = properties.SetForegroundOpacity(settings.Opacity); } formatMap.SetTextProperties(classificationType, properties); }
public static void UpdateTextProperties(IClassificationTypeRegistryService registryService, IClassificationFormatMap formatMap, Settings settings) { var classificationType = registryService.GetClassificationType(ClassifierKey); var textProperties = formatMap.GetTextProperties(classificationType); formatMap.SetTextProperties(classificationType, textProperties.SetBold(settings.IsBold)); }
void ClearForeground(IClassificationType classification) { var properties = formatMap.GetTextProperties(classification); // If this is already cleared out, skip it if (properties.ForegroundBrushEmpty) { return; } formatMap.SetTextProperties(classification, properties.ClearForegroundBrush()); }
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); }
void FixFormatMap(IEnumerable <IClassificationType> classificationTypes) { try { _inUpdate = true; foreach (var type in classificationTypes) { if (type == null) { continue; } // There are a couple we want to skip, no matter what. These are classification types that aren't // used for text formatting. string name = type.Classification.ToUpperInvariant(); if (name.Contains("WORD WRAP GLYPH") || name.Contains("LINE NUMBER") || name == "STRING") { continue; } var format = _formatMap.GetTextProperties(type); if (format.BackgroundBrushEmpty) { continue; } var solidColorBrush = format.BackgroundBrush as SolidColorBrush; if (solidColorBrush != null && solidColorBrush.Opacity == BackgroundOpacity) { format = format.SetBackgroundBrush(new SolidColorBrush(solidColorBrush.Color) { Opacity = Transparent }); _formatMap.SetTextProperties(type, format); } } } catch (Exception) { // Do nothing, just prevent this exception from bringing down the editor. } finally { _inUpdate = false; } }
static void ResetStyleCache() { lock (_syncRoot) { DefaultClassificationFormatMap.BeginBatchUpdate(); foreach (var item in _BackupFormattings) { DefaultClassificationFormatMap.SetTextProperties(item.Key, item.Value); } DefaultClassificationFormatMap.EndBatchUpdate(); var cache = new Dictionary <string, StyleBase>(_SyntaxStyleCache.Count, StringComparer.OrdinalIgnoreCase); LoadSyntaxStyleCache(cache); _SyntaxStyleCache = cache; } }
private void Bold(IClassificationType classification) { var textFormat = _formatMap.GetTextProperties(_typeRegistry.GetClassificationType("text")); var properties = _formatMap.GetTextProperties(classification); var typeface = properties.Typeface; var boldedTypeface = new Typeface(typeface.FontFamily, typeface.Style, FontWeights.Bold, typeface.Stretch); var biggerSize = textFormat.FontRenderingEmSize + 2; properties = properties.SetTypeface(boldedTypeface); properties = properties.SetFontRenderingEmSize(biggerSize); _formatMap.SetTextProperties(classification, properties); }
internal static void Fade(IClassificationFormatMap formatMap, IClassificationType classificationType) { // Argument validation if (formatMap == null) { throw new ArgumentNullException(nameof(formatMap)); } if (classificationType == null) { throw new ArgumentNullException(nameof(classificationType)); } // Perform formatting TextFormattingRunProperties properties = formatMap.GetTextProperties(classificationType); properties = properties.SetForegroundOpacity(2d / 3d); formatMap.SetTextProperties(classificationType, properties); }
private void MakeItalicsIfApplies(IClassificationType classifierType) { var tp = formatMap.GetTextProperties(classifierType); var font = tp.Typeface; // already italic if (tp.Italic || font.Style == FontStyles.Italic) { return; } if (!tp.BoldEmpty && tp.Bold) { tp = tp.SetBold(false).SetItalic(true); formatMap.SetTextProperties(classifierType, tp); } if (font.Weight > FontWeights.Normal) { var newFont = new Typeface( font.FontFamily, FontStyles.Italic, FontWeights.Normal, FontStretches.Normal); tp = tp.SetTypeface(newFont); formatMap.SetTextProperties(classifierType, tp); } }
void Italicize(IClassificationType classification) { var textFormat = formatMap.GetTextProperties(text); var properties = formatMap.GetTextProperties(classification); var typeface = properties.Typeface; // If this is already italic, skip it if (typeface.Style == FontStyles.Italic) { return; } // Add italic and (possibly) remove bold, and change to a font that has good looking // italics (i.e. *not* Consolas) var newTypeface = new Typeface(new FontFamily("Lucida Sans"), FontStyles.Italic, FontWeights.Normal, typeface.Stretch); properties = properties.SetTypeface(newTypeface); // Also, make the font size a little bit smaller than the normal text size properties = properties.SetFontRenderingEmSize(textFormat.FontRenderingEmSize - 1); // And put it back in the format map formatMap.SetTextProperties(classification, properties); }
private void Shrink(IClassificationType classification) { var properties = _formatMap.GetTextProperties(classification); var typeface = properties.Typeface; if (typeface.Style == FontStyles.Italic) { return; } _formatMap.SetTextProperties( classification, properties .SetTypeface(new Typeface(typeface.FontFamily, FontStyles.Italic, typeface.Weight, typeface.Stretch)) .SetFontRenderingEmSize(6)); }
private void UpdateFormatMap() { var colorMap = ColorMap.GetMap(); var textProperties = _formatMap.GetTextProperties(_timestampClassification); var color = colorMap[ClassificationTypeDefinitions.TimeStamp]; var wpfColor = ClassificationTypeDefinitions.ToMediaColor(color); textProperties = textProperties.SetForeground(wpfColor); _formatMap.SetTextProperties(_timestampClassification, textProperties); _textRunProperties = textProperties; _translatedCanvas.Children.Clear(); Background = _textRunProperties.BackgroundBrush; MinWidth = CalculateMarginWidth(); Update(); }
/// <summary>Set italics for classification.</summary> /// <param name="classification">The classification to process.</param> void Italicize(IClassificationType classification) { /* Get the classification text properties */ var properties = _formatMap.GetTextProperties(classification); //If italics has already been determined, skip it if (!properties.ItalicEmpty) { return; } //add italics properties = properties.SetItalic(true); // And put it back in the format map _formatMap.SetTextProperties(classification, properties); }
internal static void Italicize(IClassificationFormatMap formatMap, IClassificationType classificationType) { // Argument validation if (formatMap == null) { throw new ArgumentNullException(nameof(formatMap)); } if (classificationType == null) { throw new ArgumentNullException(nameof(classificationType)); } // Perform formatting TextFormattingRunProperties properties = formatMap.GetTextProperties(classificationType); if (properties.ItalicEmpty || !properties.Italic) { properties = properties.SetItalic(true); formatMap.SetTextProperties(classificationType, properties); } }
private void UpdateForegroundColor( string classificationTypeName, IClassificationFormatMap sourceFormatMap, IClassificationFormatMap targetFormatMap) { var classificationType = _classificationTypeRegistryService.GetClassificationType(classificationTypeName); if (classificationType == null) { return; } var sourceProps = sourceFormatMap.GetTextProperties(classificationType); var targetProps = targetFormatMap.GetTextProperties(classificationType); targetProps = targetProps.SetForegroundBrush(sourceProps.ForegroundBrush); targetFormatMap.SetTextProperties(classificationType, targetProps); }
void DecorateClassificationTypes() { if (_ClassificationFormatMap.IsInBatchUpdate) { return; } _ClassificationFormatMap.BeginBatchUpdate(); var textProperty = _ClassificationFormatMap.GetTextProperties(_RegService.GetClassificationType("text")); foreach (var item in _ClassificationFormatMap.CurrentPriorityOrder) { if (item == null) { continue; } #if DEBUG Debug.Write(item.Classification); Debug.Write(' '); foreach (var type in item.BaseTypes) { Debug.Write('/'); Debug.Write(type.Classification); } Debug.WriteLine('/'); #endif StyleBase style; if (__Styles.TryGetValue(item.Classification, out style)) { TextFormattingRunProperties initialProperty; if (__InitialProperties.TryGetValue(item.Classification, out initialProperty) == false) { var p = _ClassificationFormatMap.GetExplicitTextProperties(item); if (p == null) { continue; } __InitialProperties[item.Classification] = initialProperty = p; } _ClassificationFormatMap.SetTextProperties(item, SetProperties(initialProperty, style, textProperty.FontRenderingEmSize)); } } _ClassificationFormatMap.EndBatchUpdate(); }
public IClassificationType GetClassificationType(Color?foreground, Color?background) { var key = Tuple.Create(foreground, background); IClassificationType classificationType; if (!_classificationMap.TryGetValue(key, out classificationType)) { string classificationName = GetClassificationName(foreground, background); classificationType = Factory.ClassificationTypeRegistryService.GetClassificationType(classificationName); if (classificationType == null) { classificationType = Factory.ClassificationTypeRegistryService.CreateClassificationType( classificationName, new IClassificationType[] { Factory.StandardClassificationService.NaturalLanguage }); } _classificationMap.Add(key, classificationType); IClassificationFormatMap formatMap = Factory.ClassificationFormatMapService.GetClassificationFormatMap(_textView); formatMap.SetTextProperties(classificationType, GetFormat(foreground, background)); } return(classificationType); }
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 CodeViewDecorator(IWpfTextView view) { view.Closed += View_Closed; view.VisualElement.IsVisibleChanged += VisualElement_IsVisibleChanged; if (_Initialized == false) { view.VisualElement.IsVisibleChanged += MarkInitialized; } Config.Updated += SettingsUpdated; _ClassificationFormatMap = ServicesHelper.Instance.ClassificationFormatMap.GetClassificationFormatMap(view); _EditorFormatMap = ServicesHelper.Instance.EditorFormatMap.GetEditorFormatMap(view); //_ClassificationFormatMap.ClassificationFormatMappingChanged += FormatUpdated; _RegService = ServicesHelper.Instance.ClassificationTypeRegistry; _TextView = view; _IsViewActive = true; if (_Initialized) { Debug.WriteLine("Decorate known types"); Decorate(FormatStore.ClassificationTypeStore.Keys, true); _EditorFormatMap.FormatMappingChanged += FormatUpdated; } else { _EditorFormatMap.FormatMappingChanged += BackupFormat; _ClassificationFormatMap.BeginBatchUpdate(); foreach (var item in _ClassificationFormatMap.CurrentPriorityOrder) { if (item != null) { _ClassificationFormatMap.SetTextProperties(item, _ClassificationFormatMap.GetExplicitTextProperties(item)); } } _ClassificationFormatMap.EndBatchUpdate(); } }
void DecorateClassificationTypes() { if (_ClassificationFormatMap.IsInBatchUpdate) { return; } _ClassificationFormatMap.BeginBatchUpdate(); var defaultSize = _ClassificationFormatMap.DefaultTextProperties.FontRenderingEmSize; foreach (var item in _ClassificationFormatMap.CurrentPriorityOrder) { StyleBase style; TextFormattingRunProperties textFormatting; if (item == null || (style = TextEditorHelper.GetStyle(item.Classification)) == null || (textFormatting = TextEditorHelper.GetBackupFormatting(item.Classification)) == null) { continue; } _ClassificationFormatMap.SetTextProperties(item, SetProperties(textFormatting, style, defaultSize)); } _ClassificationFormatMap.EndBatchUpdate(); Debug.WriteLine("Decorated"); }
private void VSColorTheme_ThemeChanged(ThemeChangedEventArgs e) { if (AcuminatorVSPackage.Instance?.ClassificationFormatMapService == null || AcuminatorVSPackage.Instance.ClassificationRegistry == null || classificationTypeName == null) { return; } var fontAndColorStorage = ServiceProvider.GlobalProvider.GetService(typeof(SVsFontAndColorStorage)) as IVsFontAndColorStorage; var fontAndColorCacheManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsFontAndColorCacheManager)) as IVsFontAndColorCacheManager; if (fontAndColorStorage == null || fontAndColorCacheManager == null) { return; } Guid guidTextEditorFontCategory = DefGuidList.guidTextEditorFontCategory; fontAndColorCacheManager.CheckCache(ref guidTextEditorFontCategory, out int _); if (fontAndColorStorage.OpenCategory(ref guidTextEditorFontCategory, (uint)__FCSTORAGEFLAGS.FCSF_READONLY) != VSConstants.S_OK) { //TODO Log error } Color?foregroundColorForTheme = VSColors.GetThemedColor(classificationTypeName); if (foregroundColorForTheme == null) { return; } IClassificationFormatMap formatMap = AcuminatorVSPackage.Instance.ClassificationFormatMapService .GetClassificationFormatMap(category: textCategory); if (formatMap == null) { return; } try { formatMap.BeginBatchUpdate(); ForegroundColor = foregroundColorForTheme; var bqlOperatorClasType = AcuminatorVSPackage.Instance.ClassificationRegistry .GetClassificationType(classificationTypeName); if (bqlOperatorClasType == null) { return; } ColorableItemInfo[] colorInfo = new ColorableItemInfo[1]; if (fontAndColorStorage.GetItem(classificationTypeName, colorInfo) != VSConstants.S_OK) //comment from F# repo: "we don't touch the changes made by the user" { var properties = formatMap.GetTextProperties(bqlOperatorClasType); var newProperties = properties.SetForeground(ForegroundColor.Value); formatMap.SetTextProperties(bqlOperatorClasType, newProperties); } } catch (Exception) { //TODO Log error here } finally { formatMap.EndBatchUpdate(); } }
public void SetTextProperties(IClassificationType classificationType, TextFormattingRunProperties properties) => categoryMap.SetTextProperties(classificationType, properties);
void DecorateClassificationTypes(IEnumerable <IClassificationType> classifications, bool fullUpdate) { if (_ClassificationFormatMap.IsInBatchUpdate) { return; } var defaultSize = _ClassificationFormatMap.DefaultTextProperties.FontRenderingEmSize; var updated = new Dictionary <IClassificationType, TextFormattingRunProperties>(); StyleBase style; TextFormattingRunProperties textFormatting; foreach (var item in classifications) { if (item == null || (style = FormatStore.GetOrCreateStyle(item)) == null || (textFormatting = FormatStore.GetOrSaveBackupFormatting(item, _Initialized == false)) == null) { continue; } var p = SetProperties(textFormatting, style, defaultSize); if (p != textFormatting || fullUpdate) { updated[item] = p; } } var refreshList = new List <(IClassificationType type, TextFormattingRunProperties property)>(); foreach (var item in updated) { foreach (var subType in item.Key.GetSubTypes()) { if (updated.ContainsKey(subType) == false) { if ((style = FormatStore.GetOrCreateStyle(subType)) == null || (textFormatting = FormatStore.GetBackupFormatting(subType)) == null) { continue; } refreshList.Add((subType, SetProperties(textFormatting, style, defaultSize))); } } } if (refreshList.Count > 0) { foreach (var item in refreshList) { updated[item.type] = item.property; } } if (updated.Count > 0) { _ClassificationFormatMap.BeginBatchUpdate(); foreach (var item in updated) { _ClassificationFormatMap.SetTextProperties(item.Key, item.Value); Debug.WriteLine("Update format: " + item.Key.Classification); } _ClassificationFormatMap.EndBatchUpdate(); Debug.WriteLine($"Decorated {updated.Count} formats"); } }