예제 #1
0
        internal static WidgetStyle ReadSelectionNode(XmlReader reader)
        {
            WidgetStyle ret = null;

            string fgColor     = string.Empty;
            string bgColor     = string.Empty;
            string borderColor = string.Empty;

            reader.ReadToNextSibling(ReadWidgetStyle.XMLName_Selection);
            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case ReadWidgetStyle.attr_fgColor:
                    fgColor = (reader.Value == null ? string.Empty : reader.Value);
                    break;

                case ReadWidgetStyle.attr_bgColor:
                    bgColor = (reader.Value == null ? string.Empty : reader.Value);
                    break;

                case ReadWidgetStyle.attr_borderColor:
                    borderColor = (reader.Value == null ? string.Empty : reader.Value);
                    break;

                case XMLNameSpace:
                    break;

                default:
                    if (reader.Name.Trim().Length > 0 && reader.Name != XMLComment)
                    {
                        logger.Warn("Parsing the XML child:'" + reader.Name + "' of '" + ReadLexerType.XMLName + "' is not implemented.");
                    }
                    break;
                }
            }

            ret = new WidgetStyle(ReadWidgetStyle.XMLName_Selection);

            if (fgColor != string.Empty)
            {
                ret.fgColor = ReadWidgetStyle.SetColorFromString(ReadWidgetStyle.attr_fgColor, fgColor);
            }

            if (bgColor != string.Empty)
            {
                ret.bgColor = ReadWidgetStyle.SetColorFromString(ReadWidgetStyle.attr_bgColor, bgColor);
            }

            if (borderColor != string.Empty)
            {
                ret.borderColor = ReadWidgetStyle.SetColorFromString(ReadWidgetStyle.attr_borderColor, borderColor);
            }

            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Read the GlobalStyles XML tag with its attributes (if any) and insert
        /// a resulting <seealso cref="HighlightingTheme"/> object into the <seealso cref="HighlightingThemes"/> root object.
        /// </summary>
        internal static void ReadNode(XmlReader reader, HighlightingThemes HlThemeRoot)
        {
            reader.ReadToNextSibling(ReadGlobalStyles.XMLName);
            while (reader.Read())
            {
                if (reader.IsStartElement() == true)
                {
                    switch (reader.Name)
                    {
                    case ReadWidgetStyle.XMLName_Hyperlink:
                    case ReadWidgetStyle.XMLName_DefaultStyle:
                        WidgetStyle t = ReadWidgetStyle.ReadForegroundBackgroundColorNode(reader.ReadSubtree(), reader.Name);

                        try
                        {
                            HlThemeRoot.AddWidgetStyle(t.Name, t);
                        }
                        catch (Exception e) // Reading one errornous style node should not crash the whole process
                        {
                            logger.Error("Error reading DefaultStyle node", e);
                        }
                        break;

                    case ReadWidgetStyle.XMLName_CurrentLineBackground:
                        t = ReadWidgetStyle.ReadCurrentLineBackgroundNode(reader.ReadSubtree());

                        try
                        {
                            HlThemeRoot.AddWidgetStyle(t.Name, t);
                        }
                        catch (Exception e) // Reading one errornous style node should not crash the whole process
                        {
                            logger.Error("Error reading CurrentLineBackground node", e);
                        }
                        break;

                    case ReadWidgetStyle.XMLName_LineNumbersForeground:
                    case ReadWidgetStyle.XMLName_NonPrintableCharacter:
                        t = ReadWidgetStyle.ReadForegroundColorNode(reader.ReadSubtree(), reader.Name);

                        try
                        {
                            HlThemeRoot.AddWidgetStyle(t.Name, t);
                        }
                        catch (Exception e) // Reading one errornous style node should not crash the whole process
                        {
                            logger.Error("Error reading LineNumbersForeground node", e);
                        }
                        break;

                    case ReadWidgetStyle.XMLName_Selection:
                        t = ReadWidgetStyle.ReadSelectionNode(reader.ReadSubtree());

                        try
                        {
                            HlThemeRoot.AddWidgetStyle(t.Name, t);
                        }
                        catch (Exception e) // Reading one errornous style node should not crash the whole process
                        {
                            logger.Error("Error reading Selection node", e);
                        }
                        break;

                    case XMLNameSpace:
                        break;

                    default:
                        if (reader.Name.Trim().Length > 0 && reader.Name != XMLComment)
                        {
                            logger.Warn("Parsing the XML child:'" + reader.Name + "' of '" + ReadGlobalStyles.XMLName + "' is not implemented.");
                        }
                        break;
                    }
                }
            }
        }