4 using System.Collections.Generic;
6 using SiliconStudio.Core.Reflection;
7 using SiliconStudio.Presentation.ViewModel;
8 using SiliconStudio.Presentation.ViewModel.ActionStack;
9 using SiliconStudio.Quantum;
11 namespace SiliconStudio.Presentation.Quantum
18 private string observableNodePath;
22 private object previousValue;
25 : base(name, dirtiables)
27 if (service == null)
throw new ArgumentNullException(
"service");
28 if (!nodePath.
IsValid)
throw new InvalidOperationException(
"Unable to retrieve the path of the modified node.");
29 this.service = service;
30 this.modelContainer = modelContainer;
31 this.nodePath = nodePath;
33 this.observableNodePath = observableNodePath;
34 this.identifier = identifier;
35 this.previousValue = previousValue;
38 public string ObservableNodePath {
get {
return observableNodePath; } }
43 modelContainer = null;
45 observableNodePath = null;
52 var node = nodePath.GetNode();
54 throw new InvalidOperationException(
"Unable to retrieve the node to modify in this undo process.");
56 var currentValue = GetValue(node, index);
57 bool setByObservableNode =
false;
59 var observableViewModel = service.ViewModelProvider != null ? service.ViewModelProvider(identifier) : null;
60 if (observableViewModel != null && !observableViewModel.MatchRootNode(nodePath.RootNode))
61 observableViewModel = null;
63 if (observableViewModel != null)
65 SingleObservableNode observableNode = observableViewModel.ResolveObservableModelNode(observableNodePath, nodePath.RootNode);
66 if (observableNode != null)
68 observableNode.Value = previousValue;
69 setByObservableNode =
true;
73 if (!setByObservableNode)
75 SetValue(node, index, previousValue);
77 modelContainer.UpdateReferences(node);
80 previousValue = currentValue;
90 private static void SetValue(
IModelNode node,
object index,
object value)
97 if (collectionDescriptor != null)
99 collectionDescriptor.SetValue(node.Content.Value, (int)index, value);
101 else if (dictionaryDescriptor != null)
103 dictionaryDescriptor.SetValue(node.Content.Value, index, value);
106 throw new NotSupportedException(
"Unable to undo the change, the collection is unsupported");
110 node.Content.Value = value;
114 private static object GetValue(
IModelNode node,
object index)
120 if (collectionDescriptor != null)
122 return collectionDescriptor.GetValue(node.Content.Value, (int)index);
124 if (dictionaryDescriptor != null)
126 return dictionaryDescriptor.GetValue(node.Content.Value, index);
129 throw new NotSupportedException(
"Unable to undo the change, the collection is unsupported");
132 return node.Content.Value;
Provides a descriptor for a System.Collections.ICollection.
A container used to store models and resolve references between them.
override void FreezeMembers()
Invoked by Freeze before setting IsFrozen to true.
bool IsValid
Gets whether this path is a valid path.
Provides a descriptor for a System.Collections.IDictionary.
override void UndoAction()
Invoked by Undo after setting IsDone to true.
An abstact class that inherits from ActionItem and can be used to manage actions related to an IDirti...
A class that provides various services to ObservableViewModel objects
override void RedoAction()
Invoked by Redo after setting IsDone to true.
ValueChangedActionItem(string name, ObservableViewModelService service, ModelNodePath nodePath, string observableNodePath, ObservableViewModelIdentifier identifier, object index, IEnumerable< IDirtiableViewModel > dirtiables, ModelContainer modelContainer, object previousValue)
The IModelNode interface represents a node in a model object. A model object is represented by a grap...
A class describing the path of a node, relative to a root node. The path can cross references...