|
|
@@ -1,5 +1,6 @@
|
|
|
using System.Collections;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.Collections.Specialized;
|
|
|
using System.ComponentModel;
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
using System.Linq.Expressions;
|
|
|
@@ -111,7 +112,11 @@ namespace InABox.Avalonia
|
|
|
protected CoreRepository(IModelHost host, Func<Filter<TEntity>> filter, Func<string>? filename = null)
|
|
|
{
|
|
|
AllItems = new CoreObservableCollection<TItem>();
|
|
|
- AllItems.CollectionChanged += (sender, args) => ItemsChanged(AllItems);
|
|
|
+ AllItems.CollectionChanged += (sender, args) =>
|
|
|
+ {
|
|
|
+ _items = null;
|
|
|
+ ItemsChanged(AllItems);
|
|
|
+ };
|
|
|
// EnableSynchronization(AllItems);
|
|
|
|
|
|
//Items = new CoreObservableCollection<TItem>();
|
|
|
@@ -325,7 +330,15 @@ namespace InABox.Avalonia
|
|
|
|
|
|
private CoreTable _table = new CoreTable();
|
|
|
|
|
|
- public IEnumerable<TItem> Items => SearchAndSort();
|
|
|
+ private IEnumerable<TItem>? _items;
|
|
|
+ public IEnumerable<TItem> Items
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ _items ??= SearchAndSort();
|
|
|
+ return _items;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public int ItemCount => Items.Count();
|
|
|
|
|
|
@@ -398,14 +411,33 @@ namespace InABox.Avalonia
|
|
|
void ICoreRepository.ToggleSelection(object item) => ToggleSelection(item as TItem);
|
|
|
bool ICoreRepository.IsSelected(object item) => IsSelected(item as TItem);
|
|
|
void ICoreRepository.SetSelectedItems(IEnumerable<object> items) => SetSelectedItems(items.OfType<TItem>());
|
|
|
-
|
|
|
+
|
|
|
#endregion
|
|
|
-
|
|
|
+
|
|
|
#region Searching
|
|
|
-
|
|
|
- public Func<TItem, bool>? SearchPredicate { get; set; }
|
|
|
-
|
|
|
- public Func<List<TItem>,List<TItem>>? SortPredicate { get; set; }
|
|
|
+
|
|
|
+ private Func<TItem, bool>? _searchPredicate;
|
|
|
+ public Func<TItem, bool>? SearchPredicate
|
|
|
+ {
|
|
|
+ get => _searchPredicate;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _searchPredicate = value;
|
|
|
+ _items = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Func<List<TItem>, List<TItem>>? _sortPredicate;
|
|
|
+ public Func<List<TItem>,List<TItem>>? SortPredicate
|
|
|
+ {
|
|
|
+ get => _sortPredicate;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _sortPredicate = value;
|
|
|
+ _items = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public ICoreRepository Search(Func<TItem, bool> searchpredicate, Func<List<TItem>,List<TItem>> sortpredicate)
|
|
|
{
|
|
|
@@ -446,6 +478,7 @@ namespace InABox.Avalonia
|
|
|
|
|
|
public ICoreRepository Search()
|
|
|
{
|
|
|
+ _items = null;
|
|
|
OnPropertyChanged(nameof(Items));
|
|
|
OnPropertyChanged(nameof(ItemCount));
|
|
|
return this;
|
|
|
@@ -692,7 +725,7 @@ namespace InABox.Avalonia
|
|
|
#region CRUD Operations
|
|
|
|
|
|
public event CoreRepositoryItemCreatedEvent<TItem>? ItemAdded;
|
|
|
-
|
|
|
+
|
|
|
private T CreateItem<T>(CoreRow row)
|
|
|
where T : Shell<TParent,TEntity>, new()
|
|
|
{
|