Fix hang on grid update

This commit is contained in:
Michael Bucari-Tovo 2022-05-24 13:16:44 -06:00
parent b37472a954
commit 777dfe4c62
4 changed files with 15 additions and 10 deletions

View File

@ -33,17 +33,11 @@ namespace LibationWinForms
{ {
liberateVisibleToolStripMenuItem.Format(notLiberated); liberateVisibleToolStripMenuItem.Format(notLiberated);
liberateVisibleToolStripMenuItem.Enabled = true; liberateVisibleToolStripMenuItem.Enabled = true;
liberateVisible2ToolStripMenuItem.Format(notLiberated);
liberateVisible2ToolStripMenuItem.Enabled = true;
} }
else else
{ {
liberateVisibleToolStripMenuItem.Text = "All visible books are liberated"; liberateVisibleToolStripMenuItem.Text = "All visible books are liberated";
liberateVisibleToolStripMenuItem.Enabled = false; liberateVisibleToolStripMenuItem.Enabled = false;
liberateVisible2ToolStripMenuItem.Text = "All visible books are liberated";
liberateVisible2ToolStripMenuItem.Enabled = false;
} }
}); });
} }

View File

@ -30,6 +30,9 @@ namespace LibationWinForms.GridView
public bool SupportsFiltering => true; public bool SupportsFiltering => true;
public string Filter { get => FilterString; set => ApplyFilter(value); } public string Filter { get => FilterString; set => ApplyFilter(value); }
/// <summary>When true, itms will not be checked filtered by search criteria on item changed<summary>
public bool SuspendFilteringOnUpdate { get; set; }
protected MemberComparer<GridEntry> Comparer { get; } = new(); protected MemberComparer<GridEntry> Comparer { get; } = new();
protected override bool SupportsSortingCore => true; protected override bool SupportsSortingCore => true;
protected override bool SupportsSearchingCore => true; protected override bool SupportsSearchingCore => true;
@ -195,7 +198,7 @@ namespace LibationWinForms.GridView
{ {
if (e.ListChangedType == ListChangedType.ItemChanged) if (e.ListChangedType == ListChangedType.ItemChanged)
{ {
if (Items[e.NewIndex] is LibraryBookEntry lbItem) if (FilterString is not null && !SuspendFilteringOnUpdate && Items[e.NewIndex] is LibraryBookEntry lbItem)
{ {
SearchResults = SearchEngineCommands.Search(FilterString); SearchResults = SearchEngineCommands.Search(FilterString);
if (!SearchResults.Docs.Any(d => d.ProductId == lbItem.AudibleProductId)) if (!SearchResults.Docs.Any(d => d.ProductId == lbItem.AudibleProductId))

View File

@ -63,7 +63,11 @@ namespace LibationWinForms.GridView
} }
#endregion #endregion
public LibraryBookEntry(LibraryBook libraryBook) => setLibraryBook(libraryBook); public LibraryBookEntry(LibraryBook libraryBook)
{
setLibraryBook(libraryBook);
LoadCover();
}
public SeriesEntry Parent { get; init; } public SeriesEntry Parent { get; init; }
public void UpdateLibraryBook(LibraryBook libraryBook) public void UpdateLibraryBook(LibraryBook libraryBook)
@ -80,7 +84,7 @@ namespace LibationWinForms.GridView
{ {
LibraryBook = libraryBook; LibraryBook = libraryBook;
LoadCover(); UserDefinedItem.ItemChanged -= UserDefinedItem_ItemChanged;
// Immutable properties // Immutable properties
{ {

View File

@ -105,6 +105,8 @@ namespace LibationWinForms.GridView
string existingFilter = syncBindingSource.Filter; string existingFilter = syncBindingSource.Filter;
Filter(null); Filter(null);
bindingList.SuspendFilteringOnUpdate = true;
//Add absent books to grid, or update current books //Add absent books to grid, or update current books
var allItmes = bindingList.AllItems().LibraryBooks(); var allItmes = bindingList.AllItems().LibraryBooks();
@ -157,6 +159,8 @@ namespace LibationWinForms.GridView
} }
} }
bindingList.SuspendFilteringOnUpdate = false;
//Re-filter after updating existing / adding new books to capture any changes //Re-filter after updating existing / adding new books to capture any changes
Filter(existingFilter); Filter(existingFilter);