4 using System.Collections;
5 using System.Collections.Generic;
6 using System.Collections.Specialized;
9 namespace SiliconStudio.ActionStack
13 private readonly
int index;
15 private IReadOnlyCollection<object> items;
16 private NotifyCollectionChangedAction actionToUndo;
20 if (list == null)
throw new ArgumentNullException(
"list");
21 if (actionToUndo == NotifyCollectionChangedAction.Reset)
throw new ArgumentException(
"Reset is not supported by the undo stack.");
23 this.actionToUndo = actionToUndo;
27 : this(list, actionToUndo)
29 if (items == null)
throw new ArgumentNullException(
"items");
35 : this(list, args.Action)
39 case NotifyCollectionChangedAction.Add:
40 items = args.NewItems.Cast<
object>().ToArray();
41 index = args.NewStartingIndex;
43 case NotifyCollectionChangedAction.Move:
46 case NotifyCollectionChangedAction.Remove:
47 items = args.OldItems.Cast<
object>().ToArray();
48 index = args.OldStartingIndex;
50 case NotifyCollectionChangedAction.Replace:
51 items = args.OldItems.Cast<
object>().ToArray();
52 index = args.OldStartingIndex;
54 case NotifyCollectionChangedAction.Reset:
55 throw new NotSupportedException(
"Reset is not supported by the undo stack.");
57 items =
new object[] { };
63 public NotifyCollectionChangedAction ActionToUndo {
get {
return actionToUndo; } }
65 public int ItemCount {
get {
return items.Count; } }
79 case NotifyCollectionChangedAction.Add:
80 actionToUndo = NotifyCollectionChangedAction.Remove;
81 for (
int i = 0; i < items.Count(); ++i)
86 case NotifyCollectionChangedAction.Remove:
87 actionToUndo = NotifyCollectionChangedAction.Add;
88 foreach (var item
in items)
90 list.Insert(index, item);
93 case NotifyCollectionChangedAction.Replace:
94 var replacedItems =
new List<object>();
96 foreach (var item
in items)
98 replacedItems.Add(list[index+j]);
99 list[index + j] = item;
102 items = replacedItems;
104 case NotifyCollectionChangedAction.Move:
105 throw new NotSupportedException(
"Move is not supported by the undo stack.");
106 case NotifyCollectionChangedAction.Reset:
107 throw new NotSupportedException(
"Reset is not supported by the undo stack.");
override void FreezeMembers()
Invoked by Freeze before setting IsFrozen to true. This method will not be invoked if IsFrozen is alr...
override void UndoAction()
Invoked by Undo after setting IsDone to true.
Base class for action items.
CollectionChangedActionItem(IList list, NotifyCollectionChangedEventArgs args)
CollectionChangedActionItem(IList list, NotifyCollectionChangedAction actionToUndo, IReadOnlyCollection< object > items, int index)
override void RedoAction()
Invoked by Redo after setting IsDone to true.