6 using SiliconStudio.ActionStack;
7 using SiliconStudio.Core.Extensions;
8 using SiliconStudio.Presentation.Collections;
9 using SiliconStudio.Presentation.Extensions;
11 namespace SiliconStudio.Presentation.ViewModel.
ActionStack
19 private readonly ObservableList<ActionItemViewModel> actionItems =
new ObservableList<ActionItemViewModel>();
27 : base(actionStack.SafeArgument(
"actionStack").ServiceProvider)
29 this.actionStack = actionStack;
31 actionStack.ActionItemsAdded += ActionItemsAdded;
32 actionStack.ActionItemsCleared += ActionItemsCleared;
33 actionStack.ActionItemsDiscarded += ActionItemsDiscarded;
34 actionStack.Undone += ActionItemModified;
35 actionStack.Redone += ActionItemModified;
46 public IReadOnlyObservableCollection<ActionItemViewModel> ActionItems {
get {
return actionItems; } }
51 public bool CanUndo {
get {
return ActionItems.Count > 0 && ActionItems.First().IsDone; } }
56 public bool CanRedo {
get {
return ActionItems.Count > 0 && !ActionItems.Last().IsDone; } }
61 actionStack.ActionItemsAdded -= ActionItemsAdded;
62 actionStack.ActionItemsCleared -= ActionItemsCleared;
63 actionStack.ActionItemsDiscarded -= ActionItemsDiscarded;
64 Dispatcher.Invoke(actionItems.Clear);
72 savePoint = actionStack.CreateSavePoint(
true);
73 actionItems.ForEach(x => x.IsSavePoint = x.ActionItem.Identifier == savePoint.ActionItemIdentifier);
76 private void ActionItemModified(
object sender, ActionItemsEventArgs<IActionItem> e)
78 foreach (var actionItem
in ActionItems)
82 private void ActionItemsDiscarded(
object sender, DiscardedActionItemsEventArgs<IActionItem> e)
84 var actionsToRemove = e.ActionItems.Select(x => actionItems.FirstOrDefault(
y => y.ActionItem.Identifier == x.Identifier)).Where(
y => y != null).ToList();
85 actionsToRemove.ForEach(x => actionItems.Remove(x));
88 private void ActionItemsCleared(
object sender,
EventArgs e)
93 private void ActionItemsAdded(
object sender, ActionItemsEventArgs<IActionItem> e)
96 actionItems.Add(
new ActionItemViewModel(actionStack.ServiceProvider, actionItem));
Represents a save point marker in the undo/redo action items stack.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
This class is a view model for the ViewModelTransactionalActionStack class. It inherits from the Disp...
This abstract class is an implementation of ViewModelBase that uses a dispatcher to invoke OnProperty...
ActionStackViewModel(ViewModelTransactionalActionStack actionStack)
Initializes a new instance of the ActionStackViewModel.
Base interface for action items.
void NotifySave()
Notify that everything has been saved and create a save point in the action stack.
This class represents a thread-safe stack of action items that can be undone/redone.