From 6622947c15e53f7aac17710cd24ce2ad66f8fd9f Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Thu, 23 Sep 2010 12:38:01 +0200
Subject: [PATCH] QML editor: also check for objectName property when guessing
 the name.

---
 .../qmljscomponentfromobjectdef.cpp           | 33 ++++++++++++-------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
index 85c5d679c60..0d21a6101a5 100644
--- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
+++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
@@ -46,8 +46,23 @@ using namespace QmlJSEditor::Internal;
 
 namespace {
 
+static QString toString(Statement *statement)
+{
+    ExpressionStatement *expStmt = cast<ExpressionStatement *>(statement);
+    if (!expStmt)
+        return QString::null;
+    if (IdentifierExpression *idExp = cast<IdentifierExpression *>(expStmt->expression)) {
+        return idExp->name->asString();
+    } else if (StringLiteral *strExp = cast<StringLiteral *>(expStmt->expression)) {
+        return strExp->value->asString();
+    }
+    return QString::null;
+}
+
 static QString getIdProperty(UiObjectDefinition *def)
 {
+    QString objectName;
+
     if (def && def->initializer) {
         for (UiObjectMemberList *iter = def->initializer->members; iter; iter = iter->next) {
             if (UiScriptBinding *script = cast<UiScriptBinding*>(iter->member)) {
@@ -56,22 +71,16 @@ static QString getIdProperty(UiObjectDefinition *def)
                 if (script->qualifiedId->next)
                     continue;
                 if (script->qualifiedId->name) {
-                    if (script->qualifiedId->name->asString() == QLatin1String("id")) {
-                        ExpressionStatement *expStmt = cast<ExpressionStatement *>(script->statement);
-                        if (!expStmt)
-                            continue;
-                        if (IdentifierExpression *idExp = cast<IdentifierExpression *>(expStmt->expression)) {
-                            return idExp->name->asString();
-                        } else if (StringLiteral *strExp = cast<StringLiteral *>(expStmt->expression)) {
-                            return strExp->value->asString();
-                        }
-                    }
+                    if (script->qualifiedId->name->asString() == QLatin1String("id"))
+                        return toString(script->statement);
+                    if (script->qualifiedId->name->asString() == QLatin1String("objectName"))
+                        objectName = toString(script->statement);
                 }
             }
         }
     }
 
-    return QString();
+    return objectName;
 }
 
 class Operation: public QmlJSQuickFixOperation
@@ -90,7 +99,7 @@ public:
 
         if (m_componentName.isEmpty()) {
             setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef",
-                                                       "Move Component into separate file'"));
+                                                       "Move Component into separate file"));
         } else {
             m_componentName[0] = m_componentName.at(0).toUpper();
             setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef",
-- 
GitLab