diff --git a/src/plugins/qmldesigner/core/include/basetexteditmodifier.h b/src/plugins/qmldesigner/core/include/basetexteditmodifier.h index 5c1538bb7773e43acb7ad647efddff413c287a75..ff77662576691d20850433bac82192aad97c192b 100644 --- a/src/plugins/qmldesigner/core/include/basetexteditmodifier.h +++ b/src/plugins/qmldesigner/core/include/basetexteditmodifier.h @@ -36,6 +36,8 @@ #include <texteditor/basetexteditor.h> +#include <QtCore/QStringList> + namespace QmlJS { class Snapshot; } // namespace QmlJS @@ -52,6 +54,7 @@ public: virtual int indentDepth() const; static QmlJS::Snapshot getSnapshot(); + static QStringList importPaths(); }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp b/src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp index 424858f38d06816f0501065e5a8a135b01906c17..fc67d297afc8e33d0fbe89a6e86afe2524970b6a 100644 --- a/src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp +++ b/src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp @@ -68,12 +68,28 @@ int BaseTextEditModifier::indentDepth() const } } -QmlJS::Snapshot BaseTextEditModifier::getSnapshot() +namespace { +static inline QmlJSEditor::ModelManagerInterface *getModelManager() { ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance(); - QmlJSEditor::ModelManagerInterface *modelManager = pluginManager->getObject<QmlJSEditor::ModelManagerInterface>(); + return pluginManager->getObject<QmlJSEditor::ModelManagerInterface>(); +} +} + +QmlJS::Snapshot BaseTextEditModifier::getSnapshot() +{ + QmlJSEditor::ModelManagerInterface *modelManager = getModelManager(); if (modelManager) return modelManager->snapshot(); else return QmlJS::Snapshot(); } + +QStringList BaseTextEditModifier::importPaths() +{ + QmlJSEditor::ModelManagerInterface *modelManager = getModelManager(); + if (modelManager) + return modelManager->importPaths(); + else + return QStringList(); +} diff --git a/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp index 3d3cfb3a2a6dce1e6b4714be2c023e26208d5fcf..3a1de041b750172869af2e8aaff43b8f9b287c05 100644 --- a/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp @@ -53,13 +53,14 @@ namespace QmlDesigner { namespace Internal { struct ReadingContext { - ReadingContext(const Snapshot &snapshot, const Document::Ptr &doc) + ReadingContext(const Snapshot &snapshot, const Document::Ptr &doc, + const QStringList importPaths) : snapshot(snapshot) , doc(doc) , engine(new Interpreter::Engine) , ctxt(new Interpreter::Context(engine)) { - ctxt->build(QList<Node *>(), doc, snapshot); + ctxt->build(QList<Node *>(), doc, snapshot, importPaths); } ~ReadingContext() @@ -72,6 +73,12 @@ struct ReadingContext { typeName = qmlValue->packageName() + QLatin1String("/") + qmlValue->className(); majorVersion = qmlValue->majorVersion(); minorVersion = qmlValue->minorVersion(); + } else if (value) { + for (UiQualifiedId *iter = astTypeNode; iter; iter = iter->next) + if (!iter->next && iter->name) + typeName = iter->name->asString(); + majorVersion = Interpreter::QmlObjectValue::NoVersion; + minorVersion = Interpreter::QmlObjectValue::NoVersion; } } @@ -243,7 +250,6 @@ void TextToModelMerger::setupImports(const Document::Ptr &doc, bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differenceHandler) { - qDebug() << "**** Starting to load the file..."; setActive(true); try { @@ -254,12 +260,13 @@ bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differen if (success) { Snapshot snapshot = BaseTextEditModifier::getSnapshot(); + const QStringList importPaths = BaseTextEditModifier::importPaths(); const QString fileName = url.toLocalFile(); Document::Ptr doc = Document::create(fileName); doc->setSource(QString::fromUtf8(data.constData())); doc->parseQml(); snapshot.insert(doc); - ReadingContext ctxt(snapshot, doc); + ReadingContext ctxt(snapshot, doc, importPaths); setupImports(doc, differenceHandler); @@ -372,10 +379,14 @@ void TextToModelMerger::syncNode(ModelNode &modelNode, } else if (UiScriptBinding *script = cast<UiScriptBinding *>(member)) { const QString astPropertyName = flatten(script->qualifiedId); QString astValue; - if (script->statement) + if (script->statement) { astValue = textAt(context->doc, script->statement->firstSourceLocation(), script->statement->lastSourceLocation()); + astValue = astValue.trimmed(); + if (astValue.endsWith(QLatin1Char(';'))) + astValue = astValue.left(astValue.length() - 1); + } if (astPropertyName == QLatin1String("id")) { syncNodeId(modelNode, astValue, differenceHandler); @@ -594,7 +605,6 @@ ModelNode TextToModelMerger::createModelNode(const QString &typeName, ReadingContext *context, DifferenceHandler &differenceHandler) { - qDebug() << "Creating model node for" << typeName << majorVersion << minorVersion; ModelNode newNode = m_rewriterView->createModelNode(typeName, majorVersion, minorVersion); @@ -792,7 +802,6 @@ void ModelAmender::variantValuesDiffer(VariantProperty &modelProperty, const QVa void ModelAmender::shouldBeVariantProperty(AbstractProperty &modelProperty, const QVariant &qmlVariantValue, const QString &dynamicTypeName) { -// qDebug() << "property" << modelProperty.name() << "in node" << modelProperty.parentModelNode().id(); ModelNode theNode = modelProperty.parentModelNode(); VariantProperty newModelProperty = theNode.variantProperty(modelProperty.name());