From 3e1fc76bfe7e8d56f12154c9d4ec568e1e714a93 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 27 Apr 2022 22:03:05 +0200 Subject: [PATCH] Profile editor - Fix closing brush/effect config dialogs --- src/.idea/.idea.Artemis/.idea/avalonia.xml | 1 + .../Windows/BrushConfigurationWindowView.axaml.cs | 9 ++++++--- .../Windows/BrushConfigurationWindowViewModel.cs | 10 ++++++---- .../Windows/EffectConfigurationWindowView.axaml.cs | 7 +++++-- .../Windows/EffectConfigurationWindowViewModel.cs | 10 ++++++---- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/.idea/.idea.Artemis/.idea/avalonia.xml b/src/.idea/.idea.Artemis/.idea/avalonia.xml index 248ae2e68..33b62dcac 100644 --- a/src/.idea/.idea.Artemis/.idea/avalonia.xml +++ b/src/.idea/.idea.Artemis/.idea/avalonia.xml @@ -24,6 +24,7 @@ + diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/BrushConfigurationWindowView.axaml.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/BrushConfigurationWindowView.axaml.cs index 42011416c..3016b7d79 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/BrushConfigurationWindowView.axaml.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/BrushConfigurationWindowView.axaml.cs @@ -4,7 +4,7 @@ using Avalonia.Markup.Xaml; namespace Artemis.UI.Screens.ProfileEditor.Properties.Windows; -public class BrushConfigurationWindowView : ReactiveCoreWindow +public class BrushConfigurationWindowView : ReactiveCoreWindow { public BrushConfigurationWindowView() { @@ -20,8 +20,11 @@ public class BrushConfigurationWindowView : ReactiveCoreWindow public BrushConfigurationViewModel ConfigurationViewModel { get; } public LayerBrushConfigurationDialog Configuration { get; } - public bool CanClose() + public async Task CanClose() { - return ConfigurationViewModel.CanClose() && Dispatcher.UIThread.InvokeAsync(async () => await ConfigurationViewModel.CanCloseAsync()).GetAwaiter().GetResult(); + // ReSharper disable once MethodHasAsyncOverload - Checking both in case the plugin developer only implemented CanClose + return ConfigurationViewModel.CanClose() && await ConfigurationViewModel.CanCloseAsync(); } - private void ConfigurationViewModelOnCloseRequested(object? sender, EventArgs e) + private async void ConfigurationViewModelOnCloseRequested(object? sender, EventArgs e) { - if (CanClose()) + if (await CanClose()) Close(null); } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/EffectConfigurationWindowView.axaml.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/EffectConfigurationWindowView.axaml.cs index 8f1683152..eb1fbc70f 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/EffectConfigurationWindowView.axaml.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/EffectConfigurationWindowView.axaml.cs @@ -20,8 +20,11 @@ public class EffectConfigurationWindowView : ReactiveCoreWindow public EffectConfigurationViewModel ConfigurationViewModel { get; } public LayerEffectConfigurationDialog Configuration { get; } - public bool CanClose() + public async Task CanClose() { - return ConfigurationViewModel.CanClose() && Dispatcher.UIThread.InvokeAsync(async () => await ConfigurationViewModel.CanCloseAsync()).GetAwaiter().GetResult(); + // ReSharper disable once MethodHasAsyncOverload - Checking both in case the plugin developer only implemented CanClose + return ConfigurationViewModel.CanClose() && await ConfigurationViewModel.CanCloseAsync(); } - private void ConfigurationViewModelOnCloseRequested(object? sender, EventArgs e) + private async void ConfigurationViewModelOnCloseRequested(object? sender, EventArgs e) { - if (CanClose()) + if (await CanClose()) Close(null); } } \ No newline at end of file