ardupilot/Tools/ArdupilotMegaPlanner/Presenter/DelegateCommand.cs
Michael Oborne 46f004bcca APM Planner 1.1.95
fix config panel value change detection
add loiter_ to AC config screen
Add praram name to Friendly param, and exception ignoring.
fix param file note line
intergrate andrews gimbal config.
fix any possible log appending issues
remove old cli planner on connect
modify speech to not crash on windows mono
2012-07-01 17:51:22 +08:00

61 lines
1.8 KiB
C#

using System;
namespace ArdupilotMega.Presenter
{
/// <summary>
/// A command that executes delegates to determine whether the command can execute, and to execute the command.
/// </summary>
/// <remarks>
/// <para>
/// This command implementation is useful when the command simply needs to execute a method on a view model. The delegate for
/// determining whether the command can execute is optional. If it is not provided, the command is considered always eligible
/// to execute.
/// </para>
/// </remarks>
public class DelegateCommand : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;
public DelegateCommand(Action<object> execute)
{
_execute = execute;
}
/// <summary>
/// Constructs an instance of <c>DelegateCommand</c>.
/// </summary>
/// <param name="execute">
/// The delegate to invoke when the command is executed.
/// </param>
/// <param name="canExecute">
/// The delegate to invoke to determine whether the command can execute.
/// </param>
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
/// <summary>
/// Determines whether this command can execute.
/// </summary>
public bool CanExecute(object parameter)
{
if (_canExecute == null)
{
return true;
}
return _canExecute(parameter);
}
/// <summary>
/// Executes this command.
/// </summary>
public void Execute(object parameter)
{
_execute(parameter);
}
}
}