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); }
public HighlightedInlineBuilder BuildInlines(int lineNumber) { HighlightedInlineBuilder builder = new HighlightedInlineBuilder(document.GetLine(lineNumber).Text); if (highlighter != null) { HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber); int startOffset = highlightedLine.DocumentLine.Offset; // copy only the foreground and background colors foreach (HighlightedSection section in highlightedLine.Sections) { if (section.Color.Foreground != null) { builder.SetForeground(section.Offset - startOffset, section.Length, section.Color.Foreground.GetBrush(null)); } if (section.Color.Background != null) { builder.SetBackground(section.Offset - startOffset, section.Length, section.Color.Background.GetBrush(null)); } } } return(builder); }