#include "presaction.hpp"

#include "prescribble.hpp"



// ======== PresComplexAction ==========
PresComplexAction::~PresComplexAction()
{
    while( !m_subactions.empty() )
    {
        delete m_subactions.back();
        m_subactions.pop_back();
    }
}


bool PresComplexAction::undo( Context *a_pContext = 0 )
{
    for( ActionList::iterator it = m_subactions.begin();
         it != m_subactions.end();
         it++ )
    {
        if ( (*it)->isDone() )
            (*it)->undo();
    }
    m_done = false;
    return !m_done;
}

bool PresComplexAction::redo( Context *a_pContext = 0 )
{

    for( ActionList::iterator it = m_subactions.begin();
         it != m_subactions.end();
         it++ )
    {
        if ( !(*it)->isDone() )
            (*it)->redo();
    }
    m_done = true;
    return m_done;
}

void PresComplexAction::add( PresAction& action ){
    m_subactions.push_back( &action );
}
