Exemple #1
0
        /// <summary>
        /// Set the values of this instance, using a dictionnary of key -> values, override for this class
        /// </summary>
        public new void SetColorValues(Type thisType)
        {
            if (SavedStringValues == null)
            {
                return;
            }

            // for each field of this object, try to assign its value with the _savedStringValues dico
            foreach (var fieldInfo in thisType.GetFields().Where(fieldInfo => SavedStringValues.ContainsKey(fieldInfo.Name) && fieldInfo.DeclaringType == thisType && fieldInfo.FieldType == typeof(StyleThemeItem)))
            {
                try {
                    var value = SavedStringValues[fieldInfo.Name];
                    var items = value.Split('\t');
                    if (items.Length >= 3)
                    {
                        int fontType;
                        if (!int.TryParse(items[2].Trim(), out fontType))
                        {
                            fontType = 0;
                        }
                        fieldInfo.SetValue(this, new StyleThemeItem {
                            ForeColor = ColorTranslator.FromHtml(GetHtmlColor(items[0].Trim(), 0)),
                            BackColor = ColorTranslator.FromHtml(GetHtmlColor(items[1].Trim(), 1)),
                            FontType  = fontType,
                            FontName  = items.Length >= 4 ? items[3].Trim() : string.Empty
                        });
                    }
                } catch (Exception e) {
                    throw new Exception("Reading styles, couldn't understand the line : <" + SavedStringValues[fieldInfo.Name] + "> for the field <" + fieldInfo.Name + "> and for the theme <" + ThemeName + "> : " + e);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Set the values of this instance, using a dictionary of key -> values, override for this class
        /// </summary>
        public new void SetColorValues(Type thisType)
        {
            if (SavedStringValues == null)
            {
                return;
            }

            Items.Clear();
            typeof(SciStyleId).ForEach <SciStyleId>((name, enumVal) => {
                if (!SavedStringValues.ContainsKey(name))
                {
                    throw new Exception("Styles definition, couldn't find the styles of the field : <" + name + "> for the theme <" + ThemeName + "> : ");
                }
                try {
                    var properties = SavedStringValues[name].Split('\t');
                    if (properties.Length >= 3)
                    {
                        Items.Add(enumVal, new StyleThemeItem {
                            ForeColor = ColorTranslator.FromHtml(GetHtmlColor(properties[0].Trim(), 0)),
                            BackColor = ColorTranslator.FromHtml(GetHtmlColor(properties[1].Trim(), 1)),
                            FontType  = Int32.Parse(properties[2].Trim()),
                            FontName  = properties.Length >= 4 ? properties[3].Trim() : String.Empty
                        });
                    }
                } catch (Exception e) {
                    throw new Exception("Reading styles, couldn't understand the line : <" + SavedStringValues[name] + "> for the field <" + name + "> and for the theme <" + ThemeName + "> : " + e);
                }
            });
        }
Exemple #3
0
 /// <summary>
 /// Set the values of this instance, using a dictionnary of key -> values
 /// </summary>
 public new void SetColorValues(Type type)
 {
     // add the accent color if it doesn't exist! it means that we didn't set it, so it must be equal to ThemeAccentColor
     if (!SavedStringValues.ContainsKey("AccentColor"))
     {
         SetStringValues("AccentColor", "@ThemeAccentColor");
     }
     base.SetColorValues(type);
 }
Exemple #4
0
 private string ReplaceAliases(string value, int propNumber)
 {
     while (true)
     {
         if (value.Contains("@"))
         {
             // try to replace a variable name by it's html color value
             var regex = new Regex(@"@([a-zA-Z]*)", RegexOptions.IgnoreCase);
             value = regex.Replace(value, match => {
                 if (SavedStringValues.ContainsKey(match.Groups[1].Value))
                 {
                     return(SavedStringValues[match.Groups[1].Value].Split('\t')[propNumber]);
                 }
                 throw new Exception("Couldn't find the color " + match.Groups[1].Value + "!");
             });
             continue;
         }
         return(value);
     }
 }