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