コード例 #1
0
ファイル: UndoRedoManager.cs プロジェクト: ajbadaj/AJut
        /// <summary>
        /// Performs an undo
        /// </summary>
        /// <returns>False if there weren't any undos, true otherwise</returns>
        public bool Undo()
        {
            if (!this.AnyUndos)
            {
                return(false);
            }

            bool anyUndosChange = m_undoStack.Count == 1;
            bool anyRedosChange = m_redoStack.Count == 0;

            IUndoableAction action = m_undoStack[0];

            m_undoStack.RemoveAt(0);

            action.Undo();
            m_redoStack.Insert(0, action);

            if (anyUndosChange)
            {
                this.RaisePropertiesChanged(nameof(AnyUndos));
            }
            else if (anyRedosChange)
            {
                this.RaisePropertiesChanged(nameof(AnyRedos));
            }

            return(true);
        }
コード例 #2
0
ファイル: PaintCanvas.cs プロジェクト: ircart/asciipumper
 public void Undo()
 {
     if (UndoList.Count > 0)
     {
         IUndoableAction act = UndoList.Pop();
         act.Undo(this);
         OnUndoChanged(UndoChangedEventArgs.Empty);
         RedoList.Push(act);
         OnRedoChanged(RedoChangedEventArgs.Empty);
     }
 }
コード例 #3
0
        public IAction Undo()
        {
            if (undoStack.Count() > 0)
            {
                IUndoableAction action = null;

                while (undoStack.Count > 0)
                {
                    action = undoStack.Last();
                    Logger.Log(LOGKEY, "undo action: " + action.ToString());

                    // before event
                    if (BeforePerformAction != null)
                    {
                        var arg = new ActionEventArgs(action, ActionBehavior.Undo);
                        BeforePerformAction(this, new ActionEventArgs(action, ActionBehavior.Undo));
                        if (arg.Cancel)
                        {
                            break;
                        }
                    }

                    undoStack.Remove(action);
                    action.Undo();
                    redoStack.Push(action);

                    // after event
                    AfterPerformAction?.Invoke(this, new ActionEventArgs(action, ActionBehavior.Undo));

                    if (!(action is ISerialUndoAction))
                    {
                        break;
                    }
                }

                return(action);
            }
            return(null);
        }