Browse Source

Merge pull request #31 from noamwies/master

Navigate to class support for CamelHumps
pull/55/merge
Siegfried Oleg Pammer 12 years ago
parent
commit
bd1036050c
  1. 9
      src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs
  2. 12
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs
  3. 1
      src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj
  4. 49
      src/Main/Base/Test/Utils/Tests/CamelHumpsMatchTests.cs

9
src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs

@ -274,7 +274,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -274,7 +274,7 @@ namespace ICSharpCode.SharpDevelop.Gui
foreach (IClass c in classes) {
string className = c.Name;
if (className.Length >= classPart.Length) {
if (className.IndexOf(classPart, StringComparison.OrdinalIgnoreCase) >= 0) {
if (className.AutoCompleteWithCamelHumpsMatch(classPart)){
if (memberPart.Length > 0) {
AddAllMembersMatchingText(c, memberPart, false);
} else {
@ -284,7 +284,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -284,7 +284,7 @@ namespace ICSharpCode.SharpDevelop.Gui
}
AddClasses(classPart, memberPart, list, c.InnerClasses);
}
}
}
const int MatchType_NoMatch = -1;
const int MatchType_ContainsMatch_CaseInsensitive = 0;
@ -300,7 +300,12 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -300,7 +300,12 @@ namespace ICSharpCode.SharpDevelop.Gui
return MatchType_NoMatch;
int indexInsensitive = itemText.IndexOf(searchText, StringComparison.OrdinalIgnoreCase);
if (indexInsensitive < 0)
{
if (itemText.AutoCompleteWithCamelHumpsMatch(searchText)) {
return MatchType_ContainsMatch_CaseInsensitive;
}
return MatchType_NoMatch;
}
// This is a case insensitive match
int indexSensitive = itemText.IndexOf(searchText, StringComparison.Ordinal);
if (itemText.Length == searchText.Length) {

12
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -619,6 +619,18 @@ namespace ICSharpCode.SharpDevelop @@ -619,6 +619,18 @@ namespace ICSharpCode.SharpDevelop
return newContent;
}
public static bool AutoCompleteWithCamelHumpsMatch(this string entityName,string entityPartName)
{
string camelHumpsPrefix = new string(entityName.Where<char>( c => Char.IsUpper(c)).Select( c => c ).ToArray());
return entityName.AutoCompleteMatch(entityPartName) || camelHumpsPrefix.AutoCompleteMatch(entityPartName);
}
public static bool AutoCompleteMatch(this string entityName,string entityPartName)
{
return (entityName.IndexOf(entityPartName, StringComparison.OrdinalIgnoreCase) >= 0);
}
#region Dom, AST, Editor, Document
public static Location GetStart(this DomRegion region)
{

1
src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj

@ -129,6 +129,7 @@ @@ -129,6 +129,7 @@
<Compile Include="Utils\MockTextMarker.cs" />
<Compile Include="Utils\MockTextMarkerService.cs" />
<Compile Include="Utils\ProjectHelper.cs" />
<Compile Include="Utils\Tests\CamelHumpsMatchTests.cs" />
<Compile Include="Utils\Tests\MockAssemblyTests.cs" />
<Compile Include="VBExpressionFinderTests.cs" />
<Compile Include="WebReferences\ValidReferenceNameTests.cs" />

49
src/Main/Base/Test/Utils/Tests/CamelHumpsMatchTests.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
/*
* Created by SharpDevelop.
* User: Noam
* Date: 26/12/2012
* Time: 17:52
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Globalization;
using NUnit.Framework;
namespace ICSharpCode.SharpDevelop.Tests.Utils.Tests
{
/// <summary>
/// Description of CamelHumpsMatchTests.
/// </summary>
[TestFixture]
public class CamelHumpsMatchTests
{
[Test]
public void EntityNameStartWithEntityPartName_ShouldReturnTrue()
{
bool result = "abc".AutoCompleteWithCamelHumpsMatch("ab");
Assert.AreEqual(result,true);
}
[Test]
public void EntityNameContainEntityPartName_ShouldReturnTrue()
{
bool result = "abc".AutoCompleteWithCamelHumpsMatch("b");
Assert.AreEqual(result,true);
}
[Test]
public void EntityNameDoesntContainEntityPartName_ShouldReturnFalse()
{
bool result = "abc".AutoCompleteWithCamelHumpsMatch("de");
Assert.AreEqual(result,false);
}
[Test]
public void EntityPartNameIsTheFirstLetterInWordsByCamelHumps_ShouldReturnTrue()
{
bool result = "AbcDefGh".AutoCompleteWithCamelHumpsMatch("AD");
Assert.AreEqual(result,true);
}
}
}
Loading…
Cancel
Save