ScriptCanvasUndoHelper.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #pragma once
  9. #include <ScriptCanvas/Bus/UndoBus.h>
  10. #include <Editor/Undo/ScriptCanvasUndoManager.h>
  11. namespace ScriptCanvasEditor
  12. {
  13. // Helper class that provides the implementation for UndoRequestBus
  14. class UndoHelper
  15. : public UndoRequestBus::Handler
  16. , public AzToolsFramework::UndoSystem::IUndoNotify
  17. {
  18. public:
  19. UndoHelper();
  20. UndoHelper(EditorGraph* source);
  21. ~UndoHelper();
  22. UndoCache* GetSceneUndoCache() override;
  23. UndoData CreateUndoData() override;
  24. void SetSource(EditorGraph* source);
  25. void BeginUndoBatch(AZStd::string_view label) override;
  26. void EndUndoBatch() override;
  27. void AddUndo(AzToolsFramework::UndoSystem::URSequencePoint* seqPoint) override;
  28. void AddGraphItemChangeUndo(AZStd::string_view undoLabel) override;
  29. void AddGraphItemAdditionUndo(AZStd::string_view undoLabel) override;
  30. void AddGraphItemRemovalUndo(AZStd::string_view undoLabel) override;
  31. void Undo() override;
  32. void Redo() override;
  33. void Reset() override;
  34. bool IsActive() override;
  35. bool IsIdle() override;
  36. bool CanUndo() const override;
  37. bool CanRedo() const override;
  38. private:
  39. void OnUndoStackChanged() override;
  40. void UpdateCache();
  41. enum class Status
  42. {
  43. Idle,
  44. InUndo
  45. };
  46. Status m_status = Status::Idle;
  47. SceneUndoState m_undoState;
  48. EditorGraph* m_graph = nullptr;
  49. };
  50. }