2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/cmd_sequence.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
CmdSequence::CmdSequence()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 03:51:07 +08:00
|
|
|
CmdSequence::~CmdSequence()
|
|
|
|
|
{
|
|
|
|
|
for (Cmd* cmd : m_cmds)
|
|
|
|
|
delete cmd;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
void CmdSequence::add(Cmd* cmd)
|
|
|
|
|
{
|
|
|
|
|
m_cmds.push_back(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CmdSequence::onExecute()
|
|
|
|
|
{
|
|
|
|
|
for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it)
|
|
|
|
|
(*it)->execute(context());
|
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
void CmdSequence::onUndo()
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2015-01-19 09:05:33 +08:00
|
|
|
for (auto it = m_cmds.rbegin(), end=m_cmds.rend(); it!=end; ++it)
|
|
|
|
|
(*it)->undo();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
void CmdSequence::onRedo()
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2015-01-19 09:05:33 +08:00
|
|
|
for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it)
|
|
|
|
|
(*it)->redo();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
size_t CmdSequence::onMemSize() const
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2015-01-19 09:05:33 +08:00
|
|
|
size_t size = sizeof(*this);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
for (auto it = m_cmds.begin(), end=m_cmds.end(); it!=end; ++it)
|
|
|
|
|
size += (*it)->memSize();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CmdSequence::executeAndAdd(Cmd* cmd)
|
|
|
|
|
{
|
|
|
|
|
cmd->execute(context());
|
|
|
|
|
add(cmd);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
} // namespace app
|