Commit 676036a1 authored by Christian Kamm's avatar Christian Kamm

QmlJS: Allow for more markers than just Qt Quick Toolbar.

Change-Id: Id132b2fd42034a354baa548760083ca47d62697b
Reviewed-on: http://codereview.qt.nokia.com/2904Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
parent 6215df2b
......@@ -950,6 +950,20 @@ static UiQualifiedId *qualifiedTypeNameId(Node *m)
return 0;
}
class QtQuickToolbarMarker {};
Q_DECLARE_METATYPE(QtQuickToolbarMarker)
template <class T>
static QList<TextEditor::RefactorMarker> removeMarkersOfType(const QList<TextEditor::RefactorMarker> &markers)
{
QList<TextEditor::RefactorMarker> result;
foreach (const TextEditor::RefactorMarker &marker, markers) {
if (!marker.data.canConvert<T>())
result += marker;
}
return result;
}
void QmlJSTextEditorWidget::updateCursorPositionNow()
{
if (m_contextPane && document() && semanticInfo().isValid()
......@@ -959,9 +973,10 @@ void QmlJSTextEditorWidget::updateCursorPositionNow()
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
if (oldNode != newNode && m_oldCursorPosition != -1)
m_contextPane->apply(editor(), semanticInfo().document, 0, newNode, false);
if (m_contextPane->isAvailable(editor(), semanticInfo().document, newNode) &&
!m_contextPane->widget()->isVisible()) {
QList<TextEditor::RefactorMarker> markers;
QList<TextEditor::RefactorMarker> markers = removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers());
if (UiObjectMember *m = newNode->uiObjectMemberCast()) {
const int start = qualifiedTypeNameId(m)->identifierToken.begin();
for (UiQualifiedId *q = qualifiedTypeNameId(m); q; q = q->next) {
......@@ -973,18 +988,15 @@ void QmlJSTextEditorWidget::updateCursorPositionNow()
tc.setPosition(end);
marker.cursor = tc;
marker.tooltip = tr("Show Qt Quick ToolBar");
marker.data = QVariant::fromValue(QtQuickToolbarMarker());
markers.append(marker);
} else {
QList<TextEditor::RefactorMarker> markers;
setRefactorMarkers(markers);
}
}
}
}
setRefactorMarkers(markers);
} else if (oldNode != newNode) {
QList<TextEditor::RefactorMarker> markers;
setRefactorMarkers(markers);
setRefactorMarkers(removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers()));
}
m_oldCursorPosition = position();
......@@ -1373,8 +1385,7 @@ void QmlJSTextEditorWidget::showContextPane()
&scopeChain,
newNode, false, true);
m_oldCursorPosition = position();
QList<TextEditor::RefactorMarker> markers;
setRefactorMarkers(markers);
setRefactorMarkers(removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers()));
}
}
......@@ -1553,8 +1564,9 @@ void QmlJSTextEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo)
setExtraSelections(CodeWarningsSelection, selections);
}
void QmlJSTextEditorWidget::onRefactorMarkerClicked(const TextEditor::RefactorMarker &)
void QmlJSTextEditorWidget::onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker)
{
if (marker.data.canConvert<QtQuickToolbarMarker>())
showContextPane();
}
......
......@@ -6020,6 +6020,10 @@ QString BaseTextEditor::contextHelpId() const
return m_contextHelpId;
}
Internal::RefactorMarkers BaseTextEditorWidget::refactorMarkers() const
{
return d->m_refactorOverlay->markers();
}
void BaseTextEditorWidget::setRefactorMarkers(const Internal::RefactorMarkers &markers)
{
......
......@@ -405,7 +405,7 @@ public:
QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const;
QString extraSelectionTooltip(int pos) const;
Internal::RefactorMarkers refactorMarkers() const;
void setRefactorMarkers(const Internal::RefactorMarkers &markers);
signals:
void refactorMarkerClicked(const TextEditor::RefactorMarker &marker);
......
Markdown is supported
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