コード例 #1
0
        protected EditorFormatBase()
        {
            Type type = this.GetType();

            _classificationTypeName = type.GetCustomAttribute <NameAttribute>()?.Name;

            if (_classificationTypeName != null)
            {
                ForegroundColor = VSColors.GetThemedColor(_classificationTypeName);
            }

            ThemeUpdater.Instance.AcuminatorThemeChanged += AcuminatorThemeChangedHandler;
        }
コード例 #2
0
        protected EditorFormatBase()
        {
            VSColorTheme.ThemeChanged += VSColorTheme_ThemeChanged;

            Type type = this.GetType();

            classificationTypeName = type.GetCustomAttribute <NameAttribute>()?.Name;

            if (classificationTypeName != null)
            {
                ForegroundColor = VSColors.GetThemedColor(classificationTypeName);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
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();
            }
        }