WIP
This commit is contained in:
@@ -129,11 +129,6 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
|||||||
|
|
||||||
// A hack to wait for the dialog to finish loading up to make it appear more responsive
|
// A hack to wait for the dialog to finish loading up to make it appear more responsive
|
||||||
await Task.Delay(250);
|
await Task.Delay(250);
|
||||||
if (content is IInitialization initializer)
|
|
||||||
{
|
|
||||||
await initializer.Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content is IActivated activated)
|
if (content is IActivated activated)
|
||||||
{
|
{
|
||||||
await activated.OnActivated();
|
await activated.OnActivated();
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public class ContentTemplate :
|
|||||||
if (observableViewModel.Provider is IServiceProvider provider)
|
if (observableViewModel.Provider is IServiceProvider provider)
|
||||||
{
|
{
|
||||||
Type itemType = item.GetType();
|
Type itemType = item.GetType();
|
||||||
|
|
||||||
if (provider.GetRequiredKeyedService<IContentTemplateDescriptor>(itemType.Name.Replace("ViewModel", ""))
|
if (provider.GetRequiredKeyedService<IContentTemplateDescriptor>(itemType.Name.Replace("ViewModel", ""))
|
||||||
is IContentTemplateDescriptor descriptor)
|
is IContentTemplateDescriptor descriptor)
|
||||||
{
|
{
|
||||||
@@ -28,11 +27,6 @@ public class ContentTemplate :
|
|||||||
control.Loaded -= HandleLoaded;
|
control.Loaded -= HandleLoaded;
|
||||||
if (control.DataContext is object content)
|
if (control.DataContext is object content)
|
||||||
{
|
{
|
||||||
if (content is IInitialization initializer)
|
|
||||||
{
|
|
||||||
await initializer.Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content is IActivated activated)
|
if (content is IActivated activated)
|
||||||
{
|
{
|
||||||
await activated.OnActivated();
|
await activated.OnActivated();
|
||||||
|
|||||||
@@ -72,11 +72,6 @@ public class FrameHandler :
|
|||||||
sender.AddHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
|
sender.AddHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
|
||||||
if (sender.DataContext is object content)
|
if (sender.DataContext is object content)
|
||||||
{
|
{
|
||||||
if (content is IInitialization initializer)
|
|
||||||
{
|
|
||||||
await initializer.Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content is IActivated activated)
|
if (content is IActivated activated)
|
||||||
{
|
{
|
||||||
await activated.OnActivated();
|
await activated.OnActivated();
|
||||||
|
|||||||
@@ -17,29 +17,15 @@ public class ContentFactory(IMediator mediator,
|
|||||||
content = await mediator.Handle(descriptor.ContentType, createEvent, descriptor.Key);
|
content = await mediator.Handle(descriptor.ContentType, createEvent, descriptor.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content is null)
|
content ??= parameters is { Length: > 0 }
|
||||||
{
|
? factory.Create(descriptor.ContentType, args =>
|
||||||
if (parameters is { Length: > 0 })
|
|
||||||
{
|
|
||||||
content = factory.Create(descriptor.ContentType, args =>
|
|
||||||
{
|
{
|
||||||
if (args is IPostInitialization initialization)
|
if (args is IInitialization initialization)
|
||||||
{
|
{
|
||||||
initialization.PostInitialize();
|
initialization.Initialize();
|
||||||
}
|
}
|
||||||
}, parameters);
|
}, parameters)
|
||||||
}
|
: provider.GetRequiredKeyedService(descriptor.ContentType, descriptor.Key);
|
||||||
else
|
|
||||||
{
|
|
||||||
content = provider.GetRequiredKeyedService(descriptor.ContentType, args =>
|
|
||||||
{
|
|
||||||
if (args is IPostInitialization initialization)
|
|
||||||
{
|
|
||||||
initialization.PostInitialize();
|
|
||||||
}
|
|
||||||
}, descriptor.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Foundation;
|
|
||||||
|
|
||||||
public interface IPostInitialization
|
|
||||||
{
|
|
||||||
void PostInitialize();
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Toolkit.Foundation;
|
|
||||||
|
|
||||||
public static class IServiceProviderExtensions
|
|
||||||
{
|
|
||||||
public static object GetRequiredKeyedService(this IServiceProvider provider,
|
|
||||||
Type serviceType,
|
|
||||||
Action<object> serviceDelegate,
|
|
||||||
object? serviceKey)
|
|
||||||
{
|
|
||||||
object service = provider.GetRequiredKeyedService(serviceType, serviceKey);
|
|
||||||
serviceDelegate.Invoke(service);
|
|
||||||
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
namespace Toolkit.Foundation;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
public partial class Observable(IServiceProvider
|
public partial class Observable(IServiceProvider provider,
|
||||||
provider,
|
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
@@ -12,7 +11,6 @@ public partial class Observable(IServiceProvider
|
|||||||
ObservableObject,
|
ObservableObject,
|
||||||
IObservableViewModel,
|
IObservableViewModel,
|
||||||
IActivityIndicator,
|
IActivityIndicator,
|
||||||
IPostInitialization,
|
|
||||||
IInitialization,
|
IInitialization,
|
||||||
IActivated,
|
IActivated,
|
||||||
IDeactivating,
|
IDeactivating,
|
||||||
@@ -32,7 +30,6 @@ public partial class Observable(IServiceProvider
|
|||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool initialized;
|
private bool initialized;
|
||||||
private bool postInitialized;
|
|
||||||
|
|
||||||
public event EventHandler? DeactivateHandler;
|
public event EventHandler? DeactivateHandler;
|
||||||
|
|
||||||
@@ -67,7 +64,7 @@ public partial class Observable(IServiceProvider
|
|||||||
Disposer.Dispose(this);
|
Disposer.Dispose(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Initialize()
|
public virtual Task Initialize()
|
||||||
{
|
{
|
||||||
if (Initialized)
|
if (Initialized)
|
||||||
{
|
{
|
||||||
@@ -75,6 +72,8 @@ public partial class Observable(IServiceProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
Initialized = true;
|
Initialized = true;
|
||||||
|
|
||||||
|
Subscriber.Subscribe(this);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,17 +86,6 @@ public partial class Observable(IServiceProvider
|
|||||||
public virtual Task OnDeactivating() =>
|
public virtual Task OnDeactivating() =>
|
||||||
Task.CompletedTask;
|
Task.CompletedTask;
|
||||||
|
|
||||||
public virtual void PostInitialize()
|
|
||||||
{
|
|
||||||
if (postInitialized)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
postInitialized = true;
|
|
||||||
Subscriber.Subscribe(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Revert()
|
public void Revert()
|
||||||
{
|
{
|
||||||
foreach (object trackedProperty in trackedProperties.Values)
|
foreach (object trackedProperty in trackedProperties.Values)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ namespace Toolkit.Foundation;
|
|||||||
public partial class ObservableCollection<TItem> :
|
public partial class ObservableCollection<TItem> :
|
||||||
ObservableObject,
|
ObservableObject,
|
||||||
IObservableCollectionViewModel<TItem>,
|
IObservableCollectionViewModel<TItem>,
|
||||||
IPostInitialization,
|
|
||||||
IInitialization,
|
IInitialization,
|
||||||
IActivated,
|
IActivated,
|
||||||
IDeactivating,
|
IDeactivating,
|
||||||
@@ -50,11 +49,10 @@ public partial class ObservableCollection<TItem> :
|
|||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private int count;
|
private int count;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool initialized;
|
private bool initialized;
|
||||||
|
|
||||||
private bool postInitialized;
|
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private TItem? selectedItem;
|
private TItem? selectedItem;
|
||||||
|
|
||||||
@@ -118,6 +116,7 @@ public partial class ObservableCollection<TItem> :
|
|||||||
public IServiceProvider Provider { get; private set; }
|
public IServiceProvider Provider { get; private set; }
|
||||||
|
|
||||||
public IPublisher Publisher { get; private set; }
|
public IPublisher Publisher { get; private set; }
|
||||||
|
|
||||||
public ISubscriber Subscriber { get; }
|
public ISubscriber Subscriber { get; }
|
||||||
|
|
||||||
object ICollection.SyncRoot => this;
|
object ICollection.SyncRoot => this;
|
||||||
@@ -151,11 +150,11 @@ public partial class ObservableCollection<TItem> :
|
|||||||
where T :
|
where T :
|
||||||
TItem
|
TItem
|
||||||
{
|
{
|
||||||
T? item = Factory.Create<T>(args =>
|
T? item = Factory.Create<T>(args =>
|
||||||
{
|
{
|
||||||
if (args is IPostInitialization initialization)
|
if (args is IInitialization initialization)
|
||||||
{
|
{
|
||||||
initialization.PostInitialize();
|
initialization.Initialize();
|
||||||
}
|
}
|
||||||
}, parameters);
|
}, parameters);
|
||||||
|
|
||||||
@@ -208,6 +207,7 @@ public partial class ObservableCollection<TItem> :
|
|||||||
Clear();
|
Clear();
|
||||||
factory.Invoke(this);
|
factory.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
clearing = true;
|
clearing = true;
|
||||||
@@ -411,6 +411,8 @@ public partial class ObservableCollection<TItem> :
|
|||||||
}
|
}
|
||||||
|
|
||||||
Initialized = true;
|
Initialized = true;
|
||||||
|
|
||||||
|
Subscriber.Subscribe(this);
|
||||||
Synchronize();
|
Synchronize();
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
@@ -423,9 +425,9 @@ public partial class ObservableCollection<TItem> :
|
|||||||
{
|
{
|
||||||
T? item = Factory.Create<T>(args =>
|
T? item = Factory.Create<T>(args =>
|
||||||
{
|
{
|
||||||
if (args is IPostInitialization initialization)
|
if (args is IInitialization initialization)
|
||||||
{
|
{
|
||||||
initialization.PostInitialize();
|
initialization.Initialize();
|
||||||
}
|
}
|
||||||
}, parameters);
|
}, parameters);
|
||||||
|
|
||||||
@@ -521,17 +523,6 @@ public partial class ObservableCollection<TItem> :
|
|||||||
public virtual Task OnDeactivating() =>
|
public virtual Task OnDeactivating() =>
|
||||||
Task.CompletedTask;
|
Task.CompletedTask;
|
||||||
|
|
||||||
public virtual void PostInitialize()
|
|
||||||
{
|
|
||||||
if (postInitialized)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
postInitialized = true;
|
|
||||||
Subscriber.Subscribe(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Remove(TItem item)
|
public bool Remove(TItem item)
|
||||||
{
|
{
|
||||||
int index = collection.IndexOf(item);
|
int index = collection.IndexOf(item);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class ServiceFactory(Func<Type, object?[]?, object> factory) :
|
|||||||
public object Create(Type type, params object?[]? parameters) =>
|
public object Create(Type type, params object?[]? parameters) =>
|
||||||
factory(type, parameters);
|
factory(type, parameters);
|
||||||
|
|
||||||
public object Create(Type type, Action<object> serviceDelegate,
|
public object Create(Type type, Action<object> serviceDelegate,
|
||||||
params object?[]? parameters)
|
params object?[]? parameters)
|
||||||
{
|
{
|
||||||
object service = factory(type, parameters);
|
object service = factory(type, parameters);
|
||||||
|
|||||||
Reference in New Issue
Block a user