Browse Source

fixed Unit Tests

implemented first part of x:Static completion

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3996 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
60ba0fe3c2
  1. 24
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  2. 17
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/MarkupExtensionToken.cs
  3. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs
  4. 25
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs

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

@ -177,13 +177,21 @@ namespace ICSharpCode.XamlBinding
if (markup.PositionalArguments.Count == 1 && ch == ' ') if (markup.PositionalArguments.Count == 1 && ch == ' ')
break; break;
if (markup.PositionalArguments.Count <= 1) { if (markup.PositionalArguments.Count <= 1) {
list.Items.AddRange(CreateListForElement(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column)); if (ch == '.') {
AttributeValue selItem = markup.PositionalArguments.LastOrDefault(); // TODO : enum and field completion
} else {
if (selItem != null && selItem.IsString) { var items = GetClassesFromContext(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column);
string s = selItem.StringValue; foreach (var ns in items) {
list.PreselectionLength = s.Length; list.Items.AddRange(ns.Value.Where(c => c.Fields.Any(f => f.IsStatic) || c.Properties.Any(p => p.IsStatic)).Select(c => new XamlCompletionItem(c, ns.Key) as ICompletionItem));
list.SuggestedItem = list.Items.FirstOrDefault(item => item.Text.StartsWith(s, StringComparison.OrdinalIgnoreCase)); }
AttributeValue selItem = markup.PositionalArguments.LastOrDefault();
if (selItem != null && selItem.IsString) {
string s = selItem.StringValue;
list.PreselectionLength = s.Length;
list.SuggestedItem = list.Items.FirstOrDefault(item => item.Text.StartsWith(s, StringComparison.OrdinalIgnoreCase));
}
} }
} }
break; break;
@ -194,6 +202,8 @@ namespace ICSharpCode.XamlBinding
list.Items.AddRange(CreateListForElement(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column)); list.Items.AddRange(CreateListForElement(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column));
AttributeValue selItem = markup.PositionalArguments.LastOrDefault(); AttributeValue selItem = markup.PositionalArguments.LastOrDefault();
if (selItem != null && selItem.IsString) { if (selItem != null && selItem.IsString) {
string s = selItem.StringValue; string s = selItem.StringValue;
list.PreselectionLength = s.Length; list.PreselectionLength = s.Length;

17
src/AddIns/BackendBindings/XamlBinding/XamlBinding/MarkupExtensionToken.cs

@ -24,5 +24,22 @@ namespace ICSharpCode.XamlBinding
{ {
return "[" + Kind + " " + Value + "]"; return "[" + Kind + " " + Value + "]";
} }
public override int GetHashCode()
{
int hashCode = 0;
unchecked {
hashCode += 1000000007 * Kind.GetHashCode();
if (Value != null) hashCode += 1000000009 * Value.GetHashCode();
}
return hashCode;
}
public override bool Equals(object obj)
{
MarkupExtensionToken other = obj as MarkupExtensionToken;
if (other == null) return false;
return this.Kind == other.Kind && this.Value == other.Value;
}
} }
} }

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

@ -32,9 +32,6 @@ namespace ICSharpCode.XamlBinding
var path = XmlParser.GetActiveElementStartPathAtIndex(text, index); var path = XmlParser.GetActiveElementStartPathAtIndex(text, index);
if (path != null && path.Elements.Count > 0 && path.Elements[path.Elements.Count - 1].Name.StartsWith("/"))
return true; // is end tag!
XmlReader reader = XmlTextReader.Create(new StringReader(text)); XmlReader reader = XmlTextReader.Create(new StringReader(text));
int startTags = 0; int startTags = 0;
try { try {

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

@ -64,7 +64,7 @@ namespace ICSharpCode.XamlBinding
if (path != null && path.Elements.Count > 0) { if (path != null && path.Elements.Count > 0) {
QualifiedName last = path.Elements[path.Elements.Count - 1]; QualifiedName last = path.Elements[path.Elements.Count - 1];
if (!Utils.HasMatchingEndTag(last.Name, document, offset)) { if (!Utils.HasMatchingEndTag(last.Name, document, offset) && !last.Name.StartsWith("/")) {
editor.Document.Insert(offset, "></" + last.Name + ">"); editor.Document.Insert(offset, "></" + last.Name + ">");
editor.Caret.Offset = offset + 1; editor.Caret.Offset = offset + 1;
return CodeCompletionKeyPressResult.EatKey; return CodeCompletionKeyPressResult.EatKey;
@ -78,7 +78,7 @@ namespace ICSharpCode.XamlBinding
if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, offset)) { if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, offset)) {
int search = offset + 1; int search = offset + 1;
while (char.IsWhiteSpace(editor.Document.GetCharAt(search))) while (search < editor.Document.TextLength - 1 && char.IsWhiteSpace(editor.Document.GetCharAt(search)))
search++; search++;
if (editor.Document.GetCharAt(search) != '"') { if (editor.Document.GetCharAt(search) != '"') {
@ -233,6 +233,7 @@ namespace ICSharpCode.XamlBinding
editor.ShowCompletionWindow(list); editor.ShowCompletionWindow(list);
return true; return true;
} else { } else {
// DO NOT USE CompletionDataHelper.CreateListForContext here!!! might result in endless recursion!!!!
string attribute = XmlParser.GetAttributeNameAtIndex(editor.Document.Text, editor.Caret.Offset); string attribute = XmlParser.GetAttributeNameAtIndex(editor.Document.Text, editor.Caret.Offset);
string attribValue = XmlParser.GetAttributeValueAtIndex(editor.Document.Text, editor.Caret.Offset); string attribValue = XmlParser.GetAttributeValueAtIndex(editor.Document.Text, editor.Caret.Offset);
int offsetFromValueStart = Utils.GetOffsetFromValueStart(editor.Document.Text, editor.Caret.Offset); int offsetFromValueStart = Utils.GetOffsetFromValueStart(editor.Document.Text, editor.Caret.Offset);
@ -283,15 +284,17 @@ namespace ICSharpCode.XamlBinding
case ClassType.Delegate: case ClassType.Delegate:
IMethod invoker = c.Methods.Where(method => method.Name == "Invoke").FirstOrDefault(); IMethod invoker = c.Methods.Where(method => method.Name == "Invoke").FirstOrDefault();
if (invoker != null) { if (invoker != null) {
var path = XmlParser.GetActiveElementStartPath(editor.Document.Text, editor.Caret.Offset); var path = XmlParser.GetActiveElementStartPathAtIndex(editor.Document.Text, editor.Caret.Offset);
var item = path.Elements[path.Elements.Count - 1]; if (path != null && path.Elements.Count > 0) {
string attribute = XmlParser.GetAttributeNameAtIndex(editor.Document.Text, editor.Caret.Offset); var item = path.Elements[path.Elements.Count - 1];
var e = ResolveAttribute(attribute, editor) as IEvent; string attribute = XmlParser.GetAttributeNameAtIndex(editor.Document.Text, editor.Caret.Offset);
if (e == null) var e = ResolveAttribute(attribute, editor) as IEvent;
break; if (e == null)
string name = Utils.GetAttributeValue(editor.Document.Text, editor.Caret.Offset, "name"); break;
list.Add(new NewEventCompletionItem(e, (string.IsNullOrEmpty(name)) ? item.Name : name)); string name = Utils.GetAttributeValue(editor.Document.Text, editor.Caret.Offset, "name");
CompletionDataHelper.AddMatchingEventHandlers(editor, invoker, list); list.Add(new NewEventCompletionItem(e, (string.IsNullOrEmpty(name)) ? item.Name : name));
CompletionDataHelper.AddMatchingEventHandlers(editor, invoker, list);
}
} }
break; break;
} }

Loading…
Cancel
Save