mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-12 21:57:19 -04:00
Removal is a soft delete and nothing on screen said so. GetLibrary() filters !IsDeleted, so a trashed book leaves the grid, the search index and every status count at once, with no indication it still exists. In #1925 a purchased book sat in the trash for a week while the reporter and I looked everywhere else for it. Add a status bar segment reading '29 in trash' that opens the trash bin when clicked, and put the same count on the Settings > Trash Bin menu item. Both hide themselves when the trash is empty, which is the normal case and says nothing worth screen space. The count is a separate query rather than part of LibraryStats: GetCounts also runs against the visible subset on every filter change, where a database round trip would be wasted work. GetLibraryBookCountsByTrashFlag already existed and counts rows without loading entities. Refreshed on LibrarySizeChanged, which both removal and restore already fire, and after the trash bin dialog closes. Wording lives in LibationUiBase.TrashBinUi so Avalonia and WinForms agree. Co-authored-by: rmcrackan <rmcrackan@gmail.com>
99 lines
2.9 KiB
C#
99 lines
2.9 KiB
C#
using AudibleUtilities;
|
|
using LibationWinForms.Dialogs;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace LibationWinForms;
|
|
|
|
public partial class Form1
|
|
{
|
|
public void Configure_RemoveBooks() { }
|
|
|
|
private async void removeBooksBtn_Click(object sender, EventArgs e)
|
|
=> await productsDisplay.RemoveCheckedBooksAsync();
|
|
|
|
private void openTrashBinToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
new TrashBinDialog().ShowDialog(this);
|
|
//Restoring or permanently deleting inside the dialog changes the count behind it.
|
|
refreshBooksInTrash();
|
|
}
|
|
|
|
private void trashBinLbl_Click(object sender, EventArgs e)
|
|
=> openTrashBinToolStripMenuItem_Click(sender, e);
|
|
|
|
private void doneRemovingBtn_Click(object sender, EventArgs e)
|
|
{
|
|
removeBooksBtn.Visible = false;
|
|
doneRemovingBtn.Visible = false;
|
|
|
|
productsDisplay.CloseRemoveBooksColumn();
|
|
|
|
//Restore the filter
|
|
filterSearchTb.Enabled = true;
|
|
filterSearchTb.Visible = true;
|
|
performFilter(filterSearchTb.Text);
|
|
}
|
|
|
|
private void removeLibraryBooksToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
// if 0 accounts, this will not be visible
|
|
// if 1 account, run scanLibrariesRemovedBooks() on this account
|
|
// if multiple accounts, another menu set will open. do not run scanLibrariesRemovedBooks()
|
|
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
|
var accounts = persister.AccountsSettings.GetAll();
|
|
|
|
if (accounts.Count != 1)
|
|
return;
|
|
|
|
var firstAccount = accounts.Single();
|
|
scanLibrariesRemovedBooks(firstAccount);
|
|
}
|
|
|
|
// selectively remove books from all accounts
|
|
private void removeAllAccountsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
|
var allAccounts = persister.AccountsSettings.GetAll();
|
|
scanLibrariesRemovedBooks(allAccounts.ToArray());
|
|
}
|
|
|
|
// selectively remove books from some accounts
|
|
private void removeSomeAccountsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
using var scanAccountsDialog = new ScanAccountsDialog();
|
|
|
|
if (scanAccountsDialog.ShowDialog() != DialogResult.OK)
|
|
return;
|
|
|
|
if (!scanAccountsDialog.CheckedAccounts.Any())
|
|
return;
|
|
|
|
scanLibrariesRemovedBooks(scanAccountsDialog.CheckedAccounts.ToArray());
|
|
}
|
|
|
|
private async void scanLibrariesRemovedBooks(params Account[] accounts)
|
|
{
|
|
//This action is meant to operate on the entire library.
|
|
//For removing books within a filter set, use
|
|
//Visible Books > Remove from library
|
|
filterSearchTb.Enabled = false;
|
|
filterSearchTb.Visible = false;
|
|
productsDisplay.Filter(null);
|
|
|
|
removeBooksBtn.Visible = true;
|
|
doneRemovingBtn.Visible = true;
|
|
await productsDisplay.ScanAndRemoveBooksAsync(accounts);
|
|
}
|
|
|
|
private void productsDisplay_RemovableCountChanged(object sender, int removeCount)
|
|
{
|
|
removeBooksBtn.Text = removeCount switch
|
|
{
|
|
1 => "Remove 1 Book from Libation",
|
|
_ => $"Remove {removeCount} Books from Libation"
|
|
};
|
|
}
|
|
}
|