Browse Source

- Added TextView to Services

- implemented highlighting for events, properties and namespace declarations

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3967 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
bc05d9df74
  1. 33
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs
  2. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj
  3. 114
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs
  4. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizerServer.cs
  5. 49
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizerSettings.cs
  6. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Gui/TextView.cs

33
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Gui;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
{
public static class Extensions
{
public static string[] Split(this string s, StringSplitOptions options, params char[] delimiters)
{
return s.Split(delimiters, options);
}
}
}

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj

@ -61,11 +61,13 @@ @@ -61,11 +61,13 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="CompletionDataHelper.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Utils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XamlClassReturnType.cs" />
<Compile Include="XamlCodeCompletionBinding.cs" />
<Compile Include="XamlColorizerServer.cs" />
<Compile Include="XamlColorizerSettings.cs" />
<Compile Include="XamlCompilationUnit.cs" />
<Compile Include="XamlCompletionItem.cs" />
<Compile Include="XamlCompletionItemList.cs" />

114
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs

@ -52,16 +52,59 @@ namespace ICSharpCode.XamlBinding @@ -52,16 +52,59 @@ namespace ICSharpCode.XamlBinding
HighlightingInfo[] infos = GetInfoForLine(line);
foreach (HighlightingInfo info in infos) {
ResolveResult rr = resolver.Resolve(info.GetExpressionResult(), parseInfo, fileContent);
IReturnType type = (rr != null) ? rr.ResolvedType : null;
if (type != null) {
//if (type.IsGenericReturnType)
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty);
MemberResolveResult rr = resolver.Resolve(info.GetExpressionResult(), parseInfo, fileContent) as MemberResolveResult;
IMember member = (rr != null) ? rr.ResolvedMember : null;
if (member != null) {
if (member is IEvent)
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightEvent);
else
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty);
} else {
if (info.Token.StartsWith("xmlns"))
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightNamespaceDeclaration);
}
}
}
}
HighlightingInfo[] GetInfoForLine(DocumentLine line)
{
int index = -1;
List<HighlightingInfo> infos = new List<HighlightingInfo>();
do {
index = line.Text.IndexOf('=', index + 1);
if (index > -1) {
string expr = XmlParser.GetAttributeNameAtIndex(this.fileContent, index + line.Offset);
XmlElementPath path = XmlParser.GetActiveElementStartPathAtIndex(this.fileContent, index + line.Offset);
if (!string.IsNullOrEmpty(expr) && path != null && path.Elements.Count > 0) {
int startIndex = line.Text.Substring(0, index).LastIndexOf(expr);
infos.Add(new HighlightingInfo(expr, startIndex, startIndex + expr.Length, line.Offset, path));
}
}
} while (index > -1);
return infos.ToArray();
}
void HighlightProperty(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(settings.PropertyForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(settings.PropertyBackgroundBrush);
}
void HighlightEvent(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(settings.EventForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(settings.EventBackgroundBrush);
}
void HighlightNamespaceDeclaration(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(settings.NamespaceDeclarationForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(settings.NamespaceDeclarationBackgroundBrush);
}
struct HighlightingInfo
{
string token;
@ -99,68 +142,9 @@ namespace ICSharpCode.XamlBinding @@ -99,68 +142,9 @@ namespace ICSharpCode.XamlBinding
get { return path; }
}
public ExpressionResult GetExpressionResult()
{
public ExpressionResult GetExpressionResult() {
return new ExpressionResult(token, new XamlExpressionContext(path, token, false));
}
}
HighlightingInfo[] GetInfoForLine(DocumentLine line)
{
int index = -1;
List<HighlightingInfo> infos = new List<HighlightingInfo>();
do {
index = line.Text.IndexOf('=', index + 1);
if (index > -1) {
string expr = XmlParser.GetAttributeNameAtIndex(this.fileContent, index + line.Offset);
XmlElementPath path = XmlParser.GetActiveElementStartPathAtIndex(this.fileContent, index + line.Offset);
if (!string.IsNullOrEmpty(expr) && path != null && path.Elements.Count > 0) {
int startIndex = line.Text.Substring(0, index).LastIndexOf(expr);
infos.Add(new HighlightingInfo(expr, startIndex, startIndex + expr.Length, line.Offset, path));
}
}
} while (index > -1);
return infos.ToArray();
}
void HighlightProperty(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(settings.PropertyForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(settings.PropertyBackgroundBrush);
}
void HighlightEvent(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(settings.EventForegroundBrush);
element.TextRunProperties.SetBackgroundBrush(settings.EventBackgroundBrush);
}
}
public static class Extensions
{
public static string[] Split(this string s, StringSplitOptions options, params char[] delimiters)
{
return s.Split(delimiters, options);
}
}
public class XamlColorizerSettings
{
public Brush PropertyForegroundBrush { get; set; }
public Brush PropertyBackgroundBrush { get; set; }
public Brush EventForegroundBrush { get; set; }
public Brush EventBackgroundBrush { get; set; }
public XamlColorizerSettings()
{
this.PropertyBackgroundBrush = Brushes.Transparent;
this.PropertyForegroundBrush = Brushes.Red;
this.EventBackgroundBrush = Brushes.Transparent;
this.EventForegroundBrush = Brushes.Green;
}
}
}

3
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizerServer.cs

@ -33,9 +33,8 @@ namespace ICSharpCode.XamlBinding @@ -33,9 +33,8 @@ namespace ICSharpCode.XamlBinding
ITextEditorProvider textEditor = e.Content as ITextEditorProvider;
if (textEditor != null) {
TextView textView = textEditor.TextEditor.GetService(typeof(TextView)) as TextView;
if (textView != null) {
if (textView != null)
textView.LineTransformers.Add(new XamlColorizer(e.Content));
}
}
}
}

49
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizerSettings.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Gui;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
{
public class XamlColorizerSettings
{
public Brush PropertyForegroundBrush { get; set; }
public Brush PropertyBackgroundBrush { get; set; }
public Brush EventForegroundBrush { get; set; }
public Brush EventBackgroundBrush { get; set; }
public Brush NamespaceDeclarationForegroundBrush { get; set; }
public Brush NamespaceDeclarationBackgroundBrush { get; set; }
public XamlColorizerSettings()
{
this.PropertyBackgroundBrush = Brushes.Transparent;
this.PropertyForegroundBrush = Brushes.Red;
this.EventBackgroundBrush = Brushes.Transparent;
this.EventForegroundBrush = Brushes.Green;
this.NamespaceDeclarationBackgroundBrush = Brushes.Transparent;
this.NamespaceDeclarationForegroundBrush = Brushes.Orange;
}
}
}

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Gui/TextView.cs

@ -50,6 +50,7 @@ namespace ICSharpCode.AvalonEdit.Gui @@ -50,6 +50,7 @@ namespace ICSharpCode.AvalonEdit.Gui
/// </summary>
public TextView()
{
services.AddService(typeof(TextView), this);
this.Options = new TextEditorOptions();
textLayer = new TextLayer(this);
elementGenerators = new ObserveAddRemoveCollection<VisualLineElementGenerator>(ElementGenerator_Added, ElementGenerator_Removed);

Loading…
Cancel
Save