/// <summary> /// Appends given line to the given paragraph /// </summary> /// <param name="currentParagraph"></param> /// <param name="line"></param> public void AppendTextToParagraph(Paragraph currentParagraph, string line) { foreach (string token in Regex.Split(line, regexStatementsPattern)) { if (token.StartsWith("Load") || token.StartsWith("Select")) { //match the selected item Match m = Regex.Match(token, @"""(.*)"""); string selectedItem = m.Groups[1].Value; ComboBoxStatement statementBox; if (token.StartsWith("Load")) { statementBox = new ComboBoxStatement(Statement.Load, selectedItem); } else { statementBox = new ComboBoxStatement(Statement.Select, selectedItem); } InlineUIContainer myInlineUIContainer = new InlineUIContainer(statementBox); currentParagraph.Inlines.Add(myInlineUIContainer); } else { currentParagraph.Inlines.Add(new Run(token)); } } }
/// <summary> /// Converts flowDocument data to string between start and end textpointer /// </summary> /// <param name="start">start textpointer</param> /// <param name="end">end textpointer</param> /// <returns></returns> public string ConvertFlowDocumentDataToStringWithinSelection(TextPointer start, TextPointer end) { // NOT WORKING - it should check if the start and end document are within the same document... //if (start.IsInSameDocument(end)) //{ // throw new ArgumentException("Start and end pointers has to be within the same document."); //} StringBuilder codeBuilder = new StringBuilder(); for (TextPointer position = start; position != null && position.CompareTo(end) <= 0; position = position.GetNextContextPosition(LogicalDirection.Forward)) { if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd) { // process only runs, paragraphs, and UiElements. all other elements are ignored Paragraph paragraph; Run run; InlineUIContainer uiContainer; if ((paragraph = position.Parent as Paragraph) != null) { codeBuilder.AppendLine(); } else if ((run = position.Parent as Run) != null) { codeBuilder.Append(run.Text); } else if ((uiContainer = position.Parent as InlineUIContainer) != null) { ComboBoxStatement statementBox = uiContainer.Child as ComboBoxStatement; codeBuilder.Append(statementBox.FormattedVisualStatement); } } } return(codeBuilder.ToString()); }