Optimization
This commit is contained in:
parent
e1e265a101
commit
98a552e9af
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -8,8 +7,6 @@ using System.Windows.Forms;
|
|||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
using DataLayer;
|
using DataLayer;
|
||||||
using Dinah.Core;
|
using Dinah.Core;
|
||||||
using Dinah.Core.DataBinding;
|
|
||||||
using Dinah.Core.Threading;
|
|
||||||
using Dinah.Core.Windows.Forms;
|
using Dinah.Core.Windows.Forms;
|
||||||
using FileLiberator;
|
using FileLiberator;
|
||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
@ -181,15 +178,16 @@ namespace LibationWinForms
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindToGrid(List<LibraryBook> orderedBooks)
|
private void bindToGrid(List<LibraryBook> dbBooks)
|
||||||
{
|
{
|
||||||
bindingList = new SortableFilterableBindingList(orderedBooks.OrderByDescending(lb => lb.DateAdded).Select(lb => new GridEntry(lb)));
|
bindingList = new SortableFilterableBindingList(dbBooks.OrderByDescending(lb => lb.DateAdded).Select(lb => new GridEntry(lb)));
|
||||||
gridEntryBindingSource.DataSource = bindingList;
|
gridEntryBindingSource.DataSource = bindingList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGrid(List<LibraryBook> dbBooks)
|
private void updateGrid(List<LibraryBook> dbBooks)
|
||||||
{
|
{
|
||||||
int visibleCount = bindingList.Count;
|
int visibleCount = bindingList.Count;
|
||||||
|
string existingFilter = gridEntryBindingSource.Filter;
|
||||||
|
|
||||||
//Add absent books to grid, or update current books
|
//Add absent books to grid, or update current books
|
||||||
for (var i = dbBooks.Count - 1; i >= 0; i--)
|
for (var i = dbBooks.Count - 1; i >= 0; i--)
|
||||||
@ -205,10 +203,12 @@ namespace LibationWinForms
|
|||||||
existingItem.UpdateLibraryBook(libraryBook);
|
existingItem.UpdateLibraryBook(libraryBook);
|
||||||
}
|
}
|
||||||
|
|
||||||
//refilter for newly added items
|
if (bindingList.Count != visibleCount)
|
||||||
string existingFilter = gridEntryBindingSource.Filter;
|
{
|
||||||
Filter(null);
|
//refilter for newly added items
|
||||||
Filter(existingFilter);
|
Filter(null);
|
||||||
|
Filter(existingFilter);
|
||||||
|
}
|
||||||
|
|
||||||
// remove deleted from grid.
|
// remove deleted from grid.
|
||||||
// note: actual deletion from db must still occur via the RemoveBook feature. deleting from audible will not trigger this
|
// note: actual deletion from db must still occur via the RemoveBook feature. deleting from audible will not trigger this
|
||||||
@ -219,6 +219,7 @@ namespace LibationWinForms
|
|||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
foreach (var removed in removedBooks)
|
foreach (var removed in removedBooks)
|
||||||
|
//no need to re-filter for removed books
|
||||||
bindingList.Remove(removed);
|
bindingList.Remove(removed);
|
||||||
|
|
||||||
if (bindingList.Count != visibleCount)
|
if (bindingList.Count != visibleCount)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user