| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.Globalization; |
| using System.Globalization; |
| using System.Linq; |
| using System.Linq; |
| using System.Text; |
| using System.Text; |
| using System.Threading.Tasks; |
| using System.Threading.Tasks; |
| using System.Windows.Input; |
| using System.Windows.Input; |
| |
| |
| namespace Playnite.SDK |
| namespace Playnite.SDK |
| { |
| { |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
. | public abstract class RelayCommand : ICommand |
| public abstract class RelayCommandBase : ICommand |
| { |
| { |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| public KeyGesture Gesture |
| public KeyGesture Gesture |
| { |
| { |
| get; set; |
| get; set; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| public string GestureText => Gesture?.GetDisplayStringForCulture(CultureInfo.CurrentUICulture); |
| public string GestureText => Gesture?.GetDisplayStringForCulture(CultureInfo.CurrentUICulture); |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| public event EventHandler CanExecuteChanged |
| public event EventHandler CanExecuteChanged |
| { |
| { |
| add { CommandManager.RequerySuggested += value; } |
| add { CommandManager.RequerySuggested += value; } |
| remove { CommandManager.RequerySuggested -= value; } |
| remove { CommandManager.RequerySuggested -= value; } |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="parameter"></param> |
| /// <param name="parameter"></param> |
| /// <returns></returns> |
| /// <returns></returns> |
| public abstract bool CanExecute(object parameter); |
| public abstract bool CanExecute(object parameter); |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="parameter"></param> |
| /// <param name="parameter"></param> |
| public abstract void Execute(object parameter); |
| public abstract void Execute(object parameter); |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| |
| /// </summary> |
| |
| public class RelayCommand : RelayCommandBase |
| |
| { |
| |
| private readonly Func<bool> canExecute; |
| |
| private readonly Action execute; |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="execute"></param> |
| |
| public RelayCommand(Action execute) |
| |
| : this(execute, null, null) |
| |
| { |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="execute"></param> |
| |
| /// <param name="gesture"></param> |
| |
| public RelayCommand(Action execute, KeyGesture gesture) |
| |
| : this(execute, null, gesture) |
| |
| { |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="execute"></param> |
| |
| /// <param name="canExecute"></param> |
| |
| public RelayCommand(Action execute, Func<bool> canExecute) |
| |
| : this(execute, canExecute, null) |
| |
| { |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="execute"></param> |
| |
| /// <param name="canExecute"></param> |
| |
| /// <param name="gesture"></param> |
| |
| public RelayCommand(Action execute, Func<bool> canExecute, KeyGesture gesture) |
| |
| { |
| |
| this.execute = execute; |
| |
| this.canExecute = canExecute; |
| |
| Gesture = gesture; |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="parameter"></param> |
| |
| /// <returns></returns> |
| |
| public override bool CanExecute(object parameter = null) |
| |
| { |
| |
| if (canExecute == null) |
| |
| { |
| |
| return true; |
| |
| } |
| |
| |
| |
| return canExecute(); |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| |
| /// </summary> |
| |
| /// <param name="parameter"></param> |
| |
| public override void Execute(object parameter = null) |
| |
| { |
| |
| execute(); |
| |
| } |
| |
| } |
| |
| |
| |
| /// <summary> |
| |
| /// |
| /// </summary> |
| /// </summary> |
| /// <typeparam name="T"></typeparam> |
| /// <typeparam name="T"></typeparam> |
. | public class RelayCommand<T> : RelayCommand |
| public class RelayCommand<T> : RelayCommandBase |
| { |
| { |
| private readonly Predicate<T> canExecute; |
| private readonly Predicate<T> canExecute; |
| private readonly Action<T> execute; |
| private readonly Action<T> execute; |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="execute"></param> |
| /// <param name="execute"></param> |
| public RelayCommand(Action<T> execute) |
| public RelayCommand(Action<T> execute) |
| : this(execute, null, null) |
| : this(execute, null, null) |
. | { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="execute"></param> |
| /// <param name="execute"></param> |
| /// <param name="gesture"></param> |
| /// <param name="gesture"></param> |
| public RelayCommand(Action<T> execute, KeyGesture gesture) |
| public RelayCommand(Action<T> execute, KeyGesture gesture) |
| : this(execute, null, gesture) |
| : this(execute, null, gesture) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="execute"></param> |
| /// <param name="execute"></param> |
| /// <param name="canExecute"></param> |
| /// <param name="canExecute"></param> |
| public RelayCommand(Action<T> execute, Predicate<T> canExecute) |
| public RelayCommand(Action<T> execute, Predicate<T> canExecute) |
| : this(execute, canExecute, null) |
| : this(execute, canExecute, null) |
| { |
| { |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="execute"></param> |
| /// <param name="execute"></param> |
| /// <param name="canExecute"></param> |
| /// <param name="canExecute"></param> |
| /// <param name="gesture"></param> |
| /// <param name="gesture"></param> |
| public RelayCommand(Action<T> execute, Predicate<T> canExecute, KeyGesture gesture) |
| public RelayCommand(Action<T> execute, Predicate<T> canExecute, KeyGesture gesture) |
| { |
| { |
| this.execute = execute; |
| this.execute = execute; |
| this.canExecute = canExecute; |
| this.canExecute = canExecute; |
| Gesture = gesture; |
| Gesture = gesture; |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="parameter"></param> |
| /// <param name="parameter"></param> |
| /// <returns></returns> |
| /// <returns></returns> |
| public override bool CanExecute(object parameter) |
| public override bool CanExecute(object parameter) |
| { |
| { |
| if (canExecute == null) |
| if (canExecute == null) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| |
| |
| return canExecute((T)parameter); |
| return canExecute((T)parameter); |
| } |
| } |
| |
| |
| /// <summary> |
| /// <summary> |
. | /// |
| /// |
| /// </summary> |
| /// </summary> |
| /// <param name="parameter"></param> |
| /// <param name="parameter"></param> |
| public override void Execute(object parameter) |
| public override void Execute(object parameter) |
| { |
| { |
| execute((T)parameter); |
| execute((T)parameter); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |