QmlDesigner: Ensure we always have a document for a .qml file.

In some cases there is no document in the snapshot and
Qt Quick Designer just ignored the new document in this case.

So for example when a new tab was added and then opened the first time,
there was no document in the snapshot and Qt Creator opened the document
without Qt Quick Designer reacting to this.

Change-Id: I98f97c2443686733b7e71d852c6df63865034dfc
Reviewed-by: Marco Bubke <marco.bubke@digia.com>
This commit is contained in:
Thomas Hartmann
2014-06-25 16:05:22 +02:00
parent b05a1523f1
commit 55b61e34d6

View File

@@ -347,10 +347,22 @@ void QmlDesignerPlugin::resetModelSelection()
currentDesignDocument()->rewriterView()->setSelectedModelNodes(QList<ModelNode>());
}
static QmlJS::Document::Ptr documentForFilePath(const QString &filePath)
{
QmlJS::Document::Ptr document = QmlJS::ModelManagerInterface::instance()->snapshot().document(filePath);
if (!document) {
document = QmlJS::Document::create(filePath, QmlJS::Language::Qml);
QmlJS::ModelManagerInterface::instance()->snapshot().insert(document);
}
return document;
}
static bool checkIfEditorIsQtQuick(Core::IEditor *editor)
{
if (editor)
if (editor && editor->document()->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) {
QmlJS::Document::Ptr document = QmlJS::ModelManagerInterface::instance()->snapshot().document(editor->document()->filePath());
QmlJS::Document::Ptr document = documentForFilePath(editor->document()->filePath());
if (!document.isNull())
return document->language() == QmlJS::Language::QmlQtQuick1
|| document->language() == QmlJS::Language::QmlQtQuick2