5 using SiliconStudio.ActionStack;
6 using SiliconStudio.Core.Reflection;
8 namespace SiliconStudio.Quantum.
Commands
12 private struct UndoTokenData
14 private readonly
object previousIndex;
16 private readonly
object newIndex;
18 public UndoTokenData(
object previousIndex,
object newIndex)
20 this.previousIndex = previousIndex;
21 this.newIndex = newIndex;
24 public object PreviousIndex {
get {
return previousIndex; } }
26 public object NewIndex {
get {
return newIndex; } }
30 public string Name {
get {
return "RenameStringKey"; } }
40 return dictionaryDescriptor != null && dictionaryDescriptor.KeyType == typeof(
string);
47 var tuple = parameter as Tuple<object, object>;
48 if (dictionaryDescriptor == null || tuple == null)
49 throw new InvalidOperationException(
"This command cannot be executed on the given object.");
51 var removedObject = dictionaryDescriptor.GetValue(currentValue, tuple.Item1);
52 undoToken =
new UndoToken(
true,
new UndoTokenData(tuple.Item1, tuple.Item2));
53 dictionaryDescriptor.Remove(currentValue, tuple.Item1);
54 dictionaryDescriptor.SetValue(currentValue, tuple.Item2, removedObject);
63 var undoData = (UndoTokenData)undoToken.
TokenValue;
64 if (dictionaryDescriptor == null)
65 throw new InvalidOperationException(
"This command cannot be cancelled on the given object.");
67 if (dictionaryDescriptor.ContainsKey(currentValue, undoData.PreviousIndex))
68 throw new InvalidOperationException(
"Unable to undo remove: the dictionary contains the key to re-add.");
70 var removedObject = dictionaryDescriptor.GetValue(currentValue, undoData.NewIndex);
71 dictionaryDescriptor.Remove(currentValue, undoData.NewIndex);
72 dictionaryDescriptor.SetValue(currentValue, undoData.PreviousIndex, removedObject);
bool CanAttach(ITypeDescriptor descriptor, MemberDescriptorBase memberDescriptor)
Indicates whether this command can be attached to an object or a member with the given descriptors...
object Undo(object currentValue, ITypeDescriptor descriptor, UndoToken undoToken)
Undoes an invoke of the node command. The current value of the associated object or member...
Provides a descriptor for a System.Collections.IDictionary.
CombineMode
An enum that describes what to do with a node or a command when combining view models.
Base interface for node commands.
object Invoke(object currentValue, ITypeDescriptor descriptor, object parameter, out UndoToken undoToken)
Invokes the node command. The current value of the associated object or member.The type descriptor of...
Provides access members of a type.
object TokenValue
Gets a user-defined object hosted by the token that should store all information needed to undo a com...
Base class for IMemberDescriptor for a MemberInfo
Represents a token that stores an unique identifier and an object. This token should be generated by ...