Esempio n. 1
0
        /// <summary>
        /// Constructor which initializes the manager with up to 8 levels
        /// of undo/redo.
        /// </summary>
        /// <param name="level">the undo level</param>
        public UndoManager(int level)
        {
            undoLevel = level;
            undoList  = new UndoCollection();
            redoStack = new StackBase <CommandInfo>();
            // The following events are linked in the sense that when an item
            // is popped from the stack it'll be put in the undo collection
            // again. So, strictly speaking, you need only two of the four
            // events to make the surface aware of the history changes, but
            // we'll keep it as is. It depends on your own perception of the
            // undo/reo process.
            redoStack.OnItemPopped +=
                new EventHandler <CollectionEventArgs <CommandInfo> >(
                    HistoryChanged);

            redoStack.OnItemPushed +=
                new EventHandler <CollectionEventArgs <CommandInfo> >(
                    HistoryChanged);

            undoList.OnItemAdded +=
                new EventHandler <CollectionEventArgs <CommandInfo> >(
                    HistoryChanged);

            undoList.OnItemRemoved +=
                new EventHandler <CollectionEventArgs <CommandInfo> >(
                    HistoryChanged);
        }
 public bool BeginAction(string actionName = "Many actions")
 {
     if (!this.UndoingRedoing)
     {
         this.actionsRecorded = new UndoCollection(actionName);
         this.PerformingAction = true;
         return true;
     }
     else
     {
         return false;
     }
 }
        public void EndAction()
        {
            if (!this.UndoingRedoing)
            {
                this.undoStack.Push(this.actionsRecorded);
                this.redoStack.Clear();

                this.actionsRecorded = null;
                this.PerformingAction = false;
            }
        }