Example #1
0
		private void readMarkers(XmlReader reader)
		{
			if (reader.HasAttributes)
			{
				while (reader.MoveToNextAttribute())
					if(reader.Name.ToLower() == "inherit")
						_markers_List.Inherit = getBool(reader.Value);

				reader.MoveToElement();
			}

			if (!reader.IsEmptyElement)
			{
				while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name.Equals("markers", StringComparison.OrdinalIgnoreCase)))
				{
					reader.Read();
					if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("marker", StringComparison.OrdinalIgnoreCase))
					{
						if (reader.HasAttributes)
						{
							MarkersConfig mc = new MarkersConfig();
							while (reader.MoveToNextAttribute())
							{
								string attrName = reader.Name.ToLower();
								switch (attrName)
								{
									case "alpha":
										mc.Alpha = getInt(reader.Value);
										break;
									case "backcolor":
										mc.BackColor = getColor(reader.Value);
										break;
									case "forecolor":
										mc.ForeColor = getColor(reader.Value);
										break;
									case "name":
										mc.Name = reader.Value;
										break;
									case "number":
										mc.Number = getInt(reader.Value);
										break;
									case "inherit":
										mc.Inherit = getBool(reader.Value);
										break;
									case "symbol":
										mc.Symbol = (MarkerSymbol)Enum.Parse(typeof(MarkerSymbol), reader.Value, true);
										break;
								}
							}
							
							reader.MoveToElement();
							_markers_List.Add(mc);
						}
					}
				}
			}
			reader.Read();
		}
Example #2
0
		public void Load(XmlDocument configDocument)
		{
			
			XmlNode langNode = configDocument.DocumentElement.SelectSingleNode("./Language[@Name='" + _language + "']");
			if (langNode == null)
				return;

			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_ConvertEndOfLineOnPaste = getBool(clipboardNode.GetAttribute("ConvertEndOfLineOnPaste"));
			}
			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_ConvertOnPaste = getBool(endOfLineNode.GetAttribute("ConvertOnPaste"));
				_endOfLine_IsVisisble = getBool(endOfLineNode.GetAttribute("IsVisible"));

				try
				{
					_endOfLine_Mode = (EndOfLineMode)Enum.Parse(typeof(EndOfLineMode), endOfLineNode.GetAttribute("Mode"), true);
				}
				catch (ArgumentException) { }
			}
			endOfLineNode = 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("LineWrap") as XmlElement;
			if (lineWrapNode != null)
			{
				try
				{
					_lineWrap_LayoutCache = (LineCache)Enum.Parse(typeof(LineCache), lineWrapNode.GetAttribute("LayoutCache"), true);
				}
				catch (ArgumentException) { }

				try
				{
					_lineWrap_Mode = (WrapMode)Enum.Parse(typeof(WrapMode), lineWrapNode.GetAttribute("Mode"), true);
				}
				catch (ArgumentException) { }

				_lineWrap_PositionCacheSize = getInt(lineWrapNode.GetAttribute("PositionCacheSize"));
				_lineWrap_StartIndent = getInt(lineWrapNode.GetAttribute("StartIndent"));

				string flags = lineWrapNode.GetAttribute("VisualFlags").Trim();
				if (flags != string.Empty)
				{
					WrapVisualFlag? wvf = null;
					foreach (string flag in flags.Split(' '))
						wvf |= (WrapVisualFlag)Enum.Parse(typeof(WrapVisualFlag), flag.Trim(), true);

					if (wvf.HasValue)
						_lineWrap_VisualFlags = wvf;
				}

				try
				{
					_lineWrap_VisualFlagsLocation = (WrapVisualLocation)Enum.Parse(typeof(WrapVisualLocation), lineWrapNode.GetAttribute("VisualFlagsLocation"), 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;

			_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
				//	<Styles>
				//		<SubLanguage Name="ASP JavaScript">
				//			<Style Name="Keyword" Bold="True" />
				//		</SubLanguage>
				//	</Styles>
				//	That style's name will get interpreted as "ASP JavaScript.Keyword".
				//	which if you look at the html.txt in LexerStyleNames you'll see it
				//	maps to Style # 62

				//	Yeah I copied and pasted from above. I know. Feel free to refactor
				//	this and check it in since you're so high and mighty.
				foreach (XmlElement subLanguage in stylesNode.SelectNodes("SubLanguage"))
				{
					string subLanguageName = subLanguage.GetAttribute("Name");
					foreach (XmlElement el in subLanguage.SelectNodes("Style"))
					{
						StyleConfig sc = new StyleConfig();
						sc.Name = subLanguageName + "." + 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);
					}
				}
			}
			stylesNode = null;

			XmlElement undoRedoNode = langNode.SelectSingleNode("UndoRedo") as XmlElement;
			if (undoRedoNode != null)
			{
				_undoRedoIsUndoEnabled = getBool(undoRedoNode.GetAttribute("IsUndoEnabled"));
			}
			undoRedoNode = null;


			XmlElement whiteSpaceNode = langNode.SelectSingleNode("WhiteSpace") as XmlElement;
			if (whiteSpaceNode != null)
			{
				_whiteSpace_BackColor = getColor(whiteSpaceNode.GetAttribute("BackColor"));
				_whiteSpace_ForeColor = getColor(whiteSpaceNode.GetAttribute("ForeColor"));
				_whiteSpace_Mode = (WhiteSpaceMode)Enum.Parse(typeof(WhiteSpaceMode), whiteSpaceNode.GetAttribute("Mode"), true);
				_whiteSpace_UseWhiteSpaceBackColor = getBool(whiteSpaceNode.GetAttribute("UseWhiteSpaceBackColor"));
				_whiteSpace_UseWhiteSpaceForeColor = getBool(whiteSpaceNode.GetAttribute("UseWhiteSpaceForeColor"));
			}
			whiteSpaceNode = null;

			configDocument = null;
		}