* Bug fix: grid doesn't update correctly if all books are removed

* Beginning (incomplete) new menu for batch actions on visible books
This commit is contained in:
Robert McRackan 2022-05-11 10:13:07 -04:00
parent e368e4669b
commit c3871d3bca
4 changed files with 177 additions and 115 deletions

View file

@ -18,10 +18,16 @@ namespace LibationWinForms
private string beginBookBackupsToolStripMenuItem_format { get; }
private string beginPdfBackupsToolStripMenuItem_format { get; }
private ProductsGrid productsGrid { get; }
public Form1()
{
InitializeComponent();
productsGrid = new ProductsGrid { Dock = DockStyle.Fill };
gridPanel.Controls.Add(productsGrid);
productsGrid.VisibleCountChanged += setVisibleCount;
// back up string formats
beginBookBackupsToolStripMenuItem_format = beginBookBackupsToolStripMenuItem.Text;
beginPdfBackupsToolStripMenuItem_format = beginPdfBackupsToolStripMenuItem.Text;
@ -44,6 +50,8 @@ namespace LibationWinForms
configAndInitAutoScan();
configVisibleBooksMenu();
// init default/placeholder cover art
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
@ -69,42 +77,14 @@ namespace LibationWinForms
// suppressed filter while init'ing UI
var prev_isProcessingGridSelect = isProcessingGridSelect;
isProcessingGridSelect = true;
this.UIThreadSync(setGrid);
this.UIThreadSync(() => productsGrid.Display());
isProcessingGridSelect = prev_isProcessingGridSelect;
// UI init complete. now we can apply filter
this.UIThreadAsync(() => doFilter(lastGoodFilter));
setBackupCounts(null, null);
}
#region reload grid
private ProductsGrid productsGrid;
private void setGrid()
{
SuspendLayout();
{
// previous non-null grid with zero-count removes columns. remove/re-add grid to get columns back
if (productsGrid?.Count == 0)
{
gridPanel.Controls.Remove(productsGrid);
productsGrid.VisibleCountChanged -= setVisibleCount;
productsGrid.Dispose();
productsGrid = null;
}
if (productsGrid is null)
{
productsGrid = new ProductsGrid { Dock = DockStyle.Fill };
productsGrid.VisibleCountChanged += setVisibleCount;
gridPanel.UIThreadSync(() => gridPanel.Controls.Add(productsGrid));
}
productsGrid.Display();
}
ResumeLayout();
}
#endregion
setBackupCounts();
}
#region bottom: qty books visible
private void setVisibleCount(object _, int qty) => visibleCountLbl.Text = string.Format("Visible: {0}", qty);
@ -114,7 +94,7 @@ namespace LibationWinForms
private System.ComponentModel.BackgroundWorker updateCountsBw;
private bool runBackupCountsAgain;
private void setBackupCounts(object _, object __)
private void setBackupCounts(object _ = null, object __ = null)
{
runBackupCountsAgain = true;
@ -537,6 +517,41 @@ namespace LibationWinForms
private void EditQuickFiltersToolStripMenuItem_Click(object sender, EventArgs e) => new EditQuickFilters(this).ShowDialog();
#endregion
#region Visible Books menu
private void configVisibleBooksMenu()
{
}
private async void liberateToolStripMenuItem1_Click(object sender, EventArgs e)
{
var visibleBooks = productsGrid.GetVisible().ToList();
await BookLiberation.ProcessorAutomationController.BackupAllBooksAsync(visibleBooks);
}
private void replaceTagsToolStripMenuItem_Click(object sender, EventArgs e)
{
var visibleLibraryBooks = productsGrid.GetVisible().ToList();
foreach (var libraryBook in visibleLibraryBooks)
libraryBook.Book.UserDefinedItem.Tags = "ggggg";
LibraryCommands.UpdateUserDefinedItem(visibleLibraryBooks.Select(lb => lb.Book));
}
private void setDownloadedToolStripMenuItem_Click(object sender, EventArgs e)
{
var visibleLibraryBooks = productsGrid.GetVisible().ToList();
foreach (var libraryBook in visibleLibraryBooks)
libraryBook.Book.UserDefinedItem.BookStatus = DataLayer.LiberatedStatus.NotLiberated;
LibraryCommands.UpdateUserDefinedItem(visibleLibraryBooks.Select(lb => lb.Book));
}
private async void removeToolStripMenuItem_Click(object sender, EventArgs e)
{
var visibleIds = productsGrid.GetVisible().Select(lb => lb.Book.AudibleProductId).ToList();
await LibraryCommands.RemoveBooksAsync(visibleIds);
}
#endregion
#region Settings menu
private void accountsToolStripMenuItem_Click(object sender, EventArgs e) => new AccountsDialog(this).ShowDialog();