UndoStack.h 777 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullOwnPtrVector.h>
  8. #include <LibGUI/Forward.h>
  9. namespace GUI {
  10. class UndoStack {
  11. public:
  12. UndoStack();
  13. ~UndoStack();
  14. void push(NonnullOwnPtr<Command>&&);
  15. bool can_undo() const { return m_stack_index < m_stack.size() && !m_stack.is_empty(); }
  16. bool can_redo() const { return m_stack_index > 0 && !m_stack.is_empty(); }
  17. void undo();
  18. void redo();
  19. void finalize_current_combo();
  20. void clear();
  21. private:
  22. struct UndoCommandsContainer {
  23. NonnullOwnPtrVector<Command> m_undo_vector;
  24. };
  25. NonnullOwnPtrVector<UndoCommandsContainer> m_stack;
  26. size_t m_stack_index { 0 };
  27. };
  28. }