Debian Codegraph @

core/object/undo_redo.h

raw symbols SCIP
1 /**************************************************************************/
2 /* undo_redo.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/object/class_db.h"
34 #include "core/object/ref_counted.h"
35
36 class UndoRedo : public Object {
37 GDCLASS(UndoRedo, Object);
38 OBJ_SAVE_TYPE(UndoRedo);
39
40 public:
41 enum MergeMode {
42 MERGE_DISABLE,
43 MERGE_ENDS,
44 MERGE_ALL
45 };
46
47 typedef void (*CommitNotifyCallback)(void *p_ud, const String &p_name);
48
49 typedef void (*MethodNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount);
50 typedef void (*PropertyNotifyCallback)(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value);
51
52 private:
53 struct Operation {
54 enum Type {
55 TYPE_METHOD,
56 TYPE_PROPERTY,
57 TYPE_REFERENCE
58 } type;
59
60 bool force_keep_in_merge_ends = false;
61 Ref<RefCounted> ref;
62 ObjectID object;
63 StringName name;
64 Callable callable;
65 Variant value;
66
67 void delete_reference();
68 };
69
70 struct Action {
71 String name;
72 List<Operation> do_ops;
73 List<Operation> undo_ops;
74 uint64_t last_tick = 0;
75 bool backward_undo_ops = false;
76 };
77
78 Vector<Action> actions;
79 int current_action = -1;
80 bool force_keep_in_merge_ends = false;
81 int action_level = 0;
82 int max_steps = 0;
83 MergeMode merge_mode = MERGE_DISABLE;
84 bool merging = false;
85 uint64_t version = 1;
86 int merge_total = 0;
87
88 void _pop_history_tail();
89 void _process_operation_list(List<Operation>::Element *E, bool p_execute);
90 void _discard_redo();
91 bool _redo(bool p_execute);
92
93 CommitNotifyCallback callback = nullptr;
94 void *callback_ud = nullptr;
95 void *method_callback_ud = nullptr;
96 void *prop_callback_ud = nullptr;
97
98 MethodNotifyCallback method_callback = nullptr;
99 PropertyNotifyCallback property_callback = nullptr;
100
101 int committing = 0;
102
103 protected:
104 static void _bind_methods();
105
106 public:
107 void create_action(const String &p_name = "", MergeMode p_mode = MERGE_DISABLE, bool p_backward_undo_ops = false);
108
109 void add_do_method(const Callable &p_callable);
110 void add_undo_method(const Callable &p_callable);
111 void add_do_property(Object *p_object, const StringName &p_property, const Variant &p_value);
112 void add_undo_property(Object *p_object, const StringName &p_property, const Variant &p_value);
113 void add_do_reference(Object *p_object);
114 void add_undo_reference(Object *p_object);
115
116 void start_force_keep_in_merge_ends();
117 void end_force_keep_in_merge_ends();
118
119 bool is_committing_action() const;
120 void commit_action(bool p_execute = true);
121
122 bool redo();
123 bool undo();
124 String get_current_action_name() const;
125 int get_action_level() const;
126
127 int get_history_count();
128 int get_current_action();
129 String get_action_name(int p_id);
130 void clear_history(bool p_increase_version = true);
131 void discard_redo();
132
133 bool has_undo() const;
134 bool has_redo() const;
135
136 bool is_merging() const;
137
138 uint64_t get_version() const;
139
140 void set_max_steps(int p_max_steps);
141 int get_max_steps() const;
142
143 void set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud);
144
145 void set_method_notify_callback(MethodNotifyCallback p_method_callback, void *p_ud);
146 void set_property_notify_callback(PropertyNotifyCallback p_property_callback, void *p_ud);
147
148 ~UndoRedo();
149 };
150
151 VARIANT_ENUM_CAST(UndoRedo::MergeMode);