Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        private void AcuminatorThemeChangedHandler(object sender, AcuminatorThemeChangedEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_classificationTypeName == null)
            {
                return;
            }

            try
            {
                Color?foregroundColorForTheme = VSColors.GetThemedColor(_classificationTypeName);

                if (foregroundColorForTheme == null)
                {
                    return;
                }

                ForegroundColor = foregroundColorForTheme;

                var classificationType = e.ClassificationTypeRegistry.GetClassificationType(_classificationTypeName);

                if (classificationType == null)
                {
                    return;
                }

                ColorableItemInfo[] colorInfo = new ColorableItemInfo[1];

                if (e.FontAndColorStorage.GetItem(_classificationTypeName, colorInfo) != VSConstants.S_OK)    //comment from F# repo: "we don't touch the changes made by the user"
                {
                    var properties    = e.FormatMap.GetTextProperties(classificationType);
                    var newProperties = properties.SetForeground(ForegroundColor.Value);

                    e.FormatMap.SetTextProperties(classificationType, newProperties);
                }
            }
            catch (Exception exception)
            {
                AcuminatorVSPackage.Instance?.AcuminatorLogger
                ?.LogException(exception, logOnlyFromAcuminatorAssemblies: false, Logger.LogMode.Error);
            }
        }