using System;
using System.Windows.Input;

namespace QC.QTMApplication;

public class KeyActionCommand : ICommand
{
	private Action<object> executeAction;

	private Func<object, bool> canExecuteFunc;

	public event EventHandler CanExecuteChanged;

	public KeyActionCommand(Action<object> executeAction, Func<object, bool> canExecuteFunc)
	{
		this.executeAction = executeAction;
		this.canExecuteFunc = canExecuteFunc;
	}

	public bool CanExecute(object parameter)
	{
		if (canExecuteFunc != null)
		{
			return canExecuteFunc(parameter);
		}
		return false;
	}

	public void Execute(object parameter)
	{
		if (executeAction != null)
		{
			executeAction(parameter);
		}
	}
}
