Commit 635ca2a5 authored by Nicolas Arnaud-Cormos's avatar Nicolas Arnaud-Cormos Committed by Christian Kamm
Browse files

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: default avatarChristian Kamm <christian.d.kamm@nokia.com>
parent d136b011
......@@ -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);
}
......@@ -216,6 +216,7 @@ protected:
TextEditor::BaseTextEditor *createEditor();
void createToolBar(QmlJSEditorEditable *editable);
TextEditor::BaseTextEditorWidget::Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true);
QString foldReplacementText(const QTextBlock &block) const;
private:
bool isClosingBrace(const QList<QmlJS::Token> &tokens) const;
......
......@@ -2657,9 +2657,12 @@ QTextBlock BaseTextEditorWidget::foldedBlockAt(const QPoint &pos, QRect *box) co
QRectF lineRect = line.naturalTextRect().translated(offset.x(), top);
lineRect.adjust(0, 0, -1, -1);
QString replacement = QLatin1String(" {") + foldReplacementText(block)
+ QLatin1String("}; ");
QRectF collapseRect(lineRect.right() + 12,
lineRect.top(),
fontMetrics().width(QLatin1String(" {...}; ")),
fontMetrics().width(replacement),
lineRect.height());
if (collapseRect.contains(pos)) {
QTextBlock result = block;
......@@ -3453,9 +3456,12 @@ void BaseTextEditorWidget::paintEvent(QPaintEvent *e)
QRectF lineRect = line.naturalTextRect().translated(offset.x(), top);
lineRect.adjust(0, 0, -1, -1);
QString replacement = foldReplacementText(block);
QString rectReplacement = QLatin1String(" {") + replacement + QLatin1String("}; ");
QRectF collapseRect(lineRect.right() + 12,
lineRect.top(),
fontMetrics().width(QLatin1String(" {...}; ")),
fontMetrics().width(rectReplacement),
lineRect.height());
painter.setRenderHint(QPainter::Antialiasing, true);
painter.translate(.5, .5);
......@@ -3463,8 +3469,6 @@ void BaseTextEditorWidget::paintEvent(QPaintEvent *e)
painter.setRenderHint(QPainter::Antialiasing, false);
painter.translate(-.5, -.5);
QString replacement = QLatin1String("...");
if (TextBlockUserData *nextBlockUserData = BaseTextDocumentLayout::testUserData(nextBlock)) {
if (nextBlockUserData->foldingStartIncluded())
replacement.prepend(nextBlock.text().trimmed().left(1));
......@@ -6341,3 +6345,8 @@ IAssistInterface *BaseTextEditorWidget::createAssistInterface(AssistKind kind,
Q_UNUSED(kind);
return new DefaultAssistInterface(document(), position(), d->m_document, reason);
}
QString TextEditor::BaseTextEditorWidget::foldReplacementText(const QTextBlock &) const
{
return QLatin1String("...");
}
......@@ -507,6 +507,11 @@ protected:
void maybeClearSomeExtraSelections(const QTextCursor &cursor);
/*!
Reimplement this function to change the default replacement text.
*/
virtual QString foldReplacementText(const QTextBlock &block) const;
protected slots:
virtual void slotUpdateExtraAreaWidth();
virtual void slotModificationChanged(bool);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment