2020-08-05 14:06:55 -07:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
2020-07-20 11:22:03 -07:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-27 18:13:47 -07:00
|
|
|
|
using System.Collections.Specialized;
|
2020-08-05 14:06:55 -07:00
|
|
|
|
using PowerLauncher.ViewModel;
|
2020-07-20 11:22:03 -07:00
|
|
|
|
|
|
|
|
|
|
namespace PowerLauncher.Helper
|
|
|
|
|
|
{
|
2020-07-31 15:09:23 -07:00
|
|
|
|
public class ResultCollection : List<ResultViewModel>, INotifyCollectionChanged
|
2020-07-20 11:22:03 -07:00
|
|
|
|
{
|
2020-07-31 15:09:23 -07:00
|
|
|
|
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
2020-07-27 18:13:47 -07:00
|
|
|
|
|
2020-07-31 15:09:23 -07:00
|
|
|
|
private int CompareResultViewModel(ResultViewModel c1, ResultViewModel c2)
|
2020-07-20 11:22:03 -07:00
|
|
|
|
{
|
2020-07-31 15:09:23 -07:00
|
|
|
|
if (c1.Result.Score > c2.Result.Score)
|
2020-07-20 11:22:03 -07:00
|
|
|
|
{
|
2020-07-31 15:09:23 -07:00
|
|
|
|
return -1;
|
2020-07-20 11:22:03 -07:00
|
|
|
|
}
|
2020-07-31 15:09:23 -07:00
|
|
|
|
else if (c1.Result.Score == c2.Result.Score)
|
2020-07-20 11:22:03 -07:00
|
|
|
|
{
|
2020-07-31 15:09:23 -07:00
|
|
|
|
return 0;
|
2020-07-20 11:22:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-07-31 15:09:23 -07:00
|
|
|
|
return 1;
|
2020-07-20 11:22:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-27 18:13:47 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-31 15:09:23 -07:00
|
|
|
|
/// sort the list in descending order of score
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public new void Sort()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Sort(CompareResultViewModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Notify change in the List view items
|
2020-07-27 18:13:47 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="e">The event argument.</param>
|
2020-07-31 15:09:23 -07:00
|
|
|
|
public void NotifyChanges()
|
2020-07-27 18:13:47 -07:00
|
|
|
|
{
|
2020-07-31 15:09:23 -07:00
|
|
|
|
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
2020-07-27 18:13:47 -07:00
|
|
|
|
}
|
2020-07-20 11:22:03 -07:00
|
|
|
|
}
|
2020-08-05 14:06:55 -07:00
|
|
|
|
}
|