diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs index 9b05b2eafc..c87a792df9 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs @@ -177,13 +177,21 @@ namespace ICSharpCode.XamlBinding if (markup.PositionalArguments.Count == 1 && ch == ' ') break; if (markup.PositionalArguments.Count <= 1) { - list.Items.AddRange(CreateListForElement(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column)); - 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)); + if (ch == '.') { + // TODO : enum and field completion + } else { + var items = GetClassesFromContext(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column); + foreach (var ns in items) { + 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)); + } + + 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; @@ -194,6 +202,8 @@ namespace ICSharpCode.XamlBinding list.Items.AddRange(CreateListForElement(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column)); AttributeValue selItem = markup.PositionalArguments.LastOrDefault(); + + if (selItem != null && selItem.IsString) { string s = selItem.StringValue; list.PreselectionLength = s.Length; diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/MarkupExtensionToken.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/MarkupExtensionToken.cs index 35d5baf4dc..bec9c6221c 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/MarkupExtensionToken.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/MarkupExtensionToken.cs @@ -24,5 +24,22 @@ namespace ICSharpCode.XamlBinding { 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; + } } } diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs index f773256fb9..a16384014d 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs @@ -32,9 +32,6 @@ namespace ICSharpCode.XamlBinding 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)); int startTags = 0; try { diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs index b51d48f94a..32b20a2201 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs @@ -64,7 +64,7 @@ namespace ICSharpCode.XamlBinding if (path != null && path.Elements.Count > 0) { 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, ">"); editor.Caret.Offset = offset + 1; return CodeCompletionKeyPressResult.EatKey; @@ -78,7 +78,7 @@ namespace ICSharpCode.XamlBinding if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, offset)) { int search = offset + 1; - while (char.IsWhiteSpace(editor.Document.GetCharAt(search))) + while (search < editor.Document.TextLength - 1 && char.IsWhiteSpace(editor.Document.GetCharAt(search))) search++; if (editor.Document.GetCharAt(search) != '"') { @@ -233,6 +233,7 @@ namespace ICSharpCode.XamlBinding editor.ShowCompletionWindow(list); return true; } else { + // DO NOT USE CompletionDataHelper.CreateListForContext here!!! might result in endless recursion!!!! string attribute = XmlParser.GetAttributeNameAtIndex(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); @@ -283,15 +284,17 @@ namespace ICSharpCode.XamlBinding case ClassType.Delegate: IMethod invoker = c.Methods.Where(method => method.Name == "Invoke").FirstOrDefault(); if (invoker != null) { - var path = XmlParser.GetActiveElementStartPath(editor.Document.Text, editor.Caret.Offset); - var item = path.Elements[path.Elements.Count - 1]; - string attribute = XmlParser.GetAttributeNameAtIndex(editor.Document.Text, editor.Caret.Offset); - var e = ResolveAttribute(attribute, editor) as IEvent; - if (e == null) - break; - string name = Utils.GetAttributeValue(editor.Document.Text, editor.Caret.Offset, "name"); - list.Add(new NewEventCompletionItem(e, (string.IsNullOrEmpty(name)) ? item.Name : name)); - CompletionDataHelper.AddMatchingEventHandlers(editor, invoker, list); + var path = XmlParser.GetActiveElementStartPathAtIndex(editor.Document.Text, editor.Caret.Offset); + if (path != null && path.Elements.Count > 0) { + var item = path.Elements[path.Elements.Count - 1]; + string attribute = XmlParser.GetAttributeNameAtIndex(editor.Document.Text, editor.Caret.Offset); + var e = ResolveAttribute(attribute, editor) as IEvent; + if (e == null) + break; + string name = Utils.GetAttributeValue(editor.Document.Text, editor.Caret.Offset, "name"); + list.Add(new NewEventCompletionItem(e, (string.IsNullOrEmpty(name)) ? item.Name : name)); + CompletionDataHelper.AddMatchingEventHandlers(editor, invoker, list); + } } break; }