QmlEditor: show the id name when folding a block.

If the id of an element exists, it will be displayed instead of the normal "..."

Change-Id: I4e6633743b0e2ae014b7fbad3c752ef318c73659
Reviewed-by: Christian Kamm <christian.d.kamm@nokia.com>
This commit is contained in:
Nicolas Arnaud-Cormos
2011-09-14 22:16:28 +02:00
committed by Christian Kamm
parent d136b011e1
commit 635ca2a51a
4 changed files with 47 additions and 4 deletions

View File

@@ -1692,3 +1692,31 @@ TextEditor::IAssistInterface *QmlJSTextEditorWidget::createAssistInterface(
}
return 0;
}
QString QmlJSTextEditorWidget::foldReplacementText(const QTextBlock &block) const
{
int curlyIndex = block.text().indexOf(QLatin1Char('{'));
if ((curlyIndex == -1) || !m_semanticInfo.isValid())
return TextEditor::BaseTextEditorWidget::foldReplacementText(block);
int pos = block.position() + curlyIndex;
Node *node = m_semanticInfo.rangeAt(pos);
if (node) {
UiObjectInitializer *objectInitializer = 0;
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(node))
objectInitializer = def->initializer;
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(node))
objectInitializer = binding->initializer;
// Get the id value, if it exists, and display it
if (objectInitializer) {
QString objectId = idOfObject(objectInitializer);
if (!objectId.isEmpty())
return QLatin1String("id: ") + objectId + QLatin1String("...");
}
}
return TextEditor::BaseTextEditorWidget::foldReplacementText(block);
}