Expression/ObjectIdentifier: changed return type of renameDocumentObject and renameDocument,

to be able to signal that a rename actually took place.
This commit is contained in:
Eivind Kvedalen 2015-12-19 00:50:10 +01:00 committed by wmayer
parent 83d221e161
commit 65a610d1cb
4 changed files with 27 additions and 13 deletions

View File

@ -1090,14 +1090,14 @@ void VariableExpression::setPath(const ObjectIdentifier &path)
var = 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);
} }
// //

View File

@ -349,9 +349,9 @@ public:
void setPath(const ObjectIdentifier & path); 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; const App::Property *getProperty() const;

View File

@ -316,21 +316,30 @@ std::string ObjectIdentifier::toEscapedString() const
* @param newName New name of document object * @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)) if (ExpressionParser::isTokenAnIndentifier(newName))
documentObjectName = newName; documentObjectName = newName;
else else
documentObjectName = ObjectIdentifier::String(newName, true); documentObjectName = ObjectIdentifier::String(newName, true);
resolve();
return true;
} }
else if (propertyIndex == 1 && documentObjectName == oldName) { else if (propertyIndex == 1 && documentObjectName == oldName) {
if (ExpressionParser::isTokenAnIndentifier(newName)) if (ExpressionParser::isTokenAnIndentifier(newName))
components[0].name = newName; components[0].name = newName;
else else
components[0].name = ObjectIdentifier::String(newName, true); 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 * @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) { if (documentName == oldName) {
documentName = newName; documentName = newName;
resolve();
return true;
} }
resolve(); return false;
} }
/** /**

View File

@ -186,9 +186,9 @@ public:
const String getDocumentObjectName() const; 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; App::Document *getDocument(String name = String()) const;