diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index 0766c7bbcd1..42ccad63162 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -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 { @@ -26,6 +27,7 @@ public ResultsViewModel() Results = new ResultCollection(); BindingOperations.EnableCollectionSynchronization(Results, _collectionLock); } + public ResultsViewModel(Settings settings) : this() { _settings = settings; @@ -65,6 +67,7 @@ private int InsertIndexOf(int newScore, IList list) break; } } + return index; } @@ -83,7 +86,6 @@ private int NewIndex(int i) } } - #endregion #region Public Methods @@ -140,6 +142,7 @@ public void AddResults(List newRawResults, string resultId) UpdateResults(newResults); } + /// /// To avoid deadlock, this method should not called from main thread /// @@ -197,13 +200,15 @@ private List NewResults(IEnumerable 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), @@ -232,6 +237,7 @@ private static void FormattedTextPropertyChanged(DependencyObject d, DependencyP textBlock.Inlines.Add(inline); } + #endregion public class ResultCollection : List, INotifyCollectionChanged @@ -260,6 +266,7 @@ public void BulkAddAll(List 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 Items) { for (int i = 0; i < Items.Count; i++) @@ -268,9 +275,11 @@ private void AddAll(List 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(); @@ -290,23 +299,15 @@ public void Update(List 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++; } } }