Commit 9c70e877 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlJSEditor: using RefactorMarker for Qt Quick ToolBar

* Proper implementation using a timer

* We also do a revision check now

* The RefactorMarker is only shown for types that we support
parent bb64cc70
......@@ -60,6 +60,7 @@
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/refactoroverlay.h>
#include <qmldesigner/qmldesignerconstants.h>
#include <utils/changeset.h>
#include <utils/uncommentselection.h>
......@@ -702,6 +703,11 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
m_updateOutlineIndexTimer->setSingleShot(true);
connect(m_updateOutlineIndexTimer, SIGNAL(timeout()), this, SLOT(updateOutlineIndexNow()));
m_curserPositionTimer = new QTimer(this);
m_curserPositionTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
m_curserPositionTimer->setSingleShot(true);
connect(m_curserPositionTimer, SIGNAL(timeout()), this, SLOT(updateCursorPositionNow()));
baseTextDocument()->setSyntaxHighlighter(new Highlighter(document()));
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<ModelManagerInterface>();
......@@ -720,6 +726,9 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
connect(m_semanticHighlighter, SIGNAL(changed(QmlJSEditor::Internal::SemanticInfo)),
this, SLOT(updateSemanticInfo(QmlJSEditor::Internal::SemanticInfo)));
connect(this, SIGNAL(refactorMarkerClicked(TextEditor::Internal::RefactorMarker)),
SLOT(onRefactorMarkerClicked(TextEditor::Internal::RefactorMarker)));
setRequestMarkEnabled(true);
}
......@@ -931,6 +940,46 @@ void QmlJSTextEditor::updateOutlineIndexNow()
updateUses();
}
static UiQualifiedId *qualifiedTypeNameId(UiObjectMember *m)
{
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(m))
return def->qualifiedTypeNameId;
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(m))
return binding->qualifiedTypeNameId;
return 0;
}
void QmlJSTextEditor::updateCursorPositionNow()
{
if (m_contextPane && document() && !semanticInfo().document.isNull() &&
document()->revision() == semanticInfo().document->editorRevision()) {
Node *oldNode = m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition);
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
if (oldNode != newNode &&
m_contextPane->isAvailable(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, newNode)) {
QList<TextEditor::Internal::RefactorMarker> markers;
if (UiObjectMember *m = newNode->uiObjectMemberCast()) {
const int start = m->firstSourceLocation().begin();
for (UiQualifiedId *q = qualifiedTypeNameId(m); q; q = q->next) {
if (! q->next) {
const int end = q->identifierToken.end();
TextEditor::Internal::RefactorMarker marker;
QTextCursor tc(document());
tc.setPosition(end);
marker.cursor = tc;
marker.tooltip = tr("Show Qt Quick Helper");
markers.append(marker);
}
}
}
setRefactorMarkers(markers);
}
if (oldNode != newNode)
m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, newNode, false);
m_oldCursorPosition = position();
}
}
void QmlJSTextEditor::updateUses()
{
m_updateUsesTimer->start();
......@@ -1661,15 +1710,14 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
setExtraSelections(CodeWarningsSelection, selections);
}
void QmlJSTextEditor::onRefactorMarkerClicked(const TextEditor::Internal::RefactorMarker &)
{
showContextPane();
}
void QmlJSTextEditor::onCursorPositionChanged()
{
if (m_contextPane) {
Node *newNode = m_semanticInfo.declaringMemberNoProperties(position());
Node *oldNode = m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition);
if (oldNode != newNode)
m_contextPane->apply(editableInterface(), m_semanticInfo.document, m_semanticInfo.snapshot, newNode, false);
m_oldCursorPosition = position();
}
m_curserPositionTimer->start();
}
QModelIndex QmlJSTextEditor::indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex) const
......
......@@ -243,6 +243,7 @@ private slots:
void jumpToOutlineElement(int index);
void updateOutlineNow();
void updateOutlineIndexNow();
void updateCursorPositionNow();
void updateFileName();
void updateUses();
......@@ -255,6 +256,7 @@ private slots:
void forceSemanticRehighlight();
void updateSemanticInfo(const QmlJSEditor::Internal::SemanticInfo &semanticInfo);
void onCursorPositionChanged();
void onRefactorMarkerClicked(const TextEditor::Internal::RefactorMarker &marker);
protected:
void contextMenuEvent(QContextMenuEvent *e);
......@@ -292,6 +294,7 @@ private:
QTimer *m_semanticRehighlightTimer;
QTimer *m_updateOutlineTimer;
QTimer *m_updateOutlineIndexTimer;
QTimer *m_curserPositionTimer;
QComboBox *m_outlineCombo;
QmlOutlineModel *m_outlineModel;
QModelIndex m_outlineModelIndex;
......
......@@ -359,7 +359,7 @@ public:
void setRefactorMarkers(const Internal::RefactorMarkers &markers);
signals:
void refactorMarkerClicked(const Internal::RefactorMarker &marker);
void refactorMarkerClicked(const TextEditor::Internal::RefactorMarker &marker);
public:
......
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