Dialog deferrals
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Toolkit.Foundation;
|
using FluentAvalonia.Core;
|
||||||
|
using Toolkit.Foundation;
|
||||||
using Toolkit.UI.Controls.Avalonia;
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
namespace Toolkit.Avalonia;
|
namespace Toolkit.Avalonia;
|
||||||
@@ -20,11 +21,25 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
|||||||
{
|
{
|
||||||
if (content is IPrimaryConfirmation primaryConfirmation)
|
if (content is IPrimaryConfirmation primaryConfirmation)
|
||||||
{
|
{
|
||||||
|
List<Action> postActions = [];
|
||||||
|
if (content is IActivityIndicator activityIndicator)
|
||||||
|
{
|
||||||
|
activityIndicator.Active = true;
|
||||||
|
postActions.Add(() => activityIndicator.Active = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Deferral deferral = args.GetDeferral();
|
||||||
if (!await primaryConfirmation.Confirm())
|
if (!await primaryConfirmation.Confirm())
|
||||||
{
|
{
|
||||||
args.Cancel = true;
|
args.Cancel = true;
|
||||||
contentDialog.PrimaryButtonClick += HandlePrimaryButtonClick;
|
contentDialog.PrimaryButtonClick += HandlePrimaryButtonClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deferral.Complete();
|
||||||
|
foreach (Action action in postActions)
|
||||||
|
{
|
||||||
|
action.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,11 +52,25 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
|||||||
{
|
{
|
||||||
if (content is ISecondaryConfirmation secondaryConfirmation)
|
if (content is ISecondaryConfirmation secondaryConfirmation)
|
||||||
{
|
{
|
||||||
|
List<Action> postActions = [];
|
||||||
|
if (content is IActivityIndicator activityIndicator)
|
||||||
|
{
|
||||||
|
activityIndicator.Active = true;
|
||||||
|
postActions.Add(() => activityIndicator.Active = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Deferral deferral = args.GetDeferral();
|
||||||
if (!await secondaryConfirmation.Confirm())
|
if (!await secondaryConfirmation.Confirm())
|
||||||
{
|
{
|
||||||
args.Cancel = true;
|
args.Cancel = true;
|
||||||
contentDialog.SecondaryButtonClick += HandleSecondaryButtonClick;
|
contentDialog.SecondaryButtonClick += HandleSecondaryButtonClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deferral.Complete();
|
||||||
|
foreach (Action action in postActions)
|
||||||
|
{
|
||||||
|
action.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,11 +86,25 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
|||||||
{
|
{
|
||||||
if (content is IConfirmation confirmation)
|
if (content is IConfirmation confirmation)
|
||||||
{
|
{
|
||||||
|
List<Action> postActions = [];
|
||||||
|
if (content is IActivityIndicator activityIndicator)
|
||||||
|
{
|
||||||
|
activityIndicator.Active = true;
|
||||||
|
postActions.Add(() => activityIndicator.Active = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Deferral deferral = args.GetDeferral();
|
||||||
if (!await confirmation.Confirm())
|
if (!await confirmation.Confirm())
|
||||||
{
|
{
|
||||||
args.Cancel = true;
|
args.Cancel = true;
|
||||||
contentDialog.Closing += HandleClosing;
|
contentDialog.Closing += HandleClosing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deferral.Complete();
|
||||||
|
foreach (Action action in postActions)
|
||||||
|
{
|
||||||
|
action.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public interface IActivityIndicator
|
||||||
|
{
|
||||||
|
bool Active { get; set; }
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace Toolkit.Foundation;
|
|||||||
public partial class Observable :
|
public partial class Observable :
|
||||||
ObservableObject,
|
ObservableObject,
|
||||||
IObservableViewModel,
|
IObservableViewModel,
|
||||||
|
IActivityIndicator,
|
||||||
IInitializer,
|
IInitializer,
|
||||||
IActivated,
|
IActivated,
|
||||||
IDeactivating,
|
IDeactivating,
|
||||||
@@ -20,9 +21,13 @@ public partial class Observable :
|
|||||||
private readonly Dictionary<string, object> trackedProperties = [];
|
private readonly Dictionary<string, object> trackedProperties = [];
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isInitialized;
|
private bool initialized;
|
||||||
|
|
||||||
public Observable(IServiceProvider provider,
|
[ObservableProperty]
|
||||||
|
private bool active;
|
||||||
|
|
||||||
|
public Observable(IServiceProvider
|
||||||
|
provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
@@ -72,12 +77,12 @@ public partial class Observable :
|
|||||||
|
|
||||||
public Task Initialize()
|
public Task Initialize()
|
||||||
{
|
{
|
||||||
if (IsInitialized)
|
if (Initialized)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsInitialized = true;
|
Initialized = true;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user