summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-06-26 22:56:51 +0200
committerGitHub <noreply@github.com>2019-06-26 22:56:51 +0200
commit43a69694706ee5084c154aafb4377e10a2df1ed7 (patch)
tree08d6c0e34e670630499c2217ddd34a42c26701d3 /core
parent2c96942df9318ea8a4f3ad06d007e46e3108fa48 (diff)
parent8f23f4b44e043c6a7f69e96369e6c26fe9fd205b (diff)
Merge pull request #25863 from AlexHolly/undo-redo-version-signal
UndoRedo add version changed signal
Diffstat (limited to 'core')
-rw-r--r--core/undo_redo.cpp23
-rw-r--r--core/undo_redo.h3
2 files changed, 24 insertions, 2 deletions
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index f7ca6d3bde..f0c2b8eb9b 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -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;
@@ -523,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);
diff --git a/core/undo_redo.h b/core/undo_redo.h
index e2cc6c659b..276d00d9af 100644
--- a/core/undo_redo.h
+++ b/core/undo_redo.h
@@ -118,6 +118,9 @@ public:
String get_current_action_name() const;
void clear_history(bool p_increase_version = true);
+ bool has_undo();
+ bool has_redo();
+
uint64_t get_version() const;
void set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud);