/// <summary> /// Implements the visitor for a named color (<see cref="XshtdColor"/> object) /// that is contained in a <see cref="XshtdSyntaxDefinition"/> object. /// /// Method checks if given color name is unique and adds the color into the internal /// collection of inique colors if it is. /// </summary> /// <param name="syntax"></param> /// <param name="color"></param> /// <returns>Always returns null. Throws a <see cref="HighlightingDefinitionInvalidException"/> /// if color name is a duplicate.</returns> public object VisitColor(XshtdSyntaxDefinition syntax, XshtdColor color) { if (color.Name != null) { if (color.Name.Length == 0) { throw Error(color, "Name must not be the empty string"); } if (syntax == null) { throw Error(syntax, "Syntax Definition for theme must not be null"); } SyntaxDefinition synDef; if (def.syntaxDefDict.TryGetValue(syntax.Name, out synDef) == false) { throw Error(syntax, "Themed Syntax Definition does not exist '" + syntax.Name + "'."); } if (synDef.ColorGet(color.Name) == null) { synDef.ColorAdd(new HighlightingColor() { Name = color.Name }); } else { throw Error(color, "Duplicate color name '" + color.Name + "'."); } } return(null); }
/// <summary> /// Implements the visitor for a named color (<see cref="XshtdColor"/> object) /// that is contained in a <see cref="XshtdSyntaxDefinition"/> object. /// </summary> /// <param name="syntax"></param> /// <param name="color"></param> /// <returns></returns> public object VisitColor(XshtdSyntaxDefinition syntax, XshtdColor color) { if (color.Name == null) { throw Error(color, "Name must not be null"); } if (color.Name.Length == 0) { throw Error(color, "Name must not be the empty string"); } if (syntax == null) { throw Error(syntax, "Syntax Definition for theme must not be null"); } SyntaxDefinition synDef; HighlightingColor highColor; if (def.syntaxDefDict.TryGetValue(syntax.Name, out synDef) == false) { throw Error(syntax, "Themed Syntax Definition does not exist '" + syntax.Name + "'."); } highColor = synDef.ColorGet(color.Name); if (highColor == null) { highColor = new HighlightingColor() { Name = color.Name }; synDef.ColorAdd(highColor); } highColor.Foreground = color.Foreground; highColor.Background = color.Background; highColor.Underline = color.Underline; highColor.FontStyle = color.FontStyle; highColor.FontWeight = color.FontWeight; return(highColor); }