diff --git a/Source/HangoverAvalonia/App.axaml b/Source/HangoverAvalonia/App.axaml
index 0534c7e8..6908440c 100644
--- a/Source/HangoverAvalonia/App.axaml
+++ b/Source/HangoverAvalonia/App.axaml
@@ -6,7 +6,30 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/HangoverAvalonia/ViewModels/MainVM.Deleted.cs b/Source/HangoverAvalonia/ViewModels/MainVM.Deleted.cs
index 2c376fd7..827445d0 100644
--- a/Source/HangoverAvalonia/ViewModels/MainVM.Deleted.cs
+++ b/Source/HangoverAvalonia/ViewModels/MainVM.Deleted.cs
@@ -1,41 +1,8 @@
-using ApplicationServices;
-using DataLayer;
-using ReactiveUI;
-using System.Collections.Generic;
+namespace HangoverAvalonia.ViewModels;
-namespace HangoverAvalonia.ViewModels
+public partial class MainVM
{
- public partial class MainVM
- {
- private List _deletedBooks;
- public List DeletedBooks { get => _deletedBooks; set => this.RaiseAndSetIfChanged(ref _deletedBooks, value); }
- public string CheckedCountText => $"Checked : {_checkedBooksCount} of {_totalBooksCount}";
+ public TrashBinViewModel TrashBinViewModel { get; } = new();
- private int _totalBooksCount = 0;
- private int _checkedBooksCount = 0;
- public int CheckedBooksCount
- {
- get => _checkedBooksCount;
- set
- {
- if (_checkedBooksCount != value)
- {
- _checkedBooksCount = value;
- this.RaisePropertyChanged(nameof(CheckedCountText));
- }
- }
- }
- private void Load_deletedVM()
- {
- reload();
- }
-
- public void reload()
- {
- DeletedBooks = DbContexts.GetContext().GetDeletedLibraryBooks();
- _checkedBooksCount = 0;
- _totalBooksCount = DeletedBooks.Count;
- this.RaisePropertyChanged(nameof(CheckedCountText));
- }
- }
+ private void Load_deletedVM() { }
}
diff --git a/Source/HangoverAvalonia/ViewModels/TrashBinViewModel.cs b/Source/HangoverAvalonia/ViewModels/TrashBinViewModel.cs
new file mode 100644
index 00000000..22b5d15b
--- /dev/null
+++ b/Source/HangoverAvalonia/ViewModels/TrashBinViewModel.cs
@@ -0,0 +1,117 @@
+using ApplicationServices;
+using Avalonia.Collections;
+using DataLayer;
+using ReactiveUI;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace HangoverAvalonia.ViewModels;
+
+public class TrashBinViewModel : ViewModelBase, IDisposable
+{
+ public AvaloniaList DeletedBooks { get; }
+ public string CheckedCountText => $"Checked : {_checkedBooksCount} of {_totalBooksCount}";
+
+ private bool _controlsEnabled = true;
+ public bool ControlsEnabled { get => _controlsEnabled; set => this.RaiseAndSetIfChanged(ref _controlsEnabled, value); }
+
+ private bool? everythingChecked = false;
+ public bool? EverythingChecked
+ {
+ get => everythingChecked;
+ set
+ {
+ everythingChecked = value ?? false;
+
+ if (everythingChecked is true)
+ CheckAll();
+ else if (everythingChecked is false)
+ UncheckAll();
+ }
+ }
+
+ private int _totalBooksCount = 0;
+ private int _checkedBooksCount = -1;
+ public int CheckedBooksCount
+ {
+ get => _checkedBooksCount;
+ set
+ {
+ _checkedBooksCount = value;
+ this.RaisePropertyChanged(nameof(CheckedCountText));
+
+ everythingChecked
+ = _checkedBooksCount == 0 || _totalBooksCount == 0 ? false
+ : _checkedBooksCount == _totalBooksCount ? true
+ : null;
+
+ this.RaisePropertyChanged(nameof(EverythingChecked));
+ }
+ }
+
+ public IEnumerable CheckedBooks => DeletedBooks.Where(i => i.IsChecked).Select(i => i.Item).Cast();
+
+ public TrashBinViewModel()
+ {
+ DeletedBooks = new()
+ {
+ ResetBehavior = ResetBehavior.Remove
+ };
+
+ tracker = DeletedBooks.TrackItemPropertyChanged(CheckboxPropertyChanged);
+ Reload();
+ }
+
+ public void CheckAll()
+ {
+ foreach (var item in DeletedBooks)
+ item.IsChecked = true;
+ }
+
+ public void UncheckAll()
+ {
+ foreach (var item in DeletedBooks)
+ item.IsChecked = false;
+ }
+
+ public async Task RestoreCheckedAsync()
+ {
+ ControlsEnabled = false;
+ var qtyChanges = await Task.Run(CheckedBooks.RestoreBooks);
+ if (qtyChanges > 0)
+ Reload();
+ ControlsEnabled = true;
+ }
+
+ public async Task PermanentlyDeleteCheckedAsync()
+ {
+ ControlsEnabled = false;
+ var qtyChanges = await Task.Run(CheckedBooks.PermanentlyDeleteBooks);
+ if (qtyChanges > 0)
+ Reload();
+ ControlsEnabled = true;
+ }
+
+ public void Reload()
+ {
+ var deletedBooks = DbContexts.GetContext().GetDeletedLibraryBooks();
+
+ DeletedBooks.Clear();
+ DeletedBooks.AddRange(deletedBooks.Select(lb => new CheckBoxViewModel { Item = lb }));
+
+ _totalBooksCount = DeletedBooks.Count;
+ CheckedBooksCount = 0;
+ }
+
+ private IDisposable tracker;
+ private void CheckboxPropertyChanged(Tuple