From 777dfe4c62962cb01a1b863c12bf4d348ed14a0c Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Tue, 24 May 2022 13:16:44 -0600 Subject: [PATCH 1/2] Fix hang on grid update --- Source/LibationWinForms/Form1.VisibleBooks.cs | 6 ------ .../LibationWinForms/GridView/GridEntryBindingList.cs | 5 ++++- Source/LibationWinForms/GridView/LibraryBookEntry.cs | 10 +++++++--- Source/LibationWinForms/GridView/ProductsGrid.cs | 4 ++++ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Source/LibationWinForms/Form1.VisibleBooks.cs b/Source/LibationWinForms/Form1.VisibleBooks.cs index a17effa7..93ee1011 100644 --- a/Source/LibationWinForms/Form1.VisibleBooks.cs +++ b/Source/LibationWinForms/Form1.VisibleBooks.cs @@ -33,17 +33,11 @@ namespace LibationWinForms { liberateVisibleToolStripMenuItem.Format(notLiberated); liberateVisibleToolStripMenuItem.Enabled = true; - - liberateVisible2ToolStripMenuItem.Format(notLiberated); - liberateVisible2ToolStripMenuItem.Enabled = true; } else { liberateVisibleToolStripMenuItem.Text = "All visible books are liberated"; liberateVisibleToolStripMenuItem.Enabled = false; - - liberateVisible2ToolStripMenuItem.Text = "All visible books are liberated"; - liberateVisible2ToolStripMenuItem.Enabled = false; } }); } diff --git a/Source/LibationWinForms/GridView/GridEntryBindingList.cs b/Source/LibationWinForms/GridView/GridEntryBindingList.cs index b5ee0f8f..58be850c 100644 --- a/Source/LibationWinForms/GridView/GridEntryBindingList.cs +++ b/Source/LibationWinForms/GridView/GridEntryBindingList.cs @@ -30,6 +30,9 @@ namespace LibationWinForms.GridView public bool SupportsFiltering => true; public string Filter { get => FilterString; set => ApplyFilter(value); } + /// When true, itms will not be checked filtered by search criteria on item changed + public bool SuspendFilteringOnUpdate { get; set; } + protected MemberComparer Comparer { get; } = new(); protected override bool SupportsSortingCore => true; protected override bool SupportsSearchingCore => true; @@ -195,7 +198,7 @@ namespace LibationWinForms.GridView { 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); if (!SearchResults.Docs.Any(d => d.ProductId == lbItem.AudibleProductId)) diff --git a/Source/LibationWinForms/GridView/LibraryBookEntry.cs b/Source/LibationWinForms/GridView/LibraryBookEntry.cs index 6a312ea1..848c9e4f 100644 --- a/Source/LibationWinForms/GridView/LibraryBookEntry.cs +++ b/Source/LibationWinForms/GridView/LibraryBookEntry.cs @@ -63,7 +63,11 @@ namespace LibationWinForms.GridView } #endregion - public LibraryBookEntry(LibraryBook libraryBook) => setLibraryBook(libraryBook); + public LibraryBookEntry(LibraryBook libraryBook) + { + setLibraryBook(libraryBook); + LoadCover(); + } public SeriesEntry Parent { get; init; } public void UpdateLibraryBook(LibraryBook libraryBook) @@ -78,9 +82,9 @@ namespace LibationWinForms.GridView private void setLibraryBook(LibraryBook libraryBook) { - LibraryBook = libraryBook; + LibraryBook = libraryBook; - LoadCover(); + UserDefinedItem.ItemChanged -= UserDefinedItem_ItemChanged; // Immutable properties { diff --git a/Source/LibationWinForms/GridView/ProductsGrid.cs b/Source/LibationWinForms/GridView/ProductsGrid.cs index a715eb8e..99c52788 100644 --- a/Source/LibationWinForms/GridView/ProductsGrid.cs +++ b/Source/LibationWinForms/GridView/ProductsGrid.cs @@ -105,6 +105,8 @@ namespace LibationWinForms.GridView string existingFilter = syncBindingSource.Filter; Filter(null); + bindingList.SuspendFilteringOnUpdate = true; + //Add absent books to grid, or update current books 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 Filter(existingFilter); From 8f5467e6cae65e7b660df78b1e306c6e9cfcf43d Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Tue, 24 May 2022 13:30:39 -0600 Subject: [PATCH 2/2] Revert stupid change. --- Source/LibationWinForms/Form1.VisibleBooks.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/LibationWinForms/Form1.VisibleBooks.cs b/Source/LibationWinForms/Form1.VisibleBooks.cs index 93ee1011..a17effa7 100644 --- a/Source/LibationWinForms/Form1.VisibleBooks.cs +++ b/Source/LibationWinForms/Form1.VisibleBooks.cs @@ -33,11 +33,17 @@ namespace LibationWinForms { liberateVisibleToolStripMenuItem.Format(notLiberated); liberateVisibleToolStripMenuItem.Enabled = true; + + liberateVisible2ToolStripMenuItem.Format(notLiberated); + liberateVisible2ToolStripMenuItem.Enabled = true; } else { liberateVisibleToolStripMenuItem.Text = "All visible books are liberated"; liberateVisibleToolStripMenuItem.Enabled = false; + + liberateVisible2ToolStripMenuItem.Text = "All visible books are liberated"; + liberateVisible2ToolStripMenuItem.Enabled = false; } }); }