|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
//主要功能: Undo and Redo的全局操作函数,为了区分符号修改与文件修改的Redo/Undo
|
|
|
//
|
|
|
//程序编写: 2006-12-07
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// Action.h: interface for the CAction class.
|
|
|
//
|
|
|
// Actions are undoable operations. This class abstracts that notion
|
|
|
// by defining the following interface:
|
|
|
//
|
|
|
// void Do();
|
|
|
// -- carry out the operation; generally called only once;
|
|
|
// -- usually, the action must save the existing state before
|
|
|
// -- performing its operation
|
|
|
// void Undo();
|
|
|
// -- called to undo what was done in Do(); usually must
|
|
|
// -- save the new state, as created by Do(), before reverting
|
|
|
// -- to the previous state before Do()
|
|
|
// void Redo();
|
|
|
// -- called to redo an undone action; generally this is
|
|
|
// -- different from Do() because all states have already
|
|
|
// -- been saved explicitly by Do() or Undo(); occasionally,
|
|
|
// -- a state may be more difficult to store than to compute,
|
|
|
// -- so then this routine may just call Do()
|
|
|
//
|
|
|
// Each derived class should call its base class's implementation of
|
|
|
// these routines.
|
|
|
//
|
|
|
// Most routines are virtual to allow overrides -- even GetActionName()
|
|
|
// is redefined in one derived action (CREStyleAction). Performance
|
|
|
// is not really a factor as doing the operation the action encapsulates
|
|
|
// will be far more expensive in the general case.
|
|
|
//
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
#pragma once
|
|
|
#include <chrono>
|
|
|
#pragma warning(disable:4786)
|
|
|
#include "UMString.h"
|
|
|
|
|
|
class CActionVisitor;
|
|
|
class BlobSerializer;
|
|
|
|
|
|
namespace NAction
|
|
|
{
|
|
|
enum ActionType
|
|
|
{
|
|
|
ActionTypeLayerRename = 1, // 图层重命名
|
|
|
ActionTypeLayerAdd = 2, // 图层添加
|
|
|
ActionTypeLayerDelete = 3, // 图层删除
|
|
|
ActionTypeLayerDragDrop = 4, // 图层拖拽
|
|
|
ActionTypeLayerEmbellishCurveAdd = 5, // 图层添加曲线修饰
|
|
|
ActionTypeLayerEmbellishCurveDelete = 6, // 图层删除曲线修饰
|
|
|
ActionTypeLayerEmbellishCurveMoveUp = 7, // 图层删除曲线修饰
|
|
|
ActionTypeLayerEmbellishCurveMoveDown = 8, // 图层删除曲线修饰
|
|
|
ActionTypeLayerEmbellishPointAdd = 9, // 图层添加点修饰
|
|
|
ActionTypeLayerEmbellishPointDelete = 10, // 图层删除点修饰
|
|
|
};
|
|
|
|
|
|
class CAction
|
|
|
{
|
|
|
public:
|
|
|
CAction(void *pActionTarget, UINT uActionType = 0, bool bAutoNotify = true);
|
|
|
virtual ~CAction();
|
|
|
|
|
|
/**
|
|
|
* 设置 actionTarget,建议不要随便调用,只有反序列化等少数场景才调用它
|
|
|
*
|
|
|
* \param pActionTarget
|
|
|
*/
|
|
|
void SetActionTarget(void* pActionTarget);
|
|
|
|
|
|
const std::string& GetUUID() const;
|
|
|
|
|
|
void SetUUID(const std::string& uuid);
|
|
|
|
|
|
/**
|
|
|
* 获取该 Action 发生的时间,如果没有单独设置,则是该对象创建的时间
|
|
|
*
|
|
|
* \return
|
|
|
*/
|
|
|
std::chrono::system_clock::time_point GetTimePoint() const;
|
|
|
|
|
|
/**
|
|
|
* 设置 Action 发生的时间
|
|
|
*
|
|
|
* \param timepoint
|
|
|
*/
|
|
|
void SetTimePoint(std::chrono::system_clock::time_point timepoint);
|
|
|
|
|
|
/**
|
|
|
* 接收访问者
|
|
|
*
|
|
|
* \param visitor
|
|
|
*/
|
|
|
virtual void accept(CActionVisitor& visitor) = 0;
|
|
|
|
|
|
// Notifies the Undo Manager of this action; this
|
|
|
// routine will be called automatically if autoNotify
|
|
|
// is true; otherwise, it must be called explicitly.
|
|
|
void NotifyUndoManager();
|
|
|
|
|
|
void SetActionType(const UINT type);
|
|
|
UINT GetActionType();
|
|
|
|
|
|
/**
|
|
|
* 获取 Action 名称,区别于下面的 GetName,它依赖 type,而这个 type 又是可以随意更改的
|
|
|
*
|
|
|
* \return
|
|
|
*/
|
|
|
virtual std::string GetActionName() const = 0;
|
|
|
|
|
|
// Get or set a the name of the action.
|
|
|
const UMString& GetName() const;
|
|
|
|
|
|
// do the operation
|
|
|
virtual void Do();
|
|
|
// undo the operation
|
|
|
virtual void Undo();
|
|
|
// redo the operation
|
|
|
virtual void Redo();
|
|
|
// finish the action; useful saving important
|
|
|
// but last-minute bits of data and ending long
|
|
|
// duration actions
|
|
|
virtual void Finish();
|
|
|
// is the action done or undone?
|
|
|
virtual bool IsUndone() const;
|
|
|
|
|
|
// is the action finished yet?
|
|
|
bool IsFinished() const;
|
|
|
// was the action successful in performing the
|
|
|
// operation? generally used for OLE operations
|
|
|
bool IsSuccess() const;
|
|
|
|
|
|
// should the action notify the undo manager
|
|
|
// automatically? (you must call notify the
|
|
|
// undo manager yourself if not.)
|
|
|
void SetAutoNotify(bool an);
|
|
|
|
|
|
friend class BlobSerializer;
|
|
|
|
|
|
protected:
|
|
|
// a pointer to what the action affects; this is
|
|
|
// usually a container of some sort -- subclasses
|
|
|
// add something more specific (e.g., a contained
|
|
|
// subview); it's generic, cast as necessary
|
|
|
void * actionTarget;
|
|
|
// indicates whether the undo manager should
|
|
|
// be notified automatically of when an action
|
|
|
// has been done.
|
|
|
bool autoNotify;
|
|
|
// indicates whether the action is complete;
|
|
|
// some actions, like typing, have a duration
|
|
|
// longer than a single call to Do()
|
|
|
bool finished;
|
|
|
// indicates whether the action has been undone or not;
|
|
|
// after do & redo, it's false; after undo; it's true;
|
|
|
bool undone;
|
|
|
// for operations which have a reasonable probability
|
|
|
// of failure; generally used in highly dynamic situations
|
|
|
bool success;
|
|
|
// used for both identifying the particular action to
|
|
|
// perform (e.g., an edit action can be a cut or paste)
|
|
|
// as well as a resource string describing the action.
|
|
|
UINT actionType;
|
|
|
// name of the action; usually dependent on the action
|
|
|
// type and obtained from a resource; could be font name
|
|
|
// or something else though.
|
|
|
UMString name;
|
|
|
bool done;
|
|
|
|
|
|
private:
|
|
|
std::string m_uuid;
|
|
|
std::chrono::system_clock::time_point m_timepoint;
|
|
|
};
|
|
|
}
|