Ejemplo n.º 1
0
 private void FixItalics()
 {
     if (working || formatMap.IsInBatchUpdate)
     {
         return;
     }
     working = true;
     formatMap.BeginBatchUpdate();
     try {
         foreach (var classifierType in formatMap.CurrentPriorityOrder)
         {
             if (classifierType == null)
             {
                 continue;
             }
             if (classificationTypes.Contains(classifierType.Classification))
             {
                 SetItalics(classifierType, settings.FlowControlUseItalics);
             }
         }
     } finally {
         formatMap.EndBatchUpdate();
         working = false;
     }
 }
Ejemplo n.º 2
0
        private void VSColorTheme_ThemeChanged(ThemeChangedEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_classificationFormatMapService == null || _classificationRegistry == null)
            {
                var componentModel = _serviceProvider.GetService <SComponentModel, IComponentModel>();

                _classificationFormatMapService ??= componentModel?.GetService <IClassificationFormatMapService>();
                _classificationRegistry ??= componentModel?.GetService <IClassificationTypeRegistryService>();
            }

            if (_classificationFormatMapService == null || _classificationRegistry == null)
            {
                return;
            }

            var logger = AcuminatorVSPackage.Instance?.AcuminatorLogger;

            _fontAndColorStorage ??= _serviceProvider.GetService <SVsFontAndColorStorage, IVsFontAndColorStorage>();
            _fontAndColorCacheManager ??= _serviceProvider.GetService <SVsFontAndColorCacheManager, IVsFontAndColorCacheManager>();
            IClassificationFormatMap formatMap = _classificationFormatMapService.GetClassificationFormatMap(category: TextCategory);

            if (_fontAndColorStorage == null || _fontAndColorCacheManager == null || formatMap == null)
            {
                return;
            }

            _fontAndColorCacheManager.CheckCache(ref _mefItemsGuid, out int _);
            int openCategoryResult = _fontAndColorStorage.OpenCategory(ref _mefItemsGuid, (uint)__FCSTORAGEFLAGS.FCSF_READONLY);

            if (openCategoryResult != VSConstants.S_OK)
            {
                logger?.LogMessage($"Error on opening category in the registry during the theme change. The error code is {openCategoryResult}", Logger.LogMode.Error);
            }

            try
            {
                var acuminatorThemeChangedEventArgs = new AcuminatorThemeChangedEventArgs(_fontAndColorStorage, _classificationRegistry, formatMap);

                formatMap.BeginBatchUpdate();
                AcuminatorThemeChanged?.Invoke(this, acuminatorThemeChangedEventArgs);
            }
            catch (Exception exception)
            {
                logger?.LogException(exception, logOnlyFromAcuminatorAssemblies: false, Logger.LogMode.Error);
            }
            finally
            {
                formatMap.EndBatchUpdate();
                int refreshCacheResult = _fontAndColorCacheManager.RefreshCache(ref _mefItemsGuid);

                if (refreshCacheResult != VSConstants.S_OK)
                {
                    logger?.LogMessage($"Error on the refresh of MEF Items cache in the registry during the theme change. The error code is {refreshCacheResult}", Logger.LogMode.Error);
                }

                _fontAndColorStorage.CloseCategory();
            }
        }
        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;
            }
        }
Ejemplo n.º 4
0
        internal void FixComments()
        {
            if (_inUpdate || _formatMap == null || (_view != null && _view.IsClosed))
            {
                return;
            }

            bool batch = false;

            try
            {
                _inUpdate = true;

                if (!_formatMap.IsInBatchUpdate)
                {
                    _formatMap.BeginBatchUpdate();
                    batch = true;
                }

                // First, go through the ones we know about:

                // 1) Known comment types are italicized
                foreach (var type in CommentTypes.Select(t => _typeRegistry.GetClassificationType(t)).Where(t => t != null))
                {
                    Italicize(type);
                }

                // 2) Known doc tags
                foreach (var type in DocTagTypes.Select(t => _typeRegistry.GetClassificationType(t)).Where(t => t != null))
                {
                    Italicize(type);
                }

                // 3) Grab everything else that looks like a comment or doc tag
                foreach (var classification in _formatMap.CurrentPriorityOrder.Where(c => c != null))
                {
                    string name     = classification.Classification;
                    var    comparer = StringComparer.OrdinalIgnoreCase;
                    if (CommentTypes.Contains(name, comparer) || DocTagTypes.Contains(name, comparer))
                    {
                        continue;
                    }

                    if (name.IndexOf("comment", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("doc tag", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        Italicize(classification);
                    }
                }
            }
            finally
            {
                if (batch && _formatMap.IsInBatchUpdate)
                {
                    _formatMap.EndBatchUpdate();
                }
                _inUpdate = false;
            }
        }
Ejemplo n.º 5
0
 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;
     }
 }
Ejemplo n.º 6
0
        private void UpdateTheme(EventArgs e)
        {
            Color defaultBackground            = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
            Color defaultForeground            = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
            IClassificationFormatMap formatMap = ClassificationFormatMapService.GetClassificationFormatMap(category: "code");

            try
            {
                formatMap.BeginBatchUpdate();
            }
            finally
            {
                formatMap.EndBatchUpdate();
            }
        }
Ejemplo n.º 7
0
        internal void UpdateColors(IEnumerable <CategoryItemDecorationSettings> changedItems)
        {
            if (_classificationFormatMapService == null || _registryService == null)
            {
                SatisfyImports();
            }
            if (_classificationFormatMap == null)
            {
                _classificationFormatMap = _classificationFormatMapService.GetClassificationFormatMap(_textView);
            }
            if (_T4Types == null)
            {
                _T4Types = _classificationFormatMap.CurrentPriorityOrder.Where(x => x?.Classification.Contains("T4") == true).ToList();
            }

            try
            {
                if (_classificationFormatMap.IsInBatchUpdate)
                {
                    return;
                }

                _classificationFormatMap.BeginBatchUpdate();

                foreach (CategoryItemDecorationSettings changedItem in changedItems)
                {
                    string classificationKey = changedItem.DisplayName;
                    IClassificationType classificationType = _T4Types.FirstOrDefault(x => x.Classification.Contains(classificationKey));
                    if (classificationType == null)
                    {
                        continue;
                    }

                    TextFormattingRunProperties textProperties = CreateTextProperties(changedItem);
                    _classificationFormatMap.SetExplicitTextProperties(classificationType, textProperties);
                }
            }
            catch (Exception)
            {
                //TO-DO: Log exception
            }
            finally
            {
                _classificationFormatMap.EndBatchUpdate();
            }
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
0
        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();
            }
        }
Ejemplo n.º 11
0
        private void MakeBoldItalics()
        {
            bool enabled = settings.BoldAsItalicsEnabled;

            if (!enabled || working || formatMap.IsInBatchUpdate)
            {
                return;
            }
            working = true;
            formatMap.BeginBatchUpdate();
            try {
                foreach (var classifierType in formatMap.CurrentPriorityOrder)
                {
                    if (classifierType == null)
                    {
                        continue;
                    }
                    MakeItalicsIfApplies(classifierType);
                }
            } finally {
                formatMap.EndBatchUpdate();
                working = false;
            }
        }
Ejemplo n.º 12
0
        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");
        }
Ejemplo n.º 13
0
 public void EndBatchUpdate() => categoryMap.EndBatchUpdate();
Ejemplo n.º 14
0
        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");
            }
        }
Ejemplo n.º 15
0
        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();
            }
        }