diff --git a/Pinpoint.Plugin.AppSearch/AppSearchPlugin.cs b/Pinpoint.Plugin.AppSearch/AppSearchPlugin.cs index cc5684e..aae12d5 100644 --- a/Pinpoint.Plugin.AppSearch/AppSearchPlugin.cs +++ b/Pinpoint.Plugin.AppSearch/AppSearchPlugin.cs @@ -24,7 +24,8 @@ public class AppSearchPlugin : AbstractPlugin public override PluginManifest Manifest { get; } = new("App Search") { - Description = "Search for installed apps. Type an app name or an abbreviation thereof.\n\nExamples: \"visual studio code\", \"vsc\"" + Description = "Search for installed apps. Type an app name or an abbreviation thereof.\n\nExamples: \"visual studio code\", \"vsc\"", + Priority = PluginPriority.High, }; public override async Task Initialize() diff --git a/Pinpoint.Win/ViewModels/ObservableUniqueCollection.cs b/Pinpoint.Win/ViewModels/ObservableUniqueCollection.cs index f07e6c3..288d866 100644 --- a/Pinpoint.Win/ViewModels/ObservableUniqueCollection.cs +++ b/Pinpoint.Win/ViewModels/ObservableUniqueCollection.cs @@ -6,7 +6,7 @@ namespace Pinpoint.Win.ViewModels { public class ObservableUniqueCollection : ObservableCollection { - private readonly HashSet _hashSet = new(); + private readonly Dictionary _items = new(); public void AddRange(IEnumerable items) { @@ -25,46 +25,66 @@ public bool TryAdd(T item) protected override void InsertItem(int index, T item) { - if (_hashSet.Add(item)) + if (_items.ContainsKey(item)) { - base.InsertItem(index, item); + return; } + + _items[item] = index; + base.InsertItem(index, item); } protected override void ClearItems() { base.ClearItems(); - _hashSet.Clear(); + _items.Clear(); } protected override void RemoveItem(int index) { - var item = this[index]; - _hashSet.Remove(item); + _items.Remove(this[index]); base.RemoveItem(index); } protected override void SetItem(int index, T item) { - if (_hashSet.Add(item)) + if (_items.ContainsKey(item)) { - var oldItem = this[index]; - _hashSet.Remove(oldItem); - base.SetItem(index, item); + return; } + + _items.Remove(this[index]); + _items[item] = index; + + base.SetItem(index, item); } - public void RemoveWhere(Predicate predicate) + public void RemoveWhere(Predicate filter) { for (var i = Count - 1; i >= 0; i--) { - if (!predicate(this[i])) + if (filter(this[i])) { - continue; + RemoveItem(i); } + } + } - RemoveItem(i); + public new bool Contains(T item) + { + return _items.ContainsKey(item); + } + + public new bool Remove(T item) { + if (!_items.ContainsKey(item)) + { + return false; } + + _items.Remove(item); + base.Remove(item); + + return true; } } } \ No newline at end of file diff --git a/Pinpoint.Win/Views/MainWindow.xaml.cs b/Pinpoint.Win/Views/MainWindow.xaml.cs index 75dace0..4d67681 100644 --- a/Pinpoint.Win/Views/MainWindow.xaml.cs +++ b/Pinpoint.Win/Views/MainWindow.xaml.cs @@ -387,7 +387,7 @@ private void TxtQuery_TextChanged(object sender, System.Windows.Controls.TextCha if (!Model.PreviousQuery.Equals(query)) { - _ = Dispatcher.Invoke(async () => await UpdateResults()); + _ = Dispatcher.Invoke(UpdateResults); } } @@ -495,11 +495,14 @@ private async Task UpdateResults() results.Add(result); } - Model.Results.RemoveWhere(r => !results.Contains(r)); - var shortcutKey = 0; foreach (var result in results) { + if (Model.Results.Contains(result)) + { + Model.Results.Remove(result); + } + // If one of first 9 results, set keyboard shortcut for result if (Model.Results.TryAdd(result) && shortcutKey < 9) { @@ -507,6 +510,8 @@ private async Task UpdateResults() } } + Model.Results.RemoveWhere(r => !results.Contains(r)); + if (Model.Results.Count > 0 && LstResults.SelectedIndex == -1) { LstResults.SelectedIndex = 0;