Grid refresh performance and behavior improvements
This commit is contained in:
parent
1a95f2923b
commit
82fba7e752
@ -53,10 +53,10 @@ namespace LibationUiBase.GridView
|
||||
|
||||
var searchResultSet = SearchEngineCommands.Search(searchString);
|
||||
|
||||
var booksFilteredIn = entries.BookEntries().Join(searchResultSet.Docs, lbe => lbe.AudibleProductId, d => d.ProductId, (lbe, d) => (IGridEntry)lbe);
|
||||
var booksFilteredIn = entries.IntersectBy(searchResultSet.Docs.Select(d => d.ProductId), l => l.AudibleProductId);
|
||||
|
||||
//Find all series containing children that match the search criteria
|
||||
var seriesFilteredIn = entries.SeriesEntries().Where(s => s.Children.Join(searchResultSet.Docs, lbe => lbe.AudibleProductId, d => d.ProductId, (lbe, d) => lbe).Any());
|
||||
var seriesFilteredIn = booksFilteredIn.OfType<ILibraryBookEntry>().Where(lbe => lbe.Parent is not null).Select(lbe => lbe.Parent).Distinct();
|
||||
|
||||
return booksFilteredIn.Concat(seriesFilteredIn).ToHashSet();
|
||||
}
|
||||
|
||||
@ -97,6 +97,9 @@ namespace LibationWinForms.GridView
|
||||
/// </summary>
|
||||
private void refreshEntries()
|
||||
{
|
||||
var priorState = RaiseListChangedEvents;
|
||||
RaiseListChangedEvents = false;
|
||||
|
||||
if (FilteredInGridEntries is null)
|
||||
{
|
||||
addRemovedItemsBack(FilterRemoved.ToList());
|
||||
@ -117,7 +120,8 @@ namespace LibationWinForms.GridView
|
||||
|
||||
SortInternal();
|
||||
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
||||
ResetList();
|
||||
RaiseListChangedEvents = priorState;
|
||||
|
||||
void addRemovedItemsBack(List<IGridEntry> addBackEntries)
|
||||
{
|
||||
@ -200,7 +204,7 @@ namespace LibationWinForms.GridView
|
||||
propertyDescriptor = property;
|
||||
isSorted = true;
|
||||
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
||||
ResetList();
|
||||
}
|
||||
|
||||
private void SortInternal()
|
||||
@ -224,8 +228,15 @@ namespace LibationWinForms.GridView
|
||||
isSorted = false;
|
||||
propertyDescriptor = base.SortPropertyCore;
|
||||
Comparer.SortOrder = base.SortDirectionCore;
|
||||
ResetList();
|
||||
}
|
||||
|
||||
private void ResetList()
|
||||
{
|
||||
var priorState = RaiseListChangedEvents;
|
||||
RaiseListChangedEvents = true;
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
||||
RaiseListChangedEvents = priorState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,6 +189,9 @@ namespace LibationWinForms.GridView
|
||||
|
||||
internal void UpdateGrid(List<LibraryBook> dbBooks)
|
||||
{
|
||||
//First row that is in view in the DataGridView
|
||||
var topRow = gridEntryDataGridView.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Displayed)?.Index ?? 0;
|
||||
|
||||
#region Add new or update existing grid entries
|
||||
|
||||
//Remove filter prior to adding/updating boooks
|
||||
@ -201,6 +204,7 @@ namespace LibationWinForms.GridView
|
||||
var seriesEntries = bindingList.AllItems().SeriesEntries().ToList();
|
||||
var parentedEpisodes = dbBooks.ParentedEpisodes().ToHashSet();
|
||||
|
||||
bindingList.RaiseListChangedEvents = false;
|
||||
foreach (var libraryBook in dbBooks.OrderBy(e => e.DateAdded))
|
||||
{
|
||||
var existingEntry = allEntries.FindByAsin(libraryBook.Book.AudibleProductId);
|
||||
@ -216,8 +220,11 @@ namespace LibationWinForms.GridView
|
||||
AddOrUpdateEpisode(libraryBook, existingEntry, seriesEntries, dbBooks);
|
||||
}
|
||||
}
|
||||
bindingList.RaiseListChangedEvents = true;
|
||||
|
||||
//Re-apply filter after adding new/updating existing books to capture any changes
|
||||
//The Filter call also ensures that the binding list is reset so the DataGridView
|
||||
//is made aware of all changes that were made while RaiseListChangedEvents was false
|
||||
Filter(existingFilter);
|
||||
|
||||
#endregion
|
||||
@ -231,6 +238,8 @@ namespace LibationWinForms.GridView
|
||||
.ExceptBy(dbBooks.Select(lb => lb.Book.AudibleProductId), ge => ge.AudibleProductId);
|
||||
|
||||
RemoveBooks(removedBooks);
|
||||
|
||||
gridEntryDataGridView.FirstDisplayedScrollingRowIndex = topRow;
|
||||
}
|
||||
|
||||
public void RemoveBooks(IEnumerable<ILibraryBookEntry> removedBooks)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user