mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
Enhance result panel update
The last commit f132cb54baa000a245feb5da87149960f6dbd9f5 only fix UI flickering for different icon. This commit also fix the commit for same icon. e.g. in web search plugin, although the title is different, but the icon is not changes. part of #350
This commit is contained in:
@@ -9,7 +9,7 @@ using Wox.Plugin;
|
||||
namespace Wox.Helper
|
||||
{
|
||||
class ListBoxItems : ObservableCollection<Result>
|
||||
// todo implement custom moveItem,removeItem,insertItem
|
||||
// todo implement custom moveItem,removeItem,insertItem for better performance
|
||||
{
|
||||
public void RemoveAll(Predicate<Result> predicate)
|
||||
{
|
||||
@@ -18,6 +18,7 @@ namespace Wox.Helper
|
||||
List<Result> itemsToRemove = Items.Where(x => predicate(x)).ToList();
|
||||
if (itemsToRemove.Count > 0)
|
||||
{
|
||||
|
||||
itemsToRemove.ForEach(item => Items.Remove(item));
|
||||
|
||||
OnPropertyChanged(new PropertyChangedEventArgs("Count"));
|
||||
@@ -29,5 +30,38 @@ namespace Wox.Helper
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(List<Result> newItems)
|
||||
{
|
||||
int newCount = newItems.Count;
|
||||
int oldCount = Items.Count;
|
||||
int location = newCount > oldCount ? oldCount : newCount;
|
||||
for (int i = 0; i < location; i++)
|
||||
{
|
||||
Result oldItem = Items[i];
|
||||
Result newItem = newItems[i];
|
||||
if (!Equals(oldItem, newItem))
|
||||
{
|
||||
this[i] = newItem;
|
||||
}
|
||||
}
|
||||
|
||||
if (newCount > oldCount)
|
||||
{
|
||||
for (int i = oldCount; i < newCount; i++)
|
||||
{
|
||||
Add(newItems[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int removeIndex = newCount;
|
||||
for (int i = newCount; i < oldCount; i++)
|
||||
{
|
||||
RemoveAt(removeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user