undo_redo.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*************************************************************************/
  2. /* undo_redo.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef UNDO_REDO_H
  30. #define UNDO_REDO_H
  31. #include "object.h"
  32. #include "resource.h"
  33. class UndoRedo : public Object {
  34. OBJ_TYPE(UndoRedo,Object);
  35. public:
  36. typedef void (*CommitNotifyCallback)(void *p_ud,const String& p_name);
  37. private:
  38. struct Operation {
  39. enum Type {
  40. TYPE_METHOD,
  41. TYPE_PROPERTY,
  42. TYPE_REFERENCE
  43. };
  44. Type type;
  45. Ref<Resource> resref;
  46. ObjectID object;
  47. String name;
  48. Variant args[VARIANT_ARG_MAX];
  49. };
  50. struct Action {
  51. String name;
  52. List<Operation> do_ops;
  53. List<Operation> undo_ops;
  54. };
  55. Vector<Action> actions;
  56. int current_action;
  57. int action_level;
  58. int max_steps;
  59. bool merging;
  60. uint64_t version;
  61. void _pop_history_tail();
  62. void _process_operation_list(List<Operation>::Element *E);
  63. void _discard_redo();
  64. CommitNotifyCallback callback;
  65. void* callback_ud;
  66. public:
  67. void create_action(const String& p_name="",bool p_mergeable=false);
  68. void add_do_method(Object *p_object,const String& p_method,VARIANT_ARG_LIST);
  69. void add_undo_method(Object *p_object,const String& p_method,VARIANT_ARG_LIST);
  70. void add_do_property(Object *p_object,const String& p_property,const Variant& p_value);
  71. void add_undo_property(Object *p_object,const String& p_property,const Variant& p_value);
  72. void add_do_reference(Object *p_object);
  73. void add_undo_reference(Object *p_object);
  74. void commit_action();
  75. void redo();
  76. void undo();
  77. String get_current_action_name() const;
  78. void clear_history();
  79. void set_max_steps(int p_max_steps);
  80. int get_max_steps() const;
  81. uint64_t get_version() const;
  82. void set_commit_notify_callback(CommitNotifyCallback p_callback,void* p_ud);
  83. UndoRedo();
  84. ~UndoRedo();
  85. };
  86. #endif // UNDO_REDO_H