UndoStack.h 782 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/Function.h>
  8. #include <AK/NonnullOwnPtrVector.h>
  9. #include <LibGUI/Forward.h>
  10. namespace GUI {
  11. class UndoStack {
  12. public:
  13. UndoStack();
  14. ~UndoStack();
  15. void push(NonnullOwnPtr<Command>);
  16. bool can_undo() const;
  17. bool can_redo() const;
  18. void undo();
  19. void redo();
  20. void set_current_unmodified();
  21. bool is_current_modified() const;
  22. void clear();
  23. Optional<String> undo_action_text() const;
  24. Optional<String> redo_action_text() const;
  25. Function<void()> on_state_change;
  26. private:
  27. NonnullOwnPtrVector<Command> m_stack;
  28. size_t m_stack_index { 0 };
  29. Optional<size_t> m_clean_index;
  30. };
  31. }