Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AnonymousCommandWrapper.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 
6 using SiliconStudio.ActionStack;
7 using SiliconStudio.Presentation.ViewModel;
8 using SiliconStudio.Quantum;
9 
10 namespace SiliconStudio.Presentation.Quantum
11 {
13  {
14  private readonly ITransactionalActionStack actionStack;
15  private readonly string name;
16  private readonly CombineMode combineMode;
17  private readonly Func<object, UndoToken> redo;
18  private readonly Action<object, UndoToken> undo;
19 
20  /// <summary>
21  /// Initializes a new instance of the <see cref="AnonymousCommandWrapper"/> class.
22  /// </summary>
23  /// <param name="serviceProvider">A service provider that can provide a <see cref="ITransactionalActionStack"/> to use for this view model.</param>
24  /// <param name="name">The name of this command.</param>
25  /// <param name="combineMode">The combine mode to apply to this command.</param>
26  /// <param name="redo">The do/redo function.</param>
27  /// <param name="undo">The undo action.</param>
28  /// <param name="dirtiables">The <see cref="IDirtiableViewModel"/> instances associated to this command.</param>
29  public AnonymousCommandWrapper(IViewModelServiceProvider serviceProvider, string name, CombineMode combineMode, Func<object, UndoToken> redo, Action<object, UndoToken> undo, IEnumerable<IDirtiableViewModel> dirtiables)
30  : base(serviceProvider, dirtiables)
31  {
32  if (name == null) throw new ArgumentNullException("name");
33  if (redo == null) throw new ArgumentNullException("redo");
34  if (undo == null) throw new ArgumentNullException("undo");
35  this.name = name;
36  this.combineMode = combineMode;
37  this.redo = redo;
38  this.undo = undo;
39  actionStack = serviceProvider.Get<ITransactionalActionStack>();
40  }
41 
42  /// <inheritdoc/>
43  public override string Name { get { return name; } }
44 
45  /// <inheritdoc/>
46  public override CombineMode CombineMode { get { return combineMode; } }
47 
48  /// <inheritdoc/>
49  public override void Execute(object parameter)
50  {
51  actionStack.BeginTransaction();
52  base.Execute(parameter);
53  actionStack.EndTransaction(string.Format("Executing {0}", Name));
54  }
55 
56  /// <inheritdoc/>
57  protected override UndoToken Redo(object parameter, bool creatingActionItem)
58  {
59  return redo(parameter);
60  }
61 
62  /// <inheritdoc/>
63  protected override void Undo(object parameter, UndoToken token)
64  {
65  undo(parameter, token);
66  }
67  }
68 }
AnonymousCommandWrapper(IViewModelServiceProvider serviceProvider, string name, CombineMode combineMode, Func< object, UndoToken > redo, Action< object, UndoToken > undo, IEnumerable< IDirtiableViewModel > dirtiables)
Initializes a new instance of the AnonymousCommandWrapper class.
override UndoToken Redo(object parameter, bool creatingActionItem)
Does or redoes the execution of the command. The command parameter.Indicates whether an action item i...
CombineMode
An enum that describes what to do with a node or a command when combining view models.
Definition: CombineMode.cs:8
A base class to wrap one or multiple INodeCommand instances into a CancellableCommand.
override void Undo(object parameter, UndoToken token)
Undoes the execution of the command. The command parameter.The UndoToken generated by the execution o...
Represents a token that stores an unique identifier and an object. This token should be generated by ...
Definition: UndoToken.cs:12
Base interface for a transactional action stack.