Browse Source

Merge branch 'master' of github.com:icsharpcode/SharpDevelop into newNR

Conflicts:
	src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditSyntaxHighlighterAdapter.cs
	src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
	src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs
	src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs
	src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs
	src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/IHighlighter.cs
	src/Main/Base/Project/Src/Editor/IEditorControlService.cs
	src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs
	src/Main/Base/Project/Src/Editor/Search/SearchResultMatch.cs
	src/Main/Base/Project/Src/Editor/Search/SearchResultsPad.cs
	src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs
newNRvisualizers
Siegfried Pammer 13 years ago
parent
commit
4d8c634587
  1. 11
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs
  2. 10
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  3. 11
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs
  4. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  5. 18
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs
  6. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs
  7. 48
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizableHighlightingColorizer.cs
  8. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DiffControl.xaml
  9. 14
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DiffControl.xaml.cs
  10. 110
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DocumentSyntaxHighlighter.cs
  11. 8
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ExpressionHighlightRenderer.cs
  12. 88
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  13. 15
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs
  14. 12
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs
  15. 1
      src/AddIns/Misc/SearchAndReplace/Project/Gui/ResultsTreeView.xaml
  16. 12
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchNode.cs
  17. 22
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchResultNode.cs
  18. 36
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs
  19. 5
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedLine.cs
  20. 11
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingManager.cs
  21. 11
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/IHighlightingDefinition.cs
  22. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd
  23. 8
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd
  24. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/VBNET-Mode.xshd
  25. 8
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/XmlDoc.xshd
  26. 12
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs
  27. 15
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs
  28. 38
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdProperty.cs
  29. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj
  30. 31
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/MouseHoverLogic.cs
  31. 8
      src/Main/Base/Project/Src/Editor/IEditorControlService.cs
  32. 10
      src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs
  33. 14
      src/Main/Base/Project/Src/Editor/Search/SearchResultMatch.cs
  34. 16
      src/Main/Base/Project/Src/Editor/Search/SearchResultsPad.cs
  35. 16
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs
  36. 4
      src/Main/Base/Project/Src/Services/RefactoringService/Reference.cs
  37. 12
      src/Main/Core/Project/Src/Services/StringParser/StringParser.cs

11
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs

@ -19,6 +19,7 @@ using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.Utils; using ICSharpCode.NRefactory.Utils;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Editor.Search;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Parser; using ICSharpCode.SharpDevelop.Parser;
@ -97,24 +98,20 @@ namespace CSharpBinding
if (parseInfo == null) if (parseInfo == null)
return; return;
ReadOnlyDocument document = null; ReadOnlyDocument document = null;
DocumentHighlighter highlighter = null; ISyntaxHighlighter highlighter = null;
List<Reference> results = new List<Reference>(); List<Reference> results = new List<Reference>();
fr.FindReferencesInFile( fr.FindReferencesInFile(
searchScope, parseInfo.ParsedFile, parseInfo.CompilationUnit, compilation, searchScope, parseInfo.ParsedFile, parseInfo.CompilationUnit, compilation,
delegate (AstNode node, ResolveResult result) { delegate (AstNode node, ResolveResult result) {
if (document == null) { if (document == null) {
document = new ReadOnlyDocument(textSource); document = new ReadOnlyDocument(textSource);
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)); highlighter = SD.EditorControlService.CreateHighlighter(document, fileName);
if (highlighting != null)
highlighter = new DocumentHighlighter(document, highlighting.MainRuleSet);
else
highlighter = null;
} }
var region = new DomRegion(fileName, node.StartLocation, node.EndLocation); var region = new DomRegion(fileName, node.StartLocation, node.EndLocation);
int offset = document.GetOffset(node.StartLocation); int offset = document.GetOffset(node.StartLocation);
int length = document.GetOffset(node.EndLocation) - offset; int length = document.GetOffset(node.EndLocation) - offset;
var builder = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter); var builder = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
results.Add(new Reference(region, result, offset, length, builder)); results.Add(new Reference(region, result, offset, length, builder, highlighter.DefaultTextColor));
}, cancellationToken); }, cancellationToken);
callback(new SearchedFile(fileName, results)); callback(new SearchedFile(fileName, results));
} }

10
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -137,24 +137,20 @@ namespace CSharpBinding.Parser
throw new ArgumentException("Parse info does not have CompilationUnit"); throw new ArgumentException("Parse info does not have CompilationUnit");
ReadOnlyDocument document = null; ReadOnlyDocument document = null;
DocumentHighlighter highlighter = null; ISyntaxHighlighter highlighter = null;
new FindReferences().FindLocalReferences( new FindReferences().FindLocalReferences(
variable, csParseInfo.ParsedFile, csParseInfo.CompilationUnit, compilation, variable, csParseInfo.ParsedFile, csParseInfo.CompilationUnit, compilation,
delegate (AstNode node, ResolveResult result) { delegate (AstNode node, ResolveResult result) {
if (document == null) { if (document == null) {
document = new ReadOnlyDocument(fileContent); document = new ReadOnlyDocument(fileContent);
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(csParseInfo.FileName)); highlighter = SD.EditorControlService.CreateHighlighter(document, csParseInfo.FileName);
if (highlighting != null)
highlighter = new DocumentHighlighter(document, highlighting.MainRuleSet);
else
highlighter = null;
} }
var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation); var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation);
int offset = document.GetOffset(node.StartLocation); int offset = document.GetOffset(node.StartLocation);
int length = document.GetOffset(node.EndLocation) - offset; int length = document.GetOffset(node.EndLocation) - offset;
var builder = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter); var builder = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
callback(new Reference(region, result, offset, length, builder)); callback(new Reference(region, result, offset, length, builder, highlighter.DefaultTextColor));
}, cancellationToken); }, cancellationToken);
} }

11
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs

@ -14,6 +14,7 @@ using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Editor.Search;
using ICSharpCode.SharpDevelop.Parser; using ICSharpCode.SharpDevelop.Parser;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
@ -86,24 +87,20 @@ namespace ICSharpCode.XamlBinding
if (parseInfo == null) if (parseInfo == null)
return; return;
ReadOnlyDocument document = null; ReadOnlyDocument document = null;
DocumentHighlighter highlighter = null; ISyntaxHighlighter highlighter = null;
List<Reference> results = new List<Reference>(); List<Reference> results = new List<Reference>();
XamlResolver resolver = new XamlResolver(); XamlResolver resolver = new XamlResolver();
do { do {
if (document == null) { if (document == null) {
document = new ReadOnlyDocument(textSource); document = new ReadOnlyDocument(textSource);
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)); highlighter = SD.EditorControlService.CreateHighlighter(document, fileName);
if (highlighting != null)
highlighter = new DocumentHighlighter(document, highlighting.MainRuleSet);
else
highlighter = null;
} }
var result = resolver.Resolve(parseInfo, document.GetLocation(offset + entity.Name.Length / 2 + 1), compilation, cancellationToken); var result = resolver.Resolve(parseInfo, document.GetLocation(offset + entity.Name.Length / 2 + 1), compilation, cancellationToken);
int length = entity.Name.Length; int length = entity.Name.Length;
if ((result is TypeResolveResult && ((TypeResolveResult)result).Type.Equals(entity)) || (result is MemberResolveResult && ((MemberResolveResult)result).Member.Equals(entity))) { if ((result is TypeResolveResult && ((TypeResolveResult)result).Type.Equals(entity)) || (result is MemberResolveResult && ((MemberResolveResult)result).Member.Equals(entity))) {
var region = new DomRegion(fileName, document.GetLocation(offset), document.GetLocation(offset + length)); var region = new DomRegion(fileName, document.GetLocation(offset), document.GetLocation(offset + length));
var builder = SearchResultsPad.CreateInlineBuilder(region.Begin, region.End, document, highlighter); var builder = SearchResultsPad.CreateInlineBuilder(region.Begin, region.End, document, highlighter);
results.Add(new Reference(region, result, offset, length, builder)); results.Add(new Reference(region, result, offset, length, builder, highlighter.DefaultTextColor));
} }
offset = textSource.IndexOf(entity.Name, offset + length, textSource.TextLength - offset - length, StringComparison.OrdinalIgnoreCase); offset = textSource.IndexOf(entity.Name, offset + length, textSource.TextLength - offset - length, StringComparison.OrdinalIgnoreCase);
} while (offset > 0); } while (offset > 0);

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -104,6 +104,7 @@
<Compile Include="Src\ContextActions\FindDerivedClassesOrOverrides.cs" /> <Compile Include="Src\ContextActions\FindDerivedClassesOrOverrides.cs" />
<Compile Include="Src\ContextActions\GoToEntityAction.cs" /> <Compile Include="Src\ContextActions\GoToEntityAction.cs" />
<Compile Include="Src\DocumentSequence.cs" /> <Compile Include="Src\DocumentSequence.cs" />
<Compile Include="Src\DocumentSyntaxHighlighter.cs" />
<Compile Include="Src\EnhancedScrollBar.cs" /> <Compile Include="Src\EnhancedScrollBar.cs" />
<Compile Include="Src\Snippets\CodeSnippetComparer.cs" /> <Compile Include="Src\Snippets\CodeSnippetComparer.cs" />
<Compile Include="Src\Utils.cs" /> <Compile Include="Src\Utils.cs" />

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

@ -2,7 +2,11 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.IO;
using ICSharpCode.AvalonEdit.AddIn.Options; using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
@ -24,5 +28,19 @@ namespace ICSharpCode.AvalonEdit.AddIn
control = editor; control = editor;
return new CodeCompletionEditorAdapter(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(document,
CustomizedHighlightingColor.FetchCustomizations(def.Name), def, baseHighlighter);
return new DocumentSyntaxHighlighter(document, highlighter, def.Name);
}
} }
} }

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs

@ -8,7 +8,6 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
@ -221,11 +220,10 @@ namespace ICSharpCode.AvalonEdit.AddIn
} }
DiffControl differ = new DiffControl(); DiffControl differ = new DiffControl();
differ.editor.SyntaxHighlighting = editor.SyntaxHighlighting; differ.CopyEditorSettings(editor);
differ.editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; differ.editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
differ.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden; differ.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
differ.editor.Document.Text = oldText; differ.editor.Document.Text = oldText;
differ.Background = Brushes.White;
if (oldText == string.Empty) { if (oldText == string.Empty) {
differ.editor.Visibility = Visibility.Collapsed; differ.editor.Visibility = Visibility.Collapsed;
@ -249,7 +247,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
tooltip.Child = new Border() { tooltip.Child = new Border() {
Child = differ, Child = differ,
BorderBrush = Brushes.Black, BorderBrush = editor.TextArea.Foreground,
BorderThickness = new Thickness(1) BorderThickness = new Thickness(1)
}; };

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

@ -116,7 +116,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
continue; continue;
assignedColumnRulerColor = true; assignedColumnRulerColor = true;
if (color.Foreground != null) if (color.Foreground != null)
textEditor.TextArea.TextView.ColumnRulerPen = CreateFrozenPen(color.Foreground.Value); textEditor.TextArea.TextView.ColumnRulerPen = CreateFrozenPen(color.Foreground.Value);
break; break;
} }
} }
@ -152,12 +152,13 @@ namespace ICSharpCode.AvalonEdit.AddIn
return new CustomizingHighlighter(textView, customizations, highlightingDefinition, base.CreateHighlighter(textView, document)); return new CustomizingHighlighter(textView, customizations, highlightingDefinition, base.CreateHighlighter(textView, document));
} }
sealed class CustomizingHighlighter : IHighlighter, ISyntaxHighlighter internal sealed class CustomizingHighlighter : IHighlighter, ISyntaxHighlighter
{ {
readonly TextView textView; readonly TextView textView;
readonly IEnumerable<CustomizedHighlightingColor> customizations; readonly IEnumerable<CustomizedHighlightingColor> customizations;
readonly IHighlightingDefinition highlightingDefinition; readonly IHighlightingDefinition highlightingDefinition;
readonly IHighlighter baseHighlighter; readonly IHighlighter baseHighlighter;
readonly IDocument document;
List<IHighlighter> additionalHighlighters = new List<IHighlighter>(); List<IHighlighter> additionalHighlighters = new List<IHighlighter>();
public CustomizingHighlighter(TextView textView, IEnumerable<CustomizedHighlightingColor> customizations, IHighlightingDefinition highlightingDefinition, IHighlighter baseHighlighter) public CustomizingHighlighter(TextView textView, IEnumerable<CustomizedHighlightingColor> customizations, IHighlightingDefinition highlightingDefinition, IHighlighter baseHighlighter)
@ -168,6 +169,20 @@ namespace ICSharpCode.AvalonEdit.AddIn
Debug.Assert(baseHighlighter != null); Debug.Assert(baseHighlighter != null);
this.textView = textView; this.textView = textView;
this.document = textView.Document;
this.customizations = customizations;
this.highlightingDefinition = highlightingDefinition;
this.baseHighlighter = baseHighlighter;
baseHighlighter.HighlightingStateChanged += highlighter_HighlightingStateChanged;
}
public CustomizingHighlighter(IDocument document, IEnumerable<CustomizedHighlightingColor> customizations, IHighlightingDefinition highlightingDefinition, IHighlighter baseHighlighter)
{
Debug.Assert(customizations != null);
Debug.Assert(highlightingDefinition != null);
Debug.Assert(baseHighlighter != null);
this.document = document;
this.customizations = customizations; this.customizations = customizations;
this.highlightingDefinition = highlightingDefinition; this.highlightingDefinition = highlightingDefinition;
this.baseHighlighter = baseHighlighter; this.baseHighlighter = baseHighlighter;
@ -250,11 +265,15 @@ namespace ICSharpCode.AvalonEdit.AddIn
public void InvalidateLine(IDocumentLine line) public void InvalidateLine(IDocumentLine line)
{ {
if (textView == null)
throw new InvalidOperationException("ISyntaxHighlighter has no TextView assigned!");
textView.Redraw(line, DispatcherPriority.Background); textView.Redraw(line, DispatcherPriority.Background);
} }
public void InvalidateAll() public void InvalidateAll()
{ {
if (textView == null)
throw new InvalidOperationException("ISyntaxHighlighter has no TextView assigned!");
textView.Redraw(DispatcherPriority.Background); textView.Redraw(DispatcherPriority.Background);
} }
@ -265,6 +284,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
public IEnumerable<IDocumentLine> GetVisibleDocumentLines() public IEnumerable<IDocumentLine> GetVisibleDocumentLines()
{ {
if (textView == null)
throw new InvalidOperationException("ISyntaxHighlighter has no TextView assigned!");
List<IDocumentLine> result = new List<IDocumentLine>(); List<IDocumentLine> result = new List<IDocumentLine>();
foreach (VisualLine line in textView.VisualLines) { foreach (VisualLine line in textView.VisualLines) {
if (line.FirstDocumentLine == line.LastDocumentLine) { if (line.FirstDocumentLine == line.LastDocumentLine) {
@ -289,6 +310,29 @@ namespace ICSharpCode.AvalonEdit.AddIn
{ {
return CustomizeColor(name, CustomizedHighlightingColor.FetchCustomizations(highlightingDefinition.Name)); return CustomizeColor(name, CustomizedHighlightingColor.FetchCustomizations(highlightingDefinition.Name));
} }
public HighlightingColor DefaultTextColor {
get {
return GetNamedColor(CustomizableHighlightingColorizer.DefaultTextAndBackground);
}
}
public HighlightedInlineBuilder BuildInlines(int lineNumber)
{
HighlightedInlineBuilder builder = new HighlightedInlineBuilder(document.GetText(document.GetLineByNumber(lineNumber)));
HighlightedLine highlightedLine = 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;
}
} }
internal static HighlightingColor CustomizeColor(HighlightingColor color, IEnumerable<CustomizedHighlightingColor> customizations) internal static HighlightingColor CustomizeColor(HighlightingColor color, IEnumerable<CustomizedHighlightingColor> customizations)

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DiffControl.xaml

@ -3,7 +3,7 @@
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
xmlns:ae="http://icsharpcode.net/sharpdevelop/avalonedit" xmlns:ae="http://icsharpcode.net/sharpdevelop/avalonedit"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical" Background="White">
<ToolBar ToolBarTray.IsLocked="True" ToolBar.OverflowMode="Never"> <ToolBar ToolBarTray.IsLocked="True" ToolBar.OverflowMode="Never">
<Button x:Name="revertButton" <Button x:Name="revertButton"
Content="{sd:Localize AddIns.Subversion.Revert}" Content="{sd:Localize AddIns.Subversion.Revert}"

14
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DiffControl.xaml.cs

@ -10,8 +10,12 @@ using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.Core.Presentation; using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop;
namespace ICSharpCode.AvalonEdit.AddIn namespace ICSharpCode.AvalonEdit.AddIn
{ {
@ -39,5 +43,15 @@ namespace ICSharpCode.AvalonEdit.AddIn
editor.Copy(); editor.Copy();
} }
} }
public void CopyEditorSettings(TextEditor source)
{
string language = source.SyntaxHighlighting != null ? source.SyntaxHighlighting.Name : null;
editor.TextArea.TextView.LineTransformers.RemoveWhere(x => x is HighlightingColorizer);
editor.TextArea.TextView.LineTransformers.Insert(0, new CustomizableHighlightingColorizer(source.SyntaxHighlighting, CustomizedHighlightingColor.FetchCustomizations(language)));
CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(editor, CustomizedHighlightingColor.FetchCustomizations(language));
HighlightingOptions.ApplyToRendering(editor, CustomizedHighlightingColor.FetchCustomizations(language));
editor.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did
}
} }
} }

110
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DocumentSyntaxHighlighter.cs

@ -0,0 +1,110 @@
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
namespace ICSharpCode.AvalonEdit.AddIn
{
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 color in highlighter.GetColorStack(lineNumber - 1)
where color.Name != null
select color.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.GetText(document.GetLineByNumber(lineNumber)));
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 event EventHandler VisibleDocumentLinesChanged;
public IHighlightingDefinition HighlightingDefinition {
get {
throw new NotImplementedException();
}
}
public void AddAdditionalHighlighter(IHighlighter highlighter)
{
throw new NotImplementedException();
}
public void RemoveAdditionalHighlighter(IHighlighter highlighter)
{
throw new NotImplementedException();
}
public void InvalidateLine(IDocumentLine line)
{
throw new NotImplementedException();
}
public void InvalidateAll()
{
throw new NotImplementedException();
}
public IEnumerable<IDocumentLine> GetVisibleDocumentLines()
{
return Enumerable.Empty<IDocumentLine>();
}
}
}

8
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ExpressionHighlightRenderer.cs

@ -23,8 +23,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
Pen borderPen; Pen borderPen;
Brush backgroundBrush; Brush backgroundBrush;
TextView textView; TextView textView;
readonly Color borderColor = Color.FromArgb(52, 30, 130, 255); //Color.FromArgb(180, 70, 230, 70)) public readonly Color DefaultBorderColor = Color.FromArgb(52, 30, 130, 255); //Color.FromArgb(180, 70, 230, 70))
readonly Color fillColor = Color.FromArgb(22, 30, 130, 255); //Color.FromArgb(40, 60, 255, 60) public readonly Color DefaultFillColor = Color.FromArgb(22, 30, 130, 255); //Color.FromArgb(40, 60, 255, 60)
readonly int borderThickness = 1; readonly int borderThickness = 1;
readonly int cornerRadius = 1; readonly int cornerRadius = 1;
@ -46,8 +46,8 @@ namespace ICSharpCode.AvalonEdit.AddIn
if (textView == null) if (textView == null)
throw new ArgumentNullException("textView"); throw new ArgumentNullException("textView");
this.textView = textView; this.textView = textView;
this.borderPen = new Pen(new SolidColorBrush(borderColor), borderThickness); this.borderPen = new Pen(new SolidColorBrush(DefaultBorderColor), borderThickness);
this.backgroundBrush = new SolidColorBrush(fillColor); this.backgroundBrush = new SolidColorBrush(DefaultFillColor);
this.borderPen.Freeze(); this.borderPen.Freeze();
this.backgroundBrush.Freeze(); this.backgroundBrush.Freeze();
this.textView.BackgroundRenderers.Add(this); this.textView.BackgroundRenderers.Add(this);

88
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs

@ -171,7 +171,6 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
from name in typeof(HighlightingManager).Assembly.GetManifestResourceNames().AsParallel() from name in typeof(HighlightingManager).Assembly.GetManifestResourceNames().AsParallel()
where name.StartsWith(typeof(HighlightingManager).Namespace + ".Resources.", StringComparison.OrdinalIgnoreCase) where name.StartsWith(typeof(HighlightingManager).Namespace + ".Resources.", StringComparison.OrdinalIgnoreCase)
&& name.EndsWith(".xshd", StringComparison.OrdinalIgnoreCase) && name.EndsWith(".xshd", StringComparison.OrdinalIgnoreCase)
&& !name.EndsWith("XmlDoc.xshd", StringComparison.OrdinalIgnoreCase)
select LoadBuiltinXshd(name) select LoadBuiltinXshd(name)
).Concat( ).Concat(
ICSharpCode.Core.AddInTree.BuildItems<AddInTreeSyntaxMode>(SyntaxModeDoozer.Path, null, false).AsParallel() ICSharpCode.Core.AddInTree.BuildItems<AddInTreeSyntaxMode>(SyntaxModeDoozer.Path, null, false).AsParallel()
@ -187,7 +186,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
languageComboBox.Items.Clear(); languageComboBox.Items.Clear();
languageComboBox.Items.Add(new XshdSyntaxDefinition { Name = "All languages" }); languageComboBox.Items.Add(new XshdSyntaxDefinition { Name = "All languages" });
foreach (XshdSyntaxDefinition def in allSyntaxDefinitions) foreach (XshdSyntaxDefinition def in allSyntaxDefinitions.Where(d => !d.Name.Equals("XmlDoc", StringComparison.OrdinalIgnoreCase)))
languageComboBox.Items.Add(def); languageComboBox.Items.Add(def);
if (allSyntaxDefinitions.Count > 0) if (allSyntaxDefinitions.Count > 0)
languageComboBox.SelectedIndex = 0; languageComboBox.SelectedIndex = 0;
@ -210,7 +209,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
if (def == null) { if (def == null) {
throw new InvalidOperationException("Expected that all XSHDs are registered in default highlighting manager; but highlighting definition was not found"); throw new InvalidOperationException("Expected that all XSHDs are registered in default highlighting manager; but highlighting definition was not found");
} else { } else {
foreach (XshdColor namedColor in xshd.Elements.OfType<XshdColor>()) { var visitor = new ColorVisitor(allSyntaxDefinitions);
xshd.AcceptElements(visitor);
foreach (XshdColor namedColor in visitor.foundColors) {
if (namedColor.ExampleText != null) { if (namedColor.ExampleText != null) {
IHighlightingItem item = new NamedColorHighlightingItem(defaultText, namedColor) { ParentDefinition = def }; IHighlightingItem item = new NamedColorHighlightingItem(defaultText, namedColor) { ParentDefinition = def };
item = new CustomizedHighlightingItem(customizationList, item, xshd.Name); item = new CustomizedHighlightingItem(customizationList, item, xshd.Name);
@ -225,6 +226,60 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
} }
} }
class ColorVisitor : IXshdVisitor
{
internal readonly List<XshdColor> foundColors = new List<XshdColor>();
readonly HashSet<XshdSyntaxDefinition> visitedDefinitons = new HashSet<XshdSyntaxDefinition>();
IList<XshdSyntaxDefinition> allSyntaxDefinitions;
public ColorVisitor(IList<XshdSyntaxDefinition> allSyntaxDefinitions)
{
this.allSyntaxDefinitions = allSyntaxDefinitions;
}
public object VisitRuleSet(XshdRuleSet ruleSet)
{
ruleSet.AcceptElements(this);
return null;
}
public object VisitColor(XshdColor color)
{
foundColors.Add(color);
return null;
}
public object VisitKeywords(XshdKeywords keywords)
{
return keywords.ColorReference.AcceptVisitor(this);
}
public object VisitSpan(XshdSpan span)
{
if (span.RuleSetReference.InlineElement != null)
return span.RuleSetReference.AcceptVisitor(this);
XshdSyntaxDefinition definition = allSyntaxDefinitions.SingleOrDefault(def => def.Name == span.RuleSetReference.ReferencedDefinition);
if (definition != null && visitedDefinitons.Add(definition))
foundColors.AddRange(definition.Elements.OfType<XshdColor>());
return null;
}
public object VisitImport(XshdImport import)
{
if (import.RuleSetReference.InlineElement != null)
return import.RuleSetReference.AcceptVisitor(this);
XshdSyntaxDefinition definition = allSyntaxDefinitions.SingleOrDefault(def => def.Name == import.RuleSetReference.ReferencedDefinition);
if (definition != null && visitedDefinitons.Add(definition))
foundColors.AddRange(definition.Elements.OfType<XshdColor>());
return null;
}
public object VisitRule(XshdRule rule)
{
return rule.ColorReference.AcceptVisitor(this);
}
}
void CreateDefaultEntries(string language, out IHighlightingItem defaultText, IList<IHighlightingItem> items) void CreateDefaultEntries(string language, out IHighlightingItem defaultText, IList<IHighlightingItem> items)
{ {
// Create entry for "default text/background" // Create entry for "default text/background"
@ -583,7 +638,9 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
var highlighting = HighlightingManager.Instance.GetDefinition(language); var highlighting = HighlightingManager.Instance.GetDefinition(language);
item = null; item = null;
if (def != null && highlighting != null) { if (def != null && highlighting != null) {
var color = def.Elements.OfType<XshdColor>().FirstOrDefault(i => i.Name == sdKey); var visitor = new ColorVisitor(allSyntaxDefinitions);
def.AcceptElements(visitor);
var color = visitor.foundColors.FirstOrDefault(i => i.Name == sdKey);
if (color != null) { if (color != null) {
item = new NamedColorHighlightingItem(defaultText, color) { ParentDefinition = highlighting }; item = new NamedColorHighlightingItem(defaultText, color) { ParentDefinition = highlighting };
item = new CustomizedHighlightingItem(customizationList, item, language); item = new CustomizedHighlightingItem(customizationList, item, language);
@ -597,16 +654,15 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
static readonly MultiDictionary<string, string> mapping = new MultiDictionary<string, string>(StringComparer.Ordinal) { static readonly MultiDictionary<string, string> mapping = new MultiDictionary<string, string>(StringComparer.Ordinal) {
{ "Brace Matching (Rectangle)", BracketHighlightRenderer.BracketHighlight }, { "Brace Matching (Rectangle)", BracketHighlightRenderer.BracketHighlight },
{ "Collapsible Text", FoldingTextMarkers }, { "Collapsible Text", FoldingTextMarkers },
{ "Comment", "XML.Comment" },
{ "Comment", "VBNET.Comment" }, { "Comment", "VBNET.Comment" },
{ "Comment", "C#.Comment" }, { "Comment", "C#.Comment" },
{ "Compiler Error", ErrorPainter.ErrorColorName }, { "Compiler Error", ErrorPainter.ErrorColorName },
{ "CSS Comment", "CSS.Comment" }, { "CSS Comment", "CSS.Comment" },
{ "CSS Keyword", "" }, { "CSS Keyword", "" },
{ "CSS Property Name", "" }, { "CSS Property Name", "CSS.Property" },
{ "CSS Property Value", "" }, { "CSS Property Value", "CSS.Value" },
{ "CSS Selector", "" }, { "CSS Selector", "CSS.Selector" },
{ "CSS String Value", "" }, { "CSS String Value", "CSS.String" },
{ "Excluded Code", "" }, { "Excluded Code", "" },
{ "HTML Attribute Value", "" }, { "HTML Attribute Value", "" },
{ "HTML Attribute", "" }, { "HTML Attribute", "" },
@ -687,13 +743,15 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
{ "XAML Name", "" }, { "XAML Name", "" },
{ "XAML Text", "" }, { "XAML Text", "" },
{ "XML Attribute Quotes", "" }, { "XML Attribute Quotes", "" },
{ "XML Attribute Value", "XML." }, { "XML Attribute Value", "XML.AttributeValue" },
{ "XML Attribute", "" }, { "XML Attribute", "XML.AttributeName" },
{ "XML CData Section", "" }, { "XML CData Section", "XML.CData" },
{ "XML Comment", "" }, { "XML Comment", "XML.Comment" },
{ "XML Delimiter", "" }, { "XML Delimiter", "" },
{ "XML Doc Comment", "" }, { "XML Doc Comment", "C#.DocComment" },
{ "XML Doc Tag", "" }, { "XML Doc Tag", "C#.KnownDocTags" },
{ "XML Doc Comment", "VBNET.DocComment" },
{ "XML Doc Tag", "VBNET.KnownDocTags" },
{ "XML Name", "" }, { "XML Name", "" },
{ "XML Text", "" }, { "XML Text", "" },
}; };

15
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs

@ -2,13 +2,15 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using ICSharpCode.AvalonEdit.Editing; using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd; using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.Core;
namespace ICSharpCode.AvalonEdit.AddIn.Options namespace ICSharpCode.AvalonEdit.AddIn.Options
{ {
@ -127,7 +129,16 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
public void ShowExample(TextArea exampleTextArea) public void ShowExample(TextArea exampleTextArea)
{ {
exampleTextArea.Document.Text = color.ExampleText; exampleTextArea.Document.Text = StringParser.Parse(color.ExampleText, GetXshdProperties().ToArray());
}
IEnumerable<StringTagPair> GetXshdProperties()
{
IHighlightingDefinition2 def = ParentDefinition as IHighlightingDefinition2;
if (def == null)
yield break;
foreach (var p in def.Properties)
yield return new StringTagPair(p.Key, p.Value);
} }
event System.ComponentModel.PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add {} remove {} } event System.ComponentModel.PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add {} remove {} }

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

@ -17,6 +17,7 @@ using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Bookmarks; using ICSharpCode.SharpDevelop.Bookmarks;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
using ICSharpCode.SharpDevelop.Editor.Search; using ICSharpCode.SharpDevelop.Editor.Search;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
@ -196,7 +197,7 @@ namespace SearchAndReplace
TextDocument document = null; TextDocument document = null;
DocumentHighlighter highlighter = null; ISyntaxHighlighter highlighter = null;
int offset = 0; int offset = 0;
int length = source.TextLength; int length = source.TextLength;
if (Target == SearchTarget.CurrentSelection && Selection != null) { if (Target == SearchTarget.CurrentSelection && Selection != null) {
@ -209,15 +210,12 @@ namespace SearchAndReplace
if (document == null) { if (document == null) {
document = new TextDocument(source); document = new TextDocument(source);
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)); var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName));
if (highlighting != null) highlighter = SD.EditorControlService.CreateHighlighter(document, fileName);
highlighter = new DocumentHighlighter(document, highlighting.MainRuleSet);
else
highlighter = null;
} }
var start = document.GetLocation(result.Offset); var start = document.GetLocation(result.Offset);
var end = document.GetLocation(result.Offset + result.Length); var end = document.GetLocation(result.Offset + result.Length);
var builder = SearchResultsPad.CreateInlineBuilder(start, end, document, highlighter); 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) if (results.Count > 0)
return new SearchedFile(fileName, results); return new SearchedFile(fileName, results);
@ -317,7 +315,7 @@ namespace SearchAndReplace
if (result != null) { if (result != null) {
var start = document.GetLocation(result.Offset); var start = document.GetLocation(result.Offset);
var end = document.GetLocation(result.EndOffset); var end = document.GetLocation(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; return null;
} }

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

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

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

@ -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; IEnumerable<SearchNode> children;
public IEnumerable<SearchNode> Children { public IEnumerable<SearchNode> Children {

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

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

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

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

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

@ -50,6 +50,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </summary> /// </summary>
public IList<HighlightedSection> Sections { get; private set; } 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; }
[Conditional("DEBUG")] [Conditional("DEBUG")]
void ValidateInvariants() void ValidateInvariants()
{ {

11
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingManager.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </remarks> /// </remarks>
public class HighlightingManager : IHighlightingDefinitionReferenceResolver public class HighlightingManager : IHighlightingDefinitionReferenceResolver
{ {
sealed class DelayLoadedHighlightingDefinition : IHighlightingDefinition sealed class DelayLoadedHighlightingDefinition : IHighlightingDefinition2
{ {
readonly object lockObj = new object(); readonly object lockObj = new object();
readonly string name; readonly string name;
@ -104,6 +104,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting
{ {
return this.Name; return this.Name;
} }
public IDictionary<string, string> Properties {
get {
var def = GetDefinition() as IHighlightingDefinition2;
if (def != null)
return def.Properties;
return null;
}
}
} }
readonly object lockObj = new object(); readonly object lockObj = new object();

11
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/IHighlightingDefinition.cs

@ -40,4 +40,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting
/// </summary> /// </summary>
IEnumerable<HighlightingColor> NamedHighlightingColors { get; } IEnumerable<HighlightingColor> NamedHighlightingColors { get; }
} }
/// <summary>
/// Extension of IHighlightingDefinition to avoid breaking changes in the API.
/// </summary>
public interface IHighlightingDefinition2 : IHighlightingDefinition
{
/// <summary>
/// Gets the list of properties.
/// </summary>
IDictionary<string, string> Properties { get; }
}
} }

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd

@ -27,6 +27,8 @@
<Color name="TrueFalse" fontWeight="bold" foreground="DarkCyan" exampleText="b = false; a = true;" /> <Color name="TrueFalse" fontWeight="bold" foreground="DarkCyan" exampleText="b = false; a = true;" />
<Color name="TypeKeywords" fontWeight="bold" foreground="DarkCyan" exampleText="if (x is int) { a = x as int; type = typeof(int); size = sizeof(int); c = new object(); }"/> <Color name="TypeKeywords" fontWeight="bold" foreground="DarkCyan" exampleText="if (x is int) { a = x as int; type = typeof(int); size = sizeof(int); c = new object(); }"/>
<Property name="DocCommentMarker" value="///" />
<RuleSet name="CommentMarkerSet"> <RuleSet name="CommentMarkerSet">
<Keywords fontWeight="bold" foreground="Red"> <Keywords fontWeight="bold" foreground="Red">
<Word>TODO</Word> <Word>TODO</Word>

8
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd

@ -50,6 +50,13 @@
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<xsd:element name="Property">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="value" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
<!-- Regular expression --> <!-- Regular expression -->
<xsd:simpleType name="regex"> <xsd:simpleType name="regex">
<xsd:restriction base="xsd:string"/> <xsd:restriction base="xsd:string"/>
@ -135,6 +142,7 @@
<xsd:element name="SyntaxDefinition"> <xsd:element name="SyntaxDefinition">
<xsd:complexType> <xsd:complexType>
<xsd:choice minOccurs="1" maxOccurs="unbounded"> <xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element ref="Property"/>
<xsd:element ref="Color"/> <xsd:element ref="Color"/>
<xsd:element ref="RuleSet"/> <xsd:element ref="RuleSet"/>
</xsd:choice> </xsd:choice>

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/VBNET-Mode.xshd

@ -18,6 +18,8 @@
<Color name="FunctionKeywords" foreground="Blue" exampleText="CInt(a)" /> <Color name="FunctionKeywords" foreground="Blue" exampleText="CInt(a)" />
<Color name="ContextKeywords" foreground="Blue" exampleText="Declare Unicode Sub SomeMethod" /> <Color name="ContextKeywords" foreground="Blue" exampleText="Declare Unicode Sub SomeMethod" />
<Property name="DocCommentMarker" value="'''" />
<RuleSet ignoreCase="true"> <RuleSet ignoreCase="true">
<Span color="String"> <Span color="String">
<Begin>"</Begin> <Begin>"</Begin>

8
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/XmlDoc.xshd

@ -1,9 +1,9 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<SyntaxDefinition name="XmlDoc" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008"> <SyntaxDefinition name="XmlDoc" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="XmlString" foreground="Silver" fontWeight="bold" /> <Color name="XmlString" foreground="Silver" fontWeight="bold" exampleText="${DocCommentMarker} &lt;exception cref=&quot;System.Exception&quot; /&gt;" />
<Color name="DocComment" foreground="Gray" /> <Color name="DocComment" foreground="Gray" exampleText="${DocCommentMarker} &lt;exception cref=&quot;System.Exception&quot; /&gt;" />
<Color name="XmlPunctuation" fontWeight="bold" /> <Color name="XmlPunctuation" fontWeight="bold" exampleText="${DocCommentMarker} &lt;exception cref=&quot;System.Exception&quot; /&gt;" />
<Color name="KnownDocTags" fontWeight="bold" /> <Color name="KnownDocTags" fontWeight="bold" exampleText="${DocCommentMarker} &lt;exception cref=&quot;System.Exception&quot; /&gt;" />
<RuleSet name="DocCommentSet"> <RuleSet name="DocCommentSet">
<Span color="DocComment"> <Span color="DocComment">

12
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs

@ -64,6 +64,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
case "RuleSet": case "RuleSet":
c.Add(ParseRuleSet(reader)); c.Add(ParseRuleSet(reader));
break; break;
case "Property":
c.Add(ParseProperty(reader));
break;
case "Color": case "Color":
c.Add(ParseNamedColor(reader)); c.Add(ParseNamedColor(reader));
break; break;
@ -85,6 +88,15 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
} }
} }
static XshdElement ParseProperty(XmlReader reader)
{
XshdProperty property = new XshdProperty();
SetPosition(property, reader);
property.Name = reader.GetAttribute("name");
property.Value = reader.GetAttribute("value");
return property;
}
static XshdRuleSet ParseRuleSet(XmlReader reader) static XshdRuleSet ParseRuleSet(XmlReader reader)
{ {
XshdRuleSet ruleSet = new XshdRuleSet(); XshdRuleSet ruleSet = new XshdRuleSet();

15
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs

@ -5,15 +5,15 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using ICSharpCode.AvalonEdit.Utils; using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.Highlighting.Xshd namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
{ {
[Serializable] [Serializable]
sealed class XmlHighlightingDefinition : IHighlightingDefinition sealed class XmlHighlightingDefinition : IHighlightingDefinition2
{ {
public string Name { get; private set; } public string Name { get; private set; }
@ -37,6 +37,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
throw new HighlightingDefinitionInvalidException("Could not find main RuleSet."); throw new HighlightingDefinitionInvalidException("Could not find main RuleSet.");
// Translate elements within the rulesets (resolving references and processing imports) // Translate elements within the rulesets (resolving references and processing imports)
xshd.AcceptElements(new TranslateElementVisitor(this, rnev.ruleSets, resolver)); xshd.AcceptElements(new TranslateElementVisitor(this, rnev.ruleSets, resolver));
foreach (var p in xshd.Elements.OfType<XshdProperty>())
propDict.Add(p.Name, p.Value);
} }
#region RegisterNamedElements #region RegisterNamedElements
@ -358,6 +361,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
Dictionary<string, HighlightingRuleSet> ruleSetDict = new Dictionary<string, HighlightingRuleSet>(); Dictionary<string, HighlightingRuleSet> ruleSetDict = new Dictionary<string, HighlightingRuleSet>();
Dictionary<string, HighlightingColor> colorDict = new Dictionary<string, HighlightingColor>(); Dictionary<string, HighlightingColor> colorDict = new Dictionary<string, HighlightingColor>();
[OptionalField]
Dictionary<string, string> propDict = new Dictionary<string, string>();
public HighlightingRuleSet MainRuleSet { get; private set; } public HighlightingRuleSet MainRuleSet { get; private set; }
@ -391,5 +396,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
{ {
return this.Name; return this.Name;
} }
public IDictionary<string, string> Properties {
get {
return propDict;
}
}
} }
} }

38
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdProperty.cs

@ -0,0 +1,38 @@
// 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;
namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
{
/// <summary>
/// A property in an Xshd file.
/// </summary>
[Serializable]
public class XshdProperty : XshdElement
{
/// <summary>
/// Gets/sets the name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets/sets the value.
/// </summary>
public string Value { get; set; }
/// <summary>
/// Creates a new XshdColor instance.
/// </summary>
public XshdProperty()
{
}
/// <inheritdoc/>
public override object AcceptVisitor(IXshdVisitor visitor)
{
return null;
// return visitor.VisitProperty(this);
}
}
}

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj

@ -211,6 +211,7 @@
<Compile Include="Highlighting\Xshd\XmlHighlightingDefinition.cs" /> <Compile Include="Highlighting\Xshd\XmlHighlightingDefinition.cs" />
<Compile Include="Highlighting\Xshd\XshdColor.cs" /> <Compile Include="Highlighting\Xshd\XshdColor.cs" />
<Compile Include="Highlighting\Xshd\XshdImport.cs" /> <Compile Include="Highlighting\Xshd\XshdImport.cs" />
<Compile Include="Highlighting\Xshd\XshdProperty.cs" />
<Compile Include="Highlighting\Xshd\XshdReference.cs" /> <Compile Include="Highlighting\Xshd\XshdReference.cs" />
<Compile Include="Highlighting\Xshd\XshdElement.cs" /> <Compile Include="Highlighting\Xshd\XshdElement.cs" />
<Compile Include="Highlighting\Xshd\XshdKeywords.cs" /> <Compile Include="Highlighting\Xshd\XshdKeywords.cs" />

31
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/MouseHoverLogic.cs

@ -30,25 +30,35 @@ namespace ICSharpCode.AvalonEdit.Rendering
this.target = target; this.target = target;
this.target.MouseLeave += MouseHoverLogicMouseLeave; this.target.MouseLeave += MouseHoverLogicMouseLeave;
this.target.MouseMove += MouseHoverLogicMouseMove; this.target.MouseMove += MouseHoverLogicMouseMove;
this.target.MouseEnter += MouseHoverLogicMouseEnter;
} }
void MouseHoverLogicMouseMove(object sender, MouseEventArgs e) void MouseHoverLogicMouseMove(object sender, MouseEventArgs e)
{ {
Point newPosition = e.GetPosition(this.target); Vector mouseMovement = mouseHoverStartPoint - e.GetPosition(this.target);
Vector mouseMovement = mouseHoverStartPoint - newPosition;
if (Math.Abs(mouseMovement.X) > SystemParameters.MouseHoverWidth if (Math.Abs(mouseMovement.X) > SystemParameters.MouseHoverWidth
|| Math.Abs(mouseMovement.Y) > SystemParameters.MouseHoverHeight) || Math.Abs(mouseMovement.Y) > SystemParameters.MouseHoverHeight)
{ {
StopHovering(); StartHovering(e);
mouseHoverStartPoint = newPosition;
mouseHoverLastEventArgs = e;
mouseHoverTimer = new DispatcherTimer(SystemParameters.MouseHoverTime, DispatcherPriority.Background,
OnMouseHoverTimerElapsed, this.target.Dispatcher);
mouseHoverTimer.Start();
} }
// do not set e.Handled - allow others to also handle MouseMove // do not set e.Handled - allow others to also handle MouseMove
} }
void MouseHoverLogicMouseEnter(object sender, MouseEventArgs e)
{
StartHovering(e);
// do not set e.Handled - allow others to also handle MouseEnter
}
void StartHovering(MouseEventArgs e)
{
StopHovering();
mouseHoverStartPoint = e.GetPosition(this.target);
mouseHoverLastEventArgs = e;
mouseHoverTimer = new DispatcherTimer(SystemParameters.MouseHoverTime, DispatcherPriority.Background, OnMouseHoverTimerElapsed, this.target.Dispatcher);
mouseHoverTimer.Start();
}
void MouseHoverLogicMouseLeave(object sender, MouseEventArgs e) void MouseHoverLogicMouseLeave(object sender, MouseEventArgs e)
{ {
StopHovering(); StopHovering();
@ -116,6 +126,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
if (!disposed) { if (!disposed) {
this.target.MouseLeave -= MouseHoverLogicMouseLeave; this.target.MouseLeave -= MouseHoverLogicMouseLeave;
this.target.MouseMove -= MouseHoverLogicMouseMove; this.target.MouseMove -= MouseHoverLogicMouseMove;
this.target.MouseEnter -= MouseHoverLogicMouseEnter;
} }
disposed = true; disposed = true;
} }

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

@ -3,7 +3,9 @@
using System; using System;
using ICSharpCode.AvalonEdit; using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
namespace ICSharpCode.SharpDevelop.Editor namespace ICSharpCode.SharpDevelop.Editor
@ -16,6 +18,7 @@ namespace ICSharpCode.SharpDevelop.Editor
{ {
ITextEditor CreateEditor(out object control); ITextEditor CreateEditor(out object control);
ITextEditorOptions GlobalOptions { get; } ITextEditorOptions GlobalOptions { get; }
ISyntaxHighlighter CreateHighlighter(IDocument document, string fileName);
} }
// Fallback if AvalonEdit.AddIn is not available (e.g. some unit tests) // Fallback if AvalonEdit.AddIn is not available (e.g. some unit tests)
@ -63,5 +66,10 @@ namespace ICSharpCode.SharpDevelop.Editor
return "Consolas"; return "Consolas";
} }
} }
public ISyntaxHighlighter CreateHighlighter(IDocument document, string fileName)
{
return null;
}
} }
} }

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

@ -67,6 +67,16 @@ namespace ICSharpCode.SharpDevelop.Editor
/// Raised when the set of visible document lines has changed. /// Raised when the set of visible document lines has changed.
/// </summary> /// </summary>
event EventHandler VisibleDocumentLinesChanged; event EventHandler VisibleDocumentLinesChanged;
/// <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 public static class SyntaxHighligherKnownSpanNames

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

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

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

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

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

@ -359,24 +359,22 @@ namespace ICSharpCode.SharpDevelop.Refactoring
if (list == null) return; if (list == null) return;
List<SearchResultMatch> results = new List<SearchResultMatch>(list.Count); List<SearchResultMatch> results = new List<SearchResultMatch>(list.Count);
TextDocument document = null; TextDocument document = null;
ITextSource buffer = null;
FileName fileName = null; FileName fileName = null;
IHighlighter highlighter = null; ISyntaxHighlighter highlighter = null;
foreach (Reference r in list) { foreach (Reference r in list) {
if (document == null || fileName != r.FileName) { if (document == null || fileName != r.FileName) {
document = new TextDocument(SD.FileService.GetFileContent(r.FileName)); buffer = SD.FileService.GetFileContent(r.FileName);
fileName = r.FileName; document = new TextDocument(DocumentUtilitites.GetTextSource(buffer));
var def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(r.FileName)); fileName = new FileName(r.FileName);
if (def != null) highlighter = SD.EditorControlService.CreateHighlighter(document, fileName);
highlighter = new DocumentHighlighter(document, def.MainRuleSet);
else
highlighter = null;
} }
var start = r.StartLocation; var start = r.StartLocation;
var end = r.EndLocation; var end = r.EndLocation;
var startOffset = document.GetOffset(start); var startOffset = document.GetOffset(start);
var endOffset = document.GetOffset(end); var endOffset = document.GetOffset(end);
var builder = SearchResultsPad.CreateInlineBuilder(start, end, document, highlighter); var builder = SearchResultsPad.CreateInlineBuilder(start, end, document, highlighter);
SearchResultMatch res = new SearchResultMatch(fileName, start, end, startOffset, endOffset - startOffset, builder); SearchResultMatch res = new SearchResultMatch(fileName, start, end, startOffset, endOffset - startOffset, builder, highlighter.DefaultTextColor);
results.Add(res); results.Add(res);
} }
SearchResultsPad.Instance.ShowSearchResults(title, results); SearchResultsPad.Instance.ShowSearchResults(title, results);

4
src/Main/Base/Project/Src/Services/RefactoringService/Reference.cs

@ -17,8 +17,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{ {
ResolveResult resolveResult; ResolveResult resolveResult;
public Reference(DomRegion region, ResolveResult resolveResult, int offset, int length, HighlightedInlineBuilder builder) public Reference(DomRegion region, ResolveResult resolveResult, int offset, int length, HighlightedInlineBuilder builder, HighlightingColor defaultTextColor)
: base(FileName.Create(region.FileName), region.Begin, region.End, offset, length, builder) : base(FileName.Create(region.FileName), region.Begin, region.End, offset, length, builder, defaultTextColor)
{ {
if (region.IsEmpty) if (region.IsEmpty)
throw new ArgumentException("Region must not be empty"); throw new ArgumentException("Region must not be empty");

12
src/Main/Core/Project/Src/Services/StringParser/StringParser.cs

@ -38,6 +38,16 @@ namespace ICSharpCode.Core
return dict; return dict;
} }
/// <summary>
/// Escapes all occurrences of '${' to '${$}{'.
/// </summary>
public static string Escape(string input)
{
if (input == null)
throw new ArgumentNullException("input");
return input.Replace("${", "${$}{");
}
/// <summary> /// <summary>
/// Expands ${xyz} style property values. /// Expands ${xyz} style property values.
/// </summary> /// </summary>
@ -125,6 +135,8 @@ namespace ICSharpCode.Core
{ {
if (propertyName == null) if (propertyName == null)
throw new ArgumentNullException("propertyName"); throw new ArgumentNullException("propertyName");
if (propertyName == "$")
return "$";
if (customTags != null) { if (customTags != null) {
foreach (StringTagPair pair in customTags) { foreach (StringTagPair pair in customTags) {

Loading…
Cancel
Save