00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Ramin Kamal 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_UndoBlock.h ( Utility Library, C++) 00015 * 00016 * COMMENTS: 00017 * This class is used by UT_UndoManager to organize groups 00018 * of operations into a singe undoable block. It is basically 00019 * a stack of UT_Undo's with an associated name (for the undo 00020 * menu entry) 00021 */ 00022 00023 #ifndef __UT_UndoBlock__ 00024 #define __UT_UndoBlock__ 00025 00026 #include "UT_API.h" 00027 #include "UT_String.h" 00028 #include "UT_Undo.h" 00029 #include "UT_PtrArray.h" 00030 00031 class UT_API UT_UndoBlock : public UT_Undo 00032 { 00033 public: 00034 explicit UT_UndoBlock(const char *name, UT_UndoBlock *next = NULL); 00035 ~UT_UndoBlock(); 00036 00037 int isEmpty() { return !myUndoHead; } 00038 void addUndo(UT_Undo *); 00039 void setNestedBlockName(int level, const char *name); 00040 const char *getNestedBlockName(int level) const 00041 { 00042 if (level < myNestedNames.entries()) 00043 return myNestedNames(level); 00044 return ""; 00045 } 00046 00047 virtual void undo(); 00048 virtual void redo(); 00049 virtual int isUndoBlock() const { return 1; } 00050 00051 // needToUndo/Redo return true if any of the UT_Undos in the block return 00052 // true for the corresponding method 00053 virtual bool needToUndo(); 00054 virtual bool needToRedo(); 00055 00056 /// Free all invalid undos/redos. Returns true if any pruning was done. 00057 bool pruneInvalidUndos(); 00058 00059 virtual int64 getMemoryUsage(); 00060 00061 void clearContents(); 00062 00063 UT_UndoBlock *getNextBlock() { return myNextBlock; } 00064 const UT_UndoBlock *getNextBlock() const { return myNextBlock; } 00065 void setNextBlock(UT_UndoBlock *b) { myNextBlock = b; } 00066 00067 // This is firefighting. The undo strategy we've employed is errorprone, 00068 // and this method attempts to correct frequent programmer errors. 00069 // Essentially, when a too-many-begins error occurs, this method is 00070 // called, and it lops out any undos that don't belong in this block, 00071 // returning them. The caller is responsible for taking ownership of 00072 // these returned undos. 00073 UT_UndoBlock *repairErrors(); 00074 void debugPrint(int indent = 1) const; 00075 00076 private: 00077 UT_Undo *myUndoHead; 00078 UT_UndoBlock *myNextBlock; 00079 UT_PtrArray<char *> myNestedNames; 00080 int64 myMemoryUsage; 00081 }; 00082 #endif 00083
1.5.9