summaryrefslogtreecommitdiffstats
path: root/core/object/undo_redo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/object/undo_redo.cpp')
-rw-r--r--core/object/undo_redo.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp
index a8f2ac5bfe..6a1385e268 100644
--- a/core/object/undo_redo.cpp
+++ b/core/object/undo_redo.cpp
@@ -71,7 +71,14 @@ bool UndoRedo::_redo(bool p_execute) {
}
current_action++;
- _process_operation_list(actions.write[current_action].do_ops.front(), p_execute);
+
+ List<Operation>::Element *start_doops_element = actions.write[current_action].do_ops.front();
+ while (merge_total > 0 && start_doops_element) {
+ start_doops_element = start_doops_element->next();
+ merge_total--;
+ }
+
+ _process_operation_list(start_doops_element, p_execute);
version++;
emit_signal(SNAME("version_changed"));
@@ -104,6 +111,12 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode, bool p_back
}
}
+ if (p_mode == MERGE_ALL) {
+ merge_total = actions.write[current_action + 1].do_ops.size();
+ } else {
+ merge_total = 0;
+ }
+
actions.write[actions.size() - 1].last_tick = ticks;
// Revert reverse from previous commit.
@@ -121,6 +134,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode, bool p_back
actions.push_back(new_action);
merge_mode = MERGE_DISABLE;
+ merge_total = 0;
}
}
@@ -301,6 +315,8 @@ void UndoRedo::commit_action(bool p_execute) {
return; //still nested
}
+ bool add_message = !merging;
+
if (merging) {
version--;
merging = false;
@@ -314,7 +330,15 @@ void UndoRedo::commit_action(bool p_execute) {
_redo(p_execute); // perform action
committing--;
- if (callback && actions.size() > 0) {
+ if (max_steps > 0) {
+ // Clear early steps.
+
+ while (actions.size() > max_steps) {
+ _pop_history_tail();
+ }
+ }
+
+ if (add_message && callback && actions.size() > 0) {
callback(callback_ud, actions[actions.size() - 1].name);
}
}
@@ -463,10 +487,22 @@ bool UndoRedo::has_redo() const {
return (current_action + 1) < actions.size();
}
+bool UndoRedo::is_merging() const {
+ return merging;
+}
+
uint64_t UndoRedo::get_version() const {
return version;
}
+void UndoRedo::set_max_steps(int p_max_steps) {
+ max_steps = p_max_steps;
+}
+
+int UndoRedo::get_max_steps() const {
+ return max_steps;
+}
+
void UndoRedo::set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud) {
callback = p_callback;
callback_ud = p_ud;
@@ -511,9 +547,13 @@ void UndoRedo::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_undo"), &UndoRedo::has_undo);
ClassDB::bind_method(D_METHOD("has_redo"), &UndoRedo::has_redo);
ClassDB::bind_method(D_METHOD("get_version"), &UndoRedo::get_version);
+ ClassDB::bind_method(D_METHOD("set_max_steps", "max_steps"), &UndoRedo::set_max_steps);
+ ClassDB::bind_method(D_METHOD("get_max_steps"), &UndoRedo::get_max_steps);
ClassDB::bind_method(D_METHOD("redo"), &UndoRedo::redo);
ClassDB::bind_method(D_METHOD("undo"), &UndoRedo::undo);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "max_steps", PROPERTY_HINT_RANGE, "0,50,1,or_greater"), "set_max_steps", "get_max_steps");
+
ADD_SIGNAL(MethodInfo("version_changed"));
BIND_ENUM_CONSTANT(MERGE_DISABLE);