undo-stack-obs.hpp 883 B

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