Add ability to insert an ordered item at UI configuration time
This commit is contained in:
@@ -22,8 +22,8 @@ public class MediaControllerHandler(IMediator mediator,
|
|||||||
if (factory.Create(mediaController) is MediaControllerViewModel mediaControllerViewModel)
|
if (factory.Create(mediaController) is MediaControllerViewModel mediaControllerViewModel)
|
||||||
{
|
{
|
||||||
cache.Add(mediaController, mediaControllerViewModel);
|
cache.Add(mediaController, mediaControllerViewModel);
|
||||||
await mediator.PublishAsync(new Created<MediaControllerViewModel>(mediaControllerViewModel),
|
//await mediator.PublishAsync(new Created<MediaControllerViewModel>(mediaControllerViewModel),
|
||||||
cancellationToken);
|
// cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class MediaControllerManager(IMediator mediator,
|
|||||||
{
|
{
|
||||||
if (factory.Create(session) is MediaController mediaController)
|
if (factory.Create(session) is MediaController mediaController)
|
||||||
{
|
{
|
||||||
await mediator.PublishAsync(new Created<MediaController>(mediaController));
|
//await mediator.PublishAsync(new Created<MediaController>(mediaController));
|
||||||
cache.Add(new KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>(session, mediaController));
|
cache.Add(new KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>(session, mediaController));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ public class PrimaryWidgetConfigurationHandler(IMediator mediator,
|
|||||||
{
|
{
|
||||||
if (factory.Create(item) is IWidgetComponentViewModel value)
|
if (factory.Create(item) is IWidgetComponentViewModel value)
|
||||||
{
|
{
|
||||||
await mediator.PublishAsync(new Created<IWidgetComponentViewModel>(value),
|
await mediator.PublishAsync(Inserted<IWidgetComponentViewModel>
|
||||||
cancellationToken);
|
.For<PrimaryWidgetViewModel>(item.Order, value),
|
||||||
|
cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
namespace Hyperbar;
|
namespace Hyperbar;
|
||||||
|
|
||||||
public record Created<TValue>(TValue Value) : INotification;
|
public record Created<TValue>(TValue Value, object Target) : INotification
|
||||||
|
{
|
||||||
public record Inserted<TValue>(int Index, TValue Value) : INotification;
|
public static Created<TValue> For<TTarget>(TValue value)
|
||||||
|
{
|
||||||
|
return new Created<TValue>(value, typeof(TTarget).Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public record Inserted<TValue>(int Index, TValue Value, object Target) : INotification
|
||||||
|
{
|
||||||
|
public static Inserted<TValue> For<TTarget>(int index, TValue value)
|
||||||
|
{
|
||||||
|
return new Inserted<TValue>(index, value, typeof(TTarget).Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ public partial class ObservableCollectionViewModel<TItem> :
|
|||||||
IObservableCollectionViewModel<TItem>,
|
IObservableCollectionViewModel<TItem>,
|
||||||
INotificationHandler<Removed<TItem>>,
|
INotificationHandler<Removed<TItem>>,
|
||||||
INotificationHandler<Created<TItem>>,
|
INotificationHandler<Created<TItem>>,
|
||||||
|
INotificationHandler<Inserted<TItem>>,
|
||||||
IDisposable
|
IDisposable
|
||||||
where TItem :
|
where TItem :
|
||||||
IDisposable
|
IDisposable
|
||||||
@@ -228,16 +229,33 @@ public partial class ObservableCollectionViewModel<TItem> :
|
|||||||
public ValueTask Handle(Created<TItem> notification,
|
public ValueTask Handle(Created<TItem> notification,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (notification.Value is not null)
|
if (notification.Target.Equals(GetType().Name))
|
||||||
{
|
{
|
||||||
Add(notification.Value);
|
if (notification.Value is TItem item)
|
||||||
|
{
|
||||||
|
Add(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ValueTask.CompletedTask;
|
return ValueTask.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int IndexOf(TItem item) =>
|
public ValueTask Handle(Inserted<TItem> notification,
|
||||||
collection.IndexOf(item);
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (notification.Target.Equals(GetType().Name))
|
||||||
|
{
|
||||||
|
if (notification.Value is TItem item)
|
||||||
|
{
|
||||||
|
Insert(notification.Index, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ValueTask.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int IndexOf(TItem item) =>
|
||||||
|
collection.IndexOf(item);
|
||||||
|
|
||||||
int IList.IndexOf(object? value) =>
|
int IList.IndexOf(object? value) =>
|
||||||
IsCompatibleObject(value) ?
|
IsCompatibleObject(value) ?
|
||||||
|
|||||||
Reference in New Issue
Block a user