4 using System.Collections.Generic;
7 using SiliconStudio.ActionStack;
8 using SiliconStudio.Presentation.ViewModel;
9 using SiliconStudio.Quantum;
11 namespace SiliconStudio.Presentation.Quantum
17 private readonly
string name;
22 : base(serviceProvider, null)
24 if (commands == null)
throw new ArgumentNullException(
"commands");
26 this.commands = commands;
28 this.identifier = identifier;
30 ObservableNodePath = observableNodePath;
33 public override string Name {
get {
return name; } }
37 public override void Execute(
object parameter)
39 actionStack.BeginTransaction();
40 Redo(parameter,
true);
41 var displayName =
"Executing " + Name;
43 var observableViewModel = service.ViewModelProvider(identifier);
44 if (observableViewModel != null && !commands.Any(x => observableViewModel.MatchCombinedRootNode(x.GetCommandRootNode())))
45 observableViewModel = null;
47 var node = observableViewModel != null ? observableViewModel.ResolveObservableNode(ObservableNodePath) as
CombinedObservableNode : null;
49 actionStack.EndTransaction(displayName, x =>
new CombinedValueChangedActionItem(displayName, service, node != null ? node.Path : null, identifier, x));
52 protected override UndoToken Redo(
object parameter,
bool creatingActionItem)
54 var undoTokens =
new Dictionary<ModelNodeCommandWrapper, UndoToken>();
56 foreach (var command
in commands)
58 var undoToken = command.ExecuteCommand(parameter, creatingActionItem);
59 undoTokens.Add(command, undoToken);
60 canUndo = canUndo || undoToken.CanUndo;
63 return new UndoToken(canUndo, undoTokens);
68 var undoTokens = (Dictionary<ModelNodeCommandWrapper, UndoToken>)token.
TokenValue;
69 foreach (var command in commands)
71 command.UndoCommand(parameter, undoTokens[command]);
76 private void Refresh()
78 var observableViewModel = service.ViewModelProvider(identifier);
79 if (observableViewModel != null && !commands.Any(x => observableViewModel.MatchCombinedRootNode(x.GetCommandRootNode())))
80 observableViewModel = null;
82 var observableNode = observableViewModel != null ? observableViewModel.ResolveObservableNode(ObservableNodePath) as
CombinedObservableNode : null;
85 if (observableNode != null)
87 observableNode.Refresh();
88 observableNode.Owner.NotifyNodeChanged(observableNode.Path);
override void Execute(object parameter)
override void Undo(object parameter, UndoToken token)
Undoes the execution of the command.
override UndoToken Redo(object parameter, bool creatingActionItem)
Does or redoes the execution of the command.
A service provider class for view model objects.
CombineMode
An enum that describes what to do with a node or a command when combining view models.
A class that provides various services to ObservableViewModel objects
A base class to wrap one or multiple INodeCommand instances into a CancellableCommand.
CombinedNodeCommandWrapper(IViewModelServiceProvider serviceProvider, string name, string observableNodePath, ObservableViewModelIdentifier identifier, IEnumerable< ModelNodeCommandWrapper > commands)
object TokenValue
Gets a user-defined object hosted by the token that should store all information needed to undo a com...
Represents a token that stores an unique identifier and an object. This token should be generated by ...
Base interface for a transactional action stack.