diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2023-10-25 14:24:43 +0200 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2023-10-25 15:30:10 +0000 |
commit | 259bade04edd8f1d141c597c62a9554330888784 (patch) | |
tree | 72d8b8aebc4339f5ce12ea5358cc02e318df752b | |
parent | e27a8704df0da63232d9ebd17543711dcee23c00 (diff) |
QmlDesigner: Implement Jump To Code
Task-number: QDS-10866
Task-number: QDS-11045
Task-number: QDS-10865
Change-Id: I94f76bb6319e2711cde88adba2307a7539ac8617
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
15 files changed, 112 insertions, 29 deletions
diff --git a/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialogForm.qml b/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialogForm.qml index 7f410f1c3f..883468947f 100644 --- a/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialogForm.qml +++ b/share/qtcreator/qmldesigner/connectionseditor/ConnectionsDialogForm.qml @@ -216,11 +216,20 @@ Column { && backend.hasCondition && backend.hasElse } - HelperWidgets.AbstractButton { - id: editorButton - buttonIcon: StudioTheme.Constants.codeEditor_medium - tooltip: qsTr("Write the conditions for the components and the signals manually.") - onClicked: expressionDialogLoader.show() + Row { + + HelperWidgets.AbstractButton { + id: editorButton + buttonIcon: StudioTheme.Constants.codeEditor_medium + tooltip: qsTr("Write the conditions for the components and the signals manually.") + onClicked: expressionDialogLoader.show() + } + HelperWidgets.AbstractButton { + id: jumpToCodeButton + buttonIcon: StudioTheme.Constants.jumpToCode_medium + tooltip: qsTr("Jump to Code Editor.") + onClicked: backend.jumpToCode() + } } // Editor diff --git a/share/qtcreator/qmldesigner/designericons.json b/share/qtcreator/qmldesigner/designericons.json index 36a60ea3b3..2422559aeb 100644 --- a/share/qtcreator/qmldesigner/designericons.json +++ b/share/qtcreator/qmldesigner/designericons.json @@ -69,6 +69,9 @@ "EnterComponentIcon": { "iconName": "editComponent_small" }, + "JumpToCodeIcon": { + "iconName": "jumpToCode_small" + }, "EventListIcon": { "iconName": "events_small" }, diff --git a/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h b/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h index 5644648336..3f8cbd2134 100644 --- a/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h +++ b/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h @@ -64,6 +64,7 @@ const char layoutGridLayoutCommandId[] = "LayoutGridLayout"; const char layoutFillWidthCommandId[] = "LayoutFillWidth"; const char layoutFillHeightCommandId[] = "LayoutFillHeight"; const char goIntoComponentCommandId[] = "GoIntoComponent"; +const char jumpToCodeCommandId[] = "JumpToCode"; const char mergeTemplateCommandId[] = "MergeTemplate"; const char goToImplementationCommandId[] = "GoToImplementation"; const char makeComponentCommandId[] = "MakeComponent"; @@ -120,6 +121,7 @@ const char copyFormatDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", const char applyFormatDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Apply Formatting"); const char enterComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Edit Component"); +const char JumpToCodeDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Jump To Code"); const char mergeTemplateDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Merge with Template"); const char goToImplementationDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Go to Implementation"); const char makeComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Create Component"); @@ -220,6 +222,7 @@ enum PrioritiesEnum : int { EventListCategory, /******** Section *****************************/ AdditionsSection = 4000, + JumpToCode, EditAnnotations, AddMouseArea, MergeWithTemplate, diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp index 4f800bf939..cb38789b63 100644 --- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp @@ -1876,15 +1876,23 @@ void DesignerActionManager::createDefaultDesignerActions() addDesignerAction(new SeparatorDesignerAction(rootCategory, Priorities::ViewOprionsSection)); addDesignerAction(new SeparatorDesignerAction(rootCategory, Priorities::CustomActionsSection)); - addDesignerAction(new ModelNodeContextMenuAction( - goIntoComponentCommandId, - enterComponentDisplayName, - contextIcon(DesignerIcons::EnterComponentIcon), - rootCategory, - QKeySequence(Qt::Key_F2), - Priorities::ComponentActions + 2, - &goIntoComponentOperation, - &selectionIsComponent)); + addDesignerAction(new ModelNodeContextMenuAction(goIntoComponentCommandId, + enterComponentDisplayName, + contextIcon(DesignerIcons::EnterComponentIcon), + rootCategory, + QKeySequence(Qt::Key_F2), + Priorities::ComponentActions + 2, + &goIntoComponentOperation, + &selectionIsComponent)); + + addDesignerAction(new ModelNodeContextMenuAction(jumpToCodeCommandId, + JumpToCodeDisplayName, + contextIcon(DesignerIcons::JumpToCodeIcon), + rootCategory, + QKeySequence(Qt::Key_F4), + Priorities::JumpToCode, + &jumpToCodeOperation, + &singleSelection)); addDesignerAction(new ModelNodeContextMenuAction( editAnnotationsCommandId, diff --git a/src/plugins/qmldesigner/components/componentcore/designericons.h b/src/plugins/qmldesigner/components/componentcore/designericons.h index 6539462f8f..c2d33523c0 100644 --- a/src/plugins/qmldesigner/components/componentcore/designericons.h +++ b/src/plugins/qmldesigner/components/componentcore/designericons.h @@ -67,6 +67,7 @@ public: EditIcon, EditLightIcon, EnterComponentIcon, + JumpToCodeIcon, EventListIcon, FitSelectedIcon, FitToViewIcon, diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index bedfdb7dd1..fa2d7f854c 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -1722,9 +1722,19 @@ bool validateEffect(const QString &effectPath) Utils::FilePath getImagesDefaultDirectory() { - return Utils::FilePath::fromString( - getAssetDefaultDirectory( - "images", QmlDesignerPlugin::instance()->documentManager().currentProjectDirPath().toString())); + return Utils::FilePath::fromString(getAssetDefaultDirectory( + "images", + QmlDesignerPlugin::instance()->documentManager().currentProjectDirPath().toString())); +} + +void jumpToCode(const ModelNode &modelNode) +{ + QmlDesignerPlugin::instance()->viewManager().jumpToCodeInTextEditor(modelNode); +} + +void jumpToCodeOperation(const SelectionContext &selectionState) +{ + jumpToCode(selectionState.currentSingleSelectedNode()); } } // namespace ModelNodeOperations diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h index 94cd54c1ea..d30a69b604 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h @@ -56,6 +56,7 @@ private: namespace ModelNodeOperations { bool goIntoComponent(const ModelNode &modelNode); +void jumpToCode(const ModelNode &modelNode); void select(const SelectionContext &selectionState); void deSelect(const SelectionContext &selectionState); @@ -75,6 +76,7 @@ void setFillHeight(const SelectionContext &selectionState); void resetSize(const SelectionContext &selectionState); void resetPosition(const SelectionContext &selectionState); void goIntoComponentOperation(const SelectionContext &selectionState); +void jumpToCodeOperation(const SelectionContext &selectionState); void setId(const SelectionContext &selectionState); void resetZ(const SelectionContext &selectionState); void reverse(const SelectionContext &selectionState); diff --git a/src/plugins/qmldesigner/components/componentcore/viewmanager.cpp b/src/plugins/qmldesigner/components/componentcore/viewmanager.cpp index 26f9a97421..58f766b915 100644 --- a/src/plugins/qmldesigner/components/componentcore/viewmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/viewmanager.cpp @@ -31,6 +31,8 @@ #include <utils/algorithm.h> +#include <advanceddockingsystem/dockwidget.h> + #include <QElapsedTimer> #include <QLoggingCategory> #include <QTabWidget> @@ -516,6 +518,15 @@ void ViewManager::enableStandardViews() attachViewsExceptRewriterAndComponetView(); } +void ViewManager::jumpToCodeInTextEditor(const ModelNode &modelNode) +{ + ADS::DockWidget *dockWidget = qobject_cast<ADS::DockWidget *>( + d->textEditorView.widgetInfo().widget->parentWidget()); + if (dockWidget) + dockWidget->toggleView(true); + d->textEditorView.jumpToModelNode(modelNode); +} + void ViewManager::addView(std::unique_ptr<AbstractView> &&view) { d->additionalViews.push_back(std::move(view)); diff --git a/src/plugins/qmldesigner/components/componentcore/viewmanager.h b/src/plugins/qmldesigner/components/componentcore/viewmanager.h index a3cacbe907..935ff54cfd 100644 --- a/src/plugins/qmldesigner/components/componentcore/viewmanager.h +++ b/src/plugins/qmldesigner/components/componentcore/viewmanager.h @@ -89,6 +89,7 @@ public: void disableStandardViews(); void enableStandardViews(); + void jumpToCodeInTextEditor(const ModelNode &modelNode); QList<AbstractView *> views() const; private: // functions diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp index 5791b8ad6c..55f9f5dcae 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.cpp @@ -9,16 +9,18 @@ #include <connectioneditorevaluator.h> #include <exception.h> #include <model/modelutils.h> +#include <modelnodeoperations.h> #include <nodeabstractproperty.h> #include <nodelistproperty.h> #include <nodemetainfo.h> #include <plaintexteditmodifier.h> +#include <qmldesignerconstants.h> +#include <qmldesignerplugin.h> #include <rewritertransaction.h> #include <rewriterview.h> #include <signalhandlerproperty.h> #include <variantproperty.h> -#include <qmldesignerconstants.h> -#include <qmldesignerplugin.h> +#include <viewmanager.h> #include <utils/qtcassert.h> @@ -918,6 +920,17 @@ void ConnectionModelBackendDelegate::update() QTC_ASSERT(model, return ); } +void ConnectionModelBackendDelegate::jumpToCode() +{ + ConnectionModel *model = qobject_cast<ConnectionModel *>(parent()); + + QTC_ASSERT(model, return ); + QTC_ASSERT(model->connectionView()->isAttached(), return ); + SignalHandlerProperty signalHandlerProperty = model->signalHandlerPropertyForRow(currentRow()); + + ModelNodeOperations::jumpToCode(signalHandlerProperty.parentModelNode()); +} + void ConnectionModelBackendDelegate::handleException() { QMessageBox::warning(nullptr, tr("Error"), m_exceptionError); diff --git a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h index d25d5aa2d3..1aa94f7733 100644 --- a/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h +++ b/src/plugins/qmldesigner/components/connectioneditor/connectionmodel.h @@ -293,6 +293,8 @@ public: void setCurrentRow(int i); void update(); + Q_INVOKABLE void jumpToCode(); + signals: void currentRowChanged(); void actionTypeChanged(); diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp index 0826df5484..cdf09c1493 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp @@ -34,11 +34,12 @@ #include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsreformatter.h> +#include <qwindow.h> #include <QDebug> #include <QPair> +#include <QPointer> #include <QString> #include <QTimer> -#include <QPointer> namespace QmlDesigner { @@ -292,6 +293,14 @@ void TextEditorView::reformatFile() } } +void TextEditorView::jumpToModelNode(const ModelNode &modelNode) +{ + m_widget->jumpToModelNode(modelNode); + + m_widget->window()->windowHandle()->requestActivate(); + m_widget->textEditor()->widget()->setFocus(); +} + void TextEditorView::instancePropertyChanged(const QList<QPair<ModelNode, PropertyName> > &/*propertyList*/) { } diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.h b/src/plugins/qmldesigner/components/texteditor/texteditorview.h index e50372279d..33a5ec8276 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.h +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.h @@ -81,6 +81,8 @@ public: void reformatFile(); + void jumpToModelNode(const ModelNode &modelNode); + private: QPointer<TextEditorWidget> m_widget; Internal::TextEditorContext *m_textEditorContext; diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp index 122228f208..2da33348f2 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp @@ -98,6 +98,20 @@ void TextEditorWidget::updateSelectionByCursorPosition() m_blockRoundTrip = false; } +void TextEditorWidget::jumpToModelNode(const ModelNode &modelNode) +{ + RewriterView *rewriterView = m_textEditorView->model()->rewriterView(); + + m_blockCursorSelectionSynchronisation = true; + const int nodeOffset = rewriterView->nodeOffset(modelNode); + if (nodeOffset > 0) { + int line, column; + m_textEditor->editorWidget()->convertPosition(nodeOffset, &line, &column); + m_textEditor->editorWidget()->gotoLine(line + 1, column); + } + m_blockCursorSelectionSynchronisation = false; +} + void TextEditorWidget::jumpTextCursorToSelectedModelNode() { if (m_blockRoundTrip) @@ -115,15 +129,7 @@ void TextEditorWidget::jumpTextCursorToSelectedModelNode() selectedNode = m_textEditorView->selectedModelNodes().constFirst(); if (selectedNode.isValid()) { - RewriterView *rewriterView = m_textEditorView->model()->rewriterView(); - - const int nodeOffset = rewriterView->nodeOffset(selectedNode); - if (nodeOffset > 0) { - int line, column; - m_textEditor->editorWidget()->convertPosition(nodeOffset, &line, &column); - // line has to be 1 based, column 0 based! - m_textEditor->editorWidget()->gotoLine(line, column - 1); - } + jumpToModelNode(selectedNode); } m_updateSelectionTimer.stop(); } diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h index 947826ab59..8c5f5b2dd8 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h @@ -5,6 +5,8 @@ #include <texteditor/texteditor.h> #include <utils/uniqueobjectptr.h> +#include <modelnode.h> + #include <QTimer> #include <QVBoxLayout> #include <QWidget> @@ -43,6 +45,7 @@ public: int currentLine() const; void setBlockCursorSelectionSynchronisation(bool b); + void jumpToModelNode(const ModelNode &modelNode); protected: bool eventFilter(QObject *object, QEvent *event) override; |