From 2616dc57fb937080360977c55359141cad88cf61 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Sun, 19 Jan 2025 12:44:07 -0600 Subject: [PATCH] misc: chore: RelayCommand helper --- src/Ryujinx/UI/Helpers/Commands.cs | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/Ryujinx/UI/Helpers/Commands.cs diff --git a/src/Ryujinx/UI/Helpers/Commands.cs b/src/Ryujinx/UI/Helpers/Commands.cs new file mode 100644 index 000000000..7267ca75a --- /dev/null +++ b/src/Ryujinx/UI/Helpers/Commands.cs @@ -0,0 +1,48 @@ +using CommunityToolkit.Mvvm.Input; +using System; +using System.Threading.Tasks; + +namespace Ryujinx.Ava.UI.Helpers +{ +#nullable enable + public static class Commands + { + public static RelayCommand Create(Action action) + => new(action); + public static RelayCommand CreateConditional(Action action, Func canExecute) + => new(action, canExecute); + + public static RelayCommand CreateWithArg(Action action) + => new(action); + public static RelayCommand CreateConditionalWithArg(Action action, Predicate canExecute) + => new(action, canExecute); + + public static AsyncRelayCommand CreateAsync(Func action) + => new(action, AsyncRelayCommandOptions.None); + public static AsyncRelayCommand CreateConcurrentAsync(Func action) + => new(action, AsyncRelayCommandOptions.AllowConcurrentExecutions); + public static AsyncRelayCommand CreateSilentFailAsync(Func action) + => new(action, AsyncRelayCommandOptions.FlowExceptionsToTaskScheduler); + + public static AsyncRelayCommand CreateWithArgAsync(Func action) + => new(action, AsyncRelayCommandOptions.None); + public static AsyncRelayCommand CreateConcurrentWithArgAsync(Func action) + => new(action, AsyncRelayCommandOptions.AllowConcurrentExecutions); + public static AsyncRelayCommand CreateSilentFailWithArgAsync(Func action) + => new(action, AsyncRelayCommandOptions.FlowExceptionsToTaskScheduler); + + public static AsyncRelayCommand CreateConditionalAsync(Func action, Func canExecute) + => new(action, canExecute, AsyncRelayCommandOptions.None); + public static AsyncRelayCommand CreateConcurrentConditionalAsync(Func action, Func canExecute) + => new(action, canExecute, AsyncRelayCommandOptions.AllowConcurrentExecutions); + public static AsyncRelayCommand CreateSilentFailConditionalAsync(Func action, Func canExecute) + => new(action, canExecute, AsyncRelayCommandOptions.FlowExceptionsToTaskScheduler); + + public static AsyncRelayCommand CreateConditionalWithArgAsync(Func action, Predicate canExecute) + => new(action, canExecute, AsyncRelayCommandOptions.None); + public static AsyncRelayCommand CreateConcurrentConditionalWithArgAsync(Func action, Predicate canExecute) + => new(action, canExecute, AsyncRelayCommandOptions.AllowConcurrentExecutions); + public static AsyncRelayCommand CreateSilentFailConditionalWithArgAsync(Func action, Predicate canExecute) + => new(action, canExecute, AsyncRelayCommandOptions.FlowExceptionsToTaskScheduler); + } +}