diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 0ad90ebb77..c3a17b6cbf 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -528,12 +528,19 @@ void DocumentObject::connectRelabelSignals() if (ExpressionEngine.numExpressions() > 0) { // Not already connected? - if (!onRelabledObjectConnection.connected()) - onRelabledObjectConnection = getDocument()->signalRelabelObject.connect(boost::bind(&PropertyExpressionEngine::slotObjectRenamed, &ExpressionEngine, _1)); + if (!onRelabledObjectConnection.connected()) { + onRelabledObjectConnection = getDocument()->signalRelabelObject + .connect(boost::bind(&PropertyExpressionEngine::slotObjectRenamed, + &ExpressionEngine, _1)); + } - // Connect to signalDeletedObject, to properly track deletion of other objects that might be referenced in an expression - if (!onDeletedObjectConnection.connected()) - onDeletedObjectConnection = getDocument()->signalDeletedObject.connect(boost::bind(&PropertyExpressionEngine::slotObjectDeleted, &ExpressionEngine, _1)); + // Connect to signalDeletedObject, to properly track deletion of other objects + // that might be referenced in an expression + if (!onDeletedObjectConnection.connected()) { + onDeletedObjectConnection = getDocument()->signalDeletedObject + .connect(boost::bind(&PropertyExpressionEngine::slotObjectDeleted, + &ExpressionEngine, _1)); + } try { // Crude method to resolve all expression dependencies diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index b7b51ce3ef..306793dacf 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -362,6 +362,24 @@ bool ObjectIdentifier::renameDocumentObject(const std::string &oldName, const st return true; } } + + // If object identifier uses the label then resolving the document object will fail. + // So, it must be checked if using the new label will succeed + if (!components.empty() && components[0].getName() == oldName) { + ObjectIdentifier id(*this); + id.components[0].name = newName; + + ResolveResults result(id); + + if (result.propertyIndex == 1 && result.resolvedDocumentObjectName == newName) { + if (ExpressionParser::isTokenAnIndentifier(newName)) + components[0].name = newName; + else + components[0].name = ObjectIdentifier::String(newName, true); + + return true; + } + } return false; } @@ -385,6 +403,18 @@ bool ObjectIdentifier::validDocumentObjectRename(const std::string &oldName, con if (result.propertyIndex == 1 && result.resolvedDocumentObjectName == oldName) return true; } + + // If object identifier uses the label then resolving the document object will fail. + // So, it must be checked if using the new label will succeed + if (!components.empty() && components[0].getName() == oldName) { + ObjectIdentifier id(*this); + id.components[0].name = newName; + + ResolveResults result(id); + + if (result.propertyIndex == 1 && result.resolvedDocumentObjectName == newName) + return true; + } return false; } @@ -411,7 +441,6 @@ bool ObjectIdentifier::renameDocument(const std::string &oldName, const std::str return true; } } - return false; }