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.

178 lines
5.4 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
/////////////////////////////////////////////////////////////////////////////
// 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, // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ActionTypeLayerAdd = 2, // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ActionTypeLayerDelete = 3, // ͼ<><CDBC>ɾ<EFBFBD><C9BE>
ActionTypeLayerDragDrop = 4, // ͼ<><CDBC><EFBFBD><EFBFBD>ק
ActionTypeLayerEmbellishCurveAdd = 5, // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ActionTypeLayerEmbellishCurveDelete = 6, // ͼ<><CDBC>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ActionTypeLayerEmbellishCurveMoveUp = 7, // ͼ<><CDBC>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ActionTypeLayerEmbellishCurveMoveDown = 8, // ͼ<><CDBC>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ActionTypeLayerEmbellishPointAdd = 9, // ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>
ActionTypeLayerEmbellishPointDelete = 10, // ͼ<><CDBC>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
};
class CAction
{
public:
CAction(void *pActionTarget, UINT uActionType = 0, bool bAutoNotify = true);
virtual ~CAction();
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> actionTarget<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>ֻ<EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* \param pActionTarget
*/
void SetActionTarget(void* pActionTarget);
const std::string& GetUUID() const;
void SetUUID(const std::string& uuid);
/**
* <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD> Action <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǹö<EFBFBD><EFBFBD>󴴽<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
*
* \return
*/
std::chrono::system_clock::time_point GetTimePoint() const;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> Action <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
*
* \param timepoint
*/
void SetTimePoint(std::chrono::system_clock::time_point timepoint);
/**
* <EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* \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();
/**
* <EFBFBD><EFBFBD>ȡ Action <EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GetName<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> type<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> type <EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
*
* \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;
};
}