diff --git a/.vscode/settings.json b/.vscode/settings.json index e1c51b815bb3..af5ff1d6fc9d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,131 +1,134 @@ // Place your settings in this file to overwrite default and user settings. { - "files.associations": { - "*.idl": "java", - "Fastfile": "ruby", - "iosfwd": "cpp", - "functional": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "algorithm": "cpp", - "random": "cpp", - "__config": "cpp", - "cstddef": "cpp", - "exception": "cpp", - "initializer_list": "cpp", - "new": "cpp", - "stdexcept": "cpp", - "typeinfo": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "complex": "cpp", - "cstdarg": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "istream": "cpp", - "limits": "cpp", - "memory": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "streambuf": "cpp", - "hashtable": "cpp", - "tuple": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "__split_buffer": "cpp", - "deque": "cpp", - "iterator": "cpp", - "list": "cpp", - "map": "cpp", - "queue": "cpp", - "regex": "cpp", - "set": "cpp", - "stack": "cpp", - "string": "cpp", - "vector": "cpp", - "iostream": "cpp", - "__functional_03": "cpp", - "__hash_table": "cpp", - "__tree": "cpp", - "bitset": "cpp", - "__bit_reference": "cpp", - "__mutex_base": "cpp", - "fstream": "cpp", - "ios": "cpp", - "__locale": "cpp", - "valarray": "cpp", - "freeglut_spaceball.c": "cpp", - "__tuple": "cpp", - "hash_map": "cpp", - "hash_set": "cpp", - "system_error": "cpp", - "__nullptr": "cpp", - "__functional_base": "cpp", - "__functional_base_03": "cpp", - "chrono": "cpp", - "ratio": "cpp", - "atomic": "cpp", - "locale": "cpp", - "string_view": "cpp", - "__string": "cpp", - "cstring": "cpp", - "iomanip": "cpp", - "cstdint": "cpp", - "forward_list": "cpp", - "mutex": "cpp", - "__hash": "cpp", - "__debug": "cpp", - "__threading_support": "cpp", - "any": "cpp", - "array": "cpp", - "cinttypes": "cpp", - "numeric": "cpp", - "__memory": "cpp", - "__errc": "cpp", - "__node_handle": "cpp", - "bit": "cpp", - "optional": "cpp", - "filesystem": "cpp", - "compare": "cpp", - "concepts": "cpp", - "xfacet": "cpp", - "xhash": "cpp", - "xiosbase": "cpp", - "xlocale": "cpp", - "xlocinfo": "cpp", - "xlocmon": "cpp", - "xlocnum": "cpp", - "xloctime": "cpp", - "xmemory": "cpp", - "xstddef": "cpp", - "xstring": "cpp", - "xtr1common": "cpp", - "xtree": "cpp", - "xutility": "cpp", - "xlocbuf": "cpp", - "xlocmes": "cpp", - "xmemory0": "cpp", - "memory_resource": "cpp" - }, - "files.exclude": { - "Binaries/*build*": true, - "Binaries/Output": true, - "GDJS/Runtime-dist": true, - "docs": true, - "newIDE/electron-app/dist": true, - "newIDE/app/build": true, - "newIDE/app/resources/GDJS": true, - "newIDE/electron-app/app/www": true - }, - // Support for Flowtype (for newIDE): - "javascript.validate.enable": false, - "flow.useNPMPackagedFlow": true, + "files.associations": { + "*.idl": "java", + "Fastfile": "ruby", + "iosfwd": "cpp", + "functional": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "algorithm": "cpp", + "random": "cpp", + "__config": "cpp", + "cstddef": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "new": "cpp", + "stdexcept": "cpp", + "typeinfo": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "cstdarg": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "istream": "cpp", + "limits": "cpp", + "memory": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "streambuf": "cpp", + "hashtable": "cpp", + "tuple": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "__split_buffer": "cpp", + "deque": "cpp", + "iterator": "cpp", + "list": "cpp", + "map": "cpp", + "queue": "cpp", + "regex": "cpp", + "set": "cpp", + "stack": "cpp", + "string": "cpp", + "vector": "cpp", + "iostream": "cpp", + "__functional_03": "cpp", + "__hash_table": "cpp", + "__tree": "cpp", + "bitset": "cpp", + "__bit_reference": "cpp", + "__mutex_base": "cpp", + "fstream": "cpp", + "ios": "cpp", + "__locale": "cpp", + "valarray": "cpp", + "freeglut_spaceball.c": "cpp", + "__tuple": "cpp", + "hash_map": "cpp", + "hash_set": "cpp", + "system_error": "cpp", + "__nullptr": "cpp", + "__functional_base": "cpp", + "__functional_base_03": "cpp", + "chrono": "cpp", + "ratio": "cpp", + "atomic": "cpp", + "locale": "cpp", + "string_view": "cpp", + "__string": "cpp", + "cstring": "cpp", + "iomanip": "cpp", + "cstdint": "cpp", + "forward_list": "cpp", + "mutex": "cpp", + "__hash": "cpp", + "__debug": "cpp", + "__threading_support": "cpp", + "any": "cpp", + "array": "cpp", + "cinttypes": "cpp", + "numeric": "cpp", + "__memory": "cpp", + "__errc": "cpp", + "__node_handle": "cpp", + "bit": "cpp", + "optional": "cpp", + "filesystem": "cpp", + "compare": "cpp", + "concepts": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocinfo": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "xlocbuf": "cpp", + "xlocmes": "cpp", + "xmemory0": "cpp", + "memory_resource": "cpp", + "__bits": "cpp", + "__verbose_abort": "cpp", + "variant": "cpp" + }, + "files.exclude": { + "Binaries/*build*": true, + "Binaries/Output": true, + "GDJS/Runtime-dist": true, + "docs": true, + "newIDE/electron-app/dist": true, + "newIDE/app/build": true, + "newIDE/app/resources/GDJS": true, + "newIDE/electron-app/app/www": true + }, + // Support for Flowtype (for newIDE): + "javascript.validate.enable": false, + "flow.useNPMPackagedFlow": true, - // Clang format styling (duplicated in scripts/CMakeClangUtils.txt) - "C_Cpp.clang_format_style": "{BasedOnStyle: Google, BinPackParameters: false, BinPackArguments: false}" + // Clang format styling (duplicated in scripts/CMakeClangUtils.txt) + "C_Cpp.clang_format_style": "{BasedOnStyle: Google, BinPackParameters: false, BinPackArguments: false}" } diff --git a/Core/GDCore/IDE/Events/ProjectElementRenamer.cpp b/Core/GDCore/IDE/Events/ProjectElementRenamer.cpp index eb386dcbb7a2..0ea6b9d6d62f 100644 --- a/Core/GDCore/IDE/Events/ProjectElementRenamer.cpp +++ b/Core/GDCore/IDE/Events/ProjectElementRenamer.cpp @@ -87,11 +87,22 @@ class GD_CORE_API ExpressionIdentifierStringFinder std::unique_ptr ¶meterNode, size_t parameterIndex, const gd::String &lastObjectName) { if (parameterMetadata.GetType() == "layer") { - // Remove quotes, it won't match if it's not a literal anyway. - lastLayerName = expressionPlainString.substr( - parameterNode->location.GetStartPosition() + 1, - parameterNode->location.GetEndPosition() - - parameterNode->location.GetStartPosition() - 2); + if (parameterNode->location.GetEndPosition() - + parameterNode->location.GetStartPosition() < + 2) { + // This is either the base layer or an invalid layer name. + // Keep it as is. + lastLayerName = expressionPlainString.substr( + parameterNode->location.GetStartPosition(), + parameterNode->location.GetEndPosition() - + parameterNode->location.GetStartPosition()); + } else { + // Remove quotes, so it can be compared to the layer name. + lastLayerName = expressionPlainString.substr( + parameterNode->location.GetStartPosition() + 1, + parameterNode->location.GetEndPosition() - + parameterNode->location.GetStartPosition() - 2); + } } if (parameterMetadata.GetType() == parameterType) { auto parameterExpressionPlainString = expressionPlainString.substr( @@ -143,9 +154,15 @@ bool ProjectElementRenamer::DoVisitInstruction(gd::Instruction &instruction, const gd::Expression ¶meterValue, size_t parameterIndex, const gd::String &lastObjectName) { if (parameterMetadata.GetType() == "layer") { - // Remove quotes, it won't match if it's not a literal anyway. - lastLayerName = parameterValue.GetPlainString().substr( - 1, parameterValue.GetPlainString().length() - 2); + if (parameterValue.GetPlainString().length() < 2) { + // This is either the base layer or an invalid layer name. + // Keep it as is. + lastLayerName = parameterValue.GetPlainString(); + } else { + // Remove quotes, so it can be compared to the layer name. + lastLayerName = parameterValue.GetPlainString().substr( + 1, parameterValue.GetPlainString().length() - 2); + } } if (parameterMetadata.GetType() == parameterType && @@ -165,7 +182,6 @@ bool ProjectElementRenamer::DoVisitInstruction(gd::Instruction &instruction, node->Visit(finder); if (finder.GetOccurrences().size() > 0) { - gd::String newNameWithQuotes = "\"" + newName + "\""; gd::String oldParameterValue = parameterValue.GetPlainString(); gd::String newParameterValue; diff --git a/Core/GDCore/IDE/WholeProjectRefactorer.cpp b/Core/GDCore/IDE/WholeProjectRefactorer.cpp index 8ba7bb1af08f..5e7f75f4bdc2 100644 --- a/Core/GDCore/IDE/WholeProjectRefactorer.cpp +++ b/Core/GDCore/IDE/WholeProjectRefactorer.cpp @@ -9,32 +9,32 @@ #include "GDCore/Extensions/Metadata/MetadataProvider.h" #include "GDCore/Extensions/PlatformExtension.h" #include "GDCore/IDE/DependenciesAnalyzer.h" +#include "GDCore/IDE/EventBasedBehaviorBrowser.h" #include "GDCore/IDE/Events/ArbitraryEventsWorker.h" -#include "GDCore/IDE/Events/EventsBehaviorRenamer.h" -#include "GDCore/IDE/Events/ProjectElementRenamer.h" -#include "GDCore/IDE/Events/LinkEventTargetRenamer.h" -#include "GDCore/IDE/Events/CustomObjectTypeRenamer.h" #include "GDCore/IDE/Events/BehaviorTypeRenamer.h" +#include "GDCore/IDE/Events/CustomObjectTypeRenamer.h" +#include "GDCore/IDE/Events/EventsBehaviorRenamer.h" #include "GDCore/IDE/Events/EventsRefactorer.h" #include "GDCore/IDE/Events/ExpressionsParameterMover.h" #include "GDCore/IDE/Events/ExpressionsRenamer.h" #include "GDCore/IDE/Events/InstructionsParameterMover.h" #include "GDCore/IDE/Events/InstructionsTypeRenamer.h" -#include "GDCore/IDE/ProjectBrowser.h" -#include "GDCore/IDE/ProjectBrowserHelper.h" -#include "GDCore/IDE/WholeProjectBrowser.h" -#include "GDCore/IDE/EventBasedBehaviorBrowser.h" +#include "GDCore/IDE/Events/LinkEventTargetRenamer.h" +#include "GDCore/IDE/Events/ProjectElementRenamer.h" #include "GDCore/IDE/EventsFunctionTools.h" -#include "GDCore/IDE/Project/ArbitraryObjectsWorker.h" -#include "GDCore/IDE/Project/ArbitraryEventsFunctionsWorker.h" -#include "GDCore/IDE/Project/ArbitraryEventBasedBehaviorsWorker.h" #include "GDCore/IDE/Project/ArbitraryBehaviorSharedDataWorker.h" -#include "GDCore/IDE/Project/RequiredBehaviorRenamer.h" +#include "GDCore/IDE/Project/ArbitraryEventBasedBehaviorsWorker.h" +#include "GDCore/IDE/Project/ArbitraryEventsFunctionsWorker.h" +#include "GDCore/IDE/Project/ArbitraryObjectsWorker.h" #include "GDCore/IDE/Project/BehaviorObjectTypeRenamer.h" #include "GDCore/IDE/Project/BehaviorsSharedDataBehaviorTypeRenamer.h" #include "GDCore/IDE/Project/FunctionParameterBehaviorTypeRenamer.h" #include "GDCore/IDE/Project/FunctionParameterObjectTypeRenamer.h" +#include "GDCore/IDE/Project/RequiredBehaviorRenamer.h" +#include "GDCore/IDE/ProjectBrowser.h" +#include "GDCore/IDE/ProjectBrowserHelper.h" #include "GDCore/IDE/UnfilledRequiredBehaviorPropertyProblem.h" +#include "GDCore/IDE/WholeProjectBrowser.h" #include "GDCore/Project/Behavior.h" #include "GDCore/Project/BehaviorConfigurationContainer.h" #include "GDCore/Project/EventsBasedBehavior.h" @@ -60,17 +60,17 @@ const gd::String WholeProjectRefactorer::parentObjectParameterName = "Object"; std::set WholeProjectRefactorer::GetAllObjectTypesUsingEventsBasedBehavior( - const gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedBehavior& eventsBasedBehavior) { + const gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedBehavior &eventsBasedBehavior) { std::set allTypes; const gd::String behaviorType = gd::PlatformExtension::GetBehaviorFullType( eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName()); auto addTypesOfObjectsIn = - [&allTypes, &behaviorType](const gd::ObjectsContainer& objectsContainer) { - for (auto& object : objectsContainer.GetObjects()) { - for (auto& behavior : object->GetAllBehaviorContents()) { + [&allTypes, &behaviorType](const gd::ObjectsContainer &objectsContainer) { + for (auto &object : objectsContainer.GetObjects()) { + for (auto &behavior : object->GetAllBehaviorContents()) { if (behavior.second->GetTypeName() == behaviorType) { allTypes.insert(object->GetType()); } @@ -80,7 +80,7 @@ WholeProjectRefactorer::GetAllObjectTypesUsingEventsBasedBehavior( addTypesOfObjectsIn(project); for (std::size_t s = 0; s < project.GetLayoutsCount(); s++) { - auto& layout = project.GetLayout(s); + auto &layout = project.GetLayout(s); addTypesOfObjectsIn(layout); } @@ -88,11 +88,11 @@ WholeProjectRefactorer::GetAllObjectTypesUsingEventsBasedBehavior( } void WholeProjectRefactorer::EnsureBehaviorEventsFunctionsProperParameters( - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedBehavior& eventsBasedBehavior) { - for (auto& eventsFunction : + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedBehavior &eventsBasedBehavior) { + for (auto &eventsFunction : eventsBasedBehavior.GetEventsFunctions().GetInternalVector()) { - auto& parameters = eventsFunction->GetParameters(); + auto ¶meters = eventsFunction->GetParameters(); while (parameters.size() < 2) { gd::ParameterMetadata newParameter; parameters.push_back(newParameter); @@ -107,17 +107,17 @@ void WholeProjectRefactorer::EnsureBehaviorEventsFunctionsProperParameters( .SetType("behavior") .SetName("Behavior") .SetDescription("Behavior") - .SetExtraInfo(gd::PlatformExtension::GetBehaviorFullType(eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName())); + .SetExtraInfo(gd::PlatformExtension::GetBehaviorFullType( + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName())); } } void WholeProjectRefactorer::EnsureObjectEventsFunctionsProperParameters( - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedObject& eventsBasedObject) { - for (auto& eventsFunction : + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedObject &eventsBasedObject) { + for (auto &eventsFunction : eventsBasedObject.GetEventsFunctions().GetInternalVector()) { - auto& parameters = eventsFunction->GetParameters(); + auto ¶meters = eventsFunction->GetParameters(); while (parameters.size() < 1) { gd::ParameterMetadata newParameter; parameters.push_back(newParameter); @@ -127,23 +127,21 @@ void WholeProjectRefactorer::EnsureObjectEventsFunctionsProperParameters( .SetType("object") .SetName(parentObjectParameterName) .SetDescription("Object") - .SetExtraInfo(gd::PlatformExtension::GetObjectFullType(eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName())); + .SetExtraInfo(gd::PlatformExtension::GetObjectFullType( + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName())); } } void WholeProjectRefactorer::UpdateExtensionNameInEventsBasedBehavior( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - gd::EventsBasedBehavior& eventsBasedBehavior, - const gd::String& sourceExtensionName) { - const EventBasedBehaviorBrowser eventBasedBehaviorExposer(eventsBasedBehavior); + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + gd::EventsBasedBehavior &eventsBasedBehavior, + const gd::String &sourceExtensionName) { + const EventBasedBehaviorBrowser eventBasedBehaviorExposer( + eventsBasedBehavior); WholeProjectRefactorer::RenameEventsFunctionsExtension( - project, - eventsFunctionsExtension, - sourceExtensionName, - eventsFunctionsExtension.GetName(), - eventBasedBehaviorExposer); + project, eventsFunctionsExtension, sourceExtensionName, + eventsFunctionsExtension.GetName(), eventBasedBehaviorExposer); } void WholeProjectRefactorer::RenameEventsFunctionsExtension( @@ -156,56 +154,52 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( } void WholeProjectRefactorer::RenameEventsFunctionsExtension( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::String& oldName, - const gd::String& newName, - const gd::ProjectBrowser& projectBrowser - ) { - auto renameEventsFunction = - [&project, &oldName, &newName, &projectBrowser](const gd::EventsFunction& eventsFunction) { - DoRenameEventsFunction( - project, - eventsFunction, - gd::PlatformExtension::GetEventsFunctionFullType(oldName, eventsFunction.GetName()), - gd::PlatformExtension::GetEventsFunctionFullType(newName, eventsFunction.GetName()), - projectBrowser); - }; + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::String &oldName, const gd::String &newName, + const gd::ProjectBrowser &projectBrowser) { + auto renameEventsFunction = [&project, &oldName, &newName, &projectBrowser]( + const gd::EventsFunction &eventsFunction) { + DoRenameEventsFunction(project, eventsFunction, + gd::PlatformExtension::GetEventsFunctionFullType( + oldName, eventsFunction.GetName()), + gd::PlatformExtension::GetEventsFunctionFullType( + newName, eventsFunction.GetName()), + projectBrowser); + }; auto renameBehaviorEventsFunction = - [&project, &oldName, &newName, &projectBrowser]( - const gd::EventsBasedBehavior& eventsBasedBehavior, - const gd::EventsFunction& eventsFunction) { + [&project, &oldName, &newName, + &projectBrowser](const gd::EventsBasedBehavior &eventsBasedBehavior, + const gd::EventsFunction &eventsFunction) { if (eventsFunction.IsExpression()) { // Nothing to do, expressions are not including the extension name } if (eventsFunction.IsAction() || eventsFunction.IsCondition()) { gd::InstructionsTypeRenamer renamer = gd::InstructionsTypeRenamer( project, - gd::PlatformExtension::GetBehaviorEventsFunctionFullType(oldName, - eventsBasedBehavior.GetName(), - eventsFunction.GetName()), - gd::PlatformExtension::GetBehaviorEventsFunctionFullType(newName, - eventsBasedBehavior.GetName(), - eventsFunction.GetName())); + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + oldName, eventsBasedBehavior.GetName(), + eventsFunction.GetName()), + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + newName, eventsBasedBehavior.GetName(), + eventsFunction.GetName())); projectBrowser.ExposeEvents(project, renamer); } }; auto renameBehaviorPropertyFunctions = - [&project, &oldName, &newName, &projectBrowser]( - const gd::EventsBasedBehavior& eventsBasedBehavior, - const gd::NamedPropertyDescriptor& property) { + [&project, &oldName, &newName, + &projectBrowser](const gd::EventsBasedBehavior &eventsBasedBehavior, + const gd::NamedPropertyDescriptor &property) { gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - oldName, - eventsBasedBehavior.GetName(), + oldName, eventsBasedBehavior.GetName(), gd::EventsBasedBehavior::GetPropertyActionName( property.GetName())), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - newName, - eventsBasedBehavior.GetName(), + newName, eventsBasedBehavior.GetName(), gd::EventsBasedBehavior::GetPropertyActionName( property.GetName()))); projectBrowser.ExposeEvents(project, actionRenamer); @@ -214,13 +208,11 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - oldName, - eventsBasedBehavior.GetName(), + oldName, eventsBasedBehavior.GetName(), gd::EventsBasedBehavior::GetPropertyConditionName( property.GetName())), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - newName, - eventsBasedBehavior.GetName(), + newName, eventsBasedBehavior.GetName(), gd::EventsBasedBehavior::GetPropertyConditionName( property.GetName()))); projectBrowser.ExposeEvents(project, conditionRenamer); @@ -230,19 +222,17 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( }; auto renameBehaviorSharedPropertyFunctions = - [&project, &oldName, &newName, &projectBrowser]( - const gd::EventsBasedBehavior& eventsBasedBehavior, - const gd::NamedPropertyDescriptor& property) { + [&project, &oldName, &newName, + &projectBrowser](const gd::EventsBasedBehavior &eventsBasedBehavior, + const gd::NamedPropertyDescriptor &property) { gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - oldName, - eventsBasedBehavior.GetName(), + oldName, eventsBasedBehavior.GetName(), gd::EventsBasedBehavior::GetSharedPropertyActionName( property.GetName())), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - newName, - eventsBasedBehavior.GetName(), + newName, eventsBasedBehavior.GetName(), gd::EventsBasedBehavior::GetSharedPropertyActionName( property.GetName()))); projectBrowser.ExposeEvents(project, actionRenamer); @@ -251,13 +241,11 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - oldName, - eventsBasedBehavior.GetName(), + oldName, eventsBasedBehavior.GetName(), gd::EventsBasedBehavior::GetSharedPropertyConditionName( property.GetName())), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - newName, - eventsBasedBehavior.GetName(), + newName, eventsBasedBehavior.GetName(), gd::EventsBasedBehavior::GetSharedPropertyConditionName( property.GetName()))); projectBrowser.ExposeEvents(project, conditionRenamer); @@ -267,39 +255,37 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( }; auto renameObjectEventsFunction = - [&project, &oldName, &newName, &projectBrowser]( - const gd::EventsBasedObject& eventsBasedObject, - const gd::EventsFunction& eventsFunction) { + [&project, &oldName, &newName, + &projectBrowser](const gd::EventsBasedObject &eventsBasedObject, + const gd::EventsFunction &eventsFunction) { if (eventsFunction.IsExpression()) { // Nothing to do, expressions are not including the extension name } if (eventsFunction.IsAction() || eventsFunction.IsCondition()) { gd::InstructionsTypeRenamer renamer = gd::InstructionsTypeRenamer( project, - gd::PlatformExtension::GetObjectEventsFunctionFullType(oldName, - eventsBasedObject.GetName(), - eventsFunction.GetName()), - gd::PlatformExtension::GetObjectEventsFunctionFullType(newName, - eventsBasedObject.GetName(), - eventsFunction.GetName())); + gd::PlatformExtension::GetObjectEventsFunctionFullType( + oldName, eventsBasedObject.GetName(), + eventsFunction.GetName()), + gd::PlatformExtension::GetObjectEventsFunctionFullType( + newName, eventsBasedObject.GetName(), + eventsFunction.GetName())); projectBrowser.ExposeEvents(project, renamer); } }; auto renameObjectPropertyFunctions = - [&project, &oldName, &newName, &projectBrowser]( - const gd::EventsBasedObject& eventsBasedObject, - const gd::NamedPropertyDescriptor& property) { + [&project, &oldName, &newName, + &projectBrowser](const gd::EventsBasedObject &eventsBasedObject, + const gd::NamedPropertyDescriptor &property) { gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetObjectEventsFunctionFullType( - oldName, - eventsBasedObject.GetName(), + oldName, eventsBasedObject.GetName(), gd::EventsBasedObject::GetPropertyActionName( property.GetName())), gd::PlatformExtension::GetObjectEventsFunctionFullType( - newName, - eventsBasedObject.GetName(), + newName, eventsBasedObject.GetName(), gd::EventsBasedObject::GetPropertyActionName( property.GetName()))); projectBrowser.ExposeEvents(project, actionRenamer); @@ -308,13 +294,11 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetObjectEventsFunctionFullType( - oldName, - eventsBasedObject.GetName(), + oldName, eventsBasedObject.GetName(), gd::EventsBasedObject::GetPropertyConditionName( property.GetName())), gd::PlatformExtension::GetObjectEventsFunctionFullType( - newName, - eventsBasedObject.GetName(), + newName, eventsBasedObject.GetName(), gd::EventsBasedObject::GetPropertyConditionName( property.GetName()))); projectBrowser.ExposeEvents(project, conditionRenamer); @@ -328,16 +312,16 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( // instructions after they are renamed. // Free expressions - for (auto&& eventsFunction : eventsFunctionsExtension.GetInternalVector()) { + for (auto &&eventsFunction : eventsFunctionsExtension.GetInternalVector()) { if (eventsFunction->IsExpression()) { renameEventsFunction(*eventsFunction); } } // Behavior expressions - for (auto&& eventsBasedBehavior : + for (auto &&eventsBasedBehavior : eventsFunctionsExtension.GetEventsBasedBehaviors().GetInternalVector()) { - auto& behaviorEventsFunctions = eventsBasedBehavior->GetEventsFunctions(); - for (auto&& eventsFunction : behaviorEventsFunctions.GetInternalVector()) { + auto &behaviorEventsFunctions = eventsBasedBehavior->GetEventsFunctions(); + for (auto &&eventsFunction : behaviorEventsFunctions.GetInternalVector()) { if (eventsFunction->IsExpression()) { renameBehaviorEventsFunction(*eventsBasedBehavior, *eventsFunction); } @@ -345,17 +329,17 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( } // Free instructions - for (auto&& eventsFunction : eventsFunctionsExtension.GetInternalVector()) { + for (auto &&eventsFunction : eventsFunctionsExtension.GetInternalVector()) { if (eventsFunction->IsAction() || eventsFunction->IsCondition()) { renameEventsFunction(*eventsFunction); } } // Behavior instructions - for (auto&& eventsBasedBehavior : + for (auto &&eventsBasedBehavior : eventsFunctionsExtension.GetEventsBasedBehaviors().GetInternalVector()) { - auto& behaviorEventsFunctions = eventsBasedBehavior->GetEventsFunctions(); - for (auto&& eventsFunction : behaviorEventsFunctions.GetInternalVector()) { + auto &behaviorEventsFunctions = eventsBasedBehavior->GetEventsFunctions(); + for (auto &&eventsFunction : behaviorEventsFunctions.GetInternalVector()) { if (eventsFunction->IsAction() || eventsFunction->IsCondition()) { renameBehaviorEventsFunction(*eventsBasedBehavior, *eventsFunction); } @@ -379,10 +363,10 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( } // Object instructions - for (auto&& eventsBasedObject : + for (auto &&eventsBasedObject : eventsFunctionsExtension.GetEventsBasedObjects().GetInternalVector()) { - auto& objectEventsFunctions = eventsBasedObject->GetEventsFunctions(); - for (auto&& eventsFunction : objectEventsFunctions.GetInternalVector()) { + auto &objectEventsFunctions = eventsBasedObject->GetEventsFunctions(); + for (auto &&eventsFunction : objectEventsFunctions.GetInternalVector()) { if (eventsFunction->IsAction() || eventsFunction->IsCondition()) { renameObjectEventsFunction(*eventsBasedObject, *eventsFunction); } @@ -390,60 +374,61 @@ void WholeProjectRefactorer::RenameEventsFunctionsExtension( } // Object properties - for (auto&& eventsBasedObject : + for (auto &&eventsBasedObject : eventsFunctionsExtension.GetEventsBasedObjects().GetInternalVector()) { - auto& objectProperties = eventsBasedObject->GetPropertyDescriptors(); - for (auto&& propertyDescriptor : objectProperties.GetInternalVector()) { - renameObjectPropertyFunctions(*eventsBasedObject, - *propertyDescriptor); + auto &objectProperties = eventsBasedObject->GetPropertyDescriptors(); + for (auto &&propertyDescriptor : objectProperties.GetInternalVector()) { + renameObjectPropertyFunctions(*eventsBasedObject, *propertyDescriptor); } } // Finally, rename behaviors used in objects - for (auto&& eventsBasedBehavior : + for (auto &&eventsBasedBehavior : eventsFunctionsExtension.GetEventsBasedBehaviors().GetInternalVector()) { - DoRenameBehavior( - project, - gd::PlatformExtension::GetBehaviorFullType(oldName, eventsBasedBehavior->GetName()), - gd::PlatformExtension::GetBehaviorFullType(newName, eventsBasedBehavior->GetName()), - projectBrowser); + DoRenameBehavior(project, + gd::PlatformExtension::GetBehaviorFullType( + oldName, eventsBasedBehavior->GetName()), + gd::PlatformExtension::GetBehaviorFullType( + newName, eventsBasedBehavior->GetName()), + projectBrowser); } // Finally, rename custom objects type - for (auto&& eventsBasedObject : + for (auto &&eventsBasedObject : eventsFunctionsExtension.GetEventsBasedObjects().GetInternalVector()) { - DoRenameObject( - project, - gd::PlatformExtension::GetObjectFullType(oldName, eventsBasedObject->GetName()), - gd::PlatformExtension::GetObjectFullType(newName, eventsBasedObject->GetName()), - projectBrowser); + DoRenameObject(project, + gd::PlatformExtension::GetObjectFullType( + oldName, eventsBasedObject->GetName()), + gd::PlatformExtension::GetObjectFullType( + newName, eventsBasedObject->GetName()), + projectBrowser); } } void WholeProjectRefactorer::RenameEventsFunction( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::String& oldFunctionName, - const gd::String& newFunctionName) { - if (!eventsFunctionsExtension.HasEventsFunctionNamed(oldFunctionName)) return; + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::String &oldFunctionName, const gd::String &newFunctionName) { + if (!eventsFunctionsExtension.HasEventsFunctionNamed(oldFunctionName)) + return; - const gd::EventsFunction& eventsFunction = + const gd::EventsFunction &eventsFunction = eventsFunctionsExtension.GetEventsFunction(oldFunctionName); const WholeProjectBrowser wholeProjectExposer; DoRenameEventsFunction( - project, - eventsFunction, - gd::PlatformExtension::GetEventsFunctionFullType(eventsFunctionsExtension.GetName(), - oldFunctionName), - gd::PlatformExtension::GetEventsFunctionFullType(eventsFunctionsExtension.GetName(), - newFunctionName), + project, eventsFunction, + gd::PlatformExtension::GetEventsFunctionFullType( + eventsFunctionsExtension.GetName(), oldFunctionName), + gd::PlatformExtension::GetEventsFunctionFullType( + eventsFunctionsExtension.GetName(), newFunctionName), wholeProjectExposer); - - if (eventsFunction.GetFunctionType() == gd::EventsFunction::ExpressionAndCondition) { - for (auto&& otherFunction : eventsFunctionsExtension.GetInternalVector()) - { - if (otherFunction->GetFunctionType() == gd::EventsFunction::ActionWithOperator && + + if (eventsFunction.GetFunctionType() == + gd::EventsFunction::ExpressionAndCondition) { + for (auto &&otherFunction : eventsFunctionsExtension.GetInternalVector()) { + if (otherFunction->GetFunctionType() == + gd::EventsFunction::ActionWithOperator && otherFunction->GetGetterName() == oldFunctionName) { otherFunction->SetGetterName(newFunctionName); } @@ -452,15 +437,15 @@ void WholeProjectRefactorer::RenameEventsFunction( } void WholeProjectRefactorer::RenameBehaviorEventsFunction( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedBehavior& eventsBasedBehavior, - const gd::String& oldFunctionName, - const gd::String& newFunctionName) { - auto& eventsFunctions = eventsBasedBehavior.GetEventsFunctions(); - if (!eventsFunctions.HasEventsFunctionNamed(oldFunctionName)) return; - - const gd::EventsFunction& eventsFunction = + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedBehavior &eventsBasedBehavior, + const gd::String &oldFunctionName, const gd::String &newFunctionName) { + auto &eventsFunctions = eventsBasedBehavior.GetEventsFunctions(); + if (!eventsFunctions.HasEventsFunctionNamed(oldFunctionName)) + return; + + const gd::EventsFunction &eventsFunction = eventsFunctions.GetEventsFunction(oldFunctionName); // Order is important: we first rename the expressions then the instructions, @@ -470,27 +455,28 @@ void WholeProjectRefactorer::RenameBehaviorEventsFunction( gd::ExpressionsRenamer renamer = gd::ExpressionsRenamer(project.GetCurrentPlatform()); renamer.SetReplacedBehaviorExpression( - gd::PlatformExtension::GetBehaviorFullType(eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName()), - oldFunctionName, - newFunctionName); + gd::PlatformExtension::GetBehaviorFullType( + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName()), + oldFunctionName, newFunctionName); gd::ProjectBrowserHelper::ExposeProjectEvents(project, renamer); } if (eventsFunction.IsAction() || eventsFunction.IsCondition()) { gd::InstructionsTypeRenamer renamer = gd::InstructionsTypeRenamer( project, - gd::PlatformExtension::GetBehaviorEventsFunctionFullType(eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), - oldFunctionName), - gd::PlatformExtension::GetBehaviorEventsFunctionFullType(eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), - newFunctionName)); + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), + oldFunctionName), + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), + newFunctionName)); gd::ProjectBrowserHelper::ExposeProjectEvents(project, renamer); } - if (eventsFunction.GetFunctionType() == gd::EventsFunction::ExpressionAndCondition) { - for (auto&& otherFunction : eventsBasedBehavior.GetEventsFunctions().GetInternalVector()) - { - if (otherFunction->GetFunctionType() == gd::EventsFunction::ActionWithOperator && + if (eventsFunction.GetFunctionType() == + gd::EventsFunction::ExpressionAndCondition) { + for (auto &&otherFunction : + eventsBasedBehavior.GetEventsFunctions().GetInternalVector()) { + if (otherFunction->GetFunctionType() == + gd::EventsFunction::ActionWithOperator && otherFunction->GetGetterName() == oldFunctionName) { otherFunction->SetGetterName(newFunctionName); } @@ -499,42 +485,43 @@ void WholeProjectRefactorer::RenameBehaviorEventsFunction( } void WholeProjectRefactorer::RenameObjectEventsFunction( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedObject& eventsBasedObject, - const gd::String& oldFunctionName, - const gd::String& newFunctionName) { - auto& eventsFunctions = eventsBasedObject.GetEventsFunctions(); - if (!eventsFunctions.HasEventsFunctionNamed(oldFunctionName)) return; - - const gd::EventsFunction& eventsFunction = + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedObject &eventsBasedObject, + const gd::String &oldFunctionName, const gd::String &newFunctionName) { + auto &eventsFunctions = eventsBasedObject.GetEventsFunctions(); + if (!eventsFunctions.HasEventsFunctionNamed(oldFunctionName)) + return; + + const gd::EventsFunction &eventsFunction = eventsFunctions.GetEventsFunction(oldFunctionName); if (eventsFunction.IsExpression()) { gd::ExpressionsRenamer renamer = gd::ExpressionsRenamer(project.GetCurrentPlatform()); renamer.SetReplacedObjectExpression( - gd::PlatformExtension::GetObjectFullType(eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName()), - oldFunctionName, - newFunctionName); + gd::PlatformExtension::GetObjectFullType( + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName()), + oldFunctionName, newFunctionName); gd::ProjectBrowserHelper::ExposeProjectEvents(project, renamer); } if (eventsFunction.IsAction() || eventsFunction.IsCondition()) { gd::InstructionsTypeRenamer renamer = gd::InstructionsTypeRenamer( project, - gd::PlatformExtension::GetObjectEventsFunctionFullType(eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName(), - oldFunctionName), - gd::PlatformExtension::GetObjectEventsFunctionFullType(eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName(), - newFunctionName)); + gd::PlatformExtension::GetObjectEventsFunctionFullType( + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName(), + oldFunctionName), + gd::PlatformExtension::GetObjectEventsFunctionFullType( + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName(), + newFunctionName)); gd::ProjectBrowserHelper::ExposeProjectEvents(project, renamer); } - if (eventsFunction.GetFunctionType() == gd::EventsFunction::ExpressionAndCondition) { - for (auto&& otherFunction : eventsBasedObject.GetEventsFunctions().GetInternalVector()) - { - if (otherFunction->GetFunctionType() == gd::EventsFunction::ActionWithOperator && + if (eventsFunction.GetFunctionType() == + gd::EventsFunction::ExpressionAndCondition) { + for (auto &&otherFunction : + eventsBasedObject.GetEventsFunctions().GetInternalVector()) { + if (otherFunction->GetFunctionType() == + gd::EventsFunction::ActionWithOperator && otherFunction->GetGetterName() == oldFunctionName) { otherFunction->SetGetterName(newFunctionName); } @@ -543,125 +530,116 @@ void WholeProjectRefactorer::RenameObjectEventsFunction( } void WholeProjectRefactorer::MoveEventsFunctionParameter( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::String& functionName, - std::size_t oldIndex, + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::String &functionName, std::size_t oldIndex, std::size_t newIndex) { - if (!eventsFunctionsExtension.HasEventsFunctionNamed(functionName)) return; + if (!eventsFunctionsExtension.HasEventsFunctionNamed(functionName)) + return; - const gd::EventsFunction& eventsFunction = + const gd::EventsFunction &eventsFunction = eventsFunctionsExtension.GetEventsFunction(functionName); - const gd::String& eventsFunctionType = gd::PlatformExtension::GetEventsFunctionFullType( - eventsFunctionsExtension.GetName(), functionName); + const gd::String &eventsFunctionType = + gd::PlatformExtension::GetEventsFunctionFullType( + eventsFunctionsExtension.GetName(), functionName); if (eventsFunction.IsExpression()) { gd::ExpressionsParameterMover mover = gd::ExpressionsParameterMover(project.GetCurrentPlatform()); - mover.SetFreeExpressionMovedParameter( - eventsFunctionType, oldIndex, newIndex); + mover.SetFreeExpressionMovedParameter(eventsFunctionType, oldIndex, + newIndex); gd::ProjectBrowserHelper::ExposeProjectEvents(project, mover); } if (eventsFunction.IsAction() || eventsFunction.IsCondition()) { const int operatorIndexOffset = eventsFunction.IsExpression() ? 2 : 0; gd::InstructionsParameterMover mover = gd::InstructionsParameterMover( - project, - eventsFunctionType, - oldIndex + operatorIndexOffset, + project, eventsFunctionType, oldIndex + operatorIndexOffset, newIndex + operatorIndexOffset); gd::ProjectBrowserHelper::ExposeProjectEvents(project, mover); } } void WholeProjectRefactorer::MoveBehaviorEventsFunctionParameter( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedBehavior& eventsBasedBehavior, - const gd::String& functionName, - std::size_t oldIndex, + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedBehavior &eventsBasedBehavior, + const gd::String &functionName, std::size_t oldIndex, std::size_t newIndex) { - auto& eventsFunctions = eventsBasedBehavior.GetEventsFunctions(); - if (!eventsFunctions.HasEventsFunctionNamed(functionName)) return; + auto &eventsFunctions = eventsBasedBehavior.GetEventsFunctions(); + if (!eventsFunctions.HasEventsFunctionNamed(functionName)) + return; - const gd::EventsFunction& eventsFunction = + const gd::EventsFunction &eventsFunction = eventsFunctions.GetEventsFunction(functionName); - const gd::String& eventsFunctionType = - gd::PlatformExtension::GetBehaviorEventsFunctionFullType(eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), - functionName); + const gd::String &eventsFunctionType = + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), + functionName); if (eventsFunction.IsExpression()) { gd::ExpressionsParameterMover mover = gd::ExpressionsParameterMover(project.GetCurrentPlatform()); mover.SetBehaviorExpressionMovedParameter( - gd::PlatformExtension::GetBehaviorFullType(eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName()), - functionName, - oldIndex, - newIndex); + gd::PlatformExtension::GetBehaviorFullType( + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName()), + functionName, oldIndex, newIndex); gd::ProjectBrowserHelper::ExposeProjectEvents(project, mover); } if (eventsFunction.IsAction() || eventsFunction.IsCondition()) { const int operatorIndexOffset = eventsFunction.IsExpression() ? 2 : 0; gd::InstructionsParameterMover mover = gd::InstructionsParameterMover( - project, - eventsFunctionType, - oldIndex + operatorIndexOffset, + project, eventsFunctionType, oldIndex + operatorIndexOffset, newIndex + operatorIndexOffset); gd::ProjectBrowserHelper::ExposeProjectEvents(project, mover); } } void WholeProjectRefactorer::MoveObjectEventsFunctionParameter( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedObject& eventsBasedObject, - const gd::String& functionName, - std::size_t oldIndex, + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedObject &eventsBasedObject, + const gd::String &functionName, std::size_t oldIndex, std::size_t newIndex) { - auto& eventsFunctions = eventsBasedObject.GetEventsFunctions(); - if (!eventsFunctions.HasEventsFunctionNamed(functionName)) return; + auto &eventsFunctions = eventsBasedObject.GetEventsFunctions(); + if (!eventsFunctions.HasEventsFunctionNamed(functionName)) + return; - const gd::EventsFunction& eventsFunction = + const gd::EventsFunction &eventsFunction = eventsFunctions.GetEventsFunction(functionName); - const gd::String& eventsFunctionType = - gd::PlatformExtension::GetObjectEventsFunctionFullType(eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName(), - functionName); + const gd::String &eventsFunctionType = + gd::PlatformExtension::GetObjectEventsFunctionFullType( + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName(), + functionName); if (eventsFunction.IsExpression()) { gd::ExpressionsParameterMover mover = gd::ExpressionsParameterMover(project.GetCurrentPlatform()); mover.SetObjectExpressionMovedParameter( - gd::PlatformExtension::GetObjectFullType(eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName()), - functionName, - oldIndex, - newIndex); + gd::PlatformExtension::GetObjectFullType( + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName()), + functionName, oldIndex, newIndex); gd::ProjectBrowserHelper::ExposeProjectEvents(project, mover); } if (eventsFunction.IsAction() || eventsFunction.IsCondition()) { const int operatorIndexOffset = eventsFunction.IsExpression() ? 2 : 0; gd::InstructionsParameterMover mover = gd::InstructionsParameterMover( - project, - eventsFunctionType, - oldIndex + operatorIndexOffset, + project, eventsFunctionType, oldIndex + operatorIndexOffset, newIndex + operatorIndexOffset); gd::ProjectBrowserHelper::ExposeProjectEvents(project, mover); } } void WholeProjectRefactorer::RenameEventsBasedBehaviorProperty( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedBehavior& eventsBasedBehavior, - const gd::String& oldPropertyName, - const gd::String& newPropertyName) { - auto& properties = eventsBasedBehavior.GetPropertyDescriptors(); - if (!properties.Has(oldPropertyName)) return; + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedBehavior &eventsBasedBehavior, + const gd::String &oldPropertyName, const gd::String &newPropertyName) { + auto &properties = eventsBasedBehavior.GetPropertyDescriptors(); + if (!properties.Has(oldPropertyName)) + return; if (properties.Get(oldPropertyName).GetType() == "Behavior") { // This is a property representing another behavior that must exist on the @@ -673,8 +651,7 @@ void WholeProjectRefactorer::RenameEventsBasedBehaviorProperty( // behavior functions. gd::EventsBehaviorRenamer behaviorRenamer(project.GetCurrentPlatform(), behaviorObjectParameterName, - oldPropertyName, - newPropertyName); + oldPropertyName, newPropertyName); gd::ProjectBrowserHelper::ExposeEventsBasedBehaviorEvents( project, eventsBasedBehavior, behaviorRenamer); @@ -688,8 +665,8 @@ void WholeProjectRefactorer::RenameEventsBasedBehaviorProperty( gd::ExpressionsRenamer expressionRenamer = gd::ExpressionsRenamer(project.GetCurrentPlatform()); expressionRenamer.SetReplacedBehaviorExpression( - gd::PlatformExtension::GetBehaviorFullType(eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName()), + gd::PlatformExtension::GetBehaviorFullType( + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName()), EventsBasedBehavior::GetPropertyExpressionName(oldPropertyName), EventsBasedBehavior::GetPropertyExpressionName(newPropertyName)); gd::ProjectBrowserHelper::ExposeProjectEvents(project, expressionRenamer); @@ -697,37 +674,33 @@ void WholeProjectRefactorer::RenameEventsBasedBehaviorProperty( gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), EventsBasedBehavior::GetPropertyActionName(oldPropertyName)), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), EventsBasedBehavior::GetPropertyActionName(newPropertyName))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, actionRenamer); gd::InstructionsTypeRenamer conditionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), EventsBasedBehavior::GetPropertyConditionName(oldPropertyName)), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), EventsBasedBehavior::GetPropertyConditionName(newPropertyName))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, conditionRenamer); } } void WholeProjectRefactorer::RenameEventsBasedBehaviorSharedProperty( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedBehavior& eventsBasedBehavior, - const gd::String& oldPropertyName, - const gd::String& newPropertyName) { - auto& properties = eventsBasedBehavior.GetPropertyDescriptors(); - if (!properties.Has(oldPropertyName)) return; + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedBehavior &eventsBasedBehavior, + const gd::String &oldPropertyName, const gd::String &newPropertyName) { + auto &properties = eventsBasedBehavior.GetPropertyDescriptors(); + if (!properties.Has(oldPropertyName)) + return; if (properties.Get(oldPropertyName).GetType() == "Behavior") { // This is a property representing another behavior that must exist on the @@ -739,8 +712,7 @@ void WholeProjectRefactorer::RenameEventsBasedBehaviorSharedProperty( // behavior functions. gd::EventsBehaviorRenamer behaviorRenamer(project.GetCurrentPlatform(), behaviorObjectParameterName, - oldPropertyName, - newPropertyName); + oldPropertyName, newPropertyName); gd::ProjectBrowserHelper::ExposeEventsBasedBehaviorEvents( project, eventsBasedBehavior, behaviorRenamer); @@ -754,8 +726,8 @@ void WholeProjectRefactorer::RenameEventsBasedBehaviorSharedProperty( gd::ExpressionsRenamer expressionRenamer = gd::ExpressionsRenamer(project.GetCurrentPlatform()); expressionRenamer.SetReplacedBehaviorExpression( - gd::PlatformExtension::GetBehaviorFullType(eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName()), + gd::PlatformExtension::GetBehaviorFullType( + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName()), EventsBasedBehavior::GetSharedPropertyExpressionName(oldPropertyName), EventsBasedBehavior::GetSharedPropertyExpressionName(newPropertyName)); gd::ProjectBrowserHelper::ExposeProjectEvents(project, expressionRenamer); @@ -763,37 +735,35 @@ void WholeProjectRefactorer::RenameEventsBasedBehaviorSharedProperty( gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), EventsBasedBehavior::GetSharedPropertyActionName(oldPropertyName)), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), EventsBasedBehavior::GetSharedPropertyActionName(newPropertyName))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, actionRenamer); gd::InstructionsTypeRenamer conditionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), - EventsBasedBehavior::GetSharedPropertyConditionName(oldPropertyName)), + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), + EventsBasedBehavior::GetSharedPropertyConditionName( + oldPropertyName)), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedBehavior.GetName(), - EventsBasedBehavior::GetSharedPropertyConditionName(newPropertyName))); + eventsFunctionsExtension.GetName(), eventsBasedBehavior.GetName(), + EventsBasedBehavior::GetSharedPropertyConditionName( + newPropertyName))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, conditionRenamer); } } void WholeProjectRefactorer::RenameEventsBasedObjectProperty( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::EventsBasedObject& eventsBasedObject, - const gd::String& oldPropertyName, - const gd::String& newPropertyName) { - auto& properties = eventsBasedObject.GetPropertyDescriptors(); - if (!properties.Has(oldPropertyName)) return; + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::EventsBasedObject &eventsBasedObject, + const gd::String &oldPropertyName, const gd::String &newPropertyName) { + auto &properties = eventsBasedObject.GetPropertyDescriptors(); + if (!properties.Has(oldPropertyName)) + return; // Properties that represent primitive values will be used through // their related actions/conditions/expressions. Rename these. @@ -804,8 +774,8 @@ void WholeProjectRefactorer::RenameEventsBasedObjectProperty( gd::ExpressionsRenamer expressionRenamer = gd::ExpressionsRenamer(project.GetCurrentPlatform()); expressionRenamer.SetReplacedObjectExpression( - gd::PlatformExtension::GetObjectFullType(eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName()), + gd::PlatformExtension::GetObjectFullType( + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName()), EventsBasedObject::GetPropertyExpressionName(oldPropertyName), EventsBasedObject::GetPropertyExpressionName(newPropertyName)); gd::ProjectBrowserHelper::ExposeProjectEvents(project, expressionRenamer); @@ -813,33 +783,27 @@ void WholeProjectRefactorer::RenameEventsBasedObjectProperty( gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName(), EventsBasedObject::GetPropertyActionName(oldPropertyName)), gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName(), EventsBasedObject::GetPropertyActionName(newPropertyName))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, actionRenamer); gd::InstructionsTypeRenamer conditionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName(), EventsBasedObject::GetPropertyConditionName(oldPropertyName)), gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - eventsBasedObject.GetName(), + eventsFunctionsExtension.GetName(), eventsBasedObject.GetName(), EventsBasedObject::GetPropertyConditionName(newPropertyName))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, conditionRenamer); } void WholeProjectRefactorer::AddBehaviorAndRequiredBehaviors( - gd::Project& project, - gd::Object& object, - const gd::String& behaviorType, - const gd::String& behaviorName) { + gd::Project &project, gd::Object &object, const gd::String &behaviorType, + const gd::String &behaviorName) { if (object.AddNewBehavior(project, behaviorType, behaviorName) == nullptr) { // The behavior type/metadata can't be found. return; @@ -849,16 +813,14 @@ void WholeProjectRefactorer::AddBehaviorAndRequiredBehaviors( } void WholeProjectRefactorer::AddRequiredBehaviorsFor( - gd::Project& project, - gd::Object& object, - const gd::String& behaviorName) { + gd::Project &project, gd::Object &object, const gd::String &behaviorName) { if (!object.HasBehaviorNamed(behaviorName)) { return; }; - gd::Behavior& behavior = object.GetBehavior(behaviorName); + gd::Behavior &behavior = object.GetBehavior(behaviorName); - const gd::Platform& platform = project.GetCurrentPlatform(); - const gd::BehaviorMetadata& behaviorMetadata = + const gd::Platform &platform = project.GetCurrentPlatform(); + const gd::BehaviorMetadata &behaviorMetadata = MetadataProvider::GetBehaviorMetadata(platform, behavior.GetTypeName()); if (MetadataProvider::IsBadBehaviorMetadata(behaviorMetadata)) { // Should not happen because the behavior was added successfully (so its @@ -867,25 +829,24 @@ void WholeProjectRefactorer::AddRequiredBehaviorsFor( return; } - for (auto const& keyValue : behavior.GetProperties()) { - const gd::String& propertyName = keyValue.first; - const gd::PropertyDescriptor& property = keyValue.second; + for (auto const &keyValue : behavior.GetProperties()) { + const gd::String &propertyName = keyValue.first; + const gd::PropertyDescriptor &property = keyValue.second; if (property.GetType().LowerCase() == "behavior") { - const std::vector& extraInfo = property.GetExtraInfo(); + const std::vector &extraInfo = property.GetExtraInfo(); if (extraInfo.size() == 0) { // very unlikely continue; } - const gd::String& requiredBehaviorType = extraInfo.at(0); - const auto behaviorNames = - WholeProjectRefactorer::GetBehaviorsWithType(object, - requiredBehaviorType); - const gd::String* defaultBehaviorName = nullptr; + const gd::String &requiredBehaviorType = extraInfo.at(0); + const auto behaviorNames = WholeProjectRefactorer::GetBehaviorsWithType( + object, requiredBehaviorType); + const gd::String *defaultBehaviorName = nullptr; if (behaviorNames.size() == 0) { - const gd::BehaviorMetadata& requiredBehaviorMetadata = + const gd::BehaviorMetadata &requiredBehaviorMetadata = MetadataProvider::GetBehaviorMetadata(platform, requiredBehaviorType); - const gd::String& requiredBehaviorName = + const gd::String &requiredBehaviorName = requiredBehaviorMetadata.GetDefaultName(); WholeProjectRefactorer::AddBehaviorAndRequiredBehaviors( project, object, requiredBehaviorType, requiredBehaviorName); @@ -898,11 +859,12 @@ void WholeProjectRefactorer::AddRequiredBehaviorsFor( } } -std::vector WholeProjectRefactorer::GetBehaviorsWithType( - const gd::Object& object, const gd::String& type) { +std::vector +WholeProjectRefactorer::GetBehaviorsWithType(const gd::Object &object, + const gd::String &type) { std::vector behaviors; - for (auto& behaviorName : object.GetAllBehaviorNames()) { - const gd::Behavior& behavior = object.GetBehavior(behaviorName); + for (auto &behaviorName : object.GetAllBehaviorNames()) { + const gd::Behavior &behavior = object.GetBehavior(behaviorName); if (behavior.GetTypeName() == type) { behaviors.push_back(behaviorName); } @@ -911,37 +873,34 @@ std::vector WholeProjectRefactorer::GetBehaviorsWithType( } std::vector WholeProjectRefactorer::FindDependentBehaviorNames( - const gd::Project& project, - const gd::Object& object, - const gd::String& behaviorName) { + const gd::Project &project, const gd::Object &object, + const gd::String &behaviorName) { std::unordered_set dependentBehaviorNames; WholeProjectRefactorer::FindDependentBehaviorNames( project, object, behaviorName, dependentBehaviorNames); std::vector results; - results.insert(results.end(), - dependentBehaviorNames.begin(), + results.insert(results.end(), dependentBehaviorNames.begin(), dependentBehaviorNames.end()); return results; } void WholeProjectRefactorer::FindDependentBehaviorNames( - const gd::Project& project, - const gd::Object& object, - const gd::String& behaviorName, - std::unordered_set& dependentBehaviorNames) { - const gd::Platform& platform = project.GetCurrentPlatform(); - for (auto const& objectBehaviorName : object.GetAllBehaviorNames()) { - const gd::Behavior& behavior = object.GetBehavior(objectBehaviorName); - const auto& behaviorMetadata = MetadataProvider::GetBehaviorMetadata( - platform, behavior.GetTypeName()); + const gd::Project &project, const gd::Object &object, + const gd::String &behaviorName, + std::unordered_set &dependentBehaviorNames) { + const gd::Platform &platform = project.GetCurrentPlatform(); + for (auto const &objectBehaviorName : object.GetAllBehaviorNames()) { + const gd::Behavior &behavior = object.GetBehavior(objectBehaviorName); + const auto &behaviorMetadata = + MetadataProvider::GetBehaviorMetadata(platform, behavior.GetTypeName()); if (MetadataProvider::IsBadBehaviorMetadata(behaviorMetadata)) { // Ignore this behavior as it's unknown. continue; } - for (auto const& keyValue : behavior.GetProperties()) { - const gd::String& propertyName = keyValue.first; - const gd::PropertyDescriptor& property = keyValue.second; + for (auto const &keyValue : behavior.GetProperties()) { + const gd::String &propertyName = keyValue.first; + const gd::PropertyDescriptor &property = keyValue.second; if (property.GetType().LowerCase() == "behavior" && property.GetValue() == behaviorName && dependentBehaviorNames.find(objectBehaviorName) == @@ -956,41 +915,37 @@ void WholeProjectRefactorer::FindDependentBehaviorNames( std::vector WholeProjectRefactorer::FindInvalidRequiredBehaviorProperties( - const gd::Project& project) { + const gd::Project &project) { std::vector invalidRequiredBehaviorProperties; auto findInvalidRequiredBehaviorPropertiesInObjects = [&project, &invalidRequiredBehaviorProperties]( - const std::vector >& objectsList) { - for (auto& object : objectsList) { - for (auto& behaviorKeyValuePair : - object->GetAllBehaviorContents()) { - gd::Behavior& behavior = *behaviorKeyValuePair.second; - - for (auto const& keyValue : behavior.GetProperties()) { - const gd::String& propertyName = keyValue.first; - const gd::PropertyDescriptor& property = keyValue.second; + const std::vector> &objectsList) { + for (auto &object : objectsList) { + for (auto &behaviorKeyValuePair : object->GetAllBehaviorContents()) { + gd::Behavior &behavior = *behaviorKeyValuePair.second; + + for (auto const &keyValue : behavior.GetProperties()) { + const gd::String &propertyName = keyValue.first; + const gd::PropertyDescriptor &property = keyValue.second; if (property.GetType().LowerCase() != "behavior") { continue; } - const gd::String& requiredBehaviorName = property.GetValue(); - const std::vector& extraInfo = + const gd::String &requiredBehaviorName = property.GetValue(); + const std::vector &extraInfo = property.GetExtraInfo(); if (extraInfo.size() == 0) { // very unlikely continue; } - const gd::String& requiredBehaviorType = extraInfo.at(0); + const gd::String &requiredBehaviorType = extraInfo.at(0); if (requiredBehaviorName == "" || !object->HasBehaviorNamed(requiredBehaviorName) || object->GetBehavior(requiredBehaviorName).GetTypeName() != requiredBehaviorType) { auto problem = UnfilledRequiredBehaviorPropertyProblem( - project, - *object, - behavior, - propertyName, + project, *object, behavior, propertyName, requiredBehaviorType); invalidRequiredBehaviorProperties.push_back(problem); } @@ -1004,40 +959,38 @@ WholeProjectRefactorer::FindInvalidRequiredBehaviorProperties( // Find in layout objects. for (std::size_t i = 0; i < project.GetLayoutsCount(); ++i) { - const gd::Layout& layout = project.GetLayout(i); + const gd::Layout &layout = project.GetLayout(i); findInvalidRequiredBehaviorPropertiesInObjects(layout.GetObjects()); } return invalidRequiredBehaviorProperties; } bool WholeProjectRefactorer::FixInvalidRequiredBehaviorProperties( - gd::Project& project) { - const auto& invalidRequiredBehaviorProblems = + gd::Project &project) { + const auto &invalidRequiredBehaviorProblems = FindInvalidRequiredBehaviorProperties(project); - for (const auto& problem : invalidRequiredBehaviorProblems) { - auto& object = problem.GetSourceObject(); + for (const auto &problem : invalidRequiredBehaviorProblems) { + auto &object = problem.GetSourceObject(); auto suggestedBehaviorNames = GetBehaviorsWithType(object, problem.GetExpectedBehaviorTypeName()); - auto& behavior = problem.GetSourceBehaviorContent(); + auto &behavior = problem.GetSourceBehaviorContent(); if (suggestedBehaviorNames.empty()) { // No matching behavior on the object. // Add required behaviors on the object. - auto& expectedBehaviorMetadata = MetadataProvider::GetBehaviorMetadata( + auto &expectedBehaviorMetadata = MetadataProvider::GetBehaviorMetadata( project.GetCurrentPlatform(), problem.GetExpectedBehaviorTypeName()); if (MetadataProvider::IsBadBehaviorMetadata(expectedBehaviorMetadata)) { continue; } - const gd::String& newBehaviorName = + const gd::String &newBehaviorName = expectedBehaviorMetadata.GetDefaultName(); - AddBehaviorAndRequiredBehaviors(project, - object, + AddBehaviorAndRequiredBehaviors(project, object, problem.GetExpectedBehaviorTypeName(), newBehaviorName); - behavior.UpdateProperty(problem.GetSourcePropertyName(), - newBehaviorName); + behavior.UpdateProperty(problem.GetSourcePropertyName(), newBehaviorName); } else { // There is a matching behavior on the object use it by default. behavior.UpdateProperty( @@ -1051,24 +1004,21 @@ bool WholeProjectRefactorer::FixInvalidRequiredBehaviorProperties( } void WholeProjectRefactorer::RenameEventsBasedBehavior( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::String& oldBehaviorName, - const gd::String& newBehaviorName) { - auto& eventsBasedBehaviors = + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::String &oldBehaviorName, const gd::String &newBehaviorName) { + auto &eventsBasedBehaviors = eventsFunctionsExtension.GetEventsBasedBehaviors(); if (!eventsBasedBehaviors.Has(oldBehaviorName)) { gd::LogWarning("Warning, " + oldBehaviorName + " was not found when calling RenameEventsBasedBehavior."); return; } - auto& eventsBasedBehavior = eventsBasedBehaviors.Get(oldBehaviorName); + auto &eventsBasedBehavior = eventsBasedBehaviors.Get(oldBehaviorName); auto renameBehaviorEventsFunction = - [&project, - &eventsFunctionsExtension, - &oldBehaviorName, - &newBehaviorName](const gd::EventsFunction& eventsFunction) { + [&project, &eventsFunctionsExtension, &oldBehaviorName, + &newBehaviorName](const gd::EventsFunction &eventsFunction) { if (eventsFunction.IsExpression()) { // Nothing to do, expressions are not including the name of the // behavior @@ -1077,44 +1027,36 @@ void WholeProjectRefactorer::RenameEventsBasedBehavior( gd::InstructionsTypeRenamer renamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - oldBehaviorName, + eventsFunctionsExtension.GetName(), oldBehaviorName, eventsFunction.GetName()), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - newBehaviorName, + eventsFunctionsExtension.GetName(), newBehaviorName, eventsFunction.GetName())); gd::ProjectBrowserHelper::ExposeProjectEvents(project, renamer); } }; - auto renameBehaviorProperty = [&project, - &eventsFunctionsExtension, - &oldBehaviorName, - &newBehaviorName]( - const gd::NamedPropertyDescriptor& - property) { + auto renameBehaviorProperty = [&project, &eventsFunctionsExtension, + &oldBehaviorName, &newBehaviorName]( + const gd::NamedPropertyDescriptor + &property) { gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - oldBehaviorName, + eventsFunctionsExtension.GetName(), oldBehaviorName, EventsBasedBehavior::GetPropertyActionName(property.GetName())), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - newBehaviorName, + eventsFunctionsExtension.GetName(), newBehaviorName, EventsBasedBehavior::GetPropertyActionName(property.GetName()))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, actionRenamer); gd::InstructionsTypeRenamer conditionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - oldBehaviorName, + eventsFunctionsExtension.GetName(), oldBehaviorName, EventsBasedBehavior::GetPropertyConditionName(property.GetName())), gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - newBehaviorName, + eventsFunctionsExtension.GetName(), newBehaviorName, EventsBasedBehavior::GetPropertyConditionName(property.GetName()))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, conditionRenamer); @@ -1122,94 +1064,92 @@ void WholeProjectRefactorer::RenameEventsBasedBehavior( // the behavior }; - auto renameBehaviorSharedProperty = [&project, - &eventsFunctionsExtension, - &oldBehaviorName, - &newBehaviorName]( - const gd::NamedPropertyDescriptor& - property) { - gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( - project, - gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - oldBehaviorName, - EventsBasedBehavior::GetSharedPropertyActionName(property.GetName())), - gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - newBehaviorName, - EventsBasedBehavior::GetSharedPropertyActionName(property.GetName()))); - gd::ProjectBrowserHelper::ExposeProjectEvents(project, actionRenamer); + auto renameBehaviorSharedProperty = + [&project, &eventsFunctionsExtension, &oldBehaviorName, + &newBehaviorName](const gd::NamedPropertyDescriptor &property) { + gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( + project, + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + eventsFunctionsExtension.GetName(), oldBehaviorName, + EventsBasedBehavior::GetSharedPropertyActionName( + property.GetName())), + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + eventsFunctionsExtension.GetName(), newBehaviorName, + EventsBasedBehavior::GetSharedPropertyActionName( + property.GetName()))); + gd::ProjectBrowserHelper::ExposeProjectEvents(project, actionRenamer); - gd::InstructionsTypeRenamer conditionRenamer = gd::InstructionsTypeRenamer( - project, - gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - oldBehaviorName, - EventsBasedBehavior::GetSharedPropertyConditionName(property.GetName())), - gd::PlatformExtension::GetBehaviorEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - newBehaviorName, - EventsBasedBehavior::GetSharedPropertyConditionName(property.GetName()))); - gd::ProjectBrowserHelper::ExposeProjectEvents(project, conditionRenamer); + gd::InstructionsTypeRenamer conditionRenamer = + gd::InstructionsTypeRenamer( + project, + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + eventsFunctionsExtension.GetName(), oldBehaviorName, + EventsBasedBehavior::GetSharedPropertyConditionName( + property.GetName())), + gd::PlatformExtension::GetBehaviorEventsFunctionFullType( + eventsFunctionsExtension.GetName(), newBehaviorName, + EventsBasedBehavior::GetSharedPropertyConditionName( + property.GetName()))); + gd::ProjectBrowserHelper::ExposeProjectEvents(project, + conditionRenamer); - // Nothing to do for expression, expressions are not including the name of - // the behavior - }; + // Nothing to do for expression, expressions are not including the name + // of the behavior + }; // Order is important: we first rename the expressions then the instructions, // to avoid being unable to fetch the metadata (the types of parameters) of // instructions after they are renamed. - auto& behaviorEventsFunctions = eventsBasedBehavior.GetEventsFunctions(); + auto &behaviorEventsFunctions = eventsBasedBehavior.GetEventsFunctions(); // Behavior expressions - for (auto&& eventsFunction : behaviorEventsFunctions.GetInternalVector()) { + for (auto &&eventsFunction : behaviorEventsFunctions.GetInternalVector()) { if (eventsFunction->IsExpression()) { renameBehaviorEventsFunction(*eventsFunction); } } // Behavior instructions - for (auto&& eventsFunction : behaviorEventsFunctions.GetInternalVector()) { + for (auto &&eventsFunction : behaviorEventsFunctions.GetInternalVector()) { if (eventsFunction->IsAction() || eventsFunction->IsCondition()) { renameBehaviorEventsFunction(*eventsFunction); } } // Behavior properties - for (auto&& property : eventsBasedBehavior.GetPropertyDescriptors().GetInternalVector()) { + for (auto &&property : + eventsBasedBehavior.GetPropertyDescriptors().GetInternalVector()) { renameBehaviorProperty(*property); } - for (auto&& property : eventsBasedBehavior.GetSharedPropertyDescriptors().GetInternalVector()) { + for (auto &&property : + eventsBasedBehavior.GetSharedPropertyDescriptors().GetInternalVector()) { renameBehaviorSharedProperty(*property); } const WholeProjectBrowser wholeProjectExposer; - DoRenameBehavior( - project, - gd::PlatformExtension::GetBehaviorFullType(eventsFunctionsExtension.GetName(), oldBehaviorName), - gd::PlatformExtension::GetBehaviorFullType(eventsFunctionsExtension.GetName(), newBehaviorName), - wholeProjectExposer); + DoRenameBehavior(project, + gd::PlatformExtension::GetBehaviorFullType( + eventsFunctionsExtension.GetName(), oldBehaviorName), + gd::PlatformExtension::GetBehaviorFullType( + eventsFunctionsExtension.GetName(), newBehaviorName), + wholeProjectExposer); } void WholeProjectRefactorer::RenameEventsBasedObject( - gd::Project& project, - const gd::EventsFunctionsExtension& eventsFunctionsExtension, - const gd::String& oldObjectName, - const gd::String& newObjectName) { - auto& eventsBasedObjects = - eventsFunctionsExtension.GetEventsBasedObjects(); + gd::Project &project, + const gd::EventsFunctionsExtension &eventsFunctionsExtension, + const gd::String &oldObjectName, const gd::String &newObjectName) { + auto &eventsBasedObjects = eventsFunctionsExtension.GetEventsBasedObjects(); if (!eventsBasedObjects.Has(oldObjectName)) { gd::LogWarning("Warning, " + oldObjectName + " was not found when calling RenameEventsBasedObject."); return; } - auto& eventsBasedObject = eventsBasedObjects.Get(oldObjectName); + auto &eventsBasedObject = eventsBasedObjects.Get(oldObjectName); auto renameObjectEventsFunction = - [&project, - &eventsFunctionsExtension, - &oldObjectName, - &newObjectName](const gd::EventsFunction& eventsFunction) { + [&project, &eventsFunctionsExtension, &oldObjectName, + &newObjectName](const gd::EventsFunction &eventsFunction) { if (eventsFunction.IsExpression()) { // Nothing to do, expressions are not including the name of the // object @@ -1218,44 +1158,35 @@ void WholeProjectRefactorer::RenameEventsBasedObject( gd::InstructionsTypeRenamer renamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - oldObjectName, + eventsFunctionsExtension.GetName(), oldObjectName, eventsFunction.GetName()), gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - newObjectName, + eventsFunctionsExtension.GetName(), newObjectName, eventsFunction.GetName())); gd::ProjectBrowserHelper::ExposeProjectEvents(project, renamer); } }; - auto renameObjectProperty = [&project, - &eventsFunctionsExtension, - &oldObjectName, - &newObjectName]( - const gd::NamedPropertyDescriptor& - property) { + auto renameObjectProperty = [&project, &eventsFunctionsExtension, + &oldObjectName, &newObjectName]( + const gd::NamedPropertyDescriptor &property) { gd::InstructionsTypeRenamer actionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - oldObjectName, + eventsFunctionsExtension.GetName(), oldObjectName, EventsBasedObject::GetPropertyActionName(property.GetName())), gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - newObjectName, + eventsFunctionsExtension.GetName(), newObjectName, EventsBasedObject::GetPropertyActionName(property.GetName()))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, actionRenamer); gd::InstructionsTypeRenamer conditionRenamer = gd::InstructionsTypeRenamer( project, gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - oldObjectName, + eventsFunctionsExtension.GetName(), oldObjectName, EventsBasedObject::GetPropertyConditionName(property.GetName())), gd::PlatformExtension::GetObjectEventsFunctionFullType( - eventsFunctionsExtension.GetName(), - newObjectName, + eventsFunctionsExtension.GetName(), newObjectName, EventsBasedObject::GetPropertyConditionName(property.GetName()))); gd::ProjectBrowserHelper::ExposeProjectEvents(project, conditionRenamer); @@ -1266,42 +1197,41 @@ void WholeProjectRefactorer::RenameEventsBasedObject( // Order is important: we first rename the expressions then the instructions, // to avoid being unable to fetch the metadata (the types of parameters) of // instructions after they are renamed. - auto& objectEventsFunctions = eventsBasedObject.GetEventsFunctions(); + auto &objectEventsFunctions = eventsBasedObject.GetEventsFunctions(); // Object expressions - for (auto&& eventsFunction : objectEventsFunctions.GetInternalVector()) { + for (auto &&eventsFunction : objectEventsFunctions.GetInternalVector()) { if (eventsFunction->IsExpression()) { renameObjectEventsFunction(*eventsFunction); } } // Object instructions - for (auto&& eventsFunction : objectEventsFunctions.GetInternalVector()) { + for (auto &&eventsFunction : objectEventsFunctions.GetInternalVector()) { if (eventsFunction->IsAction() || eventsFunction->IsCondition()) { renameObjectEventsFunction(*eventsFunction); } } // Object properties - auto& properties = eventsBasedObject.GetPropertyDescriptors(); - for (auto&& property : properties.GetInternalVector()) { + auto &properties = eventsBasedObject.GetPropertyDescriptors(); + for (auto &&property : properties.GetInternalVector()) { renameObjectProperty(*property); } const WholeProjectBrowser wholeProjectExposer; - DoRenameObject( - project, - gd::PlatformExtension::GetObjectFullType(eventsFunctionsExtension.GetName(), oldObjectName), - gd::PlatformExtension::GetObjectFullType(eventsFunctionsExtension.GetName(), newObjectName), - wholeProjectExposer); + DoRenameObject(project, + gd::PlatformExtension::GetObjectFullType( + eventsFunctionsExtension.GetName(), oldObjectName), + gd::PlatformExtension::GetObjectFullType( + eventsFunctionsExtension.GetName(), newObjectName), + wholeProjectExposer); } void WholeProjectRefactorer::DoRenameEventsFunction( - gd::Project& project, - const gd::EventsFunction& eventsFunction, - const gd::String& oldFullType, - const gd::String& newFullType, - const gd::ProjectBrowser& projectBrowser) { + gd::Project &project, const gd::EventsFunction &eventsFunction, + const gd::String &oldFullType, const gd::String &newFullType, + const gd::ProjectBrowser &projectBrowser) { // Order is important: we first rename the expressions then the instructions, // to avoid being unable to fetch the metadata (the types of parameters) of // instructions after they are renamed. @@ -1335,8 +1265,10 @@ void WholeProjectRefactorer::DoRenameBehavior( // Rename behavior in layout behavior shared data. auto sharedDataBehaviorTypeRenamer = - gd::BehaviorsSharedDataBehaviorTypeRenamer(oldBehaviorType, newBehaviorType); - projectBrowser.ExposeBehaviorSharedDatas(project, sharedDataBehaviorTypeRenamer); + gd::BehaviorsSharedDataBehaviorTypeRenamer(oldBehaviorType, + newBehaviorType); + projectBrowser.ExposeBehaviorSharedDatas(project, + sharedDataBehaviorTypeRenamer); // Rename in parameters of (free/behavior) events function auto behaviorParameterRenamer = gd::FunctionParameterBehaviorTypeRenamer( @@ -1345,10 +1277,8 @@ void WholeProjectRefactorer::DoRenameBehavior( } void WholeProjectRefactorer::DoRenameObject( - gd::Project& project, - const gd::String& oldObjectType, - const gd::String& newObjectType, - const gd::ProjectBrowser& projectBrowser) { + gd::Project &project, const gd::String &oldObjectType, + const gd::String &newObjectType, const gd::ProjectBrowser &projectBrowser) { // Rename object type in objects lists. auto customObjectTypeRenamer = @@ -1367,21 +1297,16 @@ void WholeProjectRefactorer::DoRenameObject( } void WholeProjectRefactorer::ObjectOrGroupRemovedInLayout( - gd::Project& project, - gd::Layout& layout, - const gd::String& objectName, - bool isObjectGroup, - bool removeEventsAndGroups) { + gd::Project &project, gd::Layout &layout, const gd::String &objectName, + bool isObjectGroup, bool removeEventsAndGroups) { // Remove object in the current layout if (removeEventsAndGroups) { gd::EventsRefactorer::RemoveObjectInEvents(project.GetCurrentPlatform(), - project, - layout, - layout.GetEvents(), - objectName); + project, layout, + layout.GetEvents(), objectName); } - if (!isObjectGroup) { // Object groups can't have instances or be in other - // groups + if (!isObjectGroup) { // Object groups can't have instances or be in other + // groups if (removeEventsAndGroups) { for (std::size_t g = 0; g < layout.GetObjectGroups().size(); ++g) { if (layout.GetObjectGroups()[g].Find(objectName)) @@ -1403,11 +1328,11 @@ void WholeProjectRefactorer::ObjectOrGroupRemovedInLayout( } // Remove object in external layouts - if (!isObjectGroup) { // Object groups can't have instances + if (!isObjectGroup) { // Object groups can't have instances std::vector externalLayoutsNames = GetAssociatedExternalLayouts(project, layout); for (gd::String name : externalLayoutsNames) { - auto& externalLayout = project.GetExternalLayout(name); + auto &externalLayout = project.GetExternalLayout(name); externalLayout.GetInitialInstances().RemoveInitialInstancesOfObject( objectName); } @@ -1415,21 +1340,17 @@ void WholeProjectRefactorer::ObjectOrGroupRemovedInLayout( } void WholeProjectRefactorer::ObjectOrGroupRenamedInLayout( - gd::Project& project, - gd::Layout& layout, - const gd::String& oldName, - const gd::String& newName, - bool isObjectGroup) { + gd::Project &project, gd::Layout &layout, const gd::String &oldName, + const gd::String &newName, bool isObjectGroup) { + if (oldName == newName || newName.empty() || oldName.empty()) + return; // Rename object in the current layout - gd::EventsRefactorer::RenameObjectInEvents(project.GetCurrentPlatform(), - project, - layout, - layout.GetEvents(), - oldName, - newName); - - if (!isObjectGroup) { // Object groups can't have instances or be in other - // groups + gd::EventsRefactorer::RenameObjectInEvents( + project.GetCurrentPlatform(), project, layout, layout.GetEvents(), + oldName, newName); + + if (!isObjectGroup) { // Object groups can't have instances or be in other + // groups layout.GetInitialInstances().RenameInstancesOfObject(oldName, newName); for (std::size_t g = 0; g < layout.GetObjectGroups().size(); ++g) { layout.GetObjectGroups()[g].RenameObject(oldName, newName); @@ -1446,11 +1367,11 @@ void WholeProjectRefactorer::ObjectOrGroupRenamedInLayout( } // Rename object in external layouts - if (!isObjectGroup) { // Object groups can't have instances + if (!isObjectGroup) { // Object groups can't have instances std::vector externalLayoutsNames = GetAssociatedExternalLayouts(project, layout); for (gd::String name : externalLayoutsNames) { - auto& externalLayout = project.GetExternalLayout(name); + auto &externalLayout = project.GetExternalLayout(name); externalLayout.GetInitialInstances().RenameInstancesOfObject(oldName, newName); } @@ -1460,6 +1381,8 @@ void WholeProjectRefactorer::ObjectOrGroupRenamedInLayout( void WholeProjectRefactorer::RenameLayout(gd::Project &project, const gd::String &oldName, const gd::String &newName) { + if (oldName == newName || newName.empty() || oldName.empty()) + return; gd::ProjectElementRenamer projectElementRenamer( project.GetCurrentPlatform(), "sceneName", oldName, newName); gd::ProjectBrowserHelper::ExposeProjectEvents(project, projectElementRenamer); @@ -1477,12 +1400,15 @@ void WholeProjectRefactorer::RenameLayout(gd::Project &project, gd::LinkEventTargetRenamer linkEventTargetRenamer( project.GetCurrentPlatform(), oldName, newName); - gd::ProjectBrowserHelper::ExposeProjectEvents(project, linkEventTargetRenamer); + gd::ProjectBrowserHelper::ExposeProjectEvents(project, + linkEventTargetRenamer); } void WholeProjectRefactorer::RenameExternalLayout(gd::Project &project, const gd::String &oldName, const gd::String &newName) { + if (oldName == newName || newName.empty() || oldName.empty()) + return; gd::ProjectElementRenamer projectElementRenamer( project.GetCurrentPlatform(), "externalLayoutName", oldName, newName); gd::ProjectBrowserHelper::ExposeProjectEvents(project, projectElementRenamer); @@ -1491,18 +1417,24 @@ void WholeProjectRefactorer::RenameExternalLayout(gd::Project &project, void WholeProjectRefactorer::RenameExternalEvents(gd::Project &project, const gd::String &oldName, const gd::String &newName) { + if (oldName == newName || newName.empty() || oldName.empty()) + return; gd::LinkEventTargetRenamer linkEventTargetRenamer( project.GetCurrentPlatform(), oldName, newName); - gd::ProjectBrowserHelper::ExposeProjectEvents(project, linkEventTargetRenamer); + gd::ProjectBrowserHelper::ExposeProjectEvents(project, + linkEventTargetRenamer); } void WholeProjectRefactorer::RenameLayer(gd::Project &project, gd::Layout &layout, const gd::String &oldName, const gd::String &newName) { - gd::ProjectElementRenamer projectElementRenamer( - project.GetCurrentPlatform(), "layer", oldName, newName); - gd::ProjectBrowserHelper::ExposeLayoutEvents(project, layout, projectElementRenamer); + if (oldName == newName || newName.empty() || oldName.empty()) + return; + gd::ProjectElementRenamer projectElementRenamer(project.GetCurrentPlatform(), + "layer", oldName, newName); + gd::ProjectBrowserHelper::ExposeLayoutEvents(project, layout, + projectElementRenamer); } void WholeProjectRefactorer::RenameLayerEffect(gd::Project &project, @@ -1510,6 +1442,8 @@ void WholeProjectRefactorer::RenameLayerEffect(gd::Project &project, gd::Layer &layer, const gd::String &oldName, const gd::String &newName) { + if (oldName == newName || newName.empty() || oldName.empty()) + return; gd::ProjectElementRenamer projectElementRenamer( project.GetCurrentPlatform(), "layerEffectName", oldName, newName); projectElementRenamer.SetLayerConstraint(layer.GetName()); @@ -1522,6 +1456,8 @@ void WholeProjectRefactorer::RenameObjectAnimation(gd::Project &project, gd::Object &object, const gd::String &oldName, const gd::String &newName) { + if (oldName == newName || newName.empty() || oldName.empty()) + return; gd::ProjectElementRenamer projectElementRenamer( project.GetCurrentPlatform(), "objectAnimationName", oldName, newName); projectElementRenamer.SetObjectConstraint(object.GetName()); @@ -1534,6 +1470,8 @@ void WholeProjectRefactorer::RenameObjectPoint(gd::Project &project, gd::Object &object, const gd::String &oldName, const gd::String &newName) { + if (oldName == newName || newName.empty() || oldName.empty()) + return; gd::ProjectElementRenamer projectElementRenamer( project.GetCurrentPlatform(), "objectPointName", oldName, newName); projectElementRenamer.SetObjectConstraint(object.GetName()); @@ -1546,6 +1484,8 @@ void WholeProjectRefactorer::RenameObjectEffect(gd::Project &project, gd::Object &object, const gd::String &oldName, const gd::String &newName) { + if (oldName == newName || newName.empty() || oldName.empty()) + return; gd::ProjectElementRenamer projectElementRenamer( project.GetCurrentPlatform(), "objectEffectName", oldName, newName); projectElementRenamer.SetObjectConstraint(object.GetName()); @@ -1554,43 +1494,31 @@ void WholeProjectRefactorer::RenameObjectEffect(gd::Project &project, } void WholeProjectRefactorer::ObjectOrGroupRemovedInEventsBasedObject( - gd::Project& project, - gd::EventsBasedObject& eventsBasedObject, - gd::ObjectsContainer& globalObjectsContainer, - gd::ObjectsContainer& objectsContainer, - const gd::String& objectName, - bool isObjectGroup, - bool removeEventsAndGroups) { - for (auto &functionUniquePtr : eventsBasedObject.GetEventsFunctions().GetInternalVector()) { + gd::Project &project, gd::EventsBasedObject &eventsBasedObject, + gd::ObjectsContainer &globalObjectsContainer, + gd::ObjectsContainer &objectsContainer, const gd::String &objectName, + bool isObjectGroup, bool removeEventsAndGroups) { + for (auto &functionUniquePtr : + eventsBasedObject.GetEventsFunctions().GetInternalVector()) { auto function = functionUniquePtr.get(); WholeProjectRefactorer::ObjectOrGroupRemovedInEventsFunction( - project, - *function, - globalObjectsContainer, - objectsContainer, - objectName, - isObjectGroup, - isObjectGroup); + project, *function, globalObjectsContainer, objectsContainer, + objectName, isObjectGroup, isObjectGroup); } } void WholeProjectRefactorer::ObjectOrGroupRemovedInEventsFunction( - gd::Project& project, - gd::EventsFunction& eventsFunction, - gd::ObjectsContainer& globalObjectsContainer, - gd::ObjectsContainer& objectsContainer, - const gd::String& objectName, - bool isObjectGroup, - bool removeEventsAndGroups) { + gd::Project &project, gd::EventsFunction &eventsFunction, + gd::ObjectsContainer &globalObjectsContainer, + gd::ObjectsContainer &objectsContainer, const gd::String &objectName, + bool isObjectGroup, bool removeEventsAndGroups) { // Remove object in the current layout if (removeEventsAndGroups) { - gd::EventsRefactorer::RemoveObjectInEvents(project.GetCurrentPlatform(), - globalObjectsContainer, - objectsContainer, - eventsFunction.GetEvents(), - objectName); + gd::EventsRefactorer::RemoveObjectInEvents( + project.GetCurrentPlatform(), globalObjectsContainer, objectsContainer, + eventsFunction.GetEvents(), objectName); } - if (!isObjectGroup) { // Object groups can't be in other groups + if (!isObjectGroup) { // Object groups can't be in other groups if (removeEventsAndGroups) { for (std::size_t g = 0; g < eventsFunction.GetObjectGroups().size(); ++g) { @@ -1602,42 +1530,29 @@ void WholeProjectRefactorer::ObjectOrGroupRemovedInEventsFunction( } void WholeProjectRefactorer::ObjectOrGroupRenamedInEventsBasedObject( - gd::Project& project, - gd::ObjectsContainer& globalObjectsContainer, - gd::EventsBasedObject& eventsBasedObject, - const gd::String& oldName, - const gd::String& newName, - bool isObjectGroup) { - for (auto &functionUniquePtr : eventsBasedObject.GetEventsFunctions().GetInternalVector()) { + gd::Project &project, gd::ObjectsContainer &globalObjectsContainer, + gd::EventsBasedObject &eventsBasedObject, const gd::String &oldName, + const gd::String &newName, bool isObjectGroup) { + for (auto &functionUniquePtr : + eventsBasedObject.GetEventsFunctions().GetInternalVector()) { auto *function = functionUniquePtr.get(); WholeProjectRefactorer::ObjectOrGroupRenamedInEventsFunction( - project, - *function, - globalObjectsContainer, - eventsBasedObject, - oldName, - newName, - isObjectGroup); + project, *function, globalObjectsContainer, eventsBasedObject, oldName, + newName, isObjectGroup); } } void WholeProjectRefactorer::ObjectOrGroupRenamedInEventsFunction( - gd::Project& project, - gd::EventsFunction& eventsFunction, - gd::ObjectsContainer& globalObjectsContainer, - gd::ObjectsContainer& objectsContainer, - const gd::String& oldName, - const gd::String& newName, - bool isObjectGroup) { + gd::Project &project, gd::EventsFunction &eventsFunction, + gd::ObjectsContainer &globalObjectsContainer, + gd::ObjectsContainer &objectsContainer, const gd::String &oldName, + const gd::String &newName, bool isObjectGroup) { // Rename object in the current layout - gd::EventsRefactorer::RenameObjectInEvents(project.GetCurrentPlatform(), - globalObjectsContainer, - objectsContainer, - eventsFunction.GetEvents(), - oldName, - newName); - - if (!isObjectGroup) { // Object groups can't be in other groups + gd::EventsRefactorer::RenameObjectInEvents( + project.GetCurrentPlatform(), globalObjectsContainer, objectsContainer, + eventsFunction.GetEvents(), oldName, newName); + + if (!isObjectGroup) { // Object groups can't be in other groups for (std::size_t g = 0; g < eventsFunction.GetObjectGroups().size(); ++g) { eventsFunction.GetObjectGroups()[g].RenameObject(oldName, newName); } @@ -1645,31 +1560,28 @@ void WholeProjectRefactorer::ObjectOrGroupRenamedInEventsFunction( } void WholeProjectRefactorer::GlobalObjectOrGroupRenamed( - gd::Project& project, - const gd::String& oldName, - const gd::String& newName, + gd::Project &project, const gd::String &oldName, const gd::String &newName, bool isObjectGroup) { - if (!isObjectGroup) { // Object groups can't be in other groups + if (!isObjectGroup) { // Object groups can't be in other groups for (std::size_t g = 0; g < project.GetObjectGroups().size(); ++g) { project.GetObjectGroups()[g].RenameObject(oldName, newName); } } for (std::size_t i = 0; i < project.GetLayoutsCount(); ++i) { - gd::Layout& layout = project.GetLayout(i); - if (layout.HasObjectNamed(oldName)) continue; + gd::Layout &layout = project.GetLayout(i); + if (layout.HasObjectNamed(oldName)) + continue; - ObjectOrGroupRenamedInLayout( - project, layout, oldName, newName, isObjectGroup); + ObjectOrGroupRenamedInLayout(project, layout, oldName, newName, + isObjectGroup); } } void WholeProjectRefactorer::GlobalObjectOrGroupRemoved( - gd::Project& project, - const gd::String& objectName, - bool isObjectGroup, + gd::Project &project, const gd::String &objectName, bool isObjectGroup, bool removeEventsAndGroups) { - if (!isObjectGroup) { // Object groups can't be in other groups + if (!isObjectGroup) { // Object groups can't be in other groups if (removeEventsAndGroups) { for (std::size_t g = 0; g < project.GetObjectGroups().size(); ++g) { project.GetObjectGroups()[g].RemoveObject(objectName); @@ -1678,24 +1590,26 @@ void WholeProjectRefactorer::GlobalObjectOrGroupRemoved( } for (std::size_t i = 0; i < project.GetLayoutsCount(); ++i) { - gd::Layout& layout = project.GetLayout(i); - if (layout.HasObjectNamed(objectName)) continue; + gd::Layout &layout = project.GetLayout(i); + if (layout.HasObjectNamed(objectName)) + continue; - ObjectOrGroupRemovedInLayout( - project, layout, objectName, isObjectGroup, removeEventsAndGroups); + ObjectOrGroupRemovedInLayout(project, layout, objectName, isObjectGroup, + removeEventsAndGroups); } } -std::vector WholeProjectRefactorer::GetAssociatedExternalLayouts( - gd::Project& project, gd::Layout& layout) { +std::vector +WholeProjectRefactorer::GetAssociatedExternalLayouts(gd::Project &project, + gd::Layout &layout) { return GetAssociatedExternalLayouts(project, layout.GetName()); } std::vector WholeProjectRefactorer::GetAssociatedExternalLayouts( - gd::Project& project, const gd::String& layoutName) { + gd::Project &project, const gd::String &layoutName) { std::vector results; for (std::size_t i = 0; i < project.GetExternalLayoutsCount(); ++i) { - auto& externalLayout = project.GetExternalLayout(i); + auto &externalLayout = project.GetExternalLayout(i); if (externalLayout.GetAssociatedLayout() == layoutName) { results.push_back(externalLayout.GetName()); @@ -1719,4 +1633,4 @@ std::vector WholeProjectRefactorer::GetAssociatedExternalEvents( return results; } -} // namespace gd +} // namespace gd diff --git a/Core/tests/WholeProjectRefactorer.cpp b/Core/tests/WholeProjectRefactorer.cpp index d62c51b88d26..d98d79988ef4 100644 --- a/Core/tests/WholeProjectRefactorer.cpp +++ b/Core/tests/WholeProjectRefactorer.cpp @@ -3348,10 +3348,21 @@ const gd::Instruction &CreateActionWithLayerParameter(gd::Project &project, action.SetParameter(3, gd::Expression("\"My layer\"")); return event.GetActions().Insert(action); } +const gd::Instruction &CreateActionWithEmptyLayerParameter(gd::Project &project, + gd::EventsList &events) { + gd::StandardEvent &event = dynamic_cast( + events.InsertNewEvent(project, "BuiltinCommonInstructions::Standard")); + gd::Instruction action; + action.SetType("MyExtension::SetCameraCenterX"); + action.SetParametersCount(4); + action.SetParameter(3, gd::Expression("")); + return event.GetActions().Insert(action); +} const gd::Instruction & CreateExpressionWithLayerParameter(gd::Project &project, - gd::EventsList &events) { + gd::EventsList &events, + const gd::String &layerName) { gd::StandardEvent &event = dynamic_cast( events.InsertNewEvent(project, "BuiltinCommonInstructions::Standard")); @@ -3359,8 +3370,8 @@ CreateExpressionWithLayerParameter(gd::Project &project, action.SetType("MyExtension::DoSomething"); action.SetParametersCount(1); action.SetParameter( - 0, gd::Expression("MyExtension::CameraCenterX(\"My layer\") + " - "MyExtension::CameraCenterX(\"My layer\")")); + 0, gd::Expression("MyExtension::CameraCenterX(\"" + layerName + "\") + " + "MyExtension::CameraCenterX(\"" + layerName + "\")")); return event.GetActions().Insert(action); } } // namespace @@ -3390,13 +3401,13 @@ TEST_CASE("RenameLayer", "[common]") { project, otherExternalEvents.GetEvents()); auto &layoutExpression = - CreateExpressionWithLayerParameter(project, layout.GetEvents()); + CreateExpressionWithLayerParameter(project, layout.GetEvents(), "My layer"); auto &externalExpression = - CreateExpressionWithLayerParameter(project, externalEvents.GetEvents()); + CreateExpressionWithLayerParameter(project, externalEvents.GetEvents(), "My layer"); auto &otherLayoutExpression = - CreateExpressionWithLayerParameter(project, otherLayout.GetEvents()); + CreateExpressionWithLayerParameter(project, otherLayout.GetEvents(), "My layer"); auto &otherExternalExpression = CreateExpressionWithLayerParameter( - project, otherExternalEvents.GetEvents()); + project, otherExternalEvents.GetEvents(), "My layer"); gd::WholeProjectRefactorer::RenameLayer(project, layout, "My layer", "My renamed layer"); @@ -3434,7 +3445,7 @@ TEST_CASE("RenameLayer", "[common]") { auto &layout = project.InsertNewLayout("My layout", 0); auto &layoutExpression = - CreateExpressionWithLayerParameter(project, layout.GetEvents()); + CreateExpressionWithLayerParameter(project, layout.GetEvents(), "My layer"); gd::WholeProjectRefactorer::RenameLayer(project, layout, "My layer", "layerA"); @@ -3443,6 +3454,57 @@ TEST_CASE("RenameLayer", "[common]") { "MyExtension::CameraCenterX(\"layerA\") + " "MyExtension::CameraCenterX(\"layerA\")"); } + + SECTION("Can rename a layer when a layer parameter is empty") { + gd::Project project; + gd::Platform platform; + SetupProjectWithDummyPlatform(project, platform); + + auto &layout = project.InsertNewLayout("My layout", 0); + + auto &layoutAction = + CreateActionWithEmptyLayerParameter(project, layout.GetEvents()); + + gd::WholeProjectRefactorer::RenameLayer(project, layout, "My layer", + "layerA"); + + REQUIRE(layoutAction.GetParameter(0).GetPlainString() == ""); + } + + SECTION("Can't rename a layer to an empty name") { + gd::Project project; + gd::Platform platform; + SetupProjectWithDummyPlatform(project, platform); + + auto &layout = project.InsertNewLayout("My layout", 0); + + auto &layoutExpression = + CreateExpressionWithLayerParameter(project, layout.GetEvents(), "My layer"); + + gd::WholeProjectRefactorer::RenameLayer(project, layout, "My layer", + ""); + + REQUIRE(layoutExpression.GetParameter(0).GetPlainString() == + "MyExtension::CameraCenterX(\"My layer\") + " + "MyExtension::CameraCenterX(\"My layer\")"); + } + + SECTION("Can't rename a layer from an empty name") { + gd::Project project; + gd::Platform platform; + SetupProjectWithDummyPlatform(project, platform); + + auto &layout = project.InsertNewLayout("My layout", 0); + + auto &layoutExpression = + CreateExpressionWithLayerParameter(project, layout.GetEvents(), ""); + + gd::WholeProjectRefactorer::RenameLayer(project, layout, "", "My layer"); + + REQUIRE(layoutExpression.GetParameter(0).GetPlainString() == + "MyExtension::CameraCenterX(\"\") + " + "MyExtension::CameraCenterX(\"\")"); + } } namespace { diff --git a/newIDE/app/src/ObjectEditor/Editors/SpriteEditor/index.js b/newIDE/app/src/ObjectEditor/Editors/SpriteEditor/index.js index dc479d965052..cdb5b4d05c72 100644 --- a/newIDE/app/src/ObjectEditor/Editors/SpriteEditor/index.js +++ b/newIDE/app/src/ObjectEditor/Editors/SpriteEditor/index.js @@ -336,7 +336,7 @@ export default function SpriteEditor({ ? undefined // Don't check the current animation name as we're changing it. : spriteConfiguration.getAnimation(index).getName(); } - ); + ).filter(Boolean); if (newName !== '' && otherNames.some(name => name === newName)) { // The indexes can be used as a key because errors are cleared when @@ -350,7 +350,6 @@ export default function SpriteEditor({ return; } - const oldName = animation.getName(); animation.setName(newName); // TODO EBO Refactor event-based object events when an animation is renamed. if (layout && object) { @@ -358,7 +357,7 @@ export default function SpriteEditor({ project, layout, object, - oldName, + currentName, newName ); }