This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
/
SearchResultNode.cs
86 lines (73 loc) · 2.34 KB
/
SearchResultNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.Search;
namespace SearchAndReplace
{
/// <summary>
/// Represents a search result.
/// </summary>
public sealed class SearchResultNode : SearchNode
{
SearchResultMatch result;
PermanentAnchor anchor;
public SearchResultNode(SearchResultMatch result)
{
this.result = result;
this.anchor = new PermanentAnchor(result.FileName, result.StartLocation.Line, result.StartLocation.Column);
anchor.SurviveDeletion = true;
}
bool showFileName = true;
public bool ShowFileName {
get {
return showFileName;
}
set {
if (showFileName != value) {
showFileName = value;
InvalidateText();
}
}
}
public FileName FileName {
get { return anchor.FileName; }
}
protected override object CreateText()
{
var location = anchor.Location;
LoggingService.Debug("Creating text for search result (" + location.Line + ", " + location.Column + ") ");
TextBlock textBlock = new TextBlock();
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) {
textBlock.Inlines.AddRange(result.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 override void ActivateItem()
{
FileService.JumpToFilePosition(anchor.FileName, anchor.Location.Line, anchor.Location.Column);
}
}
}