Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SystemCommand.cs
Go to the documentation of this file.
1 using System;
2 using System.Windows;
3 using System.Windows.Input;
4 
5 namespace SiliconStudio.Presentation.Commands
6 {
7  internal class SystemCommand : ICommand
8  {
9  private readonly Func<Window, bool> canExecute;
10  private readonly Action<Window> execute;
11 
12  internal SystemCommand(Func<Window, bool> canExecute, Action<Window> execute)
13  {
14  if (canExecute == null) throw new ArgumentNullException("canExecute");
15  if (execute == null) throw new ArgumentNullException("execute");
16  this.canExecute = canExecute;
17  this.execute = execute;
18  }
19 
20  public bool CanExecute(object parameter)
21  {
22  var window = parameter as Window;
23  return window != null && canExecute(window);
24  }
25 
26  public void Execute(object parameter)
27  {
28  var window = parameter as Window;
29  if (window == null) throw new ArgumentException(string.Format("The parameter of this command must be an instance of 'Window'."));
30  execute(window);
31  }
32 
33  public event EventHandler CanExecuteChanged;
34  }
35 }