Browse Source

Sort search results by name (ordinal, case sensitive)

pull/728/merge
Siegfried Pammer 9 years ago
parent
commit
2786ce7a56
  1. 22
      ILSpy/ExtensionMethods.cs
  2. 24
      ILSpy/SearchPane.cs

22
ILSpy/ExtensionMethods.cs

@ -34,6 +34,28 @@ namespace ICSharpCode.ILSpy @@ -34,6 +34,28 @@ namespace ICSharpCode.ILSpy
if (!list.Contains(item))
list.Add(item);
}
public static int BinarySearch<T>(this IList<T> list, T item, int start, int count, IComparer<T> comparer)
{
if (list == null)
throw new ArgumentNullException("list");
if (start < 0 || start >= list.Count)
throw new ArgumentOutOfRangeException("start", start, "Value must be between 0 and " + (list.Count - 1));
if (count < 0 || count > list.Count - start)
throw new ArgumentOutOfRangeException("count", count, "Value must be between 0 and " + (list.Count - start));
int end = start + count - 1;
while (start <= end) {
int pivot = (start + end) / 2;
int result = comparer.Compare(item, list[pivot]);
if (result == 0)
return pivot;
if (result < 0)
end = pivot - 1;
else
start = pivot + 1;
}
return ~start;
}
public static bool IsCustomAttribute(this TypeDefinition type)
{

24
ILSpy/SearchPane.cs

@ -243,10 +243,16 @@ namespace ICSharpCode.ILSpy @@ -243,10 +243,16 @@ namespace ICSharpCode.ILSpy
}
dispatcher.BeginInvoke(
DispatcherPriority.Normal,
new Action(delegate { this.Results.Insert(this.Results.Count - 1, result); }));
new Action(delegate { InsertResult(this.Results, result); }));
cts.Token.ThrowIfCancellationRequested();
}
void InsertResult(ObservableCollection<SearchResult> results, SearchResult result)
{
int index = results.BinarySearch(result, 0, results.Count - 1, SearchResult.Comparer);
results.Insert(index < 0 ? ~index : index, result);
}
AbstractSearchStrategy GetSearchStrategy(SearchMode mode, string[] terms)
{
if (terms.Length == 1) {
@ -306,18 +312,28 @@ namespace ICSharpCode.ILSpy @@ -306,18 +312,28 @@ namespace ICSharpCode.ILSpy
add { }
remove { }
}
public static readonly System.Collections.Generic.IComparer<SearchResult> Comparer = new SearchResultComparer();
public MemberReference Member { get; set; }
public string Location { get; set; }
public string Name { get; set; }
public ImageSource Image { get; set; }
public ImageSource LocationImage { get; set; }
public override string ToString()
{
return Name;
}
class SearchResultComparer : System.Collections.Generic.IComparer<SearchResult>
{
public int Compare(SearchResult x, SearchResult y)
{
return StringComparer.Ordinal.Compare(x?.Name ?? "", y?.Name ?? "");
}
}
}
[ExportMainMenuCommand(Menu = "_View", Header = "_Search...", MenuIcon = "Images/Find.png", MenuCategory = "View", MenuOrder = 100)]

Loading…
Cancel
Save