More renaming
This commit is contained in:
@@ -62,17 +62,28 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
contentDialog.Closing -= HandleClosing;
|
||||
if (contentDialog.DataContext is object content)
|
||||
{
|
||||
bool cancelled = false;
|
||||
if (content is IConfirmation confirmation)
|
||||
{
|
||||
Deferral deferral = args.GetDeferral();
|
||||
if (!await confirmation.Confirm())
|
||||
{
|
||||
args.Cancel = true;
|
||||
cancelled = true;
|
||||
|
||||
contentDialog.Closing += HandleClosing;
|
||||
}
|
||||
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
if (!cancelled)
|
||||
{
|
||||
if (content is IDeactivating deactivating)
|
||||
{
|
||||
await deactivating.OnDeactivating();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,17 +94,6 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
contentDialog.Opened -= HandleOpened;
|
||||
if (contentDialog.DataContext is object content)
|
||||
{
|
||||
if (content is IDeactivatable deactivatable)
|
||||
{
|
||||
async void DeactivateHandler(object? sender, EventArgs args)
|
||||
{
|
||||
deactivatable.DeactivateHandler -= DeactivateHandler;
|
||||
await dispatcher.Invoke(contentDialog.Hide);
|
||||
}
|
||||
|
||||
deactivatable.DeactivateHandler += DeactivateHandler;
|
||||
}
|
||||
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
await activated.OnActivated();
|
||||
@@ -101,8 +101,23 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
}
|
||||
}
|
||||
|
||||
async void HandleClosed(FluentAvalonia.UI.Controls.ContentDialog sender,
|
||||
FluentAvalonia.UI.Controls.ContentDialogClosedEventArgs args)
|
||||
{
|
||||
contentDialog.Closed -= HandleClosed;
|
||||
if (contentDialog.DataContext is object content)
|
||||
{
|
||||
if (content is IDeactivated deactivated)
|
||||
{
|
||||
await deactivated.OnDeactivated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contentDialog.Opened += HandleOpened;
|
||||
contentDialog.Closing += HandleClosing;
|
||||
contentDialog.Closed += HandleClosed;
|
||||
|
||||
contentDialog.PrimaryButtonClick += HandlePrimaryButtonClick;
|
||||
contentDialog.SecondaryButtonClick += HandleSecondaryButtonClick;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public class AppService(IEnumerable<IInitialization> initializers,
|
||||
{
|
||||
foreach (IInitialization initializer in initializers)
|
||||
{
|
||||
await initializer.Initialize();
|
||||
await initializer.OnInitialize();
|
||||
}
|
||||
|
||||
publisher.Publish<StartedEventArgs>();
|
||||
|
||||
@@ -6,13 +6,13 @@ public class ActivityLock(IActivityIndicator activityIndicator) : AsyncLock
|
||||
{
|
||||
public override TaskAwaiter<AsyncLock> GetAwaiter()
|
||||
{
|
||||
activityIndicator.Active = true;
|
||||
activityIndicator.IsActive = true;
|
||||
return base.GetAwaiter();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
activityIndicator.Active = false;
|
||||
activityIndicator.IsActive = false;
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ComponentHost(IServiceProvider services,
|
||||
{
|
||||
foreach (IInitialization initializer in initializers)
|
||||
{
|
||||
await initializer.Initialize();
|
||||
await initializer.OnInitialize();
|
||||
}
|
||||
|
||||
foreach (IHostedService service in hostedServices)
|
||||
|
||||
@@ -9,7 +9,7 @@ public class ComponentInitializer(IEnumerable<IComponent> components,
|
||||
IServiceProvider provider) :
|
||||
IInitialization
|
||||
{
|
||||
public async Task Initialize()
|
||||
public async Task OnInitialize()
|
||||
{
|
||||
foreach (IComponent component in components)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ public class ConfigurationInitializer<TConfiguration>(IConfigurationReader<TConf
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
public Task Initialize()
|
||||
public Task OnInitialize()
|
||||
{
|
||||
if (!reader.TryRead(out TConfiguration? configuration))
|
||||
{
|
||||
|
||||
@@ -20,14 +20,14 @@ public class ContentFactory(IMediator mediator,
|
||||
{
|
||||
if (args is IInitialization initialization)
|
||||
{
|
||||
initialization.Initialize();
|
||||
initialization.OnInitialize();
|
||||
}
|
||||
}, parameters)
|
||||
: provider.GetRequiredKeyedService(descriptor.ContentType, args =>
|
||||
{
|
||||
if (args is IInitialization initialization)
|
||||
{
|
||||
initialization.Initialize();
|
||||
initialization.OnInitialize();
|
||||
}
|
||||
}, descriptor.Key);
|
||||
|
||||
|
||||
@@ -4,8 +4,3 @@ public interface IActivated
|
||||
{
|
||||
Task OnActivated();
|
||||
}
|
||||
|
||||
public interface IActivated<TResult>
|
||||
{
|
||||
Task Activated(TResult result);
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
public interface IActivityIndicator
|
||||
{
|
||||
bool Active { get; set; }
|
||||
bool IsActive { get; set; }
|
||||
}
|
||||
@@ -4,5 +4,5 @@ public interface IConfigurationInitializer<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
Task Initialize();
|
||||
Task OnInitialize();
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IDeactivatable
|
||||
{
|
||||
public event EventHandler? DeactivateHandler;
|
||||
|
||||
public Task Deactivate();
|
||||
}
|
||||
@@ -4,8 +4,3 @@ public interface IDeactivating
|
||||
{
|
||||
Task OnDeactivating();
|
||||
}
|
||||
|
||||
public interface IDeactivating<TResult>
|
||||
{
|
||||
Task<TResult> Deactivating();
|
||||
}
|
||||
@@ -2,10 +2,5 @@
|
||||
|
||||
public interface IInitialization
|
||||
{
|
||||
Task Initialize();
|
||||
}
|
||||
|
||||
public interface IInitialization<T>
|
||||
{
|
||||
Task<T> Initialize();
|
||||
Task OnInitialize();
|
||||
}
|
||||
@@ -15,7 +15,6 @@ public partial class Observable(IServiceProvider provider,
|
||||
IActivated,
|
||||
IDeactivating,
|
||||
IDeactivated,
|
||||
IDeactivatable,
|
||||
IDisposable,
|
||||
IServiceProviderRequired,
|
||||
IServiceFactoryRequired,
|
||||
@@ -26,12 +25,10 @@ public partial class Observable(IServiceProvider provider,
|
||||
private readonly Dictionary<string, object> trackedProperties = [];
|
||||
|
||||
[ObservableProperty]
|
||||
private bool active;
|
||||
private bool isActive;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool initialized;
|
||||
|
||||
public event EventHandler? DeactivateHandler;
|
||||
private bool isInitialized;
|
||||
|
||||
public IDisposer Disposer { get; } = disposer;
|
||||
|
||||
@@ -42,6 +39,7 @@ public partial class Observable(IServiceProvider provider,
|
||||
public IServiceProvider Provider { get; } = provider;
|
||||
|
||||
public IPublisher Publisher { get; } = publisher;
|
||||
|
||||
public ISubscriber Subscriber { get; } = subscriber;
|
||||
|
||||
public void Commit()
|
||||
@@ -52,36 +50,40 @@ public partial class Observable(IServiceProvider provider,
|
||||
}
|
||||
}
|
||||
|
||||
public Task Deactivate()
|
||||
{
|
||||
DeactivateHandler?.Invoke(this, new EventArgs());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
Disposer.Dispose(this);
|
||||
}
|
||||
|
||||
public virtual Task Initialize()
|
||||
public virtual Task OnInitialize()
|
||||
{
|
||||
if (Initialized)
|
||||
if (IsInitialized)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Initialized = true;
|
||||
IsInitialized = true;
|
||||
|
||||
Subscriber.Subscribe(this);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual Task OnActivated() =>
|
||||
Task.CompletedTask;
|
||||
[ObservableProperty]
|
||||
private bool isActivated;
|
||||
|
||||
public virtual Task OnDeactivated() =>
|
||||
Task.CompletedTask;
|
||||
public virtual Task OnActivated()
|
||||
{
|
||||
IsActivated = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
public virtual Task OnDeactivated()
|
||||
{
|
||||
IsActivated = false;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual Task OnDeactivating() =>
|
||||
Task.CompletedTask;
|
||||
|
||||
@@ -13,7 +13,6 @@ public partial class ObservableCollection<TItem> :
|
||||
IActivated,
|
||||
IDeactivating,
|
||||
IDeactivated,
|
||||
IDeactivatable,
|
||||
IList<TItem>,
|
||||
IList,
|
||||
IReadOnlyList<TItem>,
|
||||
@@ -42,16 +41,16 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
private readonly Dictionary<string, object> trackedProperties = [];
|
||||
|
||||
[ObservableProperty]
|
||||
private bool activated;
|
||||
|
||||
private bool clearing;
|
||||
|
||||
[ObservableProperty]
|
||||
private int count;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool initialized;
|
||||
private bool isActivated;
|
||||
|
||||
private bool isClearing;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isInitialized;
|
||||
|
||||
[ObservableProperty]
|
||||
private TItem? selectedItem;
|
||||
@@ -97,8 +96,6 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public event NotifyCollectionChangedEventHandler? CollectionChanged;
|
||||
|
||||
public event EventHandler? DeactivateHandler;
|
||||
|
||||
public IDisposer Disposer { get; private set; }
|
||||
|
||||
public IServiceFactory Factory { get; private set; }
|
||||
@@ -154,7 +151,7 @@ public partial class ObservableCollection<TItem> :
|
||||
{
|
||||
if (args is IInitialization initialization)
|
||||
{
|
||||
initialization.Initialize();
|
||||
initialization.OnInitialize();
|
||||
}
|
||||
}, parameters);
|
||||
|
||||
@@ -210,7 +207,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
clearing = true;
|
||||
isClearing = true;
|
||||
|
||||
foreach (TItem item in this.ToList())
|
||||
{
|
||||
@@ -219,7 +216,7 @@ public partial class ObservableCollection<TItem> :
|
||||
}
|
||||
|
||||
ClearItems();
|
||||
clearing = false;
|
||||
isClearing = false;
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
@@ -242,12 +239,6 @@ public partial class ObservableCollection<TItem> :
|
||||
void ICollection.CopyTo(Array array, int index) =>
|
||||
collection.CopyTo((TItem[])array, index);
|
||||
|
||||
public Task Deactivate()
|
||||
{
|
||||
DeactivateHandler?.Invoke(this, new EventArgs());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
@@ -274,7 +265,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public Task Handle(RemoveEventArgs<TItem> args)
|
||||
{
|
||||
if (Activated)
|
||||
if (IsActivated)
|
||||
{
|
||||
foreach (TItem item in this.ToList())
|
||||
{
|
||||
@@ -294,7 +285,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public Task Handle(CreateEventArgs<TItem> args)
|
||||
{
|
||||
if (Activated)
|
||||
if (IsActivated)
|
||||
{
|
||||
if (args.Sender is TItem item)
|
||||
{
|
||||
@@ -311,7 +302,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public Task Handle(InsertEventArgs<TItem> args)
|
||||
{
|
||||
if (Activated)
|
||||
if (IsActivated)
|
||||
{
|
||||
if (args.Sender is TItem item)
|
||||
{
|
||||
@@ -328,7 +319,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public Task Handle(MoveToEventArgs<TItem> args)
|
||||
{
|
||||
if (Activated)
|
||||
if (IsActivated)
|
||||
{
|
||||
Move(args.OldIndex, args.NewIndex);
|
||||
}
|
||||
@@ -342,7 +333,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public Task Handle(MoveEventArgs<TItem> args)
|
||||
{
|
||||
if (Activated)
|
||||
if (IsActivated)
|
||||
{
|
||||
if (args.Sender is TItem item)
|
||||
{
|
||||
@@ -359,7 +350,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public Task Handle(ReplaceEventArgs<TItem> args)
|
||||
{
|
||||
if (Activated)
|
||||
if (IsActivated)
|
||||
{
|
||||
if (args.Sender is TItem item)
|
||||
{
|
||||
@@ -376,7 +367,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public Task Handle(RemoveAtEventArgs<TItem> args)
|
||||
{
|
||||
if (Activated)
|
||||
if (IsActivated)
|
||||
{
|
||||
int index = args.Index;
|
||||
if (index >= 0 && index <= Count - 1)
|
||||
@@ -403,21 +394,6 @@ public partial class ObservableCollection<TItem> :
|
||||
IsCompatibleObject(value) ?
|
||||
IndexOf((TItem)value!) : -1;
|
||||
|
||||
public virtual Task Initialize()
|
||||
{
|
||||
if (Initialized)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Initialized = true;
|
||||
|
||||
Subscriber.Subscribe(this);
|
||||
Synchronize();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public TItem Insert<T>(int index = 0,
|
||||
params object?[] parameters)
|
||||
where T :
|
||||
@@ -427,7 +403,7 @@ public partial class ObservableCollection<TItem> :
|
||||
{
|
||||
if (args is IInitialization initialization)
|
||||
{
|
||||
initialization.Initialize();
|
||||
initialization.OnInitialize();
|
||||
}
|
||||
}, parameters);
|
||||
|
||||
@@ -504,7 +480,7 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public virtual Task OnActivated()
|
||||
{
|
||||
Activated = true;
|
||||
IsActivated = true;
|
||||
while (pendingEvents.Count > 0)
|
||||
{
|
||||
object current = pendingEvents.Dequeue();
|
||||
@@ -516,13 +492,27 @@ public partial class ObservableCollection<TItem> :
|
||||
|
||||
public virtual Task OnDeactivated()
|
||||
{
|
||||
Activated = false;
|
||||
IsActivated = false;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual Task OnDeactivating() =>
|
||||
Task.CompletedTask;
|
||||
|
||||
public virtual Task OnInitialize()
|
||||
{
|
||||
if (IsInitialized)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
IsInitialized = true;
|
||||
|
||||
Subscriber.Subscribe(this);
|
||||
Synchronize();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public bool Remove(TItem item)
|
||||
{
|
||||
int index = collection.IndexOf(item);
|
||||
@@ -612,7 +602,7 @@ public partial class ObservableCollection<TItem> :
|
||||
Disposer.Add(this, item);
|
||||
Disposer.Add(item, Disposable.Create(() =>
|
||||
{
|
||||
if (item is IRemovable && !clearing)
|
||||
if (item is IRemovable && !isClearing)
|
||||
{
|
||||
if (item is IList collection)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user