21 using System.Collections.Generic;
22 using System.ComponentModel.Composition;
23 using System.Windows.Media;
24 using Microsoft.VisualStudio.Text.Classification;
25 using Microsoft.VisualStudio.Text.Formatting;
27 namespace SiliconStudio.
Paradox.VisualStudio.Classifiers
32 protected string ClassificationCategory =
"text";
34 protected readonly Dictionary<VisualStudioTheme, IDictionary<string, ClassificationColor>> themeColors =
35 new Dictionary<VisualStudioTheme, IDictionary<string, ClassificationColor>>();
37 private VisualStudioThemeEngine themeEngine;
40 private IClassificationFormatMapService classificationFormatMapService = null;
43 private IClassificationTypeRegistryService classificationTypeRegistry = null;
48 themeEngine =
new VisualStudioThemeEngine(serviceProvider);
49 themeEngine.OnThemeChanged += themeEngine_OnThemeChanged;
54 themeEngine.OnThemeChanged -= themeEngine_OnThemeChanged;
55 themeEngine.Dispose();
60 return themeEngine.GetCurrentTheme();
63 void themeEngine_OnThemeChanged(
object sender,
EventArgs e)
68 private void UpdateColors()
70 var theme = themeEngine.GetCurrentTheme();
73 if (theme != currentTheme)
77 var colors = themeColors[theme];
78 var formatMap = classificationFormatMapService.GetClassificationFormatMap(ClassificationCategory);
83 formatMap.BeginBatchUpdate();
84 foreach (var pair
in colors)
86 string type = pair.Key;
87 var color = pair.Value;
89 var classificationType = classificationTypeRegistry.GetClassificationType(type);
90 var oldProp = formatMap.GetTextProperties(classificationType);
93 color.ForegroundColor == null
95 :
new SolidColorBrush(color.ForegroundColor.Value);
98 color.BackgroundColor == null
100 :
new SolidColorBrush(color.BackgroundColor.Value);
102 var newProp = TextFormattingRunProperties.CreateTextFormattingRunProperties(
103 foregroundBrush, backgroundBrush, oldProp.Typeface, null, null, oldProp.TextDecorations,
104 oldProp.TextEffects, oldProp.CultureInfo);
106 formatMap.SetTextProperties(classificationType, newProp);
111 formatMap.EndBatchUpdate();
118 var theme = GetCurrentTheme();
121 themeColors[theme].TryGetValue(classificationName, out classificationColor);
123 return classificationColor;
ClassificationColorManager(IServiceProvider serviceProvider)
ClassificationColor GetClassificationColor(string classificationName)
VisualStudioTheme GetCurrentTheme()