Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef UNDOMANAGER_H
  7. #define UNDOMANAGER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlsymbol.h"
  12. #include "tier1/utllinkedlist.h"
  13. #include "tier1/utlstack.h"
  14. //-----------------------------------------------------------------------------
  15. // Forward declarations
  16. //-----------------------------------------------------------------------------
  17. class IUndoElement;
  18. struct UndoInfo_t;
  19. class IDmNotify;
  20. //-----------------------------------------------------------------------------
  21. // Undo/Redo stuff:
  22. //-----------------------------------------------------------------------------
  23. class CUndoManager
  24. {
  25. public:
  26. CUndoManager();
  27. ~CUndoManager();
  28. void Shutdown();
  29. void SetUndoDepth( int nMaxUndoDepth );
  30. void AddUndoElement( IUndoElement *pElement );
  31. void Undo();
  32. void Redo();
  33. void TraceUndo( bool state );
  34. void EnableUndo();
  35. void DisableUndo();
  36. bool IsEnabled() const;
  37. bool HasUndoData() const;
  38. bool UndoDataDiscarded() const;
  39. bool HasRedoData() const;
  40. void WipeUndo();
  41. void WipeRedo();
  42. const char *UndoDesc() const;
  43. const char *RedoDesc() const;
  44. void PushUndo( char const *udesc, char const *rdesc, int nChainingID );
  45. void PushRedo();
  46. void AbortUndoableOperation();
  47. UtlSymId_t GetUndoDescInternal( const char *context );
  48. UtlSymId_t GetRedoDescInternal( const char *context );
  49. void GetUndoInfo( CUtlVector< UndoInfo_t >& list );
  50. bool InstallNotificationCallback( IDmNotify *pNotify );
  51. void RemoveNotificationCallback( IDmNotify *pNotify );
  52. bool IsSuppressingNotify( ) const;
  53. void SetSuppressingNotify( bool bSuppress );
  54. void PushNotificationScope( const char *pReason, int nNotifySource, int nNotifyFlags );
  55. void PopNotificationScope( bool bAbort );
  56. void NotifyState( int nNotifyFlags );
  57. static const char *GetUndoString( CUtlSymbol sym );
  58. private:
  59. void Trace( PRINTF_FORMAT_STRING const char *fmt, ... );
  60. CUtlLinkedList< IUndoElement *, int > m_UndoList;
  61. CUtlStack< IUndoElement * > m_RedoStack;
  62. CUtlVector< IDmNotify* > m_Notifiers;
  63. int m_nMaxUndoDepth;
  64. int m_nNesting;
  65. int m_nNotifyNesting;
  66. CUtlSymbol m_UndoDesc;
  67. CUtlSymbol m_RedoDesc;
  68. int m_nNotifySource;
  69. int m_nNotifyFlags;
  70. const char* m_pNotifyReason;
  71. int m_nItemsAddedSinceStartOfStream;
  72. // Signals that next undo operation is the "Start" of a stream
  73. bool m_bStreamStart : 1;
  74. bool m_bTrace : 1;
  75. bool m_bDiscarded : 1;
  76. bool m_bEnabled : 1;
  77. bool m_bSuppressingNotify : 1;
  78. static CUtlSymbolTableMT s_UndoSymbolTable;
  79. int m_nChainingID;
  80. int m_PreviousChainingID;
  81. };
  82. //-----------------------------------------------------------------------------
  83. // Is undo enabled
  84. //-----------------------------------------------------------------------------
  85. inline bool CUndoManager::IsEnabled() const
  86. {
  87. return m_bEnabled;
  88. }
  89. inline void CUndoManager::NotifyState( int nNotifyFlags )
  90. {
  91. // FIXME: Should suppress prevent notification being sent,
  92. // or prevent notification flags from being set in the first place?
  93. m_nNotifyFlags |= nNotifyFlags;
  94. }
  95. inline const char *CUndoManager::GetUndoString( CUtlSymbol sym )
  96. {
  97. return s_UndoSymbolTable.String( sym );
  98. }
  99. #endif // UNDOMANAGER_H