Files
Libation/Source/LibationAvalonia/ViewModels/MainVM.cs
T
Cursor Agentandrmcrackan 4df08d383a Show when the trash is not empty
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>
2026-08-18 18:19:37 +00:00

66 lines
2.0 KiB
C#

using ApplicationServices;
using DataLayer;
using LibationAvalonia.Views;
using LibationFileManager;
using LibationUiBase.ProcessQueue;
using ReactiveUI;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LibationAvalonia.ViewModels;
public partial class MainVM : ViewModelBase
{
public Task? BindToGridTask { get; set; }
public ProcessQueueViewModel ProcessQueue { get; } = new ProcessQueueViewModel();
public ProductsDisplayViewModel ProductsDisplay { get; } = new() { SearchEngine = MainSearchEngine.Instance };
public double? DownloadProgress { get => field; set => this.RaiseAndSetIfChanged(ref field, value); }
private readonly MainWindow MainWindow;
public MainVM(MainWindow mainWindow)
{
MainWindow = mainWindow;
ProductsDisplay.RemovableCountChanged += (_, removeCount) => RemoveBooksButtonText = removeCount == 1 ? "Remove 1 Book from Libation" : $"Remove {removeCount} Books from Libation";
LibraryCommands.LibrarySizeChanged += LibraryCommands_LibrarySizeChanged;
Configure_NonUI();
Configure_BackupCounts();
Configure_Export();
Configure_Filters();
Configure_Import();
Configure_Liberate();
Configure_ProcessQueue();
Configure_ScanAuto();
Configure_SearchIndex();
Configure_Settings();
Configure_VisibleBooks();
}
private async void LibraryCommands_LibrarySizeChanged(object? sender, List<LibraryBook> fullLibrary)
{
try
{
//Prevent race condition which can occur if an auto-scan
//completes before the initial grid binding completes.
if (BindToGridTask is null)
return;
else if (BindToGridTask.IsCompleted is false)
await BindToGridTask;
await Task.WhenAll(
SetBackupCountsAsync(fullLibrary),
RefreshBooksInTrashAsync(),
Task.Run(() => ProductsDisplay.UpdateGridAsync(fullLibrary)));
}
catch (System.Exception ex)
{
await MessageBox.ShowAdminAlert(MainWindow, "An error occurred while updating the library.", "Library Size Change Error", ex);
}
}
private static string menufyText(string header) => Configuration.IsMacOs ? header : $"_{header}";
}