Merge pull request #25863 from AlexHolly/undo-redo-version-signal
UndoRedo add version changed signal
This commit is contained in:
commit
43a6969470
3 changed files with 45 additions and 2 deletions
|
@ -336,6 +336,7 @@ bool UndoRedo::redo() {
|
||||||
|
|
||||||
_process_operation_list(actions.write[current_action].do_ops.front());
|
_process_operation_list(actions.write[current_action].do_ops.front());
|
||||||
version++;
|
version++;
|
||||||
|
emit_signal("version_changed");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -348,6 +349,8 @@ bool UndoRedo::undo() {
|
||||||
_process_operation_list(actions.write[current_action].undo_ops.front());
|
_process_operation_list(actions.write[current_action].undo_ops.front());
|
||||||
current_action--;
|
current_action--;
|
||||||
version--;
|
version--;
|
||||||
|
emit_signal("version_changed");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,18 +362,30 @@ void UndoRedo::clear_history(bool p_increase_version) {
|
||||||
while (actions.size())
|
while (actions.size())
|
||||||
_pop_history_tail();
|
_pop_history_tail();
|
||||||
|
|
||||||
if (p_increase_version)
|
if (p_increase_version) {
|
||||||
version++;
|
version++;
|
||||||
|
emit_signal("version_changed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String UndoRedo::get_current_action_name() const {
|
String UndoRedo::get_current_action_name() const {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(action_level > 0, "");
|
ERR_FAIL_COND_V(action_level > 0, "");
|
||||||
if (current_action < 0)
|
if (current_action < 0)
|
||||||
return ""; //nothing to redo
|
return "";
|
||||||
return actions[current_action].name;
|
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 {
|
uint64_t UndoRedo::get_version() const {
|
||||||
|
|
||||||
return version;
|
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("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("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("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("get_version"), &UndoRedo::get_version);
|
||||||
ClassDB::bind_method(D_METHOD("redo"), &UndoRedo::redo);
|
ClassDB::bind_method(D_METHOD("redo"), &UndoRedo::redo);
|
||||||
ClassDB::bind_method(D_METHOD("undo"), &UndoRedo::undo);
|
ClassDB::bind_method(D_METHOD("undo"), &UndoRedo::undo);
|
||||||
|
|
||||||
|
ADD_SIGNAL(MethodInfo("version_changed"));
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(MERGE_DISABLE);
|
BIND_ENUM_CONSTANT(MERGE_DISABLE);
|
||||||
BIND_ENUM_CONSTANT(MERGE_ENDS);
|
BIND_ENUM_CONSTANT(MERGE_ENDS);
|
||||||
BIND_ENUM_CONSTANT(MERGE_ALL);
|
BIND_ENUM_CONSTANT(MERGE_ALL);
|
||||||
|
|
|
@ -118,6 +118,9 @@ public:
|
||||||
String get_current_action_name() const;
|
String get_current_action_name() const;
|
||||||
void clear_history(bool p_increase_version = true);
|
void clear_history(bool p_increase_version = true);
|
||||||
|
|
||||||
|
bool has_undo();
|
||||||
|
bool has_redo();
|
||||||
|
|
||||||
uint64_t get_version() const;
|
uint64_t get_version() const;
|
||||||
|
|
||||||
void set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud);
|
void set_commit_notify_callback(CommitNotifyCallback p_callback, void *p_ud);
|
||||||
|
|
|
@ -141,6 +141,20 @@
|
||||||
This is useful mostly to check if something changed from a saved version.
|
This is useful mostly to check if something changed from a saved version.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="has_redo">
|
||||||
|
<return type="bool">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if an 'redo' action is available.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="has_undo">
|
||||||
|
<return type="bool">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if an 'undo' action is available.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="is_commiting_action" qualifiers="const">
|
<method name="is_commiting_action" qualifiers="const">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -162,6 +176,13 @@
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
|
<signals>
|
||||||
|
<signal name="version_changed">
|
||||||
|
<description>
|
||||||
|
Called when [method undo] or [method redo] was called.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
</signals>
|
||||||
<constants>
|
<constants>
|
||||||
<constant name="MERGE_DISABLE" value="0" enum="MergeMode">
|
<constant name="MERGE_DISABLE" value="0" enum="MergeMode">
|
||||||
Makes [code]do[/code]/[code]undo[/code] operations stay in separate actions.
|
Makes [code]do[/code]/[code]undo[/code] operations stay in separate actions.
|
||||||
|
|
Loading…
Reference in a new issue