////////////////////////////////////////////////////////////////////////////// //主要功能: Undo and Redo的全局操作函数,为了区分符号修改与文件修改的Redo/Undo // //程序编写: 2006-12-07 ///////////////////////////////////////////////////////////////////////////// #if !defined(UNDOMANAGER_H) #define UNDOMANAGER_H #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #ifdef _MSC_VER #pragma warning(disable:4786) #endif #include #include #include "UMString.h" namespace NAction { /** * Action 详情 */ struct ActionDetail { std::string uuid; std::string classType; std::string createAt; }; class CAction; class CActionManager { public: enum StackKind { UNDO, REDO }; public: CActionManager(void *actionTarget); virtual ~CActionManager(); void RemoveLastAction(); void ClearTarget(); long GetStackCapacity() const; void SetStackCapacity(long capacity); void SetLastAction(CAction *itsLastAction); const UMString & GetActionName(StackKind kind, long pos) const; long GetStackSize(StackKind kind) const; virtual int Undo(long nActions = 1); virtual bool CanUndo(long nActions = 1) const; virtual int Redo(long nActions = 1); virtual bool CanRedo(long nActions = 1) const; void * GetTarget() const; void TargetCleaned(); void SavePostion(); bool IsModified(); // we use a deque so that we can pop off both ends // (e.g., off the bottom during overflow) and so we // can access all actions, say when building an undo // menu, rather than just the top; also note that we // push onto the back (like you would with a vector) typedef std::deque ActionStack; const ActionStack& GetUndoStack() const; const ActionStack& GetRedoStack() const; /** * 列出 * Action 清单 * * \return */ std::vector ListActionDetails() const; /** * 恢复到指定 action,如果为 uuid 为空,表示恢复到原图件 * * \param uuid */ void RestoreToTargetAction(const std::string& targetUUID); protected: virtual void DeleteActions(ActionStack &aStack, long nActions); //virtual void NotifyTarget(UINT operation, long nActions); void * actionTarget; ActionStack undoStack, redoStack; long cleanMarker; long capacity; CAction* m_pSavedAction; private: /** * 判断指定 uuid 的 Action 是否在 undo 栈中 * * \param uuid * \return */ bool InUndoStack(const std::string& uuid) const; /** * 判断指定 uuid 的 Action 是否在 redo 栈中 * * \param uuid * \return */ bool InRedoStack(const std::string& uuid) const; }; } //end namespace #endif