Stable sorting of ResultCollection (#5850)

* Stable sorting of ResultCollection

* nit fixes for resultsViewModel and ResultCollection
This commit is contained in:
Divyansh Srivastava
2020-08-11 10:24:56 -07:00
committed by GitHub
parent ac10c988b9
commit 2d2cb22806
3 changed files with 20 additions and 30 deletions

View File

@@ -4,38 +4,19 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using PowerLauncher.ViewModel;
namespace PowerLauncher.Helper
{
public class ResultCollection : List<ResultViewModel>, INotifyCollectionChanged
{
public ResultCollection() { }
public ResultCollection(IEnumerable<ResultViewModel> rvm) : base(rvm) { }
public event NotifyCollectionChangedEventHandler CollectionChanged;
private int CompareResultViewModel(ResultViewModel c1, ResultViewModel c2)
{
if (c1.Result.Score > c2.Result.Score)
{
return -1;
}
else if (c1.Result.Score == c2.Result.Score)
{
return 0;
}
else
{
return 1;
}
}
/// <summary>
/// sort the list in descending order of score
/// </summary>
public new void Sort()
{
base.Sort(CompareResultViewModel);
}
/// <summary>
/// Notify change in the List view items
/// </summary>