|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
//主要功能: Undo and Redo的全局操作函数,为了区分符号修改与文件修改的Redo/Undo
|
|
|
//
|
|
|
//程序编写: 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;
|
|
|
}
|
|
|
} |