#region Using Directives using System; using System.Drawing; using System.IO; using System.Text.RegularExpressions; using System.Windows.Forms; using System.Xml; #endregion Using Directives namespace ScintillaNET.Configuration { public class Configuration { #region Fields private bool? _autoComplete_AutoHide; private bool? _autoComplete_AutomaticLengthEntered; private bool? _autoComplete_cancelAtStart; private bool? _autoComplete_DropRestOfWord; private string _autoComplete_fillUpCharacters; private char? _autoComplete_ImageSeperator; private bool? _autoComplete_IsCaseSensitive; private string _autoComplete_List; private bool? _autoComplete_ListInherit; private char? _autoComplete_ListSeperator; private int? _autoComplete_MaxHeight; private int? _autoComplete_MaxWidth; private bool? _autoComplete_singleLineAccept; private string _autoComplete_StopCharacters; private Color _callTip_BackColor; private Color _callTip_ForeColor; private Color _callTip_HighlightTextColor; private int? _caret_BlinkRate; private Color _caret_Color; private int? _caret_CurrentLineBackgroundAlpha; private Color _caret_CurrentLineBackgroundColor; private bool? _caret_HighlightCurrentLine; private bool? _caret_IsSticky; private CaretStyle? _caret_Style; private int? _caret_Width; private bool? _clipboard_ConvertLineBreaksOnPaste; private CommandBindingConfigList _commands_KeyBindingList = new CommandBindingConfigList(); private string _dropMarkers_SharedStackName; private bool? _endOfLine_IsVisisble; private EndOfLineMode? _endOfLine_Mode; private FoldFlag? _folding_Flags; private bool? _folding_IsEnabled; private FoldMarkerScheme? _folding_MarkerScheme; private bool? _folding_UseCompactFolding; private bool _hasData = false; private Color _hotspot_ActiveBackColor; private Color _hotspot_ActiveForeColor; private bool? _hotspot_ActiveUnderline; private bool? _hotspot_SingleLine; private bool? _hotspot_UseActiveBackColor; private bool? _hotspot_UseActiveForeColor; private bool? _indentation_BackspaceUnindents; private int? _indentation_IndentWidth; private bool? _indentation_ShowGuides; private SmartIndent? _indentation_SmartIndentType; private bool? _indentation_TabIndents; private int? _indentation_TabWidth; private bool? _indentation_UseTabs; private IndicatorConfigList _indicator_List = new IndicatorConfigList(); private string _language; private KeyWordConfigList _lexing_Keywords = new KeyWordConfigList(); private string _lexing_Language; private string _lexing_LineCommentPrefix; private LexerPropertiesConfig _lexing_Properties = new LexerPropertiesConfig(); private string _lexing_StreamCommentPrefix; private string _lexing_StreamCommentSuffix; private string _lexing_WhitespaceChars; private string _lexing_WordChars; private LineWrappingMode? _lineWrapping_Mode; private LineWrappingIndentMode? _lineWrapping_IndentMode; private int? _lineWrapping_IndentSize; private LineWrappingVisualFlags? _lineWrapping_VisualFlags; private LineWrappingVisualFlagsLocations? _lineWrapping_VisualFlagsLocations; private Color _longLines_EdgeColor; private int? _longLines_EdgeColumn; private EdgeMode? _longLines_EdgeMode; private MarginConfigList _margin_List = new MarginConfigList(); private MarkersConfigList _markers_List; private bool? _scrolling_EndAtLastLine; private int? _scrolling_HorizontalWidth; private ScrollBars? _scrolling_ScrollBars; private int? _scrolling_XOffset; private Color _selection_BackColor; private Color _selection_BackColorUnfocused; private Color _selection_ForeColor; private Color _selection_ForeColorUnfocused; private bool? _selection_Hidden; private bool? _selection_HideSelection; private SelectionMode? _selection_Mode; private SnippetsConfigList _snippetsConfigList = new SnippetsConfigList(); private StyleConfigList _styles = new StyleConfigList(); private bool? _undoRedoIsUndoEnabled; private Color _whitespace_BackColor; private Color _whitespace_ForeColor; private WhitespaceMode? _whitespace_Mode; #endregion Fields #region Methods private bool? getBool(string s) { s = s.ToLower(); switch (s) { case "true": case "t": case "1": case "y": case "yes": return true; case "false": case "f": case "0": case "n": case "no": return false; } return null; } private char? getChar(string s) { if (string.IsNullOrEmpty(s)) return null; return s[0]; } private Color getColor(string s) { return (Color)new ColorConverter().ConvertFromString(s); } private int? getInt(string s) { int i; if (int.TryParse(s, out i)) return i; return null; } private string getString(XmlAttribute a) { if (a == null) return null; return a.Value; } private StyleConfig getStyleConfigFromElement(XmlReader reader) { StyleConfig sc = new StyleConfig(); if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { string attrName = reader.Name.ToLower(); switch (attrName) { case "name": sc.Name = reader.Value; break; case "number": sc.Number = getInt(reader.Value); break; case "backcolor": sc.BackColor = getColor(reader.Value); break; case "bold": sc.Bold = getBool(reader.Value); break; case "case": sc.Case = (StyleCase)Enum.Parse(typeof(StyleCase), reader.Value, true); break; case "characterset": sc.CharacterSet = (CharacterSet)Enum.Parse(typeof(CharacterSet), reader.Value, true); break; case "fontname": sc.FontName = reader.Value; break; case "forecolor": sc.ForeColor = getColor(reader.Value); break; case "ischangeable": sc.IsChangeable = getBool(reader.Value); break; case "ishotspot": sc.IsHotspot = getBool(reader.Value); break; case "isselectioneolfilled": sc.IsSelectionEolFilled = getBool(reader.Value); break; case "isvisible": sc.IsVisible = getBool(reader.Value); break; case "italic": sc.Italic = getBool(reader.Value); break; case "size": sc.Size = getInt(reader.Value); break; case "underline": sc.Underline = getBool(reader.Value); break; case "inherit": sc.Inherit = getBool(reader.Value); break; } } reader.MoveToElement(); } return sc; } public void Load(TextReader txtReader) { XmlDocument configDocument = new XmlDocument(); configDocument.PreserveWhitespace = true; configDocument.Load(txtReader); Load(configDocument); } public void Load(XmlReader reader) { reader.ReadStartElement(); while (!reader.EOF) { if (reader.Name.Equals("language", StringComparison.OrdinalIgnoreCase) && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name.Equals("name", StringComparison.OrdinalIgnoreCase) && reader.Value.Equals(_language, StringComparison.OrdinalIgnoreCase)) { ReadLanguage(reader); _hasData = true; } } if (_hasData) reader.Skip(); } else { reader.Skip(); continue; } reader.Read(); } reader.Close(); } public void Load(XmlDocument configDocument) { XmlElement langNode = configDocument.DocumentElement.SelectSingleNode("./Language[@Name='" + _language + "']") as XmlElement; if (langNode == null) return; XmlElement autoCNode = langNode.SelectSingleNode("AutoComplete") as XmlElement; if (autoCNode != null) { _autoComplete_AutoHide = getBool(autoCNode.GetAttribute("AutoHide")); _autoComplete_AutomaticLengthEntered = getBool(autoCNode.GetAttribute("AutomaticLengthEntered")); _autoComplete_cancelAtStart = getBool(autoCNode.GetAttribute("CancelAtStart")); _autoComplete_DropRestOfWord = getBool(autoCNode.GetAttribute("DropRestOfWord")); _autoComplete_fillUpCharacters = getString(autoCNode.GetAttributeNode("FillUpCharacters")); _autoComplete_ImageSeperator = getChar(autoCNode.GetAttribute("AutomaticLengthEntered")); _autoComplete_IsCaseSensitive = getBool(autoCNode.GetAttribute("IsCaseSensitive")); _autoComplete_ListSeperator = getChar(autoCNode.GetAttribute("ListSeperator")); _autoComplete_MaxHeight = getInt(autoCNode.GetAttribute("MaxHeight")); _autoComplete_MaxWidth = getInt(autoCNode.GetAttribute("MaxWidth")); _autoComplete_singleLineAccept = getBool(autoCNode.GetAttribute("SingleLineAccept")); _autoComplete_StopCharacters = getString(autoCNode.GetAttributeNode("StopCharacters")); XmlElement listNode = autoCNode.SelectSingleNode("./List") as XmlElement; if (listNode != null) { _autoComplete_ListInherit = getBool(listNode.GetAttribute("Inherit")); _autoComplete_List = new Regex("\\s+").Replace(listNode.InnerText, " ").Trim(); } } autoCNode = null; XmlElement callTipNode = langNode.SelectSingleNode("CallTip") as XmlElement; if (callTipNode != null) { _callTip_BackColor = getColor(callTipNode.GetAttribute("BackColor")); _callTip_ForeColor = getColor(callTipNode.GetAttribute("ForeColor")); _callTip_HighlightTextColor = getColor(callTipNode.GetAttribute("HighlightTextColor")); } callTipNode = null; XmlElement caretNode = langNode.SelectSingleNode("Caret") as XmlElement; if (caretNode != null) { // This guy is a bit of an oddball becuase null means "I don't Care" // and we need some way of using the OS value. string blinkRate = caretNode.GetAttribute("BlinkRate"); if (blinkRate.ToLower() == "system") _caret_BlinkRate = SystemInformation.CaretBlinkTime; else _caret_BlinkRate = getInt(blinkRate); _caret_Color = getColor(caretNode.GetAttribute("Color")); _caret_CurrentLineBackgroundAlpha = getInt(caretNode.GetAttribute("CurrentLineBackgroundAlpha")); _caret_CurrentLineBackgroundColor = getColor(caretNode.GetAttribute("CurrentLineBackgroundColor")); _caret_HighlightCurrentLine = getBool(caretNode.GetAttribute("HighlightCurrentLine")); _caret_IsSticky = getBool(caretNode.GetAttribute("IsSticky")); try { _caret_Style = (CaretStyle)Enum.Parse(typeof(CaretStyle), caretNode.GetAttribute("Style"), true); } catch (ArgumentException) { } _caret_Width = getInt(caretNode.GetAttribute("Width")); } caretNode = null; XmlElement clipboardNode = langNode.SelectSingleNode("Clipboard") as XmlElement; if (clipboardNode != null) { _clipboard_ConvertLineBreaksOnPaste = getBool(clipboardNode.GetAttribute("ConvertLineBreaksOnPaste")); } clipboardNode = null; _commands_KeyBindingList = new CommandBindingConfigList(); XmlElement commandsNode = langNode.SelectSingleNode("Commands") as XmlElement; if (commandsNode != null) { _commands_KeyBindingList.Inherit = getBool(commandsNode.GetAttribute("Inherit")); _commands_KeyBindingList.AllowDuplicateBindings = getBool(commandsNode.GetAttribute("AllowDuplicateBindings")); foreach (XmlElement el in commandsNode.SelectNodes("./Binding")) { KeyBinding kb = new KeyBinding(); kb.KeyCode = Utilities.GetKeys(el.GetAttribute("Key")); string modifiers = el.GetAttribute("Modifier"); if (modifiers != string.Empty) { foreach (string modifier in modifiers.Split(' ')) kb.Modifiers |= (Keys)Enum.Parse(typeof(Keys), modifier.Trim(), true); } BindableCommand cmd = (BindableCommand)Enum.Parse(typeof(BindableCommand), el.GetAttribute("Command"), true); CommandBindingConfig cfg = new CommandBindingConfig(kb, getBool(el.GetAttribute("ReplaceCurrent")), cmd); _commands_KeyBindingList.Add(cfg); } } commandsNode = null; XmlElement endOfLineNode = langNode.SelectSingleNode("EndOfLine") as XmlElement; if (endOfLineNode != null) { _endOfLine_IsVisisble = getBool(endOfLineNode.GetAttribute("IsVisible")); try { _endOfLine_Mode = (EndOfLineMode)Enum.Parse(typeof(EndOfLineMode), endOfLineNode.GetAttribute("Mode"), true); } catch (ArgumentException) { } } endOfLineNode = null; XmlElement foldingNode = langNode.SelectSingleNode("Folding") as XmlElement; if (foldingNode != null) { string flags = foldingNode.GetAttribute("Flags").Trim(); if (flags != string.Empty) { FoldFlag? ff = null; foreach (string flag in flags.Split(' ')) ff |= (FoldFlag)Enum.Parse(typeof(FoldFlag), flag.Trim(), true); if (ff.HasValue) _folding_Flags = ff; } _folding_IsEnabled = getBool(foldingNode.GetAttribute("IsEnabled")); try { _folding_MarkerScheme = (FoldMarkerScheme)Enum.Parse(typeof(FoldMarkerScheme), foldingNode.GetAttribute("MarkerScheme"), true); } catch (ArgumentException) { } _folding_UseCompactFolding = getBool(foldingNode.GetAttribute("UseCompactFolding")); } foldingNode = null; XmlElement hotSpotNode = langNode.SelectSingleNode("Hotspot") as XmlElement; if (hotSpotNode != null) { _hotspot_ActiveBackColor = getColor(hotSpotNode.GetAttribute("ActiveBackColor")); _hotspot_ActiveForeColor = getColor(hotSpotNode.GetAttribute("ActiveForeColor")); _hotspot_ActiveUnderline = getBool(hotSpotNode.GetAttribute("ActiveUnderline")); _hotspot_SingleLine = getBool(hotSpotNode.GetAttribute("SingleLine")); _hotspot_UseActiveBackColor = getBool(hotSpotNode.GetAttribute("UseActiveBackColor")); _hotspot_UseActiveForeColor = getBool(hotSpotNode.GetAttribute("UseActiveForeColor")); } hotSpotNode = null; XmlElement indentationNode = langNode.SelectSingleNode("Indentation") as XmlElement; if (indentationNode != null) { _indentation_BackspaceUnindents = getBool(indentationNode.GetAttribute("BackspaceUnindents")); _indentation_IndentWidth = getInt(indentationNode.GetAttribute("IndentWidth")); _indentation_ShowGuides = getBool(indentationNode.GetAttribute("ShowGuides")); _indentation_TabIndents = getBool(indentationNode.GetAttribute("TabIndents")); _indentation_TabWidth = getInt(indentationNode.GetAttribute("TabWidth")); _indentation_UseTabs = getBool(indentationNode.GetAttribute("UseTabs")); try { _indentation_SmartIndentType = (SmartIndent)Enum.Parse(typeof(SmartIndent), indentationNode.GetAttribute("SmartIndentType"), true); } catch (ArgumentException) { } } indentationNode = null; XmlElement indicatorNode = langNode.SelectSingleNode("Indicators") as XmlElement; if (indicatorNode != null) { _indicator_List.Inherit = getBool(indicatorNode.GetAttribute("Inherit")); foreach (XmlElement el in indicatorNode.SelectNodes("Indicator")) { IndicatorConfig ic = new IndicatorConfig(); ic.Number = int.Parse(el.GetAttribute("Number")); ic.Color = getColor(el.GetAttribute("Color")); ic.Inherit = getBool(el.GetAttribute("Inherit")); ic.IsDrawnUnder = getBool(el.GetAttribute("IsDrawnUnder")); try { ic.Style = (IndicatorStyle)Enum.Parse(typeof(IndicatorStyle), el.GetAttribute("Style"), true); } catch (ArgumentException) { } _indicator_List.Add(ic); } } _lexing_Properties = new LexerPropertiesConfig(); _lexing_Keywords = new KeyWordConfigList(); XmlElement lexerNode = langNode.SelectSingleNode("Lexer") as XmlElement; if (lexerNode != null) { _lexing_WhitespaceChars = getString(lexerNode.GetAttributeNode("WhitespaceChars")); _lexing_WordChars = getString(lexerNode.GetAttributeNode("WordChars")); _lexing_Language = getString(lexerNode.GetAttributeNode("LexerName")); _lexing_LineCommentPrefix = getString(lexerNode.GetAttributeNode("LineCommentPrefix")); _lexing_StreamCommentPrefix = getString(lexerNode.GetAttributeNode("StreamCommentPrefix")); _lexing_StreamCommentSuffix = getString(lexerNode.GetAttributeNode("StreamCommentSuffix")); XmlElement propNode = lexerNode.SelectSingleNode("Properties") as XmlElement; if (propNode != null) { _lexing_Properties.Inherit = getBool(propNode.GetAttribute("Inherit")); foreach (XmlElement el in propNode.SelectNodes("Property")) _lexing_Properties.Add(el.GetAttribute("Name"), el.GetAttribute("Value")); } foreach (XmlElement el in lexerNode.SelectNodes("Keywords")) _lexing_Keywords.Add(new KeyWordConfig(getInt(el.GetAttribute("List")).Value, el.InnerText.Trim(), getBool(el.GetAttribute("Inherit")))); } lexerNode = null; XmlElement lineWrapNode = langNode.SelectSingleNode("LineWrapping") as XmlElement; if (lineWrapNode != null) { try { _lineWrapping_Mode = (LineWrappingMode)Enum.Parse(typeof(LineWrappingMode), lineWrapNode.GetAttribute("Mode"), true); } catch (ArgumentException) { } _lineWrapping_IndentSize = getInt(lineWrapNode.GetAttribute("IndentSize")); try { _lineWrapping_IndentMode = (LineWrappingIndentMode)Enum.Parse(typeof(LineWrappingIndentMode), lineWrapNode.GetAttribute("IndentMode"), true); } catch (ArgumentException) { } string flags = lineWrapNode.GetAttribute("VisualFlags").Trim(); if (flags != string.Empty) { LineWrappingVisualFlags? wvf = null; foreach (string flag in flags.Split(' ')) wvf |= (LineWrappingVisualFlags)Enum.Parse(typeof(LineWrappingVisualFlags), flag.Trim(), true); if (wvf.HasValue) _lineWrapping_VisualFlags = wvf; } try { _lineWrapping_VisualFlagsLocations = (LineWrappingVisualFlagsLocations)Enum.Parse(typeof(LineWrappingVisualFlagsLocations), lineWrapNode.GetAttribute("VisualFlagsLocations"), true); } catch (ArgumentException) { } } lineWrapNode = null; XmlElement longLinesNode = langNode.SelectSingleNode("LongLines") as XmlElement; if (longLinesNode != null) { _longLines_EdgeColor = getColor(longLinesNode.GetAttribute("EdgeColor")); _longLines_EdgeColumn = getInt(longLinesNode.GetAttribute("EdgeColumn")); try { _longLines_EdgeMode = (EdgeMode)Enum.Parse(typeof(EdgeMode), longLinesNode.GetAttribute("EdgeMode"), true); } catch (ArgumentException) { } } longLinesNode = null; _margin_List = new MarginConfigList(); XmlElement marginNode = langNode.SelectSingleNode("Margins") as XmlElement; if (marginNode != null) { _margin_List.FoldMarginColor = getColor(marginNode.GetAttribute("FoldMarginColor")); _margin_List.FoldMarginHighlightColor = getColor(marginNode.GetAttribute("FoldMarginHighlightColor")); _margin_List.Left = getInt(marginNode.GetAttribute("Left")); _margin_List.Right = getInt(marginNode.GetAttribute("Right")); _margin_List.Inherit = getBool(marginNode.GetAttribute("Inherit")); foreach (XmlElement el in marginNode.SelectNodes("./Margin")) { MarginConfig mc = new MarginConfig(); mc.Number = int.Parse(el.GetAttribute("Number")); mc.Inherit = getBool(el.GetAttribute("Inherit")); mc.AutoToggleMarkerNumber = getInt(el.GetAttribute("AutoToggleMarkerNumber")); mc.IsClickable = getBool(el.GetAttribute("IsClickable")); mc.IsFoldMargin = getBool(el.GetAttribute("IsFoldMargin")); mc.IsMarkerMargin = getBool(el.GetAttribute("IsMarkerMargin")); try { mc.Type = (MarginType)Enum.Parse(typeof(MarginType), el.GetAttribute("Type"), true); } catch (ArgumentException) { } mc.Width = getInt(el.GetAttribute("Width")); _margin_List.Add(mc); } } marginNode = null; XmlElement markersNode = langNode.SelectSingleNode("Markers") as XmlElement; _markers_List = new MarkersConfigList(); if (markersNode != null) { _markers_List.Inherit = getBool(markersNode.GetAttribute("Inherit")); foreach (XmlElement el in markersNode.SelectNodes("Marker")) { MarkersConfig mc = new MarkersConfig(); mc.Alpha = getInt(el.GetAttribute("Alpha")); mc.BackColor = getColor(el.GetAttribute("BackColor")); mc.ForeColor = getColor(el.GetAttribute("ForeColor")); mc.Name = getString(el.GetAttributeNode("Name")); mc.Number = getInt(el.GetAttribute("Number")); mc.Inherit = getBool(el.GetAttribute("Inherit")); try { mc.Symbol = (MarkerSymbol)Enum.Parse(typeof(MarkerSymbol), el.GetAttribute("Symbol"), true); } catch (ArgumentException) { } _markers_List.Add(mc); } } XmlElement scrollingNode = langNode.SelectSingleNode("Scrolling") as XmlElement; if (scrollingNode != null) { _scrolling_EndAtLastLine = getBool(scrollingNode.GetAttribute("EndAtLastLine")); _scrolling_HorizontalWidth = getInt(scrollingNode.GetAttribute("HorizontalWidth")); string flags = scrollingNode.GetAttribute("ScrollBars").Trim(); if (flags != string.Empty) { ScrollBars? sb = null; foreach (string flag in flags.Split(' ')) sb |= (ScrollBars)Enum.Parse(typeof(ScrollBars), flag.Trim(), true); if (sb.HasValue) _scrolling_ScrollBars = sb; } _scrolling_XOffset = getInt(scrollingNode.GetAttribute("XOffset")); } scrollingNode = null; XmlElement selectionNode = langNode.SelectSingleNode("Selection") as XmlElement; if (selectionNode != null) { _selection_BackColor = getColor(selectionNode.GetAttribute("BackColor")); _selection_BackColorUnfocused = getColor(selectionNode.GetAttribute("BackColorUnfocused")); _selection_ForeColor = getColor(selectionNode.GetAttribute("ForeColor")); _selection_ForeColorUnfocused = getColor(selectionNode.GetAttribute("ForeColorUnfocused")); _selection_Hidden = getBool(selectionNode.GetAttribute("Hidden")); _selection_HideSelection = getBool(selectionNode.GetAttribute("HideSelection")); try { _selection_Mode = (SelectionMode)Enum.Parse(typeof(SelectionMode), selectionNode.GetAttribute("Mode"), true); } catch (ArgumentException) { } } selectionNode = null; _snippetsConfigList = new SnippetsConfigList(); XmlElement snippetsNode = langNode.SelectSingleNode("Snippets") as XmlElement; if (snippetsNode != null) { _snippetsConfigList.ActiveSnippetColor = getColor(snippetsNode.GetAttribute("ActiveSnippetColor")); _snippetsConfigList.ActiveSnippetIndicator = getInt(snippetsNode.GetAttribute("ActiveSnippetIndicator")); _snippetsConfigList.InactiveSnippetColor = getColor(snippetsNode.GetAttribute("InactiveSnippetColor")); _snippetsConfigList.InactiveSnippetIndicator = getInt(snippetsNode.GetAttribute("InactiveSnippetIndicator")); try { _snippetsConfigList.ActiveSnippetIndicatorStyle = (IndicatorStyle)Enum.Parse(typeof(IndicatorStyle), snippetsNode.GetAttribute("ActiveSnippetIndicatorStyle"), true); } catch (ArgumentException) { } try { _snippetsConfigList.InactiveSnippetIndicatorStyle = (IndicatorStyle)Enum.Parse(typeof(IndicatorStyle), snippetsNode.GetAttribute("InactiveSnippetIndicatorStyle"), true); } catch (ArgumentException) { } _snippetsConfigList.DefaultDelimeter = getChar(snippetsNode.GetAttribute("DefaultDelimeter")); _snippetsConfigList.IsEnabled = getBool(snippetsNode.GetAttribute("IsEnabled")); _snippetsConfigList.IsOneKeySelectionEmbedEnabled = getBool(snippetsNode.GetAttribute("IsOneKeySelectionEmbedEnabled")); foreach (XmlElement el in snippetsNode.SelectNodes("Snippet")) { SnippetsConfig sc = new SnippetsConfig(); sc.Shortcut = el.GetAttribute("Shortcut"); sc.Code = el.InnerText; sc.Delimeter = getChar(el.GetAttribute("Delimeter")); sc.IsSurroundsWith = getBool(el.GetAttribute("IsSurroundsWith")); _snippetsConfigList.Add(sc); } } snippetsNode = null; _styles = new StyleConfigList(); XmlElement stylesNode = langNode.SelectSingleNode("Styles") as XmlElement; if (stylesNode != null) { _styles.Bits = getInt(stylesNode.GetAttribute("Bits")); foreach (XmlElement el in stylesNode.SelectNodes("Style")) { StyleConfig sc = new StyleConfig(); sc.Name = el.GetAttribute("Name"); sc.Number = getInt(el.GetAttribute("Number")); sc.BackColor = getColor(el.GetAttribute("BackColor")); sc.Bold = getBool(el.GetAttribute("Bold")); try { sc.Case = (StyleCase)Enum.Parse(typeof(StyleCase), el.GetAttribute("Case"), true); } catch (ArgumentException) { } try { sc.CharacterSet = (CharacterSet)Enum.Parse(typeof(CharacterSet), el.GetAttribute("CharacterSet"), true); } catch (ArgumentException) { } sc.FontName = getString(el.GetAttributeNode("FontName")); sc.ForeColor = getColor(el.GetAttribute("ForeColor")); sc.IsChangeable = getBool(el.GetAttribute("IsChangeable")); sc.IsHotspot = getBool(el.GetAttribute("IsHotspot")); sc.IsSelectionEolFilled = getBool(el.GetAttribute("IsSelectionEolFilled")); sc.IsVisible = getBool(el.GetAttribute("IsVisible")); sc.Italic = getBool(el.GetAttribute("Italic")); sc.Size = getInt(el.GetAttribute("Size")); sc.Underline = getBool(el.GetAttribute("Underline")); sc.Inherit = getBool(el.GetAttribute("Inherit")); _styles.Add(sc); } // This is a nifty added on hack made specifically for HTML. // Normally the style config elements are quite managable as there // are typically less than 10 when you don't count common styles. // // However HTML uses 9 different Sub languages that combined make // use of all 128 styles (well there are some small gaps). In order // to make this more managable I did added a SubLanguage element that // basically just prepends the Language's name and "." to the Style // Name definition. // // So for example if you had the following // // //