public bool GetTextItemInfo(
            Guid category, string name, out Color foreground, out Color background)
        {
            foreground = Colors.Transparent;
            background = Colors.Transparent;

            if (fncStorage == null)
            {
                return(false);
            }

            if (ErrorHandler.Failed(fncStorage.OpenCategory(category, OpenFlags)))
            {
                return(false);
            }

            try {
                var itemInfo = new ColorableItemInfo[1];
                if (ErrorHandler.Failed(fncStorage.GetItem(name, itemInfo)))
                {
                    return(false);
                }

                DecodePlainTextColors(ref itemInfo[0]);

                foreground = GetWpfColor(itemInfo[0].crForeground);
                background = GetWpfColor(itemInfo[0].crBackground);

                return(true);
            } finally {
                fncStorage.CloseCategory();
            }
        }
Ejemplo n.º 2
0
        internal static void AdjustFontSize(IServiceProvider serviceProvider, Guid category, short change)
        {
            IVsFontAndColorStorage   storage   = (IVsFontAndColorStorage)serviceProvider.GetService(typeof(SVsFontAndColorStorage));
            IVsFontAndColorUtilities utilities = storage as IVsFontAndColorUtilities;

            LOGFONTW[] pLOGFONT = new LOGFONTW[1];
            FontInfo[] pInfo    = new FontInfo[1];

            ErrorHandler.ThrowOnFailure(storage.OpenCategory(category, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES)));
            try
            {
                if (!ErrorHandler.Succeeded(storage.GetFont(pLOGFONT, pInfo)))
                {
                    return;
                }

                pInfo[0].wPointSize = checked ((ushort)(pInfo[0].wPointSize + change));
                ErrorHandler.ThrowOnFailure(storage.SetFont(pInfo));
                ErrorHandler.ThrowOnFailure(utilities.FreeFontInfo(pInfo));
            }
            finally
            {
                storage.CloseCategory();
            }
        }
Ejemplo n.º 3
0
        FontInfo?GetTextEditorFontInfo()
        {
            IVsFontAndColorStorage fontStorage = (IVsFontAndColorStorage)VSAsmPackage.GetGlobalService(typeof(SVsFontAndColorStorage));

            if (fontStorage == null)
            {
                return(null);
            }

            if (fontStorage.OpenCategory(TextEditorFontGuid, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) != VSConstants.S_OK)
            {
                return(null);
            }

            FontInfo[] info   = new FontInfo[1];
            int        result = fontStorage.GetFont(null, info);

            fontStorage.CloseCategory();

            if (result != VSConstants.S_OK)
            {
                return(null);
            }

            return(info[0]);
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
0
        private FontFamily GetFontFamily(FontAndColorsResourceKey key)
        {
            const __FCSTORAGEFLAGS flags = __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS |
                                           __FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS;

            fncStorage.OpenCategory(key.Category, (uint)flags);
            try {
                var fontInfos = new FontInfo[1];
                if (fncStorage.GetFont(null, fontInfos) != VSConstants.S_OK)
                {
                    return(null);
                }

                if (fontInfos[0].bFaceNameValid == 1)
                {
                    return(new FontFamily(fontInfos[0].bstrFaceName));
                }

                return(null);
            } finally {
                fncStorage.CloseCategory();
            }
        }
        static void InCategory(IVsFontAndColorStorage storage, Guid category, Action callback)
        {
            var hresult = storage.OpenCategory(ref category, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS));

            try
            {
                if (hresult == 0)
                    callback();
            }
            finally
            {
                storage.CloseCategory();
            }
        }
        static void InCategory(IVsFontAndColorStorage storage, Guid category, Action callback)
        {
            var hresult = storage.OpenCategory(ref category, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS));

            try
            {
                if (hresult == 0)
                {
                    callback();
                }
            }
            finally
            {
                storage.CloseCategory();
            }
        }
Ejemplo n.º 8
0
        private void UpdateColors()
        {
            var theme = themeEngine.GetCurrentTheme();

            // Did theme change?
            if (theme != currentTheme)
            {
                currentTheme = theme;
                var colors = themeColors[theme];

                if (fontAndColorStorage != null && fontAndColorUtilities != null)
                {
                    if (fontAndColorStorage.OpenCategory(Microsoft.VisualStudio.Editor.DefGuidList.guidTextEditorFontCategory, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES)) == VSConstants.S_OK)
                    {
                        try
                        {
                            foreach (var pair in colors)
                            {
                                var colorInfos = new ColorableItemInfo[1];
                                if (fontAndColorStorage.GetItem(pair.Key, colorInfos) == VSConstants.S_OK)
                                {
                                    if (pair.Value.ForegroundColor != null)
                                    {
                                        colorInfos[0].crForeground = (uint)(pair.Value.ForegroundColor.Value.R | (pair.Value.ForegroundColor.Value.G << 8) | (pair.Value.ForegroundColor.Value.B << 16));
                                    }

                                    if (pair.Value.BackgroundColor != null)
                                    {
                                        colorInfos[0].crBackground = (uint)(pair.Value.BackgroundColor.Value.R | (pair.Value.BackgroundColor.Value.G << 8) | (pair.Value.BackgroundColor.Value.B << 16));
                                    }

                                    fontAndColorStorage.SetItem(pair.Key, colorInfos);
                                }
                            }
                        }
                        finally
                        {
                            fontAndColorStorage.CloseCategory();
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public HighlightWordFormatDefinition()
        {
            // Default the BackgroundColor to a transparent grey
            BackgroundColor = Color.FromArgb(127, 170, 170, 170);
            DisplayName     = "Highlight Word";
            ZOrder          = 5;

            // If possible, set the Background color to match the Highlighted Reference color
            IVsFontAndColorStorage colorStorage = ServiceProvider.GlobalProvider.GetService(typeof(IVsFontAndColorStorage)) as IVsFontAndColorStorage;

            ColorableItemInfo[] itemInfoOut = new ColorableItemInfo[1];
            if (colorStorage.OpenCategory(ref _textEditorCategory, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VSConstants.S_OK)
            {
                if (colorStorage.GetItem(_itemName, itemInfoOut) == VSConstants.S_OK)
                {
                    uint hexColor = itemInfoOut[0].crBackground;
                    BackgroundColor = Color.FromArgb(255, (byte)hexColor, (byte)(hexColor >> 8), (byte)(hexColor >> 16));
                }
                colorStorage.CloseCategory();
            }
        }
Ejemplo n.º 10
0
        public static async Task AdjustFontSizeAsync(string categoryGuid, short change)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsFontAndColorStorage storage = await VS.Shell.GetFontAndColorStorageAsync();

            Assumes.Present(storage);
            // ReSharper disable once SuspiciousTypeConversion.Global
            var utilities = storage as IVsFontAndColorUtilities;

            if (utilities == null)
            {
                return;
            }

            var pLOGFONT = new LOGFONTW[1];
            var pInfo    = new FontInfo[1];
            var category = new Guid(categoryGuid);

            ErrorHandler.ThrowOnFailure(storage.OpenCategory(category, (uint)(__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES)));
            try
            {
                if (!ErrorHandler.Succeeded(storage.GetFont(pLOGFONT, pInfo)))
                {
                    return;
                }

                pInfo[0].wPointSize = checked ((ushort)(pInfo[0].wPointSize + change));
                ErrorHandler.ThrowOnFailure(storage.SetFont(pInfo));
                ErrorHandler.ThrowOnFailure(utilities.FreeFontInfo(pInfo));
            }
            finally
            {
                storage.CloseCategory();
            }
        }
Ejemplo n.º 11
0
        public void ApplyColorSet(ThemeAsset colorSet)
        {
            // these guids are like windows, a lot of different windows have plain text
            // this one is the main category, other categories may be printers etc
            m_pStorage.OpenCategory(new Guid("{A27B4E24-A735-4D1D-B8E7-9716E1E3D8E0}"), (uint)__FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES);
            {
                SetForegroundColor("Plain Text", colorSet.GetColor(eThemeColor.PlainText_FG));
                SetBackgroundColor("Plain Text", colorSet.GetColor(eThemeColor.PlainText_BG));

                SetForegroundColor("Selected Text", colorSet.GetColor(eThemeColor.SelectedText_FG));
                SetBackgroundColor("Selected Text", colorSet.GetColor(eThemeColor.SelectedText_BG));

                SetForegroundColor("Inactive Selected Text", colorSet.GetColor(eThemeColor.InactiveSelectedText_FG));
                SetBackgroundColor("Inactive Selected Text", colorSet.GetColor(eThemeColor.InactiveSelectedText_BG));
            }
            m_pStorage.CloseCategory();

            // {358463D0-D084-400F-997E-A34FC570BC72}
            // changed text, selected text, text

            // {8259ACED-490A-41B3-A0FB-64C842CCDC80}
            // changed text, selected text, text

            // {A7EE6BEE-D0AA-4B2F-AD9D-748276A725F6}
            // changed text, selected text, text

            // {40660F54-80FA-4375-89A3-8D06AA954EBA}
            // these change when "all text tool windows" changes
            // inactive selected text, plain text, selected text

            // {9E632E6E-D786-4F9A-8D3E-B9398836C784}
            // inactive selected text, plain text, selected text

            // {6BB65C5A-2F31-4BDE-9F48-8A38DC0C63E7}
            // inactive selected text, plain text, selected text

            // {CE2ECED5-C21C-464C-9B45-15E10E9F9EF9}
            // inactive selected text, plain text, selected text

            // {EE1BE240-4E81-4BEB-8EEA-54322B6B1BF5}
            // inactive selected text, plain text, selected text

            // {5C48B2CB-0366-4FBF-9786-0BB37E945687}
            // "all text tool windows"
            // inactive selected text, plain text, selected text, current list location

            // {9973EFDF-317D-431C-8BC1-5E88CBFD4F7F}
            // inactive selected text, plain text, selected text, current list location



            // what is this
            m_pStorage.OpenCategory(new Guid("{CE2ECED5-C21C-464C-9B45-15E10E9F9EF9}"), (uint)__FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES);
            {
                SetForegroundColor("Plain Text", colorSet.GetColor(eThemeColor.PlainText_FG));
                SetBackgroundColor("Plain Text", colorSet.GetColor(eThemeColor.PlainText_BG));

                SetForegroundColor("Selected Text", colorSet.GetColor(eThemeColor.SelectedText_FG));
                SetBackgroundColor("Selected Text", colorSet.GetColor(eThemeColor.SelectedText_BG));

                SetForegroundColor("Inactive Selected Text", colorSet.GetColor(eThemeColor.InactiveSelectedText_FG));
                SetBackgroundColor("Inactive Selected Text", colorSet.GetColor(eThemeColor.InactiveSelectedText_BG));
            }
            m_pStorage.CloseCategory();
        }