Browse Source

- added xml: completion

- fixed bug in xmlns completion
- use Rope<byte> in HexEditor

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4971 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
407ecdfe0d
  1. 230
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  2. 7
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs
  3. 58
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs
  4. 11
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs
  5. 5
      src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj
  6. 8
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/BufferManager.cs

230
src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs

@ -38,7 +38,9 @@ namespace ICSharpCode.XamlBinding @@ -38,7 +38,9 @@ namespace ICSharpCode.XamlBinding
};
static readonly List<ICompletionItem> standardAttributes = new List<ICompletionItem> {
new SpecialCompletionItem("xmlns:")
new SpecialCompletionItem("xmlns:"),
new XamlCompletionItem("xml", "", "space"),
new XamlCompletionItem("xml", "", "lang")
};
public static readonly ReadOnlyCollection<string> XamlNamespaceAttributes = new List<string> {
@ -80,125 +82,125 @@ namespace ICSharpCode.XamlBinding @@ -80,125 +82,125 @@ namespace ICSharpCode.XamlBinding
public static XamlContext ResolveContext(ITextBuffer fileContent, string fileName, int offset)
{
//using (new DebugTimerObject("ResolveContext")) {
XamlParser parser = string.IsNullOrEmpty(fileName) ? new XamlParser() : ParserService.GetParser(fileName) as XamlParser;
ParseInformation info = string.IsNullOrEmpty(fileName) ? null : ParserService.GetParseInformation(fileName);
XamlParser parser = string.IsNullOrEmpty(fileName) ? new XamlParser() : ParserService.GetParser(fileName) as XamlParser;
ParseInformation info = string.IsNullOrEmpty(fileName) ? null : ParserService.GetParseInformation(fileName);
using (parser.ParseAndLock(fileContent)) {
AXmlDocument document = parser.LastDocument;
AXmlObject currentData = document.GetChildAtOffset(offset);
string attribute = string.Empty, attributeValue = string.Empty;
bool inAttributeValue = false;
AttributeValue value = null;
bool isRoot = false;
int offsetFromValueStart = -1;
List<AXmlElement> ancestors = new List<AXmlElement>();
Dictionary<string, string> xmlns = new Dictionary<string, string>();
List<string> ignored = new List<string>();
string xamlNamespacePrefix = string.Empty;
var item = currentData;
while (item != document) {
if (item is AXmlElement) {
AXmlElement element = item as AXmlElement;
ancestors.Add(element);
foreach (var attr in element.Attributes) {
if (attr.IsNamespaceDeclaration) {
string prefix = (attr.Name == "xmlns") ? "" : attr.LocalName;
if (!xmlns.ContainsKey(prefix))
xmlns.Add(prefix, attr.Value);
}
if (attr.LocalName == "Ignorable" && attr.Namespace == MarkupCompatibilityNamespace)
ignored.AddRange(attr.Value.Split(' ', '\t'));
if (string.IsNullOrEmpty(xamlNamespacePrefix) && attr.Value == XamlNamespace)
xamlNamespacePrefix = attr.LocalName;
using (parser.ParseAndLock(fileContent)) {
AXmlDocument document = parser.LastDocument;
AXmlObject currentData = document.GetChildAtOffset(offset);
string attribute = string.Empty, attributeValue = string.Empty;
bool inAttributeValue = false;
AttributeValue value = null;
bool isRoot = false;
int offsetFromValueStart = -1;
List<AXmlElement> ancestors = new List<AXmlElement>();
Dictionary<string, string> xmlns = new Dictionary<string, string>();
List<string> ignored = new List<string>();
string xamlNamespacePrefix = string.Empty;
var item = currentData;
while (item != document) {
if (item is AXmlElement) {
AXmlElement element = item as AXmlElement;
ancestors.Add(element);
foreach (var attr in element.Attributes) {
if (attr.IsNamespaceDeclaration) {
string prefix = (attr.Name == "xmlns") ? "" : attr.LocalName;
if (!xmlns.ContainsKey(prefix))
xmlns.Add(prefix, attr.Value);
}
if (attr.LocalName == "Ignorable" && attr.Namespace == MarkupCompatibilityNamespace)
ignored.AddRange(attr.Value.Split(' ', '\t'));
if (string.IsNullOrEmpty(xamlNamespacePrefix) && attr.Value == XamlNamespace)
xamlNamespacePrefix = attr.LocalName;
}
item = item.Parent;
}
XamlContextDescription description = XamlContextDescription.None;
AXmlElement active = null;
AXmlElement parent = null;
if (currentData.Parent is AXmlTag) {
AXmlTag tag = currentData.Parent as AXmlTag;
if (tag.IsStartOrEmptyTag)
description = XamlContextDescription.InTag;
else if (tag.IsComment)
description = XamlContextDescription.InComment;
else if (tag.IsCData)
description = XamlContextDescription.InCData;
active = tag.Parent as AXmlElement;
}
item = item.Parent;
}
XamlContextDescription description = XamlContextDescription.None;
AXmlElement active = null;
AXmlElement parent = null;
if (currentData.Parent is AXmlTag) {
AXmlTag tag = currentData.Parent as AXmlTag;
if (tag.IsStartOrEmptyTag)
description = XamlContextDescription.InTag;
else if (tag.IsComment)
description = XamlContextDescription.InComment;
else if (tag.IsCData)
description = XamlContextDescription.InCData;
active = tag.Parent as AXmlElement;
}
if (currentData is AXmlAttribute) {
AXmlAttribute a = currentData as AXmlAttribute;
int valueStartOffset = a.StartOffset + (a.Name ?? "").Length + (a.EqualsSign ?? "").Length + 1;
attribute = a.Name;
attributeValue = a.Value;
value = MarkupExtensionParser.ParseValue(attributeValue);
if (currentData is AXmlAttribute) {
AXmlAttribute a = currentData as AXmlAttribute;
int valueStartOffset = a.StartOffset + (a.Name ?? "").Length + (a.EqualsSign ?? "").Length + 1;
attribute = a.Name;
attributeValue = a.Value;
value = MarkupExtensionParser.ParseValue(attributeValue);
inAttributeValue = offset >= valueStartOffset && offset < a.EndOffset;
if (inAttributeValue) {
offsetFromValueStart = offset - valueStartOffset;
inAttributeValue = offset >= valueStartOffset && offset < a.EndOffset;
if (inAttributeValue) {
offsetFromValueStart = offset - valueStartOffset;
description = XamlContextDescription.InAttributeValue;
if (value != null && !value.IsString)
description = XamlContextDescription.InMarkupExtension;
if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2)
description = XamlContextDescription.InAttributeValue;
if (value != null && !value.IsString)
description = XamlContextDescription.InMarkupExtension;
if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2)
description = XamlContextDescription.InAttributeValue;
} else
description = XamlContextDescription.InTag;
}
if (currentData is AXmlTag) {
AXmlTag tag = currentData as AXmlTag;
if (tag.IsStartOrEmptyTag || tag.IsEndTag)
description = XamlContextDescription.AtTag;
else if (tag.IsComment)
description = XamlContextDescription.InComment;
else if (tag.IsCData)
description = XamlContextDescription.InCData;
active = tag.Parent as AXmlElement;
}
if (active != ancestors.FirstOrDefault())
parent = ancestors.FirstOrDefault();
else
parent = ancestors.Skip(1).FirstOrDefault();
if (active == null)
active = parent;
var xAttribute = currentData as AXmlAttribute;
var context = new XamlContext() {
Description = description,
ActiveElement = (active == null) ? null : active.ToWrapper(),
ParentElement = (parent == null) ? null : parent.ToWrapper(),
Ancestors = ancestors.Select(ancestor => ancestor.ToWrapper()).ToList(),
Attribute = (xAttribute != null) ? xAttribute.ToWrapper() : null,
InRoot = isRoot,
AttributeValue = value,
RawAttributeValue = attributeValue,
ValueStartOffset = offsetFromValueStart,
XmlnsDefinitions = xmlns,
ParseInformation = info,
IgnoredXmlns = ignored.AsReadOnly(),
XamlNamespacePrefix = xamlNamespacePrefix
};
return context;
} else
description = XamlContextDescription.InTag;
}
if (currentData is AXmlTag) {
AXmlTag tag = currentData as AXmlTag;
if (tag.IsStartOrEmptyTag || tag.IsEndTag)
description = XamlContextDescription.AtTag;
else if (tag.IsComment)
description = XamlContextDescription.InComment;
else if (tag.IsCData)
description = XamlContextDescription.InCData;
active = tag.Parent as AXmlElement;
}
if (active != ancestors.FirstOrDefault())
parent = ancestors.FirstOrDefault();
else
parent = ancestors.Skip(1).FirstOrDefault();
if (active == null)
active = parent;
var xAttribute = currentData as AXmlAttribute;
var context = new XamlContext() {
Description = description,
ActiveElement = (active == null) ? null : active.ToWrapper(),
ParentElement = (parent == null) ? null : parent.ToWrapper(),
Ancestors = ancestors.Select(ancestor => ancestor.ToWrapper()).ToList(),
Attribute = (xAttribute != null) ? xAttribute.ToWrapper() : null,
InRoot = isRoot,
AttributeValue = value,
RawAttributeValue = attributeValue,
ValueStartOffset = offsetFromValueStart,
XmlnsDefinitions = xmlns,
ParseInformation = info,
IgnoredXmlns = ignored.AsReadOnly(),
XamlNamespacePrefix = xamlNamespacePrefix
};
return context;
}
//}
}
@ -424,7 +426,7 @@ namespace ICSharpCode.XamlBinding @@ -424,7 +426,7 @@ namespace ICSharpCode.XamlBinding
if (itemClass != null)
result.Add(new XamlCodeCompletionItem(itemClass, last.Prefix));
}
var xamlItems = XamlNamespaceAttributes.AsEnumerable();
if (EnableXaml2009)
@ -466,7 +468,7 @@ namespace ICSharpCode.XamlBinding @@ -466,7 +468,7 @@ namespace ICSharpCode.XamlBinding
public static XamlCompletionItemList CreateListForContext(XamlCompletionContext context)
{
XamlCompletionItemList list = new XamlCompletionItemList();
XamlCompletionItemList list = new XamlCompletionItemList(context);
ParseInformation info = context.ParseInformation;
ITextEditor editor = context.Editor;
@ -565,7 +567,7 @@ namespace ICSharpCode.XamlBinding @@ -565,7 +567,7 @@ namespace ICSharpCode.XamlBinding
public static ICompletionItemList CreateMarkupExtensionCompletion(XamlCompletionContext context)
{
var list = new XamlCompletionItemList();
var list = new XamlCompletionItemList(context);
string visibleValue = context.RawAttributeValue.Substring(0, context.ValueStartOffset + 1);
if (context.PressedKey == '=')
visibleValue += "=";

7
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs

@ -207,7 +207,7 @@ namespace ICSharpCode.XamlBinding @@ -207,7 +207,7 @@ namespace ICSharpCode.XamlBinding
// DO NOT USE CompletionDataHelper.CreateListForContext here!!! results in endless recursion!!!!
if (context.Attribute != null) {
if (!DoMarkupExtensionCompletion(context)) {
var completionList = new XamlCompletionItemList();
var completionList = new XamlCompletionItemList(context);
completionList.PreselectionLength = editor.GetWordBeforeCaretExtended().Length;
if ((context.ActiveElement.Name == "Setter" || context.ActiveElement.Name == "EventSetter") &&
@ -216,6 +216,11 @@ namespace ICSharpCode.XamlBinding @@ -216,6 +216,11 @@ namespace ICSharpCode.XamlBinding
else if ((context.ActiveElement.Name.EndsWith("Trigger") || context.ActiveElement.Name == "Condition") && context.Attribute.Name == "Value")
DoTriggerCompletion(context, completionList);
else {
if (context.Attribute.Name == "xml:space") {
completionList.Items.AddRange(new[] { new SpecialCompletionItem("preserve"),
new SpecialCompletionItem("default") });
}
var mrr = XamlResolver.Resolve(context.Attribute.Name, context) as MemberResolveResult;
if (mrr != null && mrr.ResolvedType != null) {
completionList.Items.AddRange(CompletionDataHelper.MemberCompletion(context, mrr.ResolvedType, string.Empty));

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

@ -245,28 +245,30 @@ namespace ICSharpCode.XamlBinding @@ -245,28 +245,30 @@ namespace ICSharpCode.XamlBinding
void ColorizeMember(HighlightingInfo info, DocumentLine line, IMember member)
{
try {
if (info.Token.StartsWith(info.Context.XamlNamespacePrefix + ":", StringComparison.Ordinal)) {
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty);
Action<VisualLineElement> handler = null;
if (info.Token.StartsWith(info.Context.XamlNamespacePrefix + ":", StringComparison.Ordinal))
handler = HighlightProperty;
else if (info.Context.IgnoredXmlns.Any(item => info.Token.StartsWith(item + ":", StringComparison.Ordinal)))
handler = HighlightIgnored;
else if (member != null) {
if (member is IEvent)
handler = HighlightEvent;
else
handler = HighlightProperty;
} else {
if (info.Context.IgnoredXmlns.Any(item => info.Token.StartsWith(item + ":", StringComparison.Ordinal))) {
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightIgnored);
} else {
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", StringComparison.OrdinalIgnoreCase) || info.Token.StartsWith(Utils.GetNamespacePrefix(CompletionDataHelper.MarkupCompatibilityNamespace, info.Context) + ":", StringComparison.OrdinalIgnoreCase))
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightNamespaceDeclaration);
else
Core.LoggingService.Debug(info.Token + " not highlighted; line " + line.LineNumber);
}
}
if (info.Token.StartsWith("xmlns", StringComparison.OrdinalIgnoreCase) || info.Token.StartsWith(Utils.GetNamespacePrefix(CompletionDataHelper.MarkupCompatibilityNamespace, info.Context) + ":", StringComparison.OrdinalIgnoreCase))
handler = HighlightNamespaceDeclaration;
else if (info.Token.StartsWith("xml:", StringComparison.OrdinalIgnoreCase))
handler = HighlightProperty;
else
Core.LoggingService.Debug(info.Token + " not highlighted; line " + line.LineNumber);
}
if (handler != null)
ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, handler);
} catch (ArgumentOutOfRangeException) {}
}
void ColorizeInvalidated()
{
foreach (var item in highlightCache.ToArray()) {
@ -281,7 +283,7 @@ namespace ICSharpCode.XamlBinding @@ -281,7 +283,7 @@ namespace ICSharpCode.XamlBinding
}
}
}
void InvalidateLines(DocumentLine line)
{
DocumentLine current = line;
@ -293,55 +295,55 @@ namespace ICSharpCode.XamlBinding @@ -293,55 +295,55 @@ namespace ICSharpCode.XamlBinding
current = current.NextLine;
}
}
#region highlight helpers
void HighlightProperty(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.PropertyForegroundColor.ToBrush());
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.PropertyBackgroundColor.ToBrush());
}
void HighlightEvent(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.EventForegroundColor.ToBrush());
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.EventBackgroundColor.ToBrush());
}
void HighlightNamespaceDeclaration(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.NamespaceDeclarationForegroundColor.ToBrush());
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.NamespaceDeclarationBackgroundColor.ToBrush());
}
void HighlightIgnored(VisualLineElement element)
{
element.TextRunProperties.SetForegroundBrush(XamlBindingOptions.IgnoredForegroundColor.ToBrush());
element.TextRunProperties.SetBackgroundBrush(XamlBindingOptions.IgnoredBackgroundColor.ToBrush());
}
#endregion
#region ILineTracker implementation
public void BeforeRemoveLine(DocumentLine line)
{
InvalidateLines(line.NextLine);
}
public void SetLineLength(DocumentLine line, int newTotalLength)
{
InvalidateLines(line);
}
public void LineInserted(DocumentLine insertionPos, DocumentLine newLine)
{
InvalidateLines(newLine);
}
public void RebuildDocument()
{
highlightCache.Clear();
}
#endregion
public struct HighlightingInfo
{
string token;

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

@ -22,11 +22,21 @@ namespace ICSharpCode.XamlBinding @@ -22,11 +22,21 @@ namespace ICSharpCode.XamlBinding
{
public class XamlCompletionItemList : DefaultCompletionItemList
{
XamlContext context;
public XamlCompletionItemList(XamlContext context)
{
this.context = context;
}
public override CompletionItemListKeyResult ProcessInput(char key)
{
if (key == ':' || key == '/')
return CompletionItemListKeyResult.NormalKey;
if (key == '.' && (context.InAttributeValueOrMarkupExtension && context.Attribute.Name.StartsWith("xmlns")))
return CompletionItemListKeyResult.NormalKey;
return base.ProcessInput(key);
}
@ -110,6 +120,7 @@ namespace ICSharpCode.XamlBinding @@ -110,6 +120,7 @@ namespace ICSharpCode.XamlBinding
if (item is XamlCompletionItem && xamlContext.Description == XamlContextDescription.InTag) {
context.Editor.Document.Insert(context.EndOffset, "=\"\"");
context.Editor.Caret.Offset--;
XamlCodeCompletionBinding.Instance.CtrlSpace(context.Editor);
}
switch (item.Text) {

5
src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj

@ -98,6 +98,11 @@ @@ -98,6 +98,11 @@
<EmbeddedResource Include="Resources\HexEditOptions.xfrm" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">
<Project>{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}</Project>
<Name>ICSharpCode.AvalonEdit</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>

8
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/BufferManager.cs

@ -5,11 +5,11 @@ @@ -5,11 +5,11 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.AvalonEdit.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
@ -27,7 +27,7 @@ namespace HexEditor.Util @@ -27,7 +27,7 @@ namespace HexEditor.Util
/// <summary>
/// Currently used, but not good for really big files (like 590 MB)
/// </summary>
List<byte> buffer;
Rope<byte> buffer;
/// <summary>
/// Creates a new BufferManager and attaches it to a control.
@ -37,7 +37,7 @@ namespace HexEditor.Util @@ -37,7 +37,7 @@ namespace HexEditor.Util
{
this.parent = parent;
this.buffer = new List<byte>();
this.buffer = new Rope<byte>();
}
/// <summary>
@ -67,7 +67,7 @@ namespace HexEditor.Util @@ -67,7 +67,7 @@ namespace HexEditor.Util
while (reader.PeekChar() != -1) {
this.buffer.AddRange(reader.ReadBytes(524288));
UpdateProgress((int)(((double)this.buffer.Count / (double)reader.BaseStream.Length) * 100));
UpdateProgress((int)(this.buffer.Count / (double)reader.BaseStream.Length) * 100);
}
reader.Close();

Loading…
Cancel
Save