From 65a610d1cba6bf5bd6183cdde1df15fa33bd8ff8 Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Sat, 19 Dec 2015 00:50:10 +0100 Subject: [PATCH] Expression/ObjectIdentifier: changed return type of renameDocumentObject and renameDocument, to be able to signal that a rename actually took place. --- src/App/Expression.cpp | 8 ++++---- src/App/Expression.h | 4 ++-- src/App/ObjectIdentifier.cpp | 24 +++++++++++++++++++----- src/App/ObjectIdentifier.h | 4 ++-- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 69e888d96..d78820cb2 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -1090,14 +1090,14 @@ void VariableExpression::setPath(const ObjectIdentifier &path) var = path; } -void VariableExpression::renameDocumentObject(const std::string &oldName, const std::string &newName) +bool VariableExpression::renameDocumentObject(const std::string &oldName, const std::string &newName) { - var.renameDocumentObject(oldName, newName); + return var.renameDocumentObject(oldName, newName); } -void VariableExpression::renameDocument(const std::string &oldName, const std::string &newName) +bool VariableExpression::renameDocument(const std::string &oldName, const std::string &newName) { - var.renameDocument(oldName, newName); + return var.renameDocument(oldName, newName); } // diff --git a/src/App/Expression.h b/src/App/Expression.h index c14cc310d..d80c38fad 100644 --- a/src/App/Expression.h +++ b/src/App/Expression.h @@ -349,9 +349,9 @@ public: void setPath(const ObjectIdentifier & path); - void renameDocumentObject(const std::string & oldName, const std::string & newName); + bool renameDocumentObject(const std::string & oldName, const std::string & newName); - void renameDocument(const std::string &oldName, const std::string &newName); + bool renameDocument(const std::string &oldName, const std::string &newName); const App::Property *getProperty() const; diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index b22285c2b..4b6532550 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -316,21 +316,30 @@ std::string ObjectIdentifier::toEscapedString() const * @param newName New name of document object */ -void ObjectIdentifier::renameDocumentObject(const std::string &oldName, const std::string &newName) +bool ObjectIdentifier::renameDocumentObject(const std::string &oldName, const std::string &newName) { - if (documentObjectNameSet && documentObjectName == oldName) { + if (oldName == newName) + return false; + + if (documentObjectNameSet && documentObjectName == oldName) { if (ExpressionParser::isTokenAnIndentifier(newName)) documentObjectName = newName; else documentObjectName = ObjectIdentifier::String(newName, true); + + resolve(); + return true; } else if (propertyIndex == 1 && documentObjectName == oldName) { if (ExpressionParser::isTokenAnIndentifier(newName)) components[0].name = newName; else components[0].name = ObjectIdentifier::String(newName, true); + + resolve(); + return true; } - resolve(); + return false; } /** @@ -339,13 +348,18 @@ void ObjectIdentifier::renameDocumentObject(const std::string &oldName, const st * @param newName New name of document */ -void ObjectIdentifier::renameDocument(const std::string &oldName, const std::string &newName) +bool ObjectIdentifier::renameDocument(const std::string &oldName, const std::string &newName) { + if (oldName == newName) + return false; + if (documentName == oldName) { documentName = newName; + resolve(); + return true; } - resolve(); + return false; } /** diff --git a/src/App/ObjectIdentifier.h b/src/App/ObjectIdentifier.h index 4388aca01..bdc767b0e 100644 --- a/src/App/ObjectIdentifier.h +++ b/src/App/ObjectIdentifier.h @@ -186,9 +186,9 @@ public: const String getDocumentObjectName() const; - void renameDocumentObject(const std::string & oldName, const std::string & newName); + bool renameDocumentObject(const std::string & oldName, const std::string & newName); - void renameDocument(const std::string &oldName, const std::string &newName); + bool renameDocument(const std::string &oldName, const std::string &newName); App::Document *getDocument(String name = String()) const;