forked from qt-creator/qt-creator
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
This commit is contained in:
@@ -60,6 +60,7 @@
|
|||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <texteditor/syntaxhighlighter.h>
|
#include <texteditor/syntaxhighlighter.h>
|
||||||
|
#include <texteditor/refactoroverlay.h>
|
||||||
#include <qmldesigner/qmldesignerconstants.h>
|
#include <qmldesigner/qmldesignerconstants.h>
|
||||||
#include <utils/changeset.h>
|
#include <utils/changeset.h>
|
||||||
#include <utils/uncommentselection.h>
|
#include <utils/uncommentselection.h>
|
||||||
@@ -702,6 +703,11 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
|
|||||||
m_updateOutlineIndexTimer->setSingleShot(true);
|
m_updateOutlineIndexTimer->setSingleShot(true);
|
||||||
connect(m_updateOutlineIndexTimer, SIGNAL(timeout()), this, SLOT(updateOutlineIndexNow()));
|
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()));
|
baseTextDocument()->setSyntaxHighlighter(new Highlighter(document()));
|
||||||
|
|
||||||
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<ModelManagerInterface>();
|
m_modelManager = ExtensionSystem::PluginManager::instance()->getObject<ModelManagerInterface>();
|
||||||
@@ -720,6 +726,9 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
|
|||||||
connect(m_semanticHighlighter, SIGNAL(changed(QmlJSEditor::Internal::SemanticInfo)),
|
connect(m_semanticHighlighter, SIGNAL(changed(QmlJSEditor::Internal::SemanticInfo)),
|
||||||
this, SLOT(updateSemanticInfo(QmlJSEditor::Internal::SemanticInfo)));
|
this, SLOT(updateSemanticInfo(QmlJSEditor::Internal::SemanticInfo)));
|
||||||
|
|
||||||
|
connect(this, SIGNAL(refactorMarkerClicked(TextEditor::Internal::RefactorMarker)),
|
||||||
|
SLOT(onRefactorMarkerClicked(TextEditor::Internal::RefactorMarker)));
|
||||||
|
|
||||||
setRequestMarkEnabled(true);
|
setRequestMarkEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -931,6 +940,46 @@ void QmlJSTextEditor::updateOutlineIndexNow()
|
|||||||
updateUses();
|
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()
|
void QmlJSTextEditor::updateUses()
|
||||||
{
|
{
|
||||||
m_updateUsesTimer->start();
|
m_updateUsesTimer->start();
|
||||||
@@ -1661,15 +1710,14 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
|
|||||||
setExtraSelections(CodeWarningsSelection, selections);
|
setExtraSelections(CodeWarningsSelection, selections);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlJSTextEditor::onRefactorMarkerClicked(const TextEditor::Internal::RefactorMarker &)
|
||||||
|
{
|
||||||
|
showContextPane();
|
||||||
|
}
|
||||||
|
|
||||||
void QmlJSTextEditor::onCursorPositionChanged()
|
void QmlJSTextEditor::onCursorPositionChanged()
|
||||||
{
|
{
|
||||||
if (m_contextPane) {
|
m_curserPositionTimer->start();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex QmlJSTextEditor::indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex) const
|
QModelIndex QmlJSTextEditor::indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex) const
|
||||||
|
|||||||
@@ -243,6 +243,7 @@ private slots:
|
|||||||
void jumpToOutlineElement(int index);
|
void jumpToOutlineElement(int index);
|
||||||
void updateOutlineNow();
|
void updateOutlineNow();
|
||||||
void updateOutlineIndexNow();
|
void updateOutlineIndexNow();
|
||||||
|
void updateCursorPositionNow();
|
||||||
void updateFileName();
|
void updateFileName();
|
||||||
|
|
||||||
void updateUses();
|
void updateUses();
|
||||||
@@ -255,6 +256,7 @@ private slots:
|
|||||||
void forceSemanticRehighlight();
|
void forceSemanticRehighlight();
|
||||||
void updateSemanticInfo(const QmlJSEditor::Internal::SemanticInfo &semanticInfo);
|
void updateSemanticInfo(const QmlJSEditor::Internal::SemanticInfo &semanticInfo);
|
||||||
void onCursorPositionChanged();
|
void onCursorPositionChanged();
|
||||||
|
void onRefactorMarkerClicked(const TextEditor::Internal::RefactorMarker &marker);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent *e);
|
void contextMenuEvent(QContextMenuEvent *e);
|
||||||
@@ -292,6 +294,7 @@ private:
|
|||||||
QTimer *m_semanticRehighlightTimer;
|
QTimer *m_semanticRehighlightTimer;
|
||||||
QTimer *m_updateOutlineTimer;
|
QTimer *m_updateOutlineTimer;
|
||||||
QTimer *m_updateOutlineIndexTimer;
|
QTimer *m_updateOutlineIndexTimer;
|
||||||
|
QTimer *m_curserPositionTimer;
|
||||||
QComboBox *m_outlineCombo;
|
QComboBox *m_outlineCombo;
|
||||||
QmlOutlineModel *m_outlineModel;
|
QmlOutlineModel *m_outlineModel;
|
||||||
QModelIndex m_outlineModelIndex;
|
QModelIndex m_outlineModelIndex;
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ public:
|
|||||||
|
|
||||||
void setRefactorMarkers(const Internal::RefactorMarkers &markers);
|
void setRefactorMarkers(const Internal::RefactorMarkers &markers);
|
||||||
signals:
|
signals:
|
||||||
void refactorMarkerClicked(const Internal::RefactorMarker &marker);
|
void refactorMarkerClicked(const TextEditor::Internal::RefactorMarker &marker);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user