Browse Source

add support for customized colors to SearchResultsPad

pull/27/merge
Siegfried Pammer 14 years ago
parent
commit
0da19d4e3b
  1. 86
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditSyntaxHighlighterAdapter.cs
  2. 14
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs
  3. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
  4. 12
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs
  5. 1
      src/AddIns/Misc/SearchAndReplace/Project/Gui/ResultsTreeView.xaml
  6. 12
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs
  7. 22
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs
  8. 36
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs
  9. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs
  10. 5
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/IHighlighter.cs
  11. 7
      src/Main/Base/Project/Src/Editor/IEditorControlService.cs
  12. 10
      src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs
  13. 14
      src/Main/Base/Project/Src/Editor/Search/SearchResultMatch.cs
  14. 16
      src/Main/Base/Project/Src/Editor/Search/SearchResultsPad.cs
  15. 14
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

86
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditSyntaxHighlighterAdapter.cs

@ -49,5 +49,91 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -49,5 +49,91 @@ namespace ICSharpCode.AvalonEdit.AddIn
return null;
return CustomizableHighlightingColorizer.CustomizeColor(name, CustomizedHighlightingColor.FetchCustomizations(highlighting.Name));
}
public HighlightedInlineBuilder BuildInlines(int lineNumber)
{
HighlightedInlineBuilder builder = new HighlightedInlineBuilder(textEditor.Document.GetText(textEditor.Document.GetLineByNumber(lineNumber)));
IHighlighter highlighter = textEditor.GetService(typeof(IHighlighter)) as IHighlighter;
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;
}
public HighlightingColor DefaultTextColor {
get {
return GetNamedColor(CustomizableHighlightingColorizer.DefaultTextAndBackground);
}
}
}
public class DocumentSyntaxHighlighter : ISyntaxHighlighter
{
IDocument document;
IHighlighter highlighter;
string highlightingName;
public DocumentSyntaxHighlighter(IDocument document, IHighlighter highlighter, string highlightingName)
{
if (document == null)
throw new ArgumentNullException("document");
this.document = document;
this.highlighter = highlighter;
this.highlightingName = highlightingName;
}
public IEnumerable<string> GetSpanColorNamesFromLineStart(int lineNumber)
{
if (highlighter != null) {
// delayed evaluation doesn't cause a problem here: GetSpanStack is called immediately,
// only the where/select portian is evaluated later. But that won't be a problem because the
// HighlightingSpan instance shouldn't change once it's in use.
return from span in highlighter.GetSpanStack(lineNumber - 1)
where span.SpanColor != null && span.SpanColor.Name != null
select span.SpanColor.Name;
} else {
return Enumerable.Empty<string>();
}
}
public HighlightingColor GetNamedColor(string name)
{
return CustomizableHighlightingColorizer.CustomizeColor(name, CustomizedHighlightingColor.FetchCustomizations(highlightingName));
}
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;
}
public HighlightingColor DefaultTextColor {
get {
return GetNamedColor(CustomizableHighlightingColorizer.DefaultTextAndBackground);
}
}
}
}

14
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs

@ -2,7 +2,10 @@ @@ -2,7 +2,10 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.IO;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
@ -24,5 +27,16 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -24,5 +27,16 @@ namespace ICSharpCode.AvalonEdit.AddIn
control = editor;
return new CodeCompletionEditorAdapter(editor);
}
public ISyntaxHighlighter CreateHighlighter(IDocument document, string fileName)
{
var def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName));
var doc = document.GetService(typeof(TextDocument)) as TextDocument;
if (def == null || doc == null)
return null;
var baseHighlighter = new DocumentHighlighter(doc, def.MainRuleSet);
var highlighter = new CustomizableHighlightingColorizer.CustomizingHighlighter(CustomizedHighlightingColor.FetchCustomizations(def.Name), baseHighlighter);
return new DocumentSyntaxHighlighter(document, highlighter, def.Name);
}
}
}

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs

@ -136,7 +136,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -136,7 +136,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
return new CustomizingHighlighter(customizations, base.CreateHighlighter(textView, document));
}
sealed class CustomizingHighlighter : IHighlighter
internal sealed class CustomizingHighlighter : IHighlighter
{
readonly IEnumerable<CustomizedHighlightingColor> customizations;
readonly IHighlighter baseHighlighter;

12
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs

@ -16,6 +16,7 @@ using ICSharpCode.Core; @@ -16,6 +16,7 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Bookmarks;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Editor.Search;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
@ -196,7 +197,7 @@ namespace SearchAndReplace @@ -196,7 +197,7 @@ namespace SearchAndReplace
var source = DocumentUtilitites.GetTextSource(buffer);
TextDocument document = null;
DocumentHighlighter highlighter = null;
ISyntaxHighlighter highlighter = null;
int offset = 0;
int length = source.TextLength;
if (Target == SearchTarget.CurrentSelection && Selection != null) {
@ -209,15 +210,12 @@ namespace SearchAndReplace @@ -209,15 +210,12 @@ namespace SearchAndReplace
if (document == null) {
document = new TextDocument(source);
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName));
if (highlighting != null)
highlighter = new DocumentHighlighter(document, highlighting.MainRuleSet);
else
highlighter = null;
highlighter = EditorControlService.Instance.CreateHighlighter(new AvalonEditDocumentAdapter(document, null), fileName);
}
var start = document.GetLocation(result.Offset).ToLocation();
var end = document.GetLocation(result.Offset + result.Length).ToLocation();
var builder = SearchResultsPad.CreateInlineBuilder(start, end, document, highlighter);
results.Add(new AvalonEditSearchResultMatch(fileName, start, end, result.Offset, result.Length, builder, result));
results.Add(new AvalonEditSearchResultMatch(fileName, start, end, result.Offset, result.Length, builder, highlighter.DefaultTextColor, result));
}
if (results.Count > 0)
return new SearchedFile(fileName, results);
@ -317,7 +315,7 @@ namespace SearchAndReplace @@ -317,7 +315,7 @@ namespace SearchAndReplace
if (result != null) {
var start = document.OffsetToPosition(result.Offset);
var end = document.OffsetToPosition(result.EndOffset);
return new AvalonEditSearchResultMatch(file, start, end, result.Offset, result.Length, null, result);
return new AvalonEditSearchResultMatch(file, start, end, result.Offset, result.Length, null, null, result);
}
return null;
}

1
src/AddIns/Misc/SearchAndReplace/Project/Gui/ResultsTreeView.xaml

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>

12
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs

@ -23,6 +23,18 @@ namespace SearchAndReplace @@ -23,6 +23,18 @@ namespace SearchAndReplace
}
}
bool isSelected;
public bool IsSelected {
get { return isSelected; }
set {
if (isSelected != value) {
isSelected = value;
OnPropertyChanged("IsSelected");
}
}
}
IEnumerable<SearchNode> children;
public IEnumerable<SearchNode> Children {

22
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs

@ -56,6 +56,12 @@ namespace SearchAndReplace @@ -56,6 +56,12 @@ namespace SearchAndReplace
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");
@ -64,7 +70,13 @@ namespace SearchAndReplace @@ -64,7 +70,13 @@ namespace SearchAndReplace
if (displayText != null) {
textBlock.Inlines.Add(displayText);
} else if (result.Builder != null) {
textBlock.Inlines.AddRange(result.Builder.CreateRuns());
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) {
@ -78,6 +90,14 @@ namespace SearchAndReplace @@ -78,6 +90,14 @@ namespace SearchAndReplace
return textBlock;
}
protected override void OnPropertyChanged(string propertyName)
{
base.OnPropertyChanged(propertyName);
if (propertyName == "IsSelected") {
InvalidateText();
}
}
public override void ActivateItem()
{
FileService.JumpToFilePosition(anchor.FileName, anchor.Location.Line, anchor.Location.Column);

36
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
@ -24,6 +25,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -24,6 +25,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
sealed class HighlightingState
{
internal Brush Foreground;
internal Brush Background;
internal FontFamily Family;
internal FontWeight? Weight;
internal FontStyle? Style;
@ -32,6 +34,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -32,6 +34,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
{
return new HighlightingState {
Foreground = this.Foreground,
Background = this.Background,
Family = this.Family,
Weight = this.Weight,
Style = this.Style
@ -70,6 +73,13 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -70,6 +73,13 @@ namespace ICSharpCode.AvalonEdit.Highlighting
stateChanges.Add(new HighlightingState());
}
HighlightedInlineBuilder(string text, int[] offsets, HighlightingState[] states)
{
this.text = text;
stateChangeOffsets.AddRange(offsets);
stateChanges.AddRange(states);
}
/// <summary>
/// Gets the text.
/// </summary>
@ -96,6 +106,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -96,6 +106,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting
HighlightingState state = stateChanges[i];
if (color.Foreground != null)
state.Foreground = color.Foreground.GetBrush(null);
if (color.Background != null)
state.Background = color.Background.GetBrush(null);
if (color.FontStyle != null)
state.Style = color.FontStyle;
if (color.FontWeight != null)
@ -115,6 +127,18 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -115,6 +127,18 @@ namespace ICSharpCode.AvalonEdit.Highlighting
}
}
/// <summary>
/// Sets the background brush on the specified text segment.
/// </summary>
public void SetBackground(int offset, int length, Brush brush)
{
int startIndex = GetIndexForOffset(offset);
int endIndex = GetIndexForOffset(offset + length);
for (int i = startIndex; i < endIndex; i++) {
stateChanges[i].Background = brush;
}
}
/// <summary>
/// Sets the font weight on the specified text segment.
/// </summary>
@ -164,6 +188,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -164,6 +188,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting
HighlightingState state = stateChanges[i];
if (state.Foreground != null)
r.Foreground = state.Foreground;
if (state.Background != null)
r.Background = state.Background;
if (state.Weight != null)
r.FontWeight = state.Weight.Value;
if (state.Family != null)
@ -174,5 +200,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -174,5 +200,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting
}
return runs;
}
/// <summary>
/// Clones this HighlightedInlineBuilder.
/// </summary>
public HighlightedInlineBuilder Clone()
{
return new HighlightedInlineBuilder(this.text,
stateChangeOffsets.ToArray(),
stateChanges.Select(sc => sc.Clone()).ToArray());
}
}
}

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs

@ -49,6 +49,10 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -49,6 +49,10 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </summary>
public IList<HighlightedSection> Sections { get; private set; }
/// <summary>
/// Gets the default color of all text outside a <see cref="HighlightedSection"/>.
/// </summary>
public HighlightingColor DefaultTextColor { get; set; }
sealed class HtmlElement : IComparable<HtmlElement>
{

5
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/IHighlighter.cs

@ -32,4 +32,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting @@ -32,4 +32,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// <returns>A <see cref="HighlightedLine"/> line object that represents the highlighted sections.</returns>
HighlightedLine HighlightLine(int lineNumber);
}
public interface IHighlighter2
{
}
}

7
src/Main/Base/Project/Src/Editor/IEditorControlService.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
namespace ICSharpCode.SharpDevelop.Editor
@ -14,6 +15,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -14,6 +15,7 @@ namespace ICSharpCode.SharpDevelop.Editor
{
ITextEditor CreateEditor(out object control);
ITextEditorOptions GlobalOptions { get; }
ISyntaxHighlighter CreateHighlighter(IDocument document, string fileName);
}
/// <summary>
@ -91,6 +93,11 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -91,6 +93,11 @@ namespace ICSharpCode.SharpDevelop.Editor
return "Consolas";
}
}
public ISyntaxHighlighter CreateHighlighter(IDocument document, string fileName)
{
return null;
}
}
}
}

10
src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs

@ -23,6 +23,16 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -23,6 +23,16 @@ namespace ICSharpCode.SharpDevelop.Editor
/// Retrieves the HighlightingColor with the specified name. Returns null if no color matching the name is found.
/// </summary>
HighlightingColor GetNamedColor(string name);
/// <summary>
/// Creates a <see cref="HighlightedInlineBuilder"/> for a specified line.
/// </summary>
HighlightedInlineBuilder BuildInlines(int lineNumber);
/// <summary>
/// Gets the default text color.
/// </summary>
HighlightingColor DefaultTextColor { get; }
}
public static class SyntaxHighligherKnownSpanNames

14
src/Main/Base/Project/Src/Editor/Search/SearchResultMatch.cs

@ -22,6 +22,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -22,6 +22,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
Location startLocation;
Location endLocation;
HighlightedInlineBuilder builder;
HighlightingColor defaultTextColor;
public FileName FileName {
get { return fileName; }
@ -39,6 +40,10 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -39,6 +40,10 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
get { return builder; }
}
public HighlightingColor DefaultTextColor {
get { return defaultTextColor; }
}
public int StartOffset {
get { return offset; }
}
@ -56,7 +61,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -56,7 +61,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
return pattern;
}
public SearchResultMatch(FileName fileName, Location startLocation, Location endLocation, int offset, int length, HighlightedInlineBuilder builder)
public SearchResultMatch(FileName fileName, Location startLocation, Location endLocation, int offset, int length, HighlightedInlineBuilder builder, HighlightingColor defaultTextColor)
{
this.fileName = fileName;
this.startLocation = startLocation;
@ -64,6 +69,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -64,6 +69,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
this.offset = offset;
this.length = length;
this.builder = builder;
this.defaultTextColor = defaultTextColor;
}
/// <summary>
@ -94,7 +100,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -94,7 +100,7 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
}
public SimpleSearchResultMatch(FileName fileName, Location position, int offset, string displayText)
: base(fileName, position, position, offset, 0, null)
: base(fileName, position, position, offset, 0, null, null)
{
this.displayText = displayText;
}
@ -104,8 +110,8 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -104,8 +110,8 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
{
ICSharpCode.AvalonEdit.Search.ISearchResult match;
public AvalonEditSearchResultMatch(FileName fileName, Location startLocation, Location endLocation, int offset, int length, HighlightedInlineBuilder builder, ICSharpCode.AvalonEdit.Search.ISearchResult match)
: base(fileName, startLocation, endLocation, offset, length, builder)
public AvalonEditSearchResultMatch(FileName fileName, Location startLocation, Location endLocation, int offset, int length, HighlightedInlineBuilder builder, HighlightingColor defaultTextColor, ICSharpCode.AvalonEdit.Search.ISearchResult match)
: base(fileName, startLocation, endLocation, offset, length, builder, defaultTextColor)
{
this.match = match;
}

16
src/Main/Base/Project/Src/Editor/Search/SearchResultsPad.cs

@ -147,20 +147,14 @@ namespace ICSharpCode.SharpDevelop.Editor.Search @@ -147,20 +147,14 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
return new DummySearchResult { Text = title };
}
public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, IHighlighter highlighter)
public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, ISyntaxHighlighter highlighter)
{
if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount) {
var matchedLine = document.GetLineByNumber(startPosition.Line);
HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(matchedLine));
HighlightedInlineBuilder inlineBuilder;
if (highlighter != null) {
HighlightedLine highlightedLine = highlighter.HighlightLine(startPosition.Line);
int startOffset = highlightedLine.DocumentLine.Offset;
// copy only the foreground color
foreach (HighlightedSection section in highlightedLine.Sections) {
if (section.Color.Foreground != null) {
inlineBuilder.SetForeground(section.Offset - startOffset, section.Length, section.Color.Foreground.GetBrush(null));
}
}
inlineBuilder = highlighter.BuildInlines(startPosition.Line);
} else {
inlineBuilder = new HighlightedInlineBuilder(document.GetText(document.GetLineByNumber(startPosition.Line)));
}
// now highlight the match in bold

14
src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

@ -375,23 +375,21 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -375,23 +375,21 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (list == null) return;
List<SearchResultMatch> results = new List<SearchResultMatch>(list.Count);
TextDocument document = null;
ITextBuffer buffer = null;
FileName fileName = null;
IHighlighter highlighter = null;
ISyntaxHighlighter highlighter = null;
foreach (Reference r in list) {
var f = new FileName(r.FileName);
if (document == null || !f.Equals(fileName)) {
document = new TextDocument(DocumentUtilitites.GetTextSource(ParserService.GetParseableFileContent(r.FileName)));
buffer = ParserService.GetParseableFileContent(r.FileName);
document = new TextDocument(DocumentUtilitites.GetTextSource(buffer));
fileName = new FileName(r.FileName);
var def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(r.FileName));
if (def != null)
highlighter = new DocumentHighlighter(document, def.MainRuleSet);
else
highlighter = null;
highlighter = EditorControlService.Instance.CreateHighlighter(new AvalonEditDocumentAdapter(document, null), fileName);
}
var start = document.GetLocation(r.Offset).ToLocation();
var end = document.GetLocation(r.Offset + r.Length).ToLocation();
var builder = SearchResultsPad.CreateInlineBuilder(start, end, document, highlighter);
SearchResultMatch res = new SearchResultMatch(fileName, start, end, r.Offset, r.Length, builder);
SearchResultMatch res = new SearchResultMatch(fileName, start, end, r.Offset, r.Length, builder, highlighter.DefaultTextColor);
results.Add(res);
}
SearchResultsPad.Instance.ShowSearchResults(title, results);

Loading…
Cancel
Save