forked from qt-creator/qt-creator
QmlDesigner: Fix context help in code editor
Context help is only triggered for the first widget in the focus widget's
parent hierarchy that has an IContext registered.
This change amends 411100b037
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 <henning.gruendl@qt.io>
This commit is contained in:
@@ -48,10 +48,7 @@ const char TEXTEDITOR_CONTEXT_ID[] = "QmlDesigner.TextEditorContext";
|
|||||||
TextEditorView::TextEditorView(ExternalDependenciesInterface &externalDependencies)
|
TextEditorView::TextEditorView(ExternalDependenciesInterface &externalDependencies)
|
||||||
: AbstractView{externalDependencies}
|
: AbstractView{externalDependencies}
|
||||||
, m_widget(new TextEditorWidget(this))
|
, m_widget(new TextEditorWidget(this))
|
||||||
, m_textEditorContext(new Internal::TextEditorContext(m_widget))
|
|
||||||
{
|
{
|
||||||
Core::ICore::addContextObject(m_textEditorContext);
|
|
||||||
|
|
||||||
Core::Context context(TEXTEDITOR_CONTEXT_ID);
|
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.
|
// Set the context of the text editor, but we add another special context to override shortcuts.
|
||||||
Core::Context context = textEditor->context();
|
Core::Context context = textEditor->context();
|
||||||
context.prepend(TEXTEDITOR_CONTEXT_ID);
|
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);
|
m_textEditorContext->setContext(context);
|
||||||
|
Core::ICore::addContextObject(m_textEditorContext);
|
||||||
|
|
||||||
m_widget->setTextEditor(std::move(textEditor));
|
m_widget->setTextEditor(std::move(textEditor));
|
||||||
}
|
}
|
||||||
|
@@ -85,7 +85,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<TextEditorWidget> m_widget;
|
QPointer<TextEditorWidget> m_widget;
|
||||||
Internal::TextEditorContext *m_textEditorContext;
|
Internal::TextEditorContext *m_textEditorContext = nullptr;
|
||||||
bool m_errorState = false;
|
bool m_errorState = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -85,16 +85,16 @@ void NavigatorContext::contextHelp(const HelpCallback &callback) const
|
|||||||
qobject_cast<NavigatorWidget *>(m_widget)->contextHelp(callback);
|
qobject_cast<NavigatorWidget *>(m_widget)->contextHelp(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorContext::TextEditorContext(QWidget *widget)
|
TextEditorContext::TextEditorContext(TextEditorWidget *parent)
|
||||||
: IContext(widget)
|
: IContext(parent)
|
||||||
|
, m_parent(parent)
|
||||||
{
|
{
|
||||||
setWidget(widget);
|
|
||||||
setContext(Core::Context(Constants::C_QMLTEXTEDITOR, Constants::C_QT_QUICK_TOOLS_MENU));
|
setContext(Core::Context(Constants::C_QMLTEXTEDITOR, Constants::C_QT_QUICK_TOOLS_MENU));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorContext::contextHelp(const HelpCallback &callback) const
|
void TextEditorContext::contextHelp(const HelpCallback &callback) const
|
||||||
{
|
{
|
||||||
qobject_cast<TextEditorWidget *>(m_widget)->contextHelp(callback);
|
m_parent->contextHelp(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner::Internal
|
} // namespace QmlDesigner::Internal
|
||||||
|
@@ -6,6 +6,9 @@
|
|||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class TextEditorWidget;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,8 +73,11 @@ class TextEditorContext : public Core::IContext
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextEditorContext(QWidget *widget);
|
TextEditorContext(TextEditorWidget *parent);
|
||||||
void contextHelp(const Core::IContext::HelpCallback &callback) const override;
|
void contextHelp(const Core::IContext::HelpCallback &callback) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
TextEditorWidget *m_parent = nullptr;
|
||||||
};
|
};
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user