public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int intValue && 0 <= intValue && intValue <= 7)
            {
                string key          = $"checks{intValue}";
                bool   invertColors = (bool)Application.Current.Resources["AvalonEdit.SyntaxColor.Invert"];

                var cache = invertColors ? darkImageCache : lightImageCache;

                if (!cache.TryGetValue(key, out BitmapImage image))
                {
                    var uriString = $@"pack://application:,,,/dnGREP;component/Images/checks{intValue}.png";
                    image = new BitmapImage(new Uri(uriString));

                    if (invertColors)
                    {
                        image = ColorInverter.Convert(ColorInverter.Invert(image));
                    }

                    cache.Add(key, image);
                }

                return(image);
            }
            return(null);
        }
Beispiel #2
0
        private void RegisterHighlighting(string name, string[] extensions, string resourceName, bool invertColors)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }
            if (string.IsNullOrWhiteSpace(resourceName))
            {
                throw new ArgumentNullException("resourceName");
            }

            IHighlightingDefinition highlighting = LoadHighlightingDefinition(resourceName);

            if (highlighting == null)
            {
                return;
            }

            if (invertColors)
            {
                ColorInverter.TranslateThemeColors(highlighting);
            }

            lock (lockObj)
            {
                if (invertColors)
                {
                    if (name != null)
                    {
                        invertedHighlightingsByName[name] = highlighting;
                    }
                    if (extensions != null)
                    {
                        foreach (string ext in extensions)
                        {
                            invertedHighlightingsByExtension[ext] = highlighting;
                        }
                    }
                }
                else
                {
                    if (name != null)
                    {
                        normalHighlightingsByName[name] = highlighting;
                    }
                    if (extensions != null)
                    {
                        foreach (string ext in extensions)
                        {
                            normalHighlightingsByExtension[ext] = highlighting;
                        }
                    }
                }
            }
        }