mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
This commit is contained in:
@@ -33,15 +33,17 @@
|
||||
#include "core/os/os.h"
|
||||
|
||||
void UndoRedo::_discard_redo() {
|
||||
if (current_action == actions.size() - 1)
|
||||
if (current_action == actions.size() - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = current_action + 1; i < actions.size(); i++) {
|
||||
for (List<Operation>::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) {
|
||||
if (E->get().type == Operation::TYPE_REFERENCE) {
|
||||
Object *obj = ObjectDB::get_instance(E->get().object);
|
||||
if (obj)
|
||||
if (obj) {
|
||||
memdelete(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
//ERASE do data
|
||||
@@ -68,8 +70,9 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) {
|
||||
if (E->get().type == Operation::TYPE_REFERENCE) {
|
||||
Object *obj = ObjectDB::get_instance(E->get().object);
|
||||
|
||||
if (obj)
|
||||
if (obj) {
|
||||
memdelete(obj);
|
||||
}
|
||||
}
|
||||
|
||||
E = E->next();
|
||||
@@ -101,8 +104,9 @@ void UndoRedo::add_do_method(Object *p_object, const String &p_method, VARIANT_A
|
||||
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))
|
||||
if (Object::cast_to<Resource>(p_object)) {
|
||||
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
|
||||
}
|
||||
|
||||
do_op.type = Operation::TYPE_METHOD;
|
||||
do_op.name = p_method;
|
||||
@@ -120,13 +124,15 @@ void UndoRedo::add_undo_method(Object *p_object, const String &p_method, VARIANT
|
||||
ERR_FAIL_COND((current_action + 1) >= actions.size());
|
||||
|
||||
// No undo if the merge mode is MERGE_ENDS
|
||||
if (merge_mode == MERGE_ENDS)
|
||||
if (merge_mode == MERGE_ENDS) {
|
||||
return;
|
||||
}
|
||||
|
||||
Operation undo_op;
|
||||
undo_op.object = p_object->get_instance_id();
|
||||
if (Object::cast_to<Resource>(p_object))
|
||||
if (Object::cast_to<Resource>(p_object)) {
|
||||
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
|
||||
}
|
||||
|
||||
undo_op.type = Operation::TYPE_METHOD;
|
||||
undo_op.name = p_method;
|
||||
@@ -142,8 +148,9 @@ void UndoRedo::add_do_property(Object *p_object, const String &p_property, const
|
||||
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))
|
||||
if (Object::cast_to<Resource>(p_object)) {
|
||||
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
|
||||
}
|
||||
|
||||
do_op.type = Operation::TYPE_PROPERTY;
|
||||
do_op.name = p_property;
|
||||
@@ -156,13 +163,15 @@ void UndoRedo::add_undo_property(Object *p_object, const String &p_property, con
|
||||
ERR_FAIL_COND((current_action + 1) >= actions.size());
|
||||
|
||||
// No undo if the merge mode is MERGE_ENDS
|
||||
if (merge_mode == MERGE_ENDS)
|
||||
if (merge_mode == MERGE_ENDS) {
|
||||
return;
|
||||
}
|
||||
|
||||
Operation undo_op;
|
||||
undo_op.object = p_object->get_instance_id();
|
||||
if (Object::cast_to<Resource>(p_object))
|
||||
if (Object::cast_to<Resource>(p_object)) {
|
||||
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
|
||||
}
|
||||
|
||||
undo_op.type = Operation::TYPE_PROPERTY;
|
||||
undo_op.name = p_property;
|
||||
@@ -175,8 +184,9 @@ 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))
|
||||
if (Object::cast_to<Resource>(p_object)) {
|
||||
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
|
||||
}
|
||||
|
||||
do_op.type = Operation::TYPE_REFERENCE;
|
||||
actions.write[current_action + 1].do_ops.push_back(do_op);
|
||||
@@ -187,13 +197,15 @@ void UndoRedo::add_undo_reference(Object *p_object) {
|
||||
ERR_FAIL_COND((current_action + 1) >= actions.size());
|
||||
|
||||
// No undo if the merge mode is MERGE_ENDS
|
||||
if (merge_mode == MERGE_ENDS)
|
||||
if (merge_mode == MERGE_ENDS) {
|
||||
return;
|
||||
}
|
||||
|
||||
Operation undo_op;
|
||||
undo_op.object = p_object->get_instance_id();
|
||||
if (Object::cast_to<Resource>(p_object))
|
||||
if (Object::cast_to<Resource>(p_object)) {
|
||||
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
|
||||
}
|
||||
|
||||
undo_op.type = Operation::TYPE_REFERENCE;
|
||||
actions.write[current_action + 1].undo_ops.push_back(undo_op);
|
||||
@@ -202,14 +214,16 @@ void UndoRedo::add_undo_reference(Object *p_object) {
|
||||
void UndoRedo::_pop_history_tail() {
|
||||
_discard_redo();
|
||||
|
||||
if (!actions.size())
|
||||
if (!actions.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (List<Operation>::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) {
|
||||
if (E->get().type == Operation::TYPE_REFERENCE) {
|
||||
Object *obj = ObjectDB::get_instance(E->get().object);
|
||||
if (obj)
|
||||
if (obj) {
|
||||
memdelete(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,8 +240,9 @@ bool UndoRedo::is_committing_action() const {
|
||||
void UndoRedo::commit_action() {
|
||||
ERR_FAIL_COND(action_level <= 0);
|
||||
action_level--;
|
||||
if (action_level > 0)
|
||||
if (action_level > 0) {
|
||||
return; //still nested
|
||||
}
|
||||
|
||||
if (merging) {
|
||||
version--;
|
||||
@@ -247,8 +262,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
|
||||
Operation &op = E->get();
|
||||
|
||||
Object *obj = ObjectDB::get_instance(op.object);
|
||||
if (!obj) //may have been deleted and this is fine
|
||||
if (!obj) { //may have been deleted and this is fine
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (op.type) {
|
||||
case Operation::TYPE_METHOD: {
|
||||
@@ -272,8 +288,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
|
||||
}
|
||||
#ifdef TOOLS_ENABLED
|
||||
Resource *res = Object::cast_to<Resource>(obj);
|
||||
if (res)
|
||||
if (res) {
|
||||
res->set_edited(true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -285,8 +302,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
|
||||
obj->set(op.name, op.args[0]);
|
||||
#ifdef TOOLS_ENABLED
|
||||
Resource *res = Object::cast_to<Resource>(obj);
|
||||
if (res)
|
||||
if (res) {
|
||||
res->set_edited(true);
|
||||
}
|
||||
#endif
|
||||
if (property_callback) {
|
||||
property_callback(prop_callback_ud, obj, op.name, op.args[0]);
|
||||
@@ -302,8 +320,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
|
||||
bool UndoRedo::redo() {
|
||||
ERR_FAIL_COND_V(action_level > 0, false);
|
||||
|
||||
if ((current_action + 1) >= actions.size())
|
||||
if ((current_action + 1) >= actions.size()) {
|
||||
return false; //nothing to redo
|
||||
}
|
||||
|
||||
current_action++;
|
||||
|
||||
@@ -316,8 +335,9 @@ bool UndoRedo::redo() {
|
||||
|
||||
bool UndoRedo::undo() {
|
||||
ERR_FAIL_COND_V(action_level > 0, false);
|
||||
if (current_action < 0)
|
||||
if (current_action < 0) {
|
||||
return false; //nothing to redo
|
||||
}
|
||||
_process_operation_list(actions.write[current_action].undo_ops.front());
|
||||
current_action--;
|
||||
version--;
|
||||
@@ -330,8 +350,9 @@ void UndoRedo::clear_history(bool p_increase_version) {
|
||||
ERR_FAIL_COND(action_level > 0);
|
||||
_discard_redo();
|
||||
|
||||
while (actions.size())
|
||||
while (actions.size()) {
|
||||
_pop_history_tail();
|
||||
}
|
||||
|
||||
if (p_increase_version) {
|
||||
version++;
|
||||
@@ -341,8 +362,9 @@ void UndoRedo::clear_history(bool p_increase_version) {
|
||||
|
||||
String UndoRedo::get_current_action_name() const {
|
||||
ERR_FAIL_COND_V(action_level > 0, "");
|
||||
if (current_action < 0)
|
||||
if (current_action < 0) {
|
||||
return "";
|
||||
}
|
||||
return actions[current_action].name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user