From d41015539516c7c64a06d9f79eca9eae8f8b6885 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 22 Jul 2024 14:54:35 +0200 Subject: [PATCH] QmlDesigner: Fix context help in code editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context help is only triggered for the first widget in the focus widget's parent hierarchy that has an IContext registered. This change amends 411100b0378202dc617acaa236f4730eb4cc43b2 which removed the TextEditorActionHandler by registering an editor-specific IContext for the individual TextEditorWidgets. The code editor in QmlDesigner registered an IContext for a widget that _contains_ the actual editor widget and handled context help there. Now the editor widget has an IContext, which means that the IContext that QmlDesigner registered was never asked. Directly register the QmlDesigner IContext for the text editor widget itself, so it takes part in context help resolution. Fixes: QDS-13248 Change-Id: Ib49129d9de20bdfa022a8e75ba454c7674040699 Reviewed-by: Henning Gründl --- .../qmldesigner/components/texteditor/texteditorview.cpp | 7 ++++--- .../qmldesigner/components/texteditor/texteditorview.h | 2 +- src/plugins/qmldesigner/designmodecontext.cpp | 8 ++++---- src/plugins/qmldesigner/designmodecontext.h | 8 +++++++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp index 2e52b3358ba..254cfd0bea3 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp @@ -48,10 +48,7 @@ const char TEXTEDITOR_CONTEXT_ID[] = "QmlDesigner.TextEditorContext"; TextEditorView::TextEditorView(ExternalDependenciesInterface &externalDependencies) : AbstractView{externalDependencies} , m_widget(new TextEditorWidget(this)) - , m_textEditorContext(new Internal::TextEditorContext(m_widget)) { - Core::ICore::addContextObject(m_textEditorContext); - Core::Context context(TEXTEDITOR_CONTEXT_ID); /* @@ -87,7 +84,11 @@ void TextEditorView::modelAttached(Model *model) // Set the context of the text editor, but we add another special context to override shortcuts. Core::Context context = textEditor->context(); context.prepend(TEXTEDITOR_CONTEXT_ID); + + m_textEditorContext = new Internal::TextEditorContext(m_widget); + m_textEditorContext->setWidget(textEditor->widget()); // toplevel focus widget of the editor m_textEditorContext->setContext(context); + Core::ICore::addContextObject(m_textEditorContext); m_widget->setTextEditor(std::move(textEditor)); } diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.h b/src/plugins/qmldesigner/components/texteditor/texteditorview.h index 33a5ec8276c..35a33863fab 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.h +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.h @@ -85,7 +85,7 @@ public: private: QPointer m_widget; - Internal::TextEditorContext *m_textEditorContext; + Internal::TextEditorContext *m_textEditorContext = nullptr; bool m_errorState = false; }; diff --git a/src/plugins/qmldesigner/designmodecontext.cpp b/src/plugins/qmldesigner/designmodecontext.cpp index 796261935af..2d73a01839b 100644 --- a/src/plugins/qmldesigner/designmodecontext.cpp +++ b/src/plugins/qmldesigner/designmodecontext.cpp @@ -85,16 +85,16 @@ void NavigatorContext::contextHelp(const HelpCallback &callback) const qobject_cast(m_widget)->contextHelp(callback); } -TextEditorContext::TextEditorContext(QWidget *widget) - : IContext(widget) +TextEditorContext::TextEditorContext(TextEditorWidget *parent) + : IContext(parent) + , m_parent(parent) { - setWidget(widget); setContext(Core::Context(Constants::C_QMLTEXTEDITOR, Constants::C_QT_QUICK_TOOLS_MENU)); } void TextEditorContext::contextHelp(const HelpCallback &callback) const { - qobject_cast(m_widget)->contextHelp(callback); + m_parent->contextHelp(callback); } } // namespace QmlDesigner::Internal diff --git a/src/plugins/qmldesigner/designmodecontext.h b/src/plugins/qmldesigner/designmodecontext.h index 1d146deb7d8..1ad7dded453 100644 --- a/src/plugins/qmldesigner/designmodecontext.h +++ b/src/plugins/qmldesigner/designmodecontext.h @@ -6,6 +6,9 @@ #include namespace QmlDesigner { + +class TextEditorWidget; + namespace Internal { /** @@ -70,8 +73,11 @@ class TextEditorContext : public Core::IContext Q_OBJECT public: - TextEditorContext(QWidget *widget); + TextEditorContext(TextEditorWidget *parent); void contextHelp(const Core::IContext::HelpCallback &callback) const override; + +private: + TextEditorWidget *m_parent = nullptr; }; } // namespace Internal } // namespace QmlDesigner