From 0e75a514cfb71d2a9a37fb175aa954c897b24175 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 25 Jul 2005 10:45:07 +0000 Subject: [PATCH] When typing a variable declaration like "List list = new ***", the new-completion popup preselects "List". git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@250 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Parser/ExpressionFinder.cs | 21 +++-- .../CodeCompletionListView.cs | 10 ++- .../AbstractCompletionDataProvider.cs | 86 ++++++++++++------- 3 files changed, 79 insertions(+), 38 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs index 8d6458cd48..63889456de 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs @@ -60,17 +60,28 @@ namespace CSharpBinding.Parser if (typeStart >= 0) { string className = text.Substring(typeStart, typeEnd - typeStart); int pos = className.IndexOf('<'); - string nonGenericClassName; - if (pos > 0) + string nonGenericClassName, genericPart; + if (pos > 0) { nonGenericClassName = className.Substring(0, pos); - else + genericPart = className.Substring(pos); + } else { nonGenericClassName = className; + genericPart = null; + } ClassFinder finder = new ClassFinder(fileName, text, typeStart); IClass c = finder.SearchClass(nonGenericClassName); if (c != null) { ExpressionContext context = ExpressionContext.TypeDerivingFrom(c, true); - if (context.ShowEntry(c)) - context.SuggestedItem = c; + if (context.ShowEntry(c)) { + if (genericPart != null) { + DefaultClass genericClass = new DefaultClass(c.CompilationUnit, c.ClassType, c.Modifiers, c.Region, c.DeclaringType); + genericClass.FullyQualifiedName = c.FullyQualifiedName + genericPart; + genericClass.Documentation = c.Documentation; + context.SuggestedItem = genericClass; + } else { + context.SuggestedItem = c; + } + } return context; } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionListView.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionListView.cs index cfb380d55c..6c900c0f9c 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionListView.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionListView.cs @@ -153,8 +153,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow string itemText = completionData[i].Text; string lowerText = itemText.ToLower(); if (lowerText.StartsWith(startText)) { - if (i == selectedItem) - return; double priority = completionData[i].Priority; int quality; if (lowerText == startText) { @@ -171,9 +169,13 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow if (bestQuality < quality) { useThisItem = true; } else { - useThisItem = bestQuality == quality && bestPriority < priority; - if (useThisItem && bestIndex == i) + if (bestIndex == selectedItem) { useThisItem = false; + } else if (i == selectedItem) { + useThisItem = bestQuality == quality; + } else { + useThisItem = bestQuality == quality && bestPriority < priority; + } } if (useThisItem) { bestIndex = i; diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AbstractCompletionDataProvider.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AbstractCompletionDataProvider.cs index 4e2d1dad8c..b58e29d115 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AbstractCompletionDataProvider.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AbstractCompletionDataProvider.cs @@ -30,9 +30,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor } } + int defaultIndex; + public int DefaultIndex { get { - return -1; + return defaultIndex; } } @@ -85,42 +87,68 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor if (list == null) { return; } + System.Diagnostics.Debugger.Break(); completionData.Capacity += list.Count; + CodeCompletionData suggestedData = null; foreach (object o in list) { if (context != null && !context.ShowEntry(o)) continue; - if (o is string) { - completionData.Add(new CodeCompletionData(o.ToString(), ClassBrowserIconService.NamespaceIndex)); - } else if (o is IClass) { - completionData.Add(new CodeCompletionData((IClass)o)); - } else if (o is IProperty) { - IProperty property = (IProperty)o; - if (property.Name != null && insertedPropertiesElements[property.Name] == null) { - completionData.Add(new CodeCompletionData(property)); - insertedPropertiesElements[property.Name] = property; - } - } else if (o is IMethod) { - IMethod method = (IMethod)o; - if (method.Name != null &&!method.IsConstructor) { - CodeCompletionData ccd = new CodeCompletionData(method); - if (insertedElements[method.Name] == null) { - completionData.Add(ccd); - insertedElements[method.Name] = ccd; - } else { - CodeCompletionData oldMethod = (CodeCompletionData)insertedElements[method.Name]; - ++oldMethod.Overloads; - } + CodeCompletionData ccd = CreateItem(o, context); + if (object.Equals(o, context.SuggestedItem)) + suggestedData = ccd; + if (ccd != null) + completionData.Add(ccd); + } + if (context.SuggestedItem != null) { + if (suggestedData == null) { + suggestedData = CreateItem(context.SuggestedItem, context); + if (suggestedData != null) { + completionData.Add(suggestedData); } - } else if (o is IField) { - completionData.Add(new CodeCompletionData((IField)o)); - } else if (o is IEvent) { - IEvent e = (IEvent)o; - if (e.Name != null && insertedEventElements[e.Name] == null) { - completionData.Add(new CodeCompletionData(e)); - insertedEventElements[e.Name] = e; + } + if (suggestedData != null) { + completionData.Sort(); + defaultIndex = completionData.IndexOf(suggestedData); + } + } + } + + CodeCompletionData CreateItem(object o, ExpressionContext context) + { + if (o is string) { + return new CodeCompletionData(o.ToString(), ClassBrowserIconService.NamespaceIndex); + } else if (o is IClass) { + return new CodeCompletionData((IClass)o); + } else if (o is IProperty) { + IProperty property = (IProperty)o; + if (property.Name != null && insertedPropertiesElements[property.Name] == null) { + insertedPropertiesElements[property.Name] = property; + return new CodeCompletionData(property); + } + } else if (o is IMethod) { + IMethod method = (IMethod)o; + if (method.Name != null &&!method.IsConstructor) { + CodeCompletionData ccd = new CodeCompletionData(method); + if (insertedElements[method.Name] == null) { + insertedElements[method.Name] = ccd; + return ccd; + } else { + CodeCompletionData oldMethod = (CodeCompletionData)insertedElements[method.Name]; + ++oldMethod.Overloads; } } + } else if (o is IField) { + return new CodeCompletionData((IField)o); + } else if (o is IEvent) { + IEvent e = (IEvent)o; + if (e.Name != null && insertedEventElements[e.Name] == null) { + insertedEventElements[e.Name] = e; + return new CodeCompletionData(e); + } + } else { + throw new ApplicationException("Unknown object: " + o); } + return null; } protected void AddResolveResults(ResolveResult results, ExpressionContext context)