undo-stack-obs.hpp 885 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <QString>
  3. #include <deque>
  4. #include <functional>
  5. #include <string>
  6. #include <memory>
  7. #include "ui_OBSBasic.h"
  8. class undo_stack {
  9. typedef std::function<void(const std::string &data)> undo_redo_cb;
  10. typedef std::function<void(bool is_undo)> func;
  11. typedef std::unique_ptr<Ui::OBSBasic> &ui_ptr;
  12. struct undo_redo_t {
  13. QString name;
  14. std::string undo_data;
  15. std::string redo_data;
  16. undo_redo_cb undo;
  17. undo_redo_cb redo;
  18. func d;
  19. };
  20. ui_ptr ui;
  21. std::deque<undo_redo_t> undo_items;
  22. std::deque<undo_redo_t> redo_items;
  23. bool disabled = false;
  24. void clear_redo();
  25. public:
  26. undo_stack(ui_ptr ui);
  27. void enable_undo_redo();
  28. void disable_undo_redo();
  29. void release();
  30. void clear();
  31. void add_action(const QString &name, undo_redo_cb undo,
  32. undo_redo_cb redo, std::string undo_data,
  33. std::string redo_data, func d);
  34. void undo();
  35. void redo();
  36. };