You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
2.5 KiB
C++

1 month ago
//////////////////////////////////////////////////////////////////////////////
//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>: Undo and Redo<64><6F>ȫ<EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>޸<EFBFBD><DEB8><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>޸ĵ<DEB8>Redo/Undo
//
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д: 2006-12-07
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Action.h"
#include "UndoManager.h"
#include <assert.h>
#include "SigmaResouce.h"
#include "Util.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
namespace NAction
{
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAction::CAction(void *pActionTarget, UINT uActionType, bool bAutoNotify)
: actionTarget(pActionTarget)
, actionType(uActionType)
, autoNotify(bAutoNotify)
, finished(false)
, undone(false)
, success(true)
, done(false)
, m_uuid(GenerateUUID())
, m_timepoint(std::chrono::system_clock::now())
{
#ifdef _MFC_VER
if (actionType != 0)
{
name = CSigmaResouce::GetString(actionType);
//name.LoadString(actionType);
int i = name.Find('\n');
if (i > 0) name = name.Mid(i + 1);
}
#endif
}
CAction::~CAction()
{
}
void CAction::SetActionTarget(void* pActionTarget)
{
actionTarget = pActionTarget;
}
const std::string& CAction::GetUUID() const
{
return m_uuid;
}
void CAction::SetUUID(const std::string& uuid)
{
m_uuid = uuid;
}
std::chrono::system_clock::time_point CAction::GetTimePoint() const
{
return m_timepoint;
}
void CAction::SetTimePoint(std::chrono::system_clock::time_point timepoint)
{
m_timepoint = timepoint;
}
const UMString& CAction::GetName() const
{
static CString temp = name;
if (actionType != 0)
{
temp.LoadString(actionType);
int i = temp.Find('\n');
if (i > 0) temp = temp.Mid(i + 1);
}
return temp;
//return name;
}
void CAction::NotifyUndoManager()
{
//assert(GetUndoManager());
//GetUndoManager()->SetLastAction(actionTarget, this);
}
void CAction::Do()
{
if (autoNotify)
NotifyUndoManager();
done = true;
}
bool CAction::IsFinished() const
{
return finished;
}
bool CAction::IsSuccess() const
{
return success;
}
void CAction::SetActionType(const UINT type)
{
actionType = type;
}
UINT CAction::GetActionType()
{
return actionType;
}
void CAction::SetAutoNotify(bool an)
{
autoNotify = an;
}
void CAction::Undo()
{
undone = true;
}
void CAction::Redo()
{
undone = false;
}
void CAction::Finish()
{
finished = true;
}
bool CAction::IsUndone() const
{
return undone;
}
}