1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System.Collections.Generic;
- namespace PaintDotNet.Measurement.HistoryMementos
- {
- /// <summary>
- /// Lets you combine multiple HistoryMementos that can be undon/redone
- /// in a single operation, and be referred to by one name.
- /// The actions will be undone in the reverse order they are given to
- /// the constructor via the actions array.
- /// You can use 'null' for a HistoryMemento and it will be ignored.
- /// </summary>
- public class CompoundHistoryMemento
- : HistoryMemento
- {
- private List<HistoryMemento> actions;
- protected override void OnFlush()
- {
- for (int i = 0; i < actions.Count; ++i)
- {
- if (actions[i] != null)
- {
- actions[i].Flush();
- }
- }
- }
- protected override HistoryMemento OnUndo()
- {
- List<HistoryMemento> redoActions = new List<HistoryMemento>(actions.Count);
- for (int i = 0; i < actions.Count; ++i)
- {
- HistoryMemento ha = actions[actions.Count - i - 1];
- HistoryMemento rha = null;
- if (ha != null)
- {
- rha = ha.PerformUndo();
- }
- redoActions.Add(rha);
- }
- CompoundHistoryMemento cha = new CompoundHistoryMemento(Name, Image, redoActions);
- return cha;
- }
- public void PushNewAction(HistoryMemento newHA)
- {
- actions.Add(newHA);
- }
- public CompoundHistoryMemento(string name, ImageResource image, List<HistoryMemento> actions)
- : base(name, image)
- {
- this.actions = new List<HistoryMemento>(actions);
- }
- public CompoundHistoryMemento(string name, ImageResource image, HistoryMemento[] actions)
- : base(name, image)
- {
- this.actions = new List<HistoryMemento>(actions);
- }
- public CompoundHistoryMemento(string name, ImageResource image)
- : this(name, image, new HistoryMemento[0])
- {
- }
- }
- }
|