| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2001-2015 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifdef HAVE_CONFIG_H |
| 8 | #include "config.h" |
| 9 | #endif |
| 10 | |
| 11 | #include "app/cmd_sequence.h" |
| 12 | |
| 13 | namespace app { |
| 14 | |
| 15 | CmdSequence::CmdSequence() |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | CmdSequence::~CmdSequence() |
| 20 | { |
| 21 | for (Cmd* cmd : m_cmds) |
| 22 | delete cmd; |
| 23 | } |
| 24 | |
| 25 | void CmdSequence::add(Cmd* cmd) |
| 26 | { |
| 27 | m_cmds.push_back(cmd); |
| 28 | } |
| 29 | |
| 30 | void CmdSequence::onExecute() |
| 31 | { |
| 32 | for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it) |
| 33 | (*it)->execute(context()); |
| 34 | } |
| 35 | |
| 36 | void CmdSequence::onUndo() |
| 37 | { |
| 38 | for (auto it = m_cmds.rbegin(), end=m_cmds.rend(); it!=end; ++it) |
| 39 | (*it)->undo(); |
| 40 | } |
| 41 | |
| 42 | void CmdSequence::onRedo() |
| 43 | { |
| 44 | for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it) |
| 45 | (*it)->redo(); |
| 46 | } |
| 47 | |
| 48 | size_t CmdSequence::onMemSize() const |
| 49 | { |
| 50 | size_t size = sizeof(*this); |
| 51 | |
| 52 | for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it) |
| 53 | size += (*it)->memSize(); |
| 54 | |
| 55 | return size; |
| 56 | } |
| 57 | |
| 58 | void CmdSequence::executeAndAdd(Cmd* cmd) |
| 59 | { |
| 60 | cmd->execute(context()); |
| 61 | add(cmd); |
| 62 | } |
| 63 | |
| 64 | } // namespace app |
| 65 |