Skip to content

Commit

Permalink
Extend UndoRedo handling of Resource to every Reference
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Dec 20, 2020
1 parent e9d12f9 commit 1f52782
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions core/object/undo_redo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions core/object/undo_redo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -61,7 +61,7 @@ class UndoRedo : public Object {
};

Type type;
Ref<Resource> resref;
Ref<Reference> ref;
ObjectID object;
StringName name;
Variant args[VARIANT_ARG_MAX];
Expand Down

0 comments on commit 1f52782

Please sign in to comment.