Пример #1
0
        // Loosely based on Microsoft.VisualStudio.Platform.WindowManagement.ResourceSynchronizer.AddSolidColorKeys()
        public void LoadTheme(int index)
        {
            if (service == null)
            {
                return;
            }
            Clear();

            currentTheme = service.Themes[index % service.Themes.Count];
            foreach (ColorName colorName in service.ColorNames)
            {
                IVsColorEntry entry = currentTheme[colorName];
                if (entry == null || entry.BackgroundType == 0)
                {
                    continue;
                }

                int colorId = VsColorFromName(colorName);
                if (colorId == 0)
                {
                    continue;
                }

                var color = ToColorFromRgba(entry.Background);

                Add(VsColors.GetColorKey(colorId), color);
                Add(VsBrushes.GetBrushKey(colorId), GetBrush(color));
            }
        }
Пример #2
0
        // Copied from ResourceSynchronizer and modified to use currentTheme and to add actual values instead of deferred keys.
        void AddSolidColorKeys(ResourceDictionary newDictionary)
        {
            foreach (ColorName colorName in service.ColorNames)
            {
                IVsColorEntry entry = currentTheme[colorName];
                if (entry == null)
                {
                    continue;
                }

                if (entry.BackgroundType != 0)
                {
                    ThemeResourceKey bgBrush = new ThemeResourceKey(entry.ColorName.Category, entry.ColorName.Name, ThemeResourceKeyType.BackgroundBrush);
                    ThemeResourceKey bgColor = new ThemeResourceKey(entry.ColorName.Category, entry.ColorName.Name, ThemeResourceKeyType.BackgroundColor);

                    var color = ToColorFromRgba(entry.Background);
                    newDictionary.Add(bgBrush, GetBrush(color));
                    newDictionary.Add(bgColor, color);

                    int colorId = VsColorFromName(colorName);
                    if (colorId != 0)
                    {
                        newDictionary.Add(VsColors.GetColorKey(colorId), color);
                        newDictionary.Add(VsBrushes.GetBrushKey(colorId), GetBrush(color));
                    }
                }
                if (entry.ForegroundType != 0)
                {
                    ThemeResourceKey fgBrush = new ThemeResourceKey(entry.ColorName.Category, entry.ColorName.Name, ThemeResourceKeyType.ForegroundBrush);
                    ThemeResourceKey fgColor = new ThemeResourceKey(entry.ColorName.Category, entry.ColorName.Name, ThemeResourceKeyType.ForegroundColor);
                    var color = ToColorFromRgba(entry.Foreground);
                    newDictionary.Add(fgBrush, GetBrush(color));
                    newDictionary.Add(fgColor, color);
                }
            }
        }