forked from qt-creator/qt-creator
QmlJSEditor: Use EditorWidget instead of Editor in QuickToolBar
This reduces the use of the 'editor()' "back link" which we'd like to phase out (and also actually simplifies the user code). Change-Id: I8aa13e88459d4e9cf44de683e8efd189238cc684 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
#include <qmljs/qmljsdocument.h>
|
#include <qmljs/qmljsdocument.h>
|
||||||
#include <qmljs/parser/qmljsastfwd_p.h>
|
#include <qmljs/parser/qmljsastfwd_p.h>
|
||||||
|
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
namespace TextEditor { class BaseTextEditorWidget; }
|
||||||
|
|
||||||
namespace QmlJS {
|
namespace QmlJS {
|
||||||
|
|
||||||
@@ -50,9 +50,9 @@ class QMLJS_EXPORT IContextPane : public QObject
|
|||||||
public:
|
public:
|
||||||
IContextPane(QObject *parent = 0) : QObject(parent) {}
|
IContextPane(QObject *parent = 0) : QObject(parent) {}
|
||||||
virtual ~IContextPane() {}
|
virtual ~IContextPane() {}
|
||||||
virtual void apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force = false) = 0;
|
virtual void apply(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force = false) = 0;
|
||||||
virtual void setEnabled(bool) = 0;
|
virtual void setEnabled(bool) = 0;
|
||||||
virtual bool isAvailable(TextEditor::BaseTextEditor *editor, Document::Ptr document, AST::Node *node) = 0;
|
virtual bool isAvailable(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, AST::Node *node) = 0;
|
||||||
virtual QWidget* widget() = 0;
|
virtual QWidget* widget() = 0;
|
||||||
signals:
|
signals:
|
||||||
void closed();
|
void closed();
|
||||||
|
|||||||
@@ -306,9 +306,9 @@ void QmlJSEditorWidget::updateContextPane()
|
|||||||
Node *oldNode = info.declaringMemberNoProperties(m_oldCursorPosition);
|
Node *oldNode = info.declaringMemberNoProperties(m_oldCursorPosition);
|
||||||
Node *newNode = info.declaringMemberNoProperties(position());
|
Node *newNode = info.declaringMemberNoProperties(position());
|
||||||
if (oldNode != newNode && m_oldCursorPosition != -1)
|
if (oldNode != newNode && m_oldCursorPosition != -1)
|
||||||
m_contextPane->apply(editor(), info.document, 0, newNode, false);
|
m_contextPane->apply(this, info.document, 0, newNode, false);
|
||||||
|
|
||||||
if (m_contextPane->isAvailable(editor(), info.document, newNode) &&
|
if (m_contextPane->isAvailable(this, info.document, newNode) &&
|
||||||
!m_contextPane->widget()->isVisible()) {
|
!m_contextPane->widget()->isVisible()) {
|
||||||
QList<RefactorMarker> markers = removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers());
|
QList<RefactorMarker> markers = removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers());
|
||||||
if (UiObjectMember *m = newNode->uiObjectMemberCast()) {
|
if (UiObjectMember *m = newNode->uiObjectMemberCast()) {
|
||||||
@@ -663,7 +663,7 @@ void QmlJSEditorWidget::showContextPane()
|
|||||||
if (m_contextPane && info.isValid()) {
|
if (m_contextPane && info.isValid()) {
|
||||||
Node *newNode = info.declaringMemberNoProperties(position());
|
Node *newNode = info.declaringMemberNoProperties(position());
|
||||||
ScopeChain scopeChain = info.scopeChain(info.rangePath(position()));
|
ScopeChain scopeChain = info.scopeChain(info.rangePath(position()));
|
||||||
m_contextPane->apply(editor(), info.document,
|
m_contextPane->apply(this, info.document,
|
||||||
&scopeChain,
|
&scopeChain,
|
||||||
newNode, false, true);
|
newNode, false, true);
|
||||||
m_oldCursorPosition = position();
|
m_oldCursorPosition = position();
|
||||||
@@ -716,7 +716,7 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|||||||
menu->addMenu(refactoringMenu);
|
menu->addMenu(refactoringMenu);
|
||||||
if (action->objectName() == QLatin1String(Constants::SHOW_QT_QUICK_HELPER)) {
|
if (action->objectName() == QLatin1String(Constants::SHOW_QT_QUICK_HELPER)) {
|
||||||
bool enabled = m_contextPane->isAvailable(
|
bool enabled = m_contextPane->isAvailable(
|
||||||
editor(), m_qmlJsEditorDocument->semanticInfo().document,
|
this, m_qmlJsEditorDocument->semanticInfo().document,
|
||||||
m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(position()));
|
m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(position()));
|
||||||
action->setEnabled(enabled);
|
action->setEnabled(enabled);
|
||||||
}
|
}
|
||||||
@@ -760,7 +760,7 @@ void QmlJSEditorWidget::wheelEvent(QWheelEvent *event)
|
|||||||
BaseTextEditorWidget::wheelEvent(event);
|
BaseTextEditorWidget::wheelEvent(event);
|
||||||
|
|
||||||
if (visible)
|
if (visible)
|
||||||
m_contextPane->apply(editor(), m_qmlJsEditorDocument->semanticInfo().document, 0,
|
m_contextPane->apply(this, m_qmlJsEditorDocument->semanticInfo().document, 0,
|
||||||
m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(m_oldCursorPosition),
|
m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(m_oldCursorPosition),
|
||||||
false, true);
|
false, true);
|
||||||
}
|
}
|
||||||
@@ -792,7 +792,7 @@ void QmlJSEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo)
|
|||||||
if (m_contextPane) {
|
if (m_contextPane) {
|
||||||
Node *newNode = semanticInfo.declaringMemberNoProperties(position());
|
Node *newNode = semanticInfo.declaringMemberNoProperties(position());
|
||||||
if (newNode) {
|
if (newNode) {
|
||||||
m_contextPane->apply(editor(), semanticInfo.document, 0, newNode, true);
|
m_contextPane->apply(this, semanticInfo.document, 0, newNode, true);
|
||||||
m_contextPaneTimer.start(); //update text marker
|
m_contextPaneTimer.start(); //update text marker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -834,7 +834,7 @@ bool QmlJSEditorWidget::hideContextPane()
|
|||||||
{
|
{
|
||||||
bool b = (m_contextPane) && m_contextPane->widget()->isVisible();
|
bool b = (m_contextPane) && m_contextPane->widget()->isVisible();
|
||||||
if (b)
|
if (b)
|
||||||
m_contextPane->apply(editor(), m_qmlJsEditorDocument->semanticInfo().document, 0, 0, false);
|
m_contextPane->apply(this, m_qmlJsEditorDocument->semanticInfo().document, 0, 0, false);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -845,7 +845,7 @@ IAssistInterface *QmlJSEditorWidget::createAssistInterface(
|
|||||||
if (assistKind == TextEditor::Completion) {
|
if (assistKind == TextEditor::Completion) {
|
||||||
return new QmlJSCompletionAssistInterface(document(),
|
return new QmlJSCompletionAssistInterface(document(),
|
||||||
position(),
|
position(),
|
||||||
editor()->document()->filePath(),
|
textDocument()->filePath(),
|
||||||
reason,
|
reason,
|
||||||
m_qmlJsEditorDocument->semanticInfo());
|
m_qmlJsEditorDocument->semanticInfo());
|
||||||
} else if (assistKind == TextEditor::QuickFix) {
|
} else if (assistKind == TextEditor::QuickFix) {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ static inline const ObjectValue * getPropertyChangesTarget(Node *node, const Sco
|
|||||||
|
|
||||||
QuickToolBar::QuickToolBar(QObject *parent)
|
QuickToolBar::QuickToolBar(QObject *parent)
|
||||||
: ::QmlJS::IContextPane(parent)
|
: ::QmlJS::IContextPane(parent)
|
||||||
, m_editor(0)
|
, m_editorWidget(0)
|
||||||
, m_blockWriting(false)
|
, m_blockWriting(false)
|
||||||
{
|
{
|
||||||
m_node = 0;
|
m_node = 0;
|
||||||
@@ -115,7 +115,7 @@ QuickToolBar::~QuickToolBar()
|
|||||||
m_widget = 0;
|
m_widget = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force)
|
void QuickToolBar::apply(TextEditor::BaseTextEditorWidget *editorWidget, Document::Ptr document, const ScopeChain *scopeChain, AST::Node *node, bool update, bool force)
|
||||||
{
|
{
|
||||||
if (!QuickToolBarSettings::get().enableContextPane && !force && !update) {
|
if (!QuickToolBarSettings::get().enableContextPane && !force && !update) {
|
||||||
contextWidget()->hide();
|
contextWidget()->hide();
|
||||||
@@ -125,7 +125,7 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
|
|||||||
if (document.isNull())
|
if (document.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (update && editor != m_editor)
|
if (update && editorWidget != m_editorWidget)
|
||||||
return; //do not update for different editor
|
return; //do not update for different editor
|
||||||
|
|
||||||
m_blockWriting = true;
|
m_blockWriting = true;
|
||||||
@@ -155,9 +155,9 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
|
|||||||
}
|
}
|
||||||
|
|
||||||
setEnabled(document->isParsedCorrectly());
|
setEnabled(document->isParsedCorrectly());
|
||||||
m_editor = editor;
|
m_editorWidget = editorWidget;
|
||||||
contextWidget()->setParent(editor->widget()->parentWidget());
|
contextWidget()->setParent(editorWidget->parentWidget());
|
||||||
contextWidget()->colorDialog()->setParent(editor->widget()->parentWidget());
|
contextWidget()->colorDialog()->setParent(editorWidget->parentWidget());
|
||||||
|
|
||||||
if (cast<UiObjectDefinition*>(node) || cast<UiObjectBinding*>(node)) {
|
if (cast<UiObjectDefinition*>(node) || cast<UiObjectBinding*>(node)) {
|
||||||
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(node);
|
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(node);
|
||||||
@@ -192,12 +192,12 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
|
|||||||
int column1;
|
int column1;
|
||||||
int line2;
|
int line2;
|
||||||
int column2;
|
int column2;
|
||||||
m_editor->convertPosition(offset, &line1, &column1); //get line
|
m_editorWidget->convertPosition(offset, &line1, &column1); //get line
|
||||||
m_editor->convertPosition(end, &line2, &column2); //get line
|
m_editorWidget->convertPosition(end, &line2, &column2); //get line
|
||||||
|
|
||||||
QRegion reg;
|
QRegion reg;
|
||||||
if (line1 > -1 && line2 > -1)
|
if (line1 > -1 && line2 > -1)
|
||||||
reg = m_editor->editorWidget()->translatedLineRegion(line1 - 1, line2);
|
reg = m_editorWidget->translatedLineRegion(line1 - 1, line2);
|
||||||
|
|
||||||
QRect rect;
|
QRect rect;
|
||||||
rect.setHeight(widget()->height() + 10);
|
rect.setHeight(widget()->height() + 10);
|
||||||
@@ -208,16 +208,15 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
|
|||||||
if (contextWidget()->acceptsType(m_prototypes)) {
|
if (contextWidget()->acceptsType(m_prototypes)) {
|
||||||
m_node = 0;
|
m_node = 0;
|
||||||
PropertyReader propertyReader(document, initializer);
|
PropertyReader propertyReader(document, initializer);
|
||||||
QTextCursor tc = editor->textCursor();
|
QTextCursor tc = m_editorWidget->textCursor();
|
||||||
QPlainTextEdit *editorWidget = editor->editorWidget();
|
|
||||||
tc.setPosition(offset);
|
tc.setPosition(offset);
|
||||||
QPoint p1 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(editorWidget->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
|
QPoint p1 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(m_editorWidget->cursorRect(tc).topLeft()) - QPoint(0, contextWidget()->height() + 10));
|
||||||
tc.setPosition(end);
|
tc.setPosition(end);
|
||||||
QPoint p2 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(editorWidget->cursorRect(tc).bottomLeft()) + QPoint(0, 10));
|
QPoint p2 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(m_editorWidget->cursorRect(tc).bottomLeft()) + QPoint(0, 10));
|
||||||
QPoint offset = QPoint(10, 0);
|
QPoint offset = QPoint(10, 0);
|
||||||
if (reg.boundingRect().width() < 400)
|
if (reg.boundingRect().width() < 400)
|
||||||
offset = QPoint(400 - reg.boundingRect().width() + 10 ,0);
|
offset = QPoint(400 - reg.boundingRect().width() + 10 ,0);
|
||||||
QPoint p3 = editorWidget->mapToParent(editorWidget->viewport()->mapToParent(reg.boundingRect().topRight()) + offset);
|
QPoint p3 = m_editorWidget->mapToParent(m_editorWidget->viewport()->mapToParent(reg.boundingRect().topRight()) + offset);
|
||||||
p2.setX(p1.x());
|
p2.setX(p1.x());
|
||||||
contextWidget()->setIsPropertyChanges(isPropertyChanges);
|
contextWidget()->setIsPropertyChanges(isPropertyChanges);
|
||||||
if (!update)
|
if (!update)
|
||||||
@@ -246,7 +245,7 @@ void QuickToolBar::apply(TextEditor::BaseTextEditor *editor, Document::Ptr docum
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuickToolBar::isAvailable(TextEditor::BaseTextEditor *, Document::Ptr document, AST::Node *node)
|
bool QuickToolBar::isAvailable(TextEditor::BaseTextEditorWidget *, Document::Ptr document, AST::Node *node)
|
||||||
{
|
{
|
||||||
if (document.isNull())
|
if (document.isNull())
|
||||||
return false;
|
return false;
|
||||||
@@ -319,12 +318,12 @@ void QuickToolBar::setProperty(const QString &propertyName, const QVariant &valu
|
|||||||
|
|
||||||
int changeSetPos = changeSet.operationList().last().pos1;
|
int changeSetPos = changeSet.operationList().last().pos1;
|
||||||
int changeSetLength = changeSet.operationList().last().text.length();
|
int changeSetLength = changeSet.operationList().last().text.length();
|
||||||
QTextCursor tc = m_editor->editorWidget()->textCursor();
|
QTextCursor tc = m_editorWidget->textCursor();
|
||||||
tc.beginEditBlock();
|
tc.beginEditBlock();
|
||||||
changeSet.apply(&tc);
|
changeSet.apply(&tc);
|
||||||
|
|
||||||
m_editor->convertPosition(changeSetPos, &line, &column); //get line
|
m_editorWidget->convertPosition(changeSetPos, &line, &column); //get line
|
||||||
m_editor->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line
|
m_editorWidget->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line
|
||||||
|
|
||||||
indentLines(line, endLine);
|
indentLines(line, endLine);
|
||||||
tc.endEditBlock();
|
tc.endEditBlock();
|
||||||
@@ -348,7 +347,7 @@ void QuickToolBar::removeProperty(const QString &propertyName)
|
|||||||
Utils::ChangeSet changeSet;
|
Utils::ChangeSet changeSet;
|
||||||
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
|
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
|
||||||
rewriter.removeBindingByName(initializer, propertyName);
|
rewriter.removeBindingByName(initializer, propertyName);
|
||||||
QTextCursor tc(m_editor->editorWidget()->document());
|
QTextCursor tc(m_editorWidget->document());
|
||||||
changeSet.apply(&tc);
|
changeSet.apply(&tc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,7 +387,7 @@ void QuickToolBar::onPropertyRemovedAndChange(const QString &remove, const QStri
|
|||||||
if (!m_doc)
|
if (!m_doc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QTextCursor tc = m_editor->textCursor();
|
QTextCursor tc = m_editorWidget->textCursor();
|
||||||
tc.beginEditBlock();
|
tc.beginEditBlock();
|
||||||
|
|
||||||
if (removeFirst) {
|
if (removeFirst) {
|
||||||
@@ -424,13 +423,13 @@ void QuickToolBar::onEnabledChanged(bool b)
|
|||||||
void QuickToolBar::indentLines(int startLine, int endLine)
|
void QuickToolBar::indentLines(int startLine, int endLine)
|
||||||
{
|
{
|
||||||
if (startLine > 0) {
|
if (startLine > 0) {
|
||||||
TextEditor::TabSettings tabSettings = m_editor->textDocument()->tabSettings();
|
TextEditor::TabSettings tabSettings = m_editorWidget->textDocument()->tabSettings();
|
||||||
for (int i = startLine; i <= endLine; i++) {
|
for (int i = startLine; i <= endLine; i++) {
|
||||||
QTextBlock start = m_editor->qdocument()->findBlockByNumber(i);
|
QTextBlock start = m_editorWidget->document()->findBlockByNumber(i);
|
||||||
|
|
||||||
if (start.isValid()) {
|
if (start.isValid()) {
|
||||||
QmlJSEditor::Internal::Indenter indenterMy;
|
QmlJSEditor::Internal::Indenter indenterMy;
|
||||||
indenterMy.indentBlock(m_editor->qdocument(), start, QChar::Null, tabSettings);
|
indenterMy.indentBlock(m_editorWidget->document(), start, QChar::Null, tabSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,6 @@
|
|||||||
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
|
||||||
|
|
||||||
namespace QmlEditorWidgets { class ContextPaneWidget; }
|
namespace QmlEditorWidgets { class ContextPaneWidget; }
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
@@ -47,8 +45,8 @@ class QuickToolBar : public QmlJS::IContextPane
|
|||||||
public:
|
public:
|
||||||
QuickToolBar(QObject *parent = 0);
|
QuickToolBar(QObject *parent = 0);
|
||||||
~QuickToolBar();
|
~QuickToolBar();
|
||||||
void apply(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, const QmlJS::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false);
|
void apply(TextEditor::BaseTextEditorWidget *widget, QmlJS::Document::Ptr document, const QmlJS::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false);
|
||||||
bool isAvailable(TextEditor::BaseTextEditor *editor, QmlJS::Document::Ptr document, QmlJS::AST::Node *node);
|
bool isAvailable(TextEditor::BaseTextEditorWidget *widget, QmlJS::Document::Ptr document, QmlJS::AST::Node *node);
|
||||||
void setProperty(const QString &propertyName, const QVariant &value);
|
void setProperty(const QString &propertyName, const QVariant &value);
|
||||||
void removeProperty(const QString &propertyName);
|
void removeProperty(const QString &propertyName);
|
||||||
void setEnabled(bool);
|
void setEnabled(bool);
|
||||||
@@ -68,7 +66,7 @@ private:
|
|||||||
QPointer<QmlEditorWidgets::ContextPaneWidget> m_widget;
|
QPointer<QmlEditorWidgets::ContextPaneWidget> m_widget;
|
||||||
QmlJS::Document::Ptr m_doc;
|
QmlJS::Document::Ptr m_doc;
|
||||||
QmlJS::AST::Node *m_node;
|
QmlJS::AST::Node *m_node;
|
||||||
TextEditor::BaseTextEditor *m_editor;
|
TextEditor::BaseTextEditorWidget *m_editorWidget;
|
||||||
bool m_blockWriting;
|
bool m_blockWriting;
|
||||||
QStringList m_propertyOrder;
|
QStringList m_propertyOrder;
|
||||||
QStringList m_prototypes;
|
QStringList m_prototypes;
|
||||||
|
|||||||
Reference in New Issue
Block a user