diff --git a/src/plugins/qmldesigner/components/componentcore/crumblebar.cpp b/src/plugins/qmldesigner/components/componentcore/crumblebar.cpp index 47cbdcdf40e18aa56d3236acaa2511b33ae08120..891a82c4f7c009611af2557617d265a897cf5efb 100644 --- a/src/plugins/qmldesigner/components/componentcore/crumblebar.cpp +++ b/src/plugins/qmldesigner/components/componentcore/crumblebar.cpp @@ -147,15 +147,18 @@ void CrumbleBar::onCrumblePathElementClicked(const QVariant &data) && clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) { nextFileIsCalledInternally(); currentDesignDocument()->changeToDocumentModel(); + QmlDesignerPlugin::instance()->viewManager().setComponentViewToMaster(); } else { crumblePath()->popElement(); nextFileIsCalledInternally(); Core::EditorManager::openEditor(clickedCrumbleBarInfo.fileName, Core::Id(), Core::EditorManager::DoNotMakeVisible); if (!clickedCrumbleBarInfo.componentId.isEmpty()) { - currentDesignDocument()->changeToSubComponent( - currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId)); - //pushInFileComponent(clickedCrumbleBarInfo.componentId); + ModelNode componentNode = currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId); + currentDesignDocument()->changeToSubComponent(componentNode); + QmlDesignerPlugin::instance()->viewManager().setComponentNode(componentNode); + } else { + QmlDesignerPlugin::instance()->viewManager().setComponentViewToMaster(); } } updateVisibility(); diff --git a/src/plugins/qmldesigner/components/integration/componentaction.cpp b/src/plugins/qmldesigner/components/integration/componentaction.cpp index 78667b67769448ea52565bce5b02e077b90e0879..194e3ebb08301a46e838a1e269f0a66a5988146c 100644 --- a/src/plugins/qmldesigner/components/integration/componentaction.cpp +++ b/src/plugins/qmldesigner/components/integration/componentaction.cpp @@ -68,9 +68,12 @@ void ComponentAction::emitCurrentComponentChanged(int index) if (dontEmitCurrentComponentChanged) return; - ModelNode componentNode = m_componentView->modelNode(index); + ModelNode componentModelNode = m_componentView->modelNode(index); - emit currentComponentChanged(componentNode); + if (componentModelNode.isRootNode()) + emit changedToMaster(); + else + emit currentComponentChanged(componentModelNode); } } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/integration/componentaction.h b/src/plugins/qmldesigner/components/integration/componentaction.h index d421d2f5dae424fed94c393995755472ec5cefcd..875ddacc14141049f679a8aeaf94026a12059c34 100644 --- a/src/plugins/qmldesigner/components/integration/componentaction.h +++ b/src/plugins/qmldesigner/components/integration/componentaction.h @@ -56,6 +56,7 @@ protected: signals: void currentComponentChanged(const ModelNode &node); + void changedToMaster(); void currentIndexChanged(int index); public slots: diff --git a/src/plugins/qmldesigner/components/integration/componentview.cpp b/src/plugins/qmldesigner/components/integration/componentview.cpp index 80c0489a647fb01539eb5bd827758dc32e83ad7b..082b3e220b9dde3a75acfaf8cc3878c173ccb207 100644 --- a/src/plugins/qmldesigner/components/integration/componentview.cpp +++ b/src/plugins/qmldesigner/components/integration/componentview.cpp @@ -71,6 +71,11 @@ void ComponentView::setComponentNode(const ModelNode &node) m_componentAction->setCurrentIndex(indexForNode(node)); } +void ComponentView::setComponentToMaster() +{ + m_componentAction->setCurrentIndex(indexOfMaster()); +} + void ComponentView::removeSingleNodeFromList(const ModelNode &node) { for (int row = 0; row < m_standardItemModel->rowCount(); row++) { @@ -89,6 +94,24 @@ int ComponentView::indexForNode(const ModelNode &node) return -1; } +int ComponentView::indexOfMaster() +{ + for (int row = 0; row < m_standardItemModel->rowCount(); row++) { + if (m_standardItemModel->item(row)->data(ModelNodeRole).toInt() == 0) + return row; + } + + return -1; +} + +void ComponentView::addMasterDocument() +{ + QStandardItem *item = new QStandardItem("master"); + item->setData(QVariant::fromValue(0), ModelNodeRole); + item->setEditable(false); + m_standardItemModel->appendRow(item); +} + void ComponentView::modelAttached(Model *model) { if (AbstractView::model() == model) @@ -129,8 +152,15 @@ void ComponentView::searchForComponentAndAddToList(const ModelNode &node) nodeList.append(node.allSubModelNodes()); + bool masterNotAdded = true; + foreach (const ModelNode &node, nodeList) { if (node.nodeSourceType() == ModelNode::NodeWithComponentSource) { + if (masterNotAdded) { + masterNotAdded = true; + addMasterDocument(); + } + if (!node.id().isEmpty()) { QStandardItem *item = new QStandardItem(node.id()); item->setData(QVariant::fromValue(node.internalId()), ModelNodeRole); diff --git a/src/plugins/qmldesigner/components/integration/componentview.h b/src/plugins/qmldesigner/components/integration/componentview.h index 3c5f3ab74b203f2acb250a3a9408b2f4c9f059a5..43842dcab0362eb48a34936e3a901059d20154a6 100644 --- a/src/plugins/qmldesigner/components/integration/componentview.h +++ b/src/plugins/qmldesigner/components/integration/componentview.h @@ -116,6 +116,7 @@ public: ModelNode modelNode(int index) const; void setComponentNode(const ModelNode &node); + void setComponentToMaster(); signals: void componentListChanged(const QStringList &componentList); @@ -126,6 +127,8 @@ private: //functions void searchForComponentAndRemoveFromList(const ModelNode &node); void removeSingleNodeFromList(const ModelNode &node); int indexForNode(const ModelNode &node); + int indexOfMaster(); + void addMasterDocument(); private: QStandardItemModel *m_standardItemModel; diff --git a/src/plugins/qmldesigner/components/integration/designdocument.cpp b/src/plugins/qmldesigner/components/integration/designdocument.cpp index 510022e76b2d90989383347a95f0d819f1313447..6855346372e6b5869df1018e2a7a701c6033dee4 100644 --- a/src/plugins/qmldesigner/components/integration/designdocument.cpp +++ b/src/plugins/qmldesigner/components/integration/designdocument.cpp @@ -264,6 +264,7 @@ void DesignDocument::changeToDocumentModel() viewManager().detachRewriterView(); viewManager().detachViewsExceptRewriterAndComponetView(); + m_inFileComponentModel.reset(); viewManager().attachRewriterView(); @@ -297,6 +298,19 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode) attachRewriterToModel(); QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrumbleBar(componentNode); + QmlDesignerPlugin::instance()->viewManager().setComponentNode(componentNode); +} + +void DesignDocument::changeToMaster() +{ + if (QmlDesignerPlugin::instance()->currentDesignDocument() != this) + return; + + if (m_inFileComponentModel) + changeToDocumentModel(); + + QmlDesignerPlugin::instance()->viewManager().pushFileOnCrumbleBar(fileName()); + QmlDesignerPlugin::instance()->viewManager().setComponentNode(rootModelNode()); } void DesignDocument::attachRewriterToModel() diff --git a/src/plugins/qmldesigner/components/integration/designdocument.h b/src/plugins/qmldesigner/components/integration/designdocument.h index e4178b03282259c1a5c8924e86b5c715652a6099..36261b99f4e668ea89f7d10dd0f8de5e7508d28d 100644 --- a/src/plugins/qmldesigner/components/integration/designdocument.h +++ b/src/plugins/qmldesigner/components/integration/designdocument.h @@ -118,6 +118,7 @@ public slots: void redo(); void updateActiveQtVersion(); void changeToSubComponent(const ModelNode &componentNode); + void changeToMaster(); private slots: void updateFileName(const QString &oldFileName, const QString &newFileName); diff --git a/src/plugins/qmldesigner/designercore/include/viewmanager.h b/src/plugins/qmldesigner/designercore/include/viewmanager.h index fb2e7b71c0da21f164da186daf99655726a32d99..97d7367c5c4362066b66f31f298cf40039eafac6 100644 --- a/src/plugins/qmldesigner/designercore/include/viewmanager.h +++ b/src/plugins/qmldesigner/designercore/include/viewmanager.h @@ -70,6 +70,7 @@ public: void setItemLibraryViewResourcePath(const QString &resourcePath); void setComponentNode(const ModelNode &componentNode); + void setComponentViewToMaster(); void setNodeInstanceViewQtPath(const QString & qtPath); void resetPropertyEditorView(); diff --git a/src/plugins/qmldesigner/designercore/model/viewmanager.cpp b/src/plugins/qmldesigner/designercore/model/viewmanager.cpp index 6ed7323f2c133abac78c89cf1407a8e333275d09..2dd3c68ce02901c953b505a9b2c7ae8b6b6a3581 100644 --- a/src/plugins/qmldesigner/designercore/model/viewmanager.cpp +++ b/src/plugins/qmldesigner/designercore/model/viewmanager.cpp @@ -132,11 +132,14 @@ void ViewManager::attachComponentView() { documentModel()->attachView(&m_componentView); QObject::connect(m_componentView.action(), SIGNAL(currentComponentChanged(ModelNode)), currentDesignDocument(), SLOT(changeToSubComponent(ModelNode))); + QObject::connect(m_componentView.action(), SIGNAL(changedToMaster()), currentDesignDocument(), SLOT(changeToMaster())); } void ViewManager::detachComponentView() { QObject::disconnect(m_componentView.action(), SIGNAL(currentComponentChanged(ModelNode)), currentDesignDocument(), SLOT(changeToSubComponent(ModelNode))); + QObject::disconnect(m_componentView.action(), SIGNAL(changedToMaster()), currentDesignDocument(), SLOT(changeToMaster())); + documentModel()->detachView(&m_componentView); } @@ -166,6 +169,11 @@ void ViewManager::setComponentNode(const ModelNode &componentNode) m_componentView.setComponentNode(componentNode); } +void ViewManager::setComponentViewToMaster() +{ + m_componentView.setComponentToMaster(); +} + void ViewManager::setNodeInstanceViewQtPath(const QString &qtPath) { m_nodeInstanceView.setPathToQt(qtPath); diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index d9e93b302934848beff8e33962817e588ba15bbe..0c7f9b33ced66e57cc9857d93bb1b774f2d82471 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -233,6 +233,7 @@ void QmlDesignerPlugin::changeEditor() if (m_documentManager.hasCurrentDesignDocument()) { activateAutoSynchronization(); m_viewManager.pushFileOnCrumbleBar(m_documentManager.currentDesignDocument()->fileName()); + m_viewManager.setComponentViewToMaster(); } m_shortCutManager.updateUndoActions(currentDesignDocument());