forked from qt-creator/qt-creator
QmlDesigner: Fix crumble bar
Change-Id: I8eefba1b5b9839b28be5dbae379366714f40ed27 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
@@ -49,8 +49,15 @@ FormEditorCrumbleBar::FormEditorCrumbleBar(QObject *parent) :
|
||||
|
||||
void FormEditorCrumbleBar::pushFile(const QString &fileName)
|
||||
{
|
||||
if (m_isInternalCalled == false)
|
||||
if (m_isInternalCalled == false) {
|
||||
crumblePath()->clear();
|
||||
} else {
|
||||
CrumbleBarInfo lastElementCrumbleBarInfo = crumblePath()->dataForLastIndex().value<CrumbleBarInfo>();
|
||||
|
||||
if (!lastElementCrumbleBarInfo.componentId.isEmpty()
|
||||
&& lastElementCrumbleBarInfo.fileName == fileName)
|
||||
crumblePath()->popElement();
|
||||
}
|
||||
|
||||
CrumbleBarInfo crumbleBarInfo;
|
||||
crumbleBarInfo.fileName = fileName;
|
||||
@@ -77,6 +84,8 @@ void FormEditorCrumbleBar::pushInFileComponent(const QString &componentId)
|
||||
crumblePath()->popElement();
|
||||
|
||||
crumblePath()->pushElement(componentId, QVariant::fromValue(crumbleBarInfo));
|
||||
|
||||
m_isInternalCalled = false;
|
||||
}
|
||||
|
||||
void FormEditorCrumbleBar::nextFileIsCalledInternally()
|
||||
@@ -91,23 +100,33 @@ Utils::CrumblePath *FormEditorCrumbleBar::crumblePath()
|
||||
|
||||
void FormEditorCrumbleBar::onCrumblePathElementClicked(const QVariant &data)
|
||||
{
|
||||
CrumbleBarInfo crumbleBarInfo = data.value<CrumbleBarInfo>();
|
||||
CrumbleBarInfo clickedCrumbleBarInfo = data.value<CrumbleBarInfo>();
|
||||
|
||||
if (crumbleBarInfo == crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
|
||||
if (clickedCrumbleBarInfo == crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
|
||||
return;
|
||||
|
||||
while (crumbleBarInfo != crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
|
||||
while (clickedCrumbleBarInfo != crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
|
||||
crumblePath()->popElement();
|
||||
|
||||
if (!crumbleBarInfo.componentId.isEmpty())
|
||||
if (!crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().componentId.isEmpty())
|
||||
crumblePath()->popElement();
|
||||
|
||||
crumblePath()->popElement();
|
||||
|
||||
m_isInternalCalled = true;
|
||||
Core::EditorManager::openEditor(crumbleBarInfo.fileName);
|
||||
if (!crumbleBarInfo.componentId.isEmpty())
|
||||
currentDesignDocument()->changeToSubComponent(currentDesignDocument()->rewriterView()->modelNodeForId(crumbleBarInfo.componentId));
|
||||
if (clickedCrumbleBarInfo.componentId.isEmpty()
|
||||
&& clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) {
|
||||
nextFileIsCalledInternally();
|
||||
currentDesignDocument()->changeToDocumentModel();
|
||||
} else {
|
||||
crumblePath()->popElement();
|
||||
nextFileIsCalledInternally();
|
||||
Core::EditorManager::openEditor(clickedCrumbleBarInfo.fileName);
|
||||
if (!clickedCrumbleBarInfo.componentId.isEmpty()) {
|
||||
currentDesignDocument()->changeToSubComponent(
|
||||
currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId));
|
||||
pushInFileComponent(clickedCrumbleBarInfo.componentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool operator ==(const CrumbleBarInfo &first, const CrumbleBarInfo &second)
|
||||
|
||||
@@ -39,13 +39,16 @@ namespace QmlDesigner {
|
||||
|
||||
ComponentAction::ComponentAction(ComponentView *componentView)
|
||||
: QWidgetAction(componentView),
|
||||
m_componentView(componentView)
|
||||
m_componentView(componentView),
|
||||
dontEmitCurrentComponentChanged(false)
|
||||
{
|
||||
}
|
||||
|
||||
void ComponentAction::setCurrentIndex(int index)
|
||||
{
|
||||
dontEmitCurrentComponentChanged = true;
|
||||
emit currentIndexChanged(index);
|
||||
dontEmitCurrentComponentChanged = false;
|
||||
}
|
||||
|
||||
QWidget *ComponentAction::createWidget(QWidget *parent)
|
||||
@@ -54,25 +57,19 @@ QWidget *ComponentAction::createWidget(QWidget *parent)
|
||||
comboBox->setMinimumWidth(120);
|
||||
comboBox->setToolTip(tr("Edit sub components defined in this file"));
|
||||
comboBox->setModel(m_componentView->standardItemModel());
|
||||
connect(comboBox, SIGNAL(currentIndexChanged(int)), SLOT(emitCurrentComponentChanged(int)));
|
||||
comboBox->setCurrentIndex(-1);
|
||||
connect(comboBox, SIGNAL(activated(int)), SLOT(emitCurrentComponentChanged(int)));
|
||||
connect(this, SIGNAL(currentIndexChanged(int)), comboBox, SLOT(setCurrentIndex(int)));
|
||||
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
static const QString fileNameOfCurrentDocument()
|
||||
{
|
||||
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()->textEditor()->document()->fileName();
|
||||
}
|
||||
|
||||
void ComponentAction::emitCurrentComponentChanged(int index)
|
||||
{
|
||||
ModelNode componentNode = m_componentView->modelNode(index);
|
||||
if (dontEmitCurrentComponentChanged)
|
||||
return;
|
||||
|
||||
if ( index > 0)
|
||||
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrambleBar(componentNode.id());
|
||||
else
|
||||
QmlDesignerPlugin::instance()->viewManager().pushFileOnCrambleBar(fileNameOfCurrentDocument());
|
||||
ModelNode componentNode = m_componentView->modelNode(index);
|
||||
|
||||
emit currentComponentChanged(componentNode);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ public slots:
|
||||
|
||||
private:
|
||||
QWeakPointer<ComponentView> m_componentView;
|
||||
bool dontEmitCurrentComponentChanged;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -78,14 +78,6 @@ QWidget *ComponentView::widget()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ComponentView::appendWholeDocumentAsComponent()
|
||||
{
|
||||
QStandardItem *item = new QStandardItem(tr("whole document"));
|
||||
item->setData(QVariant::fromValue(rootModelNode()), ModelNodeRole);
|
||||
item->setEditable(false);
|
||||
m_standardItemModel->appendRow(item);
|
||||
}
|
||||
|
||||
void ComponentView::removeSingleNodeFromList(const ModelNode &node)
|
||||
{
|
||||
for (int row = 0; row < m_standardItemModel->rowCount(); row++) {
|
||||
@@ -114,7 +106,6 @@ void ComponentView::modelAttached(Model *model)
|
||||
|
||||
AbstractView::modelAttached(model);
|
||||
|
||||
appendWholeDocumentAsComponent();
|
||||
searchForComponentAndAddToList(rootModelNode());
|
||||
|
||||
m_componentAction->blockSignals(block);
|
||||
|
||||
@@ -116,7 +116,6 @@ private: //functions
|
||||
void updateModel();
|
||||
void searchForComponentAndAddToList(const ModelNode &node);
|
||||
void searchForComponentAndRemoveFromList(const ModelNode &node);
|
||||
void appendWholeDocumentAsComponent();
|
||||
void removeSingleNodeFromList(const ModelNode &node);
|
||||
int indexForNode(const ModelNode &node);
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ QList<RewriterView::Error> DesignDocument::qmlSyntaxErrors() const
|
||||
|
||||
bool DesignDocument::hasQmlSyntaxErrors() const
|
||||
{
|
||||
return !m_currentModel->rewriterView()->errors().isEmpty();
|
||||
return m_currentModel->rewriterView() && !m_currentModel->rewriterView()->errors().isEmpty();
|
||||
}
|
||||
|
||||
QString DesignDocument::displayName() const
|
||||
@@ -314,26 +314,18 @@ void DesignDocument::loadDocument(QPlainTextEdit *edit)
|
||||
m_documentLoaded = true;
|
||||
}
|
||||
|
||||
static const QString fileNameOfCurrentDocument()
|
||||
{
|
||||
return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()->textEditor()->document()->fileName();
|
||||
}
|
||||
|
||||
void DesignDocument::changeCurrentModelTo(const ModelNode &node)
|
||||
{
|
||||
if (QmlDesignerPlugin::instance()->currentDesignDocument() != this)
|
||||
return;
|
||||
|
||||
if (rootModelNode() == node) {
|
||||
changeToDocumentModel();
|
||||
} else {
|
||||
changeToSubComponent(node);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// s_clearCrumblePath = false;
|
||||
// while (m_formEditorView->crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().modelNode.isValid() &&
|
||||
// !m_formEditorView->crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().modelNode.isRootNode())
|
||||
// m_formEditorView->crumblePath()->popElement();
|
||||
// if (node.isRootNode() && m_formEditorView->crumblePath()->dataForLastIndex().isValid())
|
||||
// m_formEditorView->crumblePath()->popElement();
|
||||
// s_clearCrumblePath = true;
|
||||
changeToSubComponent(node);
|
||||
}
|
||||
|
||||
void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
||||
@@ -354,6 +346,8 @@ void DesignDocument::changeToSubComponent(const ModelNode &componentNode)
|
||||
|
||||
activateCurrentModel(m_inFileComponentTextModifier.data());
|
||||
}
|
||||
if (!componentNode.id().isEmpty())
|
||||
QmlDesignerPlugin::instance()->viewManager().pushInFileComponentOnCrambleBar(componentNode.id());
|
||||
}
|
||||
|
||||
void DesignDocument::changeToExternalSubComponent(const QString &fileName)
|
||||
|
||||
@@ -101,6 +101,8 @@ public:
|
||||
|
||||
void goIntoComponent();
|
||||
|
||||
void changeToDocumentModel();
|
||||
|
||||
signals:
|
||||
void displayNameChanged(const QString &newFileName);
|
||||
void dirtyStateChanged(bool newState);
|
||||
@@ -127,7 +129,6 @@ private slots:
|
||||
void updateFileName(const QString &oldFileName, const QString &newFileName);
|
||||
|
||||
private: // functions
|
||||
void changeToDocumentModel();
|
||||
void changeToInFileComponentModel();
|
||||
|
||||
QWidget *centralWidget() const;
|
||||
|
||||
@@ -242,8 +242,8 @@ void QmlDesignerPlugin::changeEditor()
|
||||
m_shortCutManager.connectUndoActions(currentDesignDocument());
|
||||
|
||||
if (m_documentManager.hasCurrentDesignDocument()) {
|
||||
m_viewManager.pushFileOnCrambleBar(m_documentManager.currentDesignDocument()->fileName());
|
||||
activateAutoSynchronization();
|
||||
m_viewManager.pushFileOnCrambleBar(m_documentManager.currentDesignDocument()->fileName());
|
||||
}
|
||||
|
||||
m_shortCutManager.updateUndoActions(currentDesignDocument());
|
||||
|
||||
Reference in New Issue
Block a user