Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CollectionChangedViewModelActionItem.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections;
5 using System.Collections.Generic;
6 using System.Collections.Specialized;
7 
8 using SiliconStudio.ActionStack;
9 using SiliconStudio.Presentation.Services;
10 
11 namespace SiliconStudio.Presentation.ViewModel.ActionStack
12 {
14  {
15  private readonly CollectionChangedActionItem innerActionItem;
16  private IDispatcherService dispatcher;
17 
19  : base(name, dirtiables)
20  {
21  if (dispatcher == null) throw new ArgumentNullException("dispatcher");
22  this.dispatcher = dispatcher;
23  }
24 
25  public CollectionChangedViewModelActionItem(string name, IEnumerable<IDirtiableViewModel> dirtiables, IList list, NotifyCollectionChangedAction actionToUndo, IReadOnlyCollection<object> items, int index, IDispatcherService dispatcher)
26  : this(name, dirtiables, dispatcher)
27  {
28  innerActionItem = new CollectionChangedActionItem(list, actionToUndo, items, index);
29  }
30 
31  public CollectionChangedViewModelActionItem(string name, IEnumerable<IDirtiableViewModel> dirtiables, IList list, NotifyCollectionChangedEventArgs args, IDispatcherService dispatcher)
32  : this(name, dirtiables, dispatcher)
33  {
34  innerActionItem = new CollectionChangedActionItem(list, args);
35  }
36 
37  public NotifyCollectionChangedAction ActionToUndo { get { return innerActionItem.ActionToUndo; } }
38 
39  public int ItemCount { get { return innerActionItem.ItemCount; } }
40 
41  /// <inheritdoc/>
42  protected override void FreezeMembers()
43  {
44  dispatcher = null;
45  innerActionItem.Freeze();
46  }
47 
48  /// <inheritdoc/>
49  protected override void UndoAction()
50  {
51  dispatcher.Invoke(() => innerActionItem.Undo());
52  }
53 
54  /// <inheritdoc/>
55  protected override void RedoAction()
56  {
57  // Once we have un-done, the previous value is updated so Redo is just Undoing the Undo
58  UndoAction();
59  }
60  }
61 }
CollectionChangedViewModelActionItem(string name, IEnumerable< IDirtiableViewModel > dirtiables, IList list, NotifyCollectionChangedAction actionToUndo, IReadOnlyCollection< object > items, int index, IDispatcherService dispatcher)
override void FreezeMembers()
Invoked by Freeze before setting IsFrozen to true. This method will not be invoked if IsFrozen is alr...
An abstact class that inherits from ActionItem and can be used to manage actions related to an IDirti...
CollectionChangedViewModelActionItem(string name, IEnumerable< IDirtiableViewModel > dirtiables, IList list, NotifyCollectionChangedEventArgs args, IDispatcherService dispatcher)
This class represents a thread-safe stack of action items that can be undone/redone.
Definition: ActionStack.cs:12