GUndoStack.h 743 B

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. #include <AK/NonnullOwnPtrVector.h>
  3. #include <LibGUI/GCommand.h>
  4. class GCommand;
  5. class GUndoStack {
  6. public:
  7. GUndoStack();
  8. ~GUndoStack();
  9. void push(NonnullOwnPtr<GCommand>&&);
  10. bool can_undo() const { return m_stack_index < m_stack.size() && !m_stack.is_empty(); }
  11. bool can_redo() const { return m_stack_index > 0 && m_stack[m_stack_index - 1].m_undo_vector.size() > 0 && !m_stack.is_empty(); }
  12. void undo();
  13. void redo();
  14. void finalize_current_combo();
  15. private:
  16. struct UndoCommandsContainer {
  17. NonnullOwnPtrVector<GCommand> m_undo_vector;
  18. };
  19. NonnullOwnPtrVector<UndoCommandsContainer> m_stack;
  20. int m_stack_index { 0 };
  21. int m_last_updated_undo_vector_size { 0 };
  22. };