Counter Strike : Global Offensive Source Code
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.

116 lines
3.1 KiB

  1. //====== Copyright � 1996-2005, 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/utlsymbollarge.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. CUtlSymbolLarge GetUndoDescInternal( const char *context );
  48. CUtlSymbolLarge 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. private:
  58. void Trace( const char *fmt, ... );
  59. CUtlLinkedList< IUndoElement *, int > m_UndoList;
  60. CUtlStack< IUndoElement * > m_RedoStack;
  61. CUtlVector< IDmNotify* > m_Notifiers;
  62. int m_nMaxUndoDepth;
  63. int m_nNesting;
  64. int m_nNotifyNesting;
  65. CUtlSymbolLarge m_UndoDesc;
  66. CUtlSymbolLarge m_RedoDesc;
  67. int m_nNotifySource;
  68. int m_nNotifyFlags;
  69. const char* m_pNotifyReason;
  70. int m_nItemsAddedSinceStartOfStream;
  71. // Signals that next undo operation is the "Start" of a stream
  72. bool m_bStreamStart : 1;
  73. bool m_bTrace : 1;
  74. bool m_bDiscarded : 1;
  75. bool m_bEnabled : 1;
  76. bool m_bSuppressingNotify : 1;
  77. int m_nChainingID;
  78. int m_PreviousChainingID;
  79. };
  80. //-----------------------------------------------------------------------------
  81. // Is undo enabled
  82. //-----------------------------------------------------------------------------
  83. inline bool CUndoManager::IsEnabled() const
  84. {
  85. return m_bEnabled;
  86. }
  87. inline void CUndoManager::NotifyState( int nNotifyFlags )
  88. {
  89. // FIXME: Should suppress prevent notification being sent,
  90. // or prevent notification flags from being set in the first place?
  91. m_nNotifyFlags |= nNotifyFlags;
  92. }
  93. #endif // UNDOMANAGER_H