Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions Flow.Launcher/ViewModel/ResultsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using ABI.Windows.Services.Maps;

namespace Flow.Launcher.ViewModel
{
Expand All @@ -26,6 +27,7 @@ public ResultsViewModel()
Results = new ResultCollection();
BindingOperations.EnableCollectionSynchronization(Results, _collectionLock);
}

public ResultsViewModel(Settings settings) : this()
{
_settings = settings;
Expand Down Expand Up @@ -65,6 +67,7 @@ private int InsertIndexOf(int newScore, IList<ResultViewModel> list)
break;
}
}

return index;
}

Expand All @@ -83,7 +86,6 @@ private int NewIndex(int i)
}
}


#endregion

#region Public Methods
Expand Down Expand Up @@ -140,6 +142,7 @@ public void AddResults(List<Result> newRawResults, string resultId)

UpdateResults(newResults);
}

/// <summary>
/// To avoid deadlock, this method should not called from main thread
/// </summary>
Expand Down Expand Up @@ -197,13 +200,15 @@ private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsFo
return Results;

return Results.Where(r => r != null && !resultsForUpdates.Any(u => u.ID == r.Result.PluginID))
.Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
.OrderByDescending(rv => rv.Result.Score)
.ToList();
.Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
.OrderByDescending(rv => rv.Result.Score)
.ToList();
}

#endregion

#region FormattedText Dependency Property

public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached(
"FormattedText",
typeof(Inline),
Expand Down Expand Up @@ -232,6 +237,7 @@ private static void FormattedTextPropertyChanged(DependencyObject d, DependencyP

textBlock.Inlines.Add(inline);
}

#endregion

public class ResultCollection : List<ResultViewModel>, INotifyCollectionChanged
Expand Down Expand Up @@ -260,6 +266,7 @@ public void BulkAddAll(List<ResultViewModel> resultViews)
// wpf use directx / double buffered already, so just reset all won't cause ui flickering
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}

private void AddAll(List<ResultViewModel> Items)
{
for (int i = 0; i < Items.Count; i++)
Expand All @@ -268,9 +275,11 @@ private void AddAll(List<ResultViewModel> Items)
if (_token.IsCancellationRequested)
return;
Add(item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, i));
OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, i));
}
}

public void RemoveAll(int Capacity = 512)
{
Clear();
Expand All @@ -290,23 +299,15 @@ public void Update(List<ResultViewModel> newItems, CancellationToken token = def
if (Count == 0 && newItems.Count == 0 || _token.IsCancellationRequested)
return;

if (editTime < 10 || newItems.Count < 30)
{
if (Count != 0) RemoveAll(newItems.Count);
AddAll(newItems);
editTime++;
return;
}
else
Clear();

BulkAddAll(newItems);
if (Capacity > 8000 && newItems.Count < 3000)
{
Clear();
BulkAddAll(newItems);
if (Capacity > 8000 && newItems.Count < 3000)
{
Capacity = newItems.Count;
}
editTime++;
Capacity = newItems.Count;
}

editTime++;
}
}
}
Expand Down