コード例 #1
0
 /// <summary>
 /// Does/Redoes the command</summary>
 public override void Do()
 {
     for (int i = 0; i < m_commands.Count; ++i)
     {
         Command command = m_commands[i];
         // if a command can't be completed successfully, back up to consistent state
         bool success = false;
         try
         {
             command.Do();
             success = true;
         }
         finally
         {
             if (!success)
             {
                 for (--i; i >= 0; --i)
                 {
                     Command done = m_commands[i];
                     done.Undo();
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: CommandHistory.cs プロジェクト: zparr/ATF
        /// <summary>
        /// Undo the last "done" command</summary>
        /// <returns>Last Command done</returns>
        public Command Undo()
        {
            if (!CanUndo)
            {
                throw new InvalidOperationException("Can't undo");
            }

            Command command = m_commands[m_commandCount.Current - 1];

            m_commandCount.Decrement();

            command.Undo();

            OnCommandUndone();

            return(command);
        }