Removed backup async lazy-loading collection, the queueing variant in now proven; added ItemFetched event so users can run additional processing when items have been fetched from the dataabse; fixed message presenter, yes/no and ok/cancel messages are now centered and parented to the main window as well

This commit is contained in:
Markus Ewald 2025-07-31 10:01:38 +02:00
parent d969811427
commit 76a31e15f4
4 changed files with 30 additions and 832 deletions

View file

@ -26,7 +26,6 @@ using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Collections.Concurrent;
#if !NO_SPECIALIZED_COLLECTIONS
using System.Collections.Specialized;
#endif
@ -172,6 +171,9 @@ namespace Nuclex.Avalonia.Collections {
/// <summary>Raised when the collection has been cleared</summary>
public event EventHandler? Cleared { add {} remove{} }
/// <summary>Triggered when additional items have been lazy-loaded</summary>
public event EventHandler<LazyFetchEventArgs>? ItemsFetched;
#if !NO_SPECIALIZED_COLLECTIONS
/// <summary>Called when the collection has changed</summary>
public event NotifyCollectionChangedEventHandler? CollectionChanged;
@ -533,18 +535,15 @@ namespace Nuclex.Avalonia.Collections {
/// <param name="newItem">New item the original item was replaced with</param>
/// <param name="index">Index of the replaced item</param>
protected virtual void OnReplaced(TItem oldItem, TItem newItem, int index) {
if(ItemReplaced != null) {
ItemReplaced(this, new ItemReplaceEventArgs<TItem>(oldItem, newItem));
}
ItemReplaced?.Invoke(this, new ItemReplaceEventArgs<TItem>(oldItem, newItem));
#if !NO_SPECIALIZED_COLLECTIONS
if(CollectionChanged != null) {
CollectionChanged(
this,
new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Replace, newItem, oldItem, index
)
);
}
CollectionChanged?.Invoke(
this,
new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Replace, newItem, oldItem, index
)
);
#endif
}
@ -566,6 +565,13 @@ namespace Nuclex.Avalonia.Collections {
}
#endif
/// <summary>Fires the 'ItemsFetched' event</summary>
/// <param name="startIndex">Index of the first fetched item</param>
/// <param name="count">Number of items that have been fetched</param>
protected virtual void OnFetched(int startIndex, int count) {
ItemsFetched?.Invoke(this, new LazyFetchEventArgs(startIndex, count));
}
/// <summary>Retrieves an item by index without triggering a fetch</summary>
/// <param name="index">Index of the item that will be retrieved</param>
/// <returns>The item at the specified index</returns>
@ -722,8 +728,6 @@ namespace Nuclex.Avalonia.Collections {
return;
}
itemCount = this.assumedCount.Value;
//if(thi)
}
// If the page is already fetched (or in flight), do nothing
@ -833,6 +837,9 @@ namespace Nuclex.Avalonia.Collections {
OnReplaced(previousItems[index], this.typedList[index + offset], index + offset);
}
// Notify that we've fetched additional items
OnFetched(offset, count);
// See if there is another page we need to fetch. If there is, continue
// with that page, otherwise, we're done, so we clear the isFetching flag
// to make the next caller that wants items fetch them rather than queue them.