UndoUtil.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. #include "UndoUtil.h"
  10. #include "Include/EditorCoreAPI.h"
  11. CUndo::CUndo(const char* description)
  12. : m_bCancelled(false)
  13. {
  14. if (!IsRecording())
  15. {
  16. GetIEditor()->BeginUndo();
  17. azstrncpy(m_description, scDescSize, description, scDescSize);
  18. m_description[scDescSize - 1] = '\0';
  19. m_bStartedRecord = true;
  20. }
  21. else
  22. {
  23. m_bStartedRecord = false;
  24. }
  25. };
  26. CUndo::~CUndo()
  27. {
  28. if (m_bStartedRecord)
  29. {
  30. if (m_bCancelled)
  31. {
  32. GetIEditor()->CancelUndo();
  33. }
  34. else
  35. {
  36. GetIEditor()->AcceptUndo(m_description);
  37. }
  38. }
  39. };
  40. bool CUndo::IsRecording()
  41. {
  42. if (IEditor* editor = GetIEditor())
  43. {
  44. return editor->IsUndoRecording();
  45. }
  46. return false;
  47. }
  48. bool CUndo::IsSuspended()
  49. {
  50. if (IEditor* editor = GetIEditor())
  51. {
  52. return editor->IsUndoSuspended();
  53. }
  54. return false;
  55. }
  56. void CUndo::Record(IUndoObject* undo)
  57. {
  58. if (IEditor* editor = GetIEditor())
  59. {
  60. editor->RecordUndo(undo);
  61. }
  62. }
  63. CUndoSuspend::CUndoSuspend()
  64. {
  65. if (IEditor* editor = GetIEditor())
  66. {
  67. editor->SuspendUndo();
  68. }
  69. };
  70. CUndoSuspend::~CUndoSuspend()
  71. {
  72. if (IEditor* editor = GetIEditor())
  73. {
  74. editor->ResumeUndo();
  75. }
  76. };