1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profile editor - Fix closing brush/effect config dialogs

This commit is contained in:
Robert 2022-04-27 22:03:05 +02:00
parent eac08050bc
commit 3e1fc76bfe
5 changed files with 24 additions and 13 deletions

View File

@ -24,6 +24,7 @@
<entry key="Artemis.UI/Screens/ProfileEditor/Panels/Properties/Tree/ContentDialogs/SidebarCategoryEditView.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />
<entry key="Artemis.UI/Screens/ProfileEditor/Panels/Properties/Tree/TreeGroupView.axaml" value="Artemis.UI.Windows/Artemis.UI.Windows.csproj" />
<entry key="Artemis.UI/Screens/ProfileEditor/Panels/Properties/Tree/TreePropertyView.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />
<entry key="Artemis.UI/Screens/ProfileEditor/Panels/Properties/Windows/EffectConfigurationWindowView.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />
<entry key="Artemis.UI/Screens/Settings/Tabs/GeneralTabView.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />
<entry key="Artemis.UI/Screens/Sidebar/ContentDialogs/SidebarCategoryEditView.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />
<entry key="Avalonia/Artemis.UI/Screens/Debugger/Tabs/Render/RenderDebugView.axaml" value="Avalonia/Artemis.UI.Linux/Artemis.UI.Linux.csproj" />

View File

@ -4,7 +4,7 @@ using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.ProfileEditor.Properties.Windows;
public class BrushConfigurationWindowView : ReactiveCoreWindow<EffectConfigurationWindowViewModel>
public class BrushConfigurationWindowView : ReactiveCoreWindow<BrushConfigurationWindowViewModel>
{
public BrushConfigurationWindowView()
{
@ -20,8 +20,11 @@ public class BrushConfigurationWindowView : ReactiveCoreWindow<EffectConfigurati
Closing += OnClosing;
}
private void OnClosing(object? sender, CancelEventArgs e)
private async void OnClosing(object? sender, CancelEventArgs e)
{
e.Cancel = ViewModel?.CanClose() ?? true;
if (ViewModel == null)
return;
e.Cancel = !await ViewModel.CanClose();
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Artemis.UI.Shared;
using Artemis.UI.Shared.LayerBrushes;
using Avalonia.Threading;
@ -18,14 +19,15 @@ public class BrushConfigurationWindowViewModel : DialogViewModelBase<object?>
public BrushConfigurationViewModel ConfigurationViewModel { get; }
public LayerBrushConfigurationDialog Configuration { get; }
public bool CanClose()
public async Task<bool> 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);
}
}

View File

@ -20,8 +20,11 @@ public class EffectConfigurationWindowView : ReactiveCoreWindow<EffectConfigurat
Closing += OnClosing;
}
private void OnClosing(object? sender, CancelEventArgs e)
private async void OnClosing(object? sender, CancelEventArgs e)
{
e.Cancel = ViewModel?.CanClose() ?? true;
if (ViewModel == null)
return;
e.Cancel = !await ViewModel.CanClose();
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Artemis.UI.Shared;
using Artemis.UI.Shared.LayerEffects;
using Avalonia.Threading;
@ -18,14 +19,15 @@ public class EffectConfigurationWindowViewModel : DialogViewModelBase<object?>
public EffectConfigurationViewModel ConfigurationViewModel { get; }
public LayerEffectConfigurationDialog Configuration { get; }
public bool CanClose()
public async Task<bool> 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);
}
}