Refactor
This commit is contained in:
parent
4111d5fa48
commit
f8f5eac109
104
Source/LibationWinForms/Form1.RemoveBooks.cs
Normal file
104
Source/LibationWinForms/Form1.RemoveBooks.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
using AudibleUtilities;
|
||||||
|
using LibationWinForms.Dialogs;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace LibationWinForms
|
||||||
|
{
|
||||||
|
public partial class Form1
|
||||||
|
{
|
||||||
|
private ToolStripButton removeCheckedBtn = new();
|
||||||
|
public void Configure_RemoveBooks()
|
||||||
|
{
|
||||||
|
|
||||||
|
#region Create and Add Tool Strip Button
|
||||||
|
removeCheckedBtn.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
||||||
|
removeCheckedBtn.Name = "removeSelectedBtn";
|
||||||
|
removeCheckedBtn.Text = "Remove 0 Books";
|
||||||
|
removeCheckedBtn.AutoToolTip = false;
|
||||||
|
removeCheckedBtn.ToolTipText = "Remove checked books and series\r\nfrom Libation's database.\r\n\r\nThey will remain in your Audible account.";
|
||||||
|
removeCheckedBtn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
removeCheckedBtn.Alignment = ToolStripItemAlignment.Left;
|
||||||
|
removeCheckedBtn.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
removeCheckedBtn.Font = new System.Drawing.Font(removeCheckedBtn.Font, System.Drawing.FontStyle.Bold);
|
||||||
|
removeCheckedBtn.Click += (_, _) => productsDisplay.RemoveCheckedBooksAsync();
|
||||||
|
removeCheckedBtn.Visible = false;
|
||||||
|
statusStrip1.Items.Insert(1, removeCheckedBtn);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
productsDisplay.Filter(null);
|
||||||
|
|
||||||
|
removeCheckedBtn.Visible = true;
|
||||||
|
closeRemoveBooksColumnToolStripMenuItem.Visible = true;
|
||||||
|
await productsDisplay.ScanAndRemoveBooksAsync(accounts);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeRemoveBooksColumnToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
removeCheckedBtn.Visible = false;
|
||||||
|
closeRemoveBooksColumnToolStripMenuItem.Visible = false;
|
||||||
|
productsDisplay.CloseRemoveBooksColumn();
|
||||||
|
|
||||||
|
//Restore the filter
|
||||||
|
filterSearchTb.Enabled = true;
|
||||||
|
performFilter(filterSearchTb.Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void productsDisplay_RemovableCountChanged(object sender, int removeCount)
|
||||||
|
{
|
||||||
|
removeCheckedBtn.Text = removeCount switch
|
||||||
|
{
|
||||||
|
1 => "Remove 1 Book",
|
||||||
|
_ => $"Remove {removeCount} Books"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,27 +13,10 @@ namespace LibationWinForms
|
|||||||
// this is for manual scan/import. Unrelated to auto-scan
|
// this is for manual scan/import. Unrelated to auto-scan
|
||||||
public partial class Form1
|
public partial class Form1
|
||||||
{
|
{
|
||||||
|
|
||||||
private ToolStripButton removeCheckedBtn = new();
|
|
||||||
private void Configure_ScanManual()
|
private void Configure_ScanManual()
|
||||||
{
|
{
|
||||||
this.Load += refreshImportMenu;
|
this.Load += refreshImportMenu;
|
||||||
AccountsSettingsPersister.Saved += refreshImportMenu;
|
AccountsSettingsPersister.Saved += refreshImportMenu;
|
||||||
|
|
||||||
#region Create and Add Tool Strip Button
|
|
||||||
removeCheckedBtn.DisplayStyle = ToolStripItemDisplayStyle.Text;
|
|
||||||
removeCheckedBtn.Name = "removeSelectedBtn";
|
|
||||||
removeCheckedBtn.Text = "Remove 0 Books";
|
|
||||||
removeCheckedBtn.AutoToolTip = false;
|
|
||||||
removeCheckedBtn.ToolTipText = "Remove checked books and series\r\nfrom Libation's database.\r\n\r\nThey will remain in your Audible account.";
|
|
||||||
removeCheckedBtn.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
|
||||||
removeCheckedBtn.Alignment = ToolStripItemAlignment.Left;
|
|
||||||
removeCheckedBtn.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
removeCheckedBtn.Font = new System.Drawing.Font(removeCheckedBtn.Font, System.Drawing.FontStyle.Bold);
|
|
||||||
removeCheckedBtn.Click += (_, _) => productsDisplay.RemoveCheckedBooksAsync();
|
|
||||||
removeCheckedBtn.Visible = false;
|
|
||||||
statusStrip1.Items.Insert(1, removeCheckedBtn);
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshImportMenu(object _, EventArgs __)
|
private void refreshImportMenu(object _, EventArgs __)
|
||||||
@ -84,77 +67,7 @@ namespace LibationWinForms
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
await scanLibrariesAsync(scanAccountsDialog.CheckedAccounts);
|
await scanLibrariesAsync(scanAccountsDialog.CheckedAccounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
productsDisplay.Filter(null);
|
|
||||||
|
|
||||||
removeCheckedBtn.Visible = true;
|
|
||||||
closeRemoveBooksColumnToolStripMenuItem.Visible = true;
|
|
||||||
await productsDisplay.ScanAndRemoveBooksAsync(accounts);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeRemoveBooksColumnToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
removeCheckedBtn.Visible = false;
|
|
||||||
closeRemoveBooksColumnToolStripMenuItem.Visible = false;
|
|
||||||
productsDisplay.CloseRemoveBooksColumn();
|
|
||||||
|
|
||||||
//Restore the filter
|
|
||||||
filterSearchTb.Enabled = true;
|
|
||||||
performFilter(filterSearchTb.Text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void productsDisplay_RemovableCountChanged(object sender, int removeCount)
|
|
||||||
{
|
|
||||||
removeCheckedBtn.Text = removeCount switch
|
|
||||||
{
|
|
||||||
1 => "Remove 1 Book",
|
|
||||||
_ => $"Remove {removeCount} Books"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task scanLibrariesAsync(IEnumerable<Account> accounts) => await scanLibrariesAsync(accounts.ToArray());
|
private async Task scanLibrariesAsync(IEnumerable<Account> accounts) => await scanLibrariesAsync(accounts.ToArray());
|
||||||
private async Task scanLibrariesAsync(params Account[] accounts)
|
private async Task scanLibrariesAsync(params Account[] accounts)
|
||||||
|
|||||||
@ -44,6 +44,7 @@ namespace LibationWinForms
|
|||||||
Configure_VisibleBooks();
|
Configure_VisibleBooks();
|
||||||
Configure_QuickFilters();
|
Configure_QuickFilters();
|
||||||
Configure_ScanManual();
|
Configure_ScanManual();
|
||||||
|
Configure_RemoveBooks();
|
||||||
Configure_Liberate();
|
Configure_Liberate();
|
||||||
Configure_Export();
|
Configure_Export();
|
||||||
Configure_Settings();
|
Configure_Settings();
|
||||||
|
|||||||
@ -44,7 +44,7 @@
|
|||||||
this.productsGrid.CoverClicked += new LibationWinForms.GridView.GridEntryClickedEventHandler(this.productsGrid_CoverClicked);
|
this.productsGrid.CoverClicked += new LibationWinForms.GridView.GridEntryClickedEventHandler(this.productsGrid_CoverClicked);
|
||||||
this.productsGrid.DetailsClicked += new LibationWinForms.GridView.LibraryBookEntryClickedEventHandler(this.productsGrid_DetailsClicked);
|
this.productsGrid.DetailsClicked += new LibationWinForms.GridView.LibraryBookEntryClickedEventHandler(this.productsGrid_DetailsClicked);
|
||||||
this.productsGrid.DescriptionClicked += new LibationWinForms.GridView.GridEntryRectangleClickedEventHandler(this.productsGrid_DescriptionClicked);
|
this.productsGrid.DescriptionClicked += new LibationWinForms.GridView.GridEntryRectangleClickedEventHandler(this.productsGrid_DescriptionClicked);
|
||||||
this.productsGrid.RemovableCountChanged += new LibationWinForms.GridView.GridEntryClickedEventHandler(this.productsGrid_RemovableCountChanged);
|
this.productsGrid.RemovableCountChanged += new System.EventHandler(this.productsGrid_RemovableCountChanged);
|
||||||
//
|
//
|
||||||
// ProductsDisplay
|
// ProductsDisplay
|
||||||
//
|
//
|
||||||
|
|||||||
@ -82,7 +82,7 @@ namespace LibationWinForms.GridView
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UI display functions
|
#region Scan and Remove Books
|
||||||
|
|
||||||
public void CloseRemoveBooksColumn()
|
public void CloseRemoveBooksColumn()
|
||||||
=> productsGrid.RemoveColumnVisible = false;
|
=> productsGrid.RemoveColumnVisible = false;
|
||||||
@ -127,7 +127,7 @@ namespace LibationWinForms.GridView
|
|||||||
foreach (var r in removable)
|
foreach (var r in removable)
|
||||||
r.Remove = RemoveStatus.Removed;
|
r.Remove = RemoveStatus.Removed;
|
||||||
|
|
||||||
productsGrid_RemovableCountChanged(null);
|
productsGrid_RemovableCountChanged(this, null);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -139,6 +139,10 @@ namespace LibationWinForms.GridView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region UI display functions
|
||||||
|
|
||||||
public void Display()
|
public void Display()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -183,9 +187,9 @@ namespace LibationWinForms.GridView
|
|||||||
LiberateClicked?.Invoke(this, liveGridEntry.LibraryBook);
|
LiberateClicked?.Invoke(this, liveGridEntry.LibraryBook);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void productsGrid_RemovableCountChanged(GridEntry liveGridEntry)
|
private void productsGrid_RemovableCountChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
RemovableCountChanged?.Invoke(this, productsGrid.GetAllBookEntries().Count(lbe => lbe.Remove is RemoveStatus.Removed));
|
RemovableCountChanged?.Invoke(sender, productsGrid.GetAllBookEntries().Count(lbe => lbe.Remove is RemoveStatus.Removed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace LibationWinForms.GridView
|
|||||||
public event LibraryBookEntryClickedEventHandler DetailsClicked;
|
public event LibraryBookEntryClickedEventHandler DetailsClicked;
|
||||||
public event GridEntryRectangleClickedEventHandler DescriptionClicked;
|
public event GridEntryRectangleClickedEventHandler DescriptionClicked;
|
||||||
public new event EventHandler<ScrollEventArgs> Scroll;
|
public new event EventHandler<ScrollEventArgs> Scroll;
|
||||||
public event GridEntryClickedEventHandler RemovableCountChanged;
|
public event EventHandler RemovableCountChanged;
|
||||||
|
|
||||||
private GridEntryBindingList bindingList;
|
private GridEntryBindingList bindingList;
|
||||||
internal IEnumerable<LibraryBook> GetVisibleBooks()
|
internal IEnumerable<LibraryBook> GetVisibleBooks()
|
||||||
@ -88,7 +88,7 @@ namespace LibationWinForms.GridView
|
|||||||
if (e.ColumnIndex == removeGVColumn.Index)
|
if (e.ColumnIndex == removeGVColumn.Index)
|
||||||
{
|
{
|
||||||
gridEntryDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
|
gridEntryDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
|
||||||
RemovableCountChanged?.Invoke(entry);
|
RemovableCountChanged?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user