diff options
Diffstat (limited to 'src')
11 files changed, 66 insertions, 0 deletions
diff --git a/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h b/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h index d90bb465ac..233dc87f6c 100644 --- a/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h +++ b/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h @@ -72,6 +72,7 @@ const char resetPositionDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMen const char goIntoComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Go into Component"); const char goToImplementationDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Go to Implementation"); +const char moveToComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Move to Component"); const char setIdDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Set Id"); diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp index 167365fd74..57f1ca61da 100644 --- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp @@ -510,6 +510,8 @@ void DesignerActionManager::createDefaultDesignerActions() (goIntoComponentDisplayName, rootCategory, priorityGoIntoComponent, &goIntoComponent, &selectionIsComponent)); addDesignerAction(new ModelNodeAction (goToImplementationDisplayName, rootCategory, 42, &gotoImplementation, &singleSelectedAndUiFile, &singleSelectedAndUiFile)); + addDesignerAction(new ModelNodeAction + (moveToComponentDisplayName, rootCategory, 44, &moveToComponent, &singleSelection, &singleSelection)); } diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index 6c6b9198aa..ac3487b4d4 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -773,6 +773,16 @@ void removePositioner(const SelectionContext &selectionContext) removeLayout(selectionContext); } +void moveToComponent(const SelectionContext &selectionContext) +{ + ModelNode modelNode; + if (selectionContext.singleNodeIsSelected()) + modelNode = selectionContext.selectedModelNodes().first(); + + if (modelNode.isValid()) + selectionContext.view()->model()->rewriterView()->moveToComponent(modelNode); +} + } // namespace Mode } //QmlDesigner diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h index bdc43684ce..560d54d218 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h @@ -66,6 +66,7 @@ void layoutGridLayout(const SelectionContext &selectionState); void gotoImplementation(const SelectionContext &selectionState); void removeLayout(const SelectionContext &selectionContext); void removePositioner(const SelectionContext &selectionContext); +void moveToComponent(const SelectionContext &selectionContext); } // namespace ModelNodeOperationso diff --git a/src/plugins/qmldesigner/designercore/include/basetexteditmodifier.h b/src/plugins/qmldesigner/designercore/include/basetexteditmodifier.h index 58c1950ebd..d2a9a106c0 100644 --- a/src/plugins/qmldesigner/designercore/include/basetexteditmodifier.h +++ b/src/plugins/qmldesigner/designercore/include/basetexteditmodifier.h @@ -46,6 +46,7 @@ public: virtual int indentDepth() const; virtual bool renameId(const QString &oldId, const QString &newId); + virtual bool moveToComponent(int nodeOffset); }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/include/componenttextmodifier.h b/src/plugins/qmldesigner/designercore/include/componenttextmodifier.h index 94b268ada5..6d19faf7ae 100644 --- a/src/plugins/qmldesigner/designercore/include/componenttextmodifier.h +++ b/src/plugins/qmldesigner/designercore/include/componenttextmodifier.h @@ -54,6 +54,7 @@ public: virtual void reactivateChangeSignals(); virtual bool renameId(const QString & /* oldId */, const QString & /* newId */) { return false; } + virtual bool moveToComponent(int /* nodeOffset */) { return false; } public slots: void contentsChange(int position, int charsRemoved, int charsAdded); diff --git a/src/plugins/qmldesigner/designercore/include/plaintexteditmodifier.h b/src/plugins/qmldesigner/designercore/include/plaintexteditmodifier.h index 7530be3b40..b3cfd3698a 100644 --- a/src/plugins/qmldesigner/designercore/include/plaintexteditmodifier.h +++ b/src/plugins/qmldesigner/designercore/include/plaintexteditmodifier.h @@ -69,6 +69,7 @@ public: virtual void reactivateChangeSignals(); virtual bool renameId(const QString & /* oldId */, const QString & /* newId */) { return false; } + virtual bool moveToComponent(int /* nodeOffset */) { return false; } protected: QPlainTextEdit *plainTextEdit() const diff --git a/src/plugins/qmldesigner/designercore/include/rewriterview.h b/src/plugins/qmldesigner/designercore/include/rewriterview.h index 8a319b6e34..ed343cf478 100644 --- a/src/plugins/qmldesigner/designercore/include/rewriterview.h +++ b/src/plugins/qmldesigner/designercore/include/rewriterview.h @@ -176,6 +176,8 @@ public: QSet<QPair<QString, QString> > qrcMapping() const; + void moveToComponent(const ModelNode &modelNode); + signals: void errorsChanged(const QList<RewriterError> &errors); diff --git a/src/plugins/qmldesigner/designercore/include/textmodifier.h b/src/plugins/qmldesigner/designercore/include/textmodifier.h index 863ecabd9f..e1cd9bdbff 100644 --- a/src/plugins/qmldesigner/designercore/include/textmodifier.h +++ b/src/plugins/qmldesigner/designercore/include/textmodifier.h @@ -82,6 +82,8 @@ public: virtual bool renameId(const QString &oldId, const QString &newId) = 0; + virtual bool moveToComponent(int nodeOffset) = 0; + signals: void textChanged(); diff --git a/src/plugins/qmldesigner/designercore/model/basetexteditmodifier.cpp b/src/plugins/qmldesigner/designercore/model/basetexteditmodifier.cpp index 2fad6ee4ff..77ab8f2e31 100644 --- a/src/plugins/qmldesigner/designercore/model/basetexteditmodifier.cpp +++ b/src/plugins/qmldesigner/designercore/model/basetexteditmodifier.cpp @@ -26,11 +26,15 @@ #include "basetexteditmodifier.h" #include <qmljs/qmljsmodelmanagerinterface.h> +#include <qmljs/parser/qmljsast_p.h> #include <qmljstools/qmljsindenter.h> #include <qmljseditor/qmljseditordocument.h> +#include <qmljseditor/qmljscomponentfromobjectdef.h> #include <texteditor/tabsettings.h> #include <utils/changeset.h> +#include <typeinfo> + using namespace QmlDesigner; BaseTextEditModifier::BaseTextEditModifier(TextEditor::TextEditorWidget *textEdit): @@ -100,3 +104,37 @@ bool BaseTextEditModifier::renameId(const QString &oldId, const QString &newId) } return false; } + +static QmlJS::AST::UiObjectDefinition *getObjectDefinition(QList<QmlJS::AST::Node *> path, QmlJS::AST::UiQualifiedId *qualifiedId) +{ + QmlJS::AST::UiObjectDefinition *object = 0; + for (int i = path.size() - 1; i >= 0; --i) { + auto node = path.at(i); + if (auto objDef = QmlJS::AST::cast<QmlJS::AST::UiObjectDefinition *>(node)) { + if (objDef->qualifiedTypeNameId == qualifiedId) + object = objDef; + } + } + return object; +} + +bool BaseTextEditModifier::moveToComponent(int nodeOffset) +{ + if (TextEditor::TextEditorWidget *bte = qobject_cast<TextEditor::TextEditorWidget*>(plainTextEdit())) { + if (QmlJSEditor::QmlJSEditorDocument *document + = qobject_cast<QmlJSEditor::QmlJSEditorDocument *>(bte->textDocument())) { + + auto *qualifiedId = QmlJS::AST::cast<QmlJS::AST::UiQualifiedId *>(document->semanticInfo().astNodeAt(nodeOffset)); + QList<QmlJS::AST::Node *> path = document->semanticInfo().rangePath(nodeOffset); + QmlJS::AST::UiObjectDefinition *object = getObjectDefinition(path, qualifiedId); + + if (!object) + return false; + + QmlJSEditor::ComponentFromObjectDef::perform(document->filePath().toString(), object); + return true; + + } + } + return false; +} diff --git a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp index 3376e7e52d..4b3179001c 100644 --- a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp +++ b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp @@ -715,6 +715,13 @@ QSet<QPair<QString, QString> > RewriterView::qrcMapping() const return m_textToModelMerger->qrcMapping(); } +void RewriterView::moveToComponent(const ModelNode &modelNode) +{ + int offset = nodeOffset(modelNode); + + textModifier()->moveToComponent(offset); +} + void RewriterView::qmlTextChanged() { if (inErrorState()) |