private Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter) { if (document == null) { throw new System.ArgumentNullException("document"); } Paragraph paragraph = new Paragraph(); foreach (DocumentLine current in document.Lines) { int lineNumber = current.LineNumber; HighlightedInlineBuilder highlightedInlineBuilder = new HighlightedInlineBuilder(document.GetText(current)); if (highlighter != null) { HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber); int offset = current.Offset; foreach (HighlightedSection current2 in highlightedLine.Sections) { highlightedInlineBuilder.SetHighlighting(current2.Offset - offset, current2.Length, current2.Color); } } paragraph.Inlines.AddRange(highlightedInlineBuilder.CreateRuns()); paragraph.Inlines.Add(new LineBreak()); } return(paragraph); }
private Block ConvertTextDocumentToBlock() { TextDocument document = textEditor.Document; IHighlighter highlighter = textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter; Paragraph p = new Paragraph(); foreach (DocumentLine line in document.Lines) { int lineNumber = line.LineNumber; HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line)); if (highlighter != null) { HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber); int lineStartOffset = line.Offset; foreach (HighlightedSection section in highlightedLine.Sections) { inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color); } } p.Inlines.AddRange(inlineBuilder.CreateRuns()); p.Inlines.Add(new LineBreak()); } return(p); }
/// <summary> /// Converts a TextDocument to Block. /// </summary> /// <remarks> /// This portion of code by Daniel Grunwald from an AvalonEdit related <a href="http://community.sharpdevelop.net/forums/t/12012.aspx">forum post</a> /// </remarks> static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter) { if (document == null) { throw new ArgumentNullException("document"); } Paragraph p = new Paragraph(); foreach (DocumentLine line in document.Lines) { int lineNumber = line.LineNumber; HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line)); if (highlighter != null) { HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber); int lineStartOffset = line.Offset; foreach (HighlightedSection section in highlightedLine.Sections) { inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color); } } p.Inlines.AddRange(inlineBuilder.CreateRuns()); p.Inlines.Add(new LineBreak()); } return(p); }
protected override object CreateText() { var location = anchor.Location; LoggingService.Debug("Creating text for search result (" + location.Line + ", " + location.Column + ") "); TextBlock textBlock = new TextBlock(); textBlock.Inlines.Add("(" + location.Line + ", " + location.Column + ")\t"); string displayText = result.DisplayText; if (displayText != null) { textBlock.Inlines.Add(displayText); } else if (inlineBuilder != null) { textBlock.Inlines.AddRange(inlineBuilder.CreateRuns()); } if (showFileName) { textBlock.Inlines.Add( new Run { Text = StringParser.Parse("\t${res:MainWindow.Windows.SearchResultPanel.In} ") + Path.GetFileName(anchor.FileName) + "(" + Path.GetDirectoryName(anchor.FileName) + ")", FontStyle = FontStyles.Italic }); } return(textBlock); }
public static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter) { if (document == null) throw new ArgumentNullException("document"); // Table table = new Table(); // table.Columns.Add(new TableColumn { Width = GridLength.Auto }); // table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) }); // TableRowGroup trg = new TableRowGroup(); // table.RowGroups.Add(trg); Paragraph p = new Paragraph(); foreach (DocumentLine line in document.Lines) { int lineNumber = line.LineNumber; // TableRow row = new TableRow(); // trg.Rows.Add(row); // row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right }); HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line)); if (highlighter != null) { HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber); int lineStartOffset = line.Offset; foreach (HighlightedSection section in highlightedLine.Sections) inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color); } // Paragraph p = new Paragraph(); // row.Cells.Add(new TableCell(p)); p.Inlines.AddRange(inlineBuilder.CreateRuns()); p.Inlines.Add(new LineBreak()); } return p; }
protected override object CreateText() { var location = anchor.Location; LoggingService.Debug("Creating text for search result (" + location.Line + ", " + location.Column + ") "); TextBlock textBlock = new TextBlock(); if (result.DefaultTextColor != null && !IsSelected) { if (result.DefaultTextColor.Background != null) { textBlock.Background = result.DefaultTextColor.Background.GetBrush(null); } if (result.DefaultTextColor.Foreground != null) { textBlock.Foreground = result.DefaultTextColor.Foreground.GetBrush(null); } } textBlock.FontFamily = new FontFamily(EditorControlService.GlobalOptions.FontFamily); textBlock.Inlines.Add("(" + location.Line + ", " + location.Column + ")\t"); string displayText = result.DisplayText; if (displayText != null) { textBlock.Inlines.Add(displayText); } else if (result.Builder != null) { HighlightedInlineBuilder builder = result.Builder; if (IsSelected) { builder = builder.Clone(); builder.SetForeground(0, builder.Text.Length, null); builder.SetBackground(0, builder.Text.Length, null); } textBlock.Inlines.AddRange(builder.CreateRuns()); } if (showFileName) { textBlock.Inlines.Add( new Run { Text = StringParser.Parse("\t${res:MainWindow.Windows.SearchResultPanel.In} ") + Path.GetFileName(anchor.FileName) + "(" + Path.GetDirectoryName(anchor.FileName) + ")", FontStyle = FontStyles.Italic }); } return(textBlock); }
void GenerateHeader() { CSharpAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; var stringBuilder = new StringBuilder(); var formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex); ambience.ConvertEntity(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop()); var inlineBuilder = new HighlightedInlineBuilder(stringBuilder.ToString()); inlineBuilder.SetFontWeight(formatter.parameterStartOffset, formatter.parameterLength, FontWeights.Bold); header.Inlines.Clear(); header.Inlines.AddRange(inlineBuilder.CreateRuns()); }
void GenerateHeader() { CSharpAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; var stringBuilder = new StringBuilder(); TokenWriter formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex); ambience.ConvertSymbol(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop()); var documentation = XmlDocumentationElement.Get(Method); ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; var inlineBuilder = new HighlightedInlineBuilder(stringBuilder.ToString()); header.Inlines.Clear(); header.Inlines.AddRange(inlineBuilder.CreateRuns()); }