Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ModifyValueCommand.cs
Go to the documentation of this file.
1 using SiliconStudio.ActionStack;
2 using SiliconStudio.Core.Reflection;
3 
4 namespace SiliconStudio.Quantum.Commands
5 {
6  // TODO: This class is temporary to workaround the cancellation of commands that just modify the value of the node
7  public abstract class ModifyValueCommand : INodeCommand
8  {
9  /// <inheritdoc/>
10  public abstract string Name { get; }
11 
12  /// <inheritdoc/>
13  public abstract CombineMode CombineMode { get; }
14 
15  /// <inheritdoc/>
16  public abstract bool CanAttach(ITypeDescriptor typeDescriptor, MemberDescriptorBase memberDescriptor);
17 
18  public object Invoke(object currentValue, ITypeDescriptor descriptor, object parameter, out UndoToken undoToken)
19  {
20  var newValue = ModifyValue(currentValue, descriptor, parameter);
21  undoToken = !Equals(newValue, currentValue) ? new UndoToken(true, currentValue) : new UndoToken(false);
22  return newValue;
23  }
24 
25  public object Undo(object currentValue, ITypeDescriptor descriptor, UndoToken undoToken)
26  {
27  return undoToken.TokenValue;
28  }
29 
30  protected abstract object ModifyValue(object currentValue, ITypeDescriptor descriptor, object parameter);
31  }
32 }
object Undo(object currentValue, ITypeDescriptor descriptor, UndoToken undoToken)
Undoes an invoke of the node command.
CombineMode
An enum that describes what to do with a node or a command when combining view models.
Definition: CombineMode.cs:8
Base interface for node commands.
Definition: INodeCommand.cs:11
Provides access members of a type.
object Invoke(object currentValue, ITypeDescriptor descriptor, object parameter, out UndoToken undoToken)
Invokes the node command.
Base class for IMemberDescriptor for a MemberInfo
Represents a token that stores an unique identifier and an object. This token should be generated by ...
Definition: UndoToken.cs:12