Extend UndoRedo handling of Resource to every Reference

This commit is contained in:
Pedro J. Estébanez 2020-10-27 01:44:30 +01:00
parent e9d12f9e4e
commit 1f52782bbb
2 changed files with 15 additions and 14 deletions

View file

@ -31,6 +31,7 @@
#include "undo_redo.h"
#include "core/os/os.h"
#include "core/resource.h"
void UndoRedo::_discard_redo() {
if (current_action == actions.size() - 1) {
@ -104,8 +105,8 @@ void UndoRedo::add_do_method(Object *p_object, const StringName &p_method, VARIA
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
if (Object::cast_to<Reference>(p_object)) {
do_op.ref = Ref<Reference>(Object::cast_to<Reference>(p_object));
}
do_op.type = Operation::TYPE_METHOD;
@ -130,8 +131,8 @@ void UndoRedo::add_undo_method(Object *p_object, const StringName &p_method, VAR
Operation undo_op;
undo_op.object = p_object->get_instance_id();
if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
if (Object::cast_to<Reference>(p_object)) {
undo_op.ref = Ref<Reference>(Object::cast_to<Reference>(p_object));
}
undo_op.type = Operation::TYPE_METHOD;
@ -149,8 +150,8 @@ void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, c
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
if (Object::cast_to<Reference>(p_object)) {
do_op.ref = Ref<Reference>(Object::cast_to<Reference>(p_object));
}
do_op.type = Operation::TYPE_PROPERTY;
@ -171,8 +172,8 @@ void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property,
Operation undo_op;
undo_op.object = p_object->get_instance_id();
if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
if (Object::cast_to<Reference>(p_object)) {
undo_op.ref = Ref<Reference>(Object::cast_to<Reference>(p_object));
}
undo_op.type = Operation::TYPE_PROPERTY;
@ -187,8 +188,8 @@ void UndoRedo::add_do_reference(Object *p_object) {
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
if (Object::cast_to<Reference>(p_object)) {
do_op.ref = Ref<Reference>(Object::cast_to<Reference>(p_object));
}
do_op.type = Operation::TYPE_REFERENCE;
@ -207,8 +208,8 @@ void UndoRedo::add_undo_reference(Object *p_object) {
Operation undo_op;
undo_op.object = p_object->get_instance_id();
if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
if (Object::cast_to<Reference>(p_object)) {
undo_op.ref = Ref<Reference>(Object::cast_to<Reference>(p_object));
}
undo_op.type = Operation::TYPE_REFERENCE;

View file

@ -31,8 +31,8 @@
#ifndef UNDO_REDO_H
#define UNDO_REDO_H
#include "core/io/resource.h"
#include "core/object/class_db.h"
#include "core/object/reference.h"
class UndoRedo : public Object {
GDCLASS(UndoRedo, Object);
@ -61,7 +61,7 @@ private:
};
Type type;
Ref<Resource> resref;
Ref<Reference> ref;
ObjectID object;
StringName name;
Variant args[VARIANT_ARG_MAX];