summaryrefslogtreecommitdiff
path: root/core/undo_redo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/undo_redo.cpp')
-rw-r--r--core/undo_redo.cpp39
1 files changed, 28 insertions, 11 deletions
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index 69581e4115..f0c2b8eb9b 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -239,8 +239,8 @@ void UndoRedo::_pop_history_tail() {
}
}
-bool UndoRedo::is_commiting_action() const {
- return commiting > 0;
+bool UndoRedo::is_committing_action() const {
+ return committing > 0;
}
void UndoRedo::commit_action() {
@@ -255,9 +255,9 @@ void UndoRedo::commit_action() {
merging = false;
}
- commiting++;
+ committing++;
redo(); // perform action
- commiting--;
+ committing--;
if (callback && actions.size() > 0) {
callback(callback_ud, actions[actions.size() - 1].name);
}
@@ -336,6 +336,7 @@ bool UndoRedo::redo() {
_process_operation_list(actions.write[current_action].do_ops.front());
version++;
+ emit_signal("version_changed");
return true;
}
@@ -348,6 +349,8 @@ bool UndoRedo::undo() {
_process_operation_list(actions.write[current_action].undo_ops.front());
current_action--;
version--;
+ emit_signal("version_changed");
+
return true;
}
@@ -359,18 +362,30 @@ void UndoRedo::clear_history(bool p_increase_version) {
while (actions.size())
_pop_history_tail();
- if (p_increase_version)
+ if (p_increase_version) {
version++;
+ emit_signal("version_changed");
+ }
}
String UndoRedo::get_current_action_name() const {
ERR_FAIL_COND_V(action_level > 0, "");
if (current_action < 0)
- return ""; //nothing to redo
+ return "";
return actions[current_action].name;
}
+bool UndoRedo::has_undo() {
+
+ return current_action >= 0;
+}
+
+bool UndoRedo::has_redo() {
+
+ return (current_action + 1) < actions.size();
+}
+
uint64_t UndoRedo::get_version() const {
return version;
@@ -396,7 +411,7 @@ void UndoRedo::set_property_notify_callback(PropertyNotifyCallback p_property_ca
UndoRedo::UndoRedo() {
- commiting = 0;
+ committing = 0;
version = 1;
action_level = 0;
current_action = -1;
@@ -496,10 +511,8 @@ void UndoRedo::_bind_methods() {
ClassDB::bind_method(D_METHOD("create_action", "name", "merge_mode"), &UndoRedo::create_action, DEFVAL(MERGE_DISABLE));
ClassDB::bind_method(D_METHOD("commit_action"), &UndoRedo::commit_action);
- ClassDB::bind_method(D_METHOD("is_commiting_action"), &UndoRedo::is_commiting_action);
-
- //ClassDB::bind_method(D_METHOD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method);
- //ClassDB::bind_method(D_METHOD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method);
+ // FIXME: Typo in "commiting", fix in 4.0 when breaking compat.
+ ClassDB::bind_method(D_METHOD("is_commiting_action"), &UndoRedo::is_committing_action);
{
MethodInfo mi;
@@ -525,10 +538,14 @@ void UndoRedo::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_undo_reference", "object"), &UndoRedo::add_undo_reference);
ClassDB::bind_method(D_METHOD("clear_history", "increase_version"), &UndoRedo::clear_history, DEFVAL(true));
ClassDB::bind_method(D_METHOD("get_current_action_name"), &UndoRedo::get_current_action_name);
+ 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("redo"), &UndoRedo::redo);
ClassDB::bind_method(D_METHOD("undo"), &UndoRedo::undo);
+ ADD_SIGNAL(MethodInfo("version_changed"));
+
BIND_ENUM_CONSTANT(MERGE_DISABLE);
BIND_ENUM_CONSTANT(MERGE_ENDS);
BIND_ENUM_CONSTANT(MERGE_ALL);