internal CustomControlEntry(ComplexControlEntryDefinition entry) { if (entry.appliesTo != null) { SelectedBy = EntrySelectedBy.Get(entry.appliesTo.referenceList); } CustomItems = new List <CustomItemBase>(); foreach (var tok in entry.itemDefinition.formatTokenList) { CustomItems.Add(CustomItemBase.Create(tok)); } }
internal static CustomItemBase Create(FormatToken token) { if (token is NewLineToken) { return(new CustomItemNewline()); } var textToken = token as TextToken; if (textToken != null) { return(new CustomItemText { Text = textToken.text }); } var frameToken = token as FrameToken; if (frameToken != null) { var frame = new CustomItemFrame { RightIndent = (uint)frameToken.frameInfoDefinition.rightIndentation, LeftIndent = (uint)frameToken.frameInfoDefinition.leftIndentation }; var firstLine = frameToken.frameInfoDefinition.firstLine; if (firstLine > 0) { frame.FirstLineIndent = (uint)firstLine; } else if (firstLine < 0) { frame.FirstLineHanging = (uint)-firstLine; } foreach (var frameItemToken in frameToken.itemDefinition.formatTokenList) { frame.CustomItems.Add(CustomItemBase.Create(frameItemToken)); } return(frame); } var cpt = token as CompoundPropertyToken; if (cpt != null) { var cie = new CustomItemExpression { EnumerateCollection = cpt.enumerateCollection }; if (cpt.conditionToken != null) { cie.ItemSelectionCondition = new DisplayEntry(cpt.conditionToken); } if (cpt.expression.expressionValue != null) { cie.Expression = new DisplayEntry(cpt.expression); } if (cpt.control != null) { cie.CustomControl = new CustomControl((ComplexControlBody)cpt.control, null); } return(cie); } var fpt = token as FieldPropertyToken; if (fpt != null) { } Diagnostics.Assert(false, "Unexpected formatting token kind"); return(null); }
private FormatToken LoadFormatTokenFromObjectModel(CustomItemBase item, int viewIndex, string typeName) { var newline = item as CustomItemNewline; if (newline != null) { return new NewLineToken { count = newline.Count }; } var text = item as CustomItemText; if (text != null) { return new TextToken { text = text.Text }; } var expr = item as CustomItemExpression; if (expr != null) { var cpt = new CompoundPropertyToken { enumerateCollection = expr.EnumerateCollection }; if (expr.ItemSelectionCondition != null) { cpt.conditionToken = LoadExpressionFromObjectModel(expr.ItemSelectionCondition, viewIndex, typeName); } if (expr.Expression != null) { cpt.expression = LoadExpressionFromObjectModel(expr.Expression, viewIndex, typeName); } if (expr.CustomControl != null) { cpt.control = LoadCustomControlFromObjectModel(expr.CustomControl, viewIndex, typeName); } return cpt; } var frame = (CustomItemFrame)item; var frameToken = new FrameToken { frameInfoDefinition = { leftIndentation = (int) frame.LeftIndent, rightIndentation = (int) frame.RightIndent, firstLine = frame.FirstLineHanging != 0 ? -(int) frame.FirstLineHanging : (int) frame.FirstLineIndent } }; foreach (var i in frame.CustomItems) { frameToken.itemDefinition.formatTokenList.Add(LoadFormatTokenFromObjectModel(i, viewIndex, typeName)); } return frameToken; }
internal void WriteCustomItem(CustomItemBase item) { var newline = item as CustomItemNewline; if (newline != null) { for (int i = 0; i < newline.Count; i++) { _writer.WriteElementString("NewLine", ""); } return; } var text = item as CustomItemText; if (text != null) { _writer.WriteElementString("Text", text.Text); return; } var expr = item as CustomItemExpression; if (expr != null) { _writer.WriteStartElement("ExpressionBinding"); if (expr.EnumerateCollection) { _writer.WriteElementString("EnumerateCollection", ""); } if (expr.ItemSelectionCondition != null) { _writer.WriteStartElement("ItemSelectionCondition"); WriteDisplayEntry(expr.ItemSelectionCondition); _writer.WriteEndElement(/*</ItemSelectionCondition>*/); } if (expr.Expression != null) { WriteDisplayEntry(expr.Expression); } if (expr.CustomControl != null) { WriteCustomControl(expr.CustomControl); } _writer.WriteEndElement(/*</ExpressionBinding>*/); return; } var frame = (CustomItemFrame)item; _writer.WriteStartElement("Frame"); if (frame.LeftIndent != 0) _writer.WriteElementString("LeftIndent", frame.LeftIndent.ToString(CultureInfo.InvariantCulture)); if (frame.RightIndent != 0) _writer.WriteElementString("RightIndent", frame.RightIndent.ToString(CultureInfo.InvariantCulture)); if (frame.FirstLineHanging != 0) _writer.WriteElementString("FirstLineHanging", frame.FirstLineHanging.ToString(CultureInfo.InvariantCulture)); if (frame.FirstLineIndent != 0) _writer.WriteElementString("FirstLineIndent", frame.FirstLineIndent.ToString(CultureInfo.InvariantCulture)); _writer.WriteStartElement("CustomItem"); foreach (var frameItem in frame.CustomItems) { WriteCustomItem(frameItem); } _writer.WriteEndElement(/*</CustomItem>*/); _writer.WriteEndElement(/*</Frame>*/); }