forked from qt-creator/qt-creator
TextEditor: Let BaseHoverHandler handle help id callbacks
...to support asynchronous hover handlers like ClangHoverHandler. Change-Id: I8dc7189db37ec3a923cf493b8957c59ec9be447c Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -70,16 +70,16 @@ void BaseHoverHandler::setPriority(int priority)
|
||||
m_priority = priority;
|
||||
}
|
||||
|
||||
QString BaseHoverHandler::contextHelpId(TextEditorWidget *widget, int pos)
|
||||
void BaseHoverHandler::contextHelpId(TextEditorWidget *widget,
|
||||
int pos,
|
||||
const Core::IContext::HelpIdCallback &callback)
|
||||
{
|
||||
// If the tooltip is visible and there is a help match, this match is used to update
|
||||
// the help id. Otherwise, let the identification process happen.
|
||||
if (!Utils::ToolTip::isVisible() || !lastHelpItemIdentified().isValid())
|
||||
process(widget, pos, [](int){});
|
||||
|
||||
if (lastHelpItemIdentified().isValid())
|
||||
return lastHelpItemIdentified().helpId();
|
||||
return QString();
|
||||
process(widget, pos, [this, widget, callback](int) { propagateHelpId(widget, callback); });
|
||||
else
|
||||
propagateHelpId(widget, callback);
|
||||
}
|
||||
|
||||
void BaseHoverHandler::setToolTip(const QString &tooltip)
|
||||
@@ -102,6 +102,17 @@ const HelpItem &BaseHoverHandler::lastHelpItemIdentified() const
|
||||
return m_lastHelpItemIdentified;
|
||||
}
|
||||
|
||||
void BaseHoverHandler::propagateHelpId(TextEditorWidget *widget,
|
||||
const Core::IContext::HelpIdCallback &callback)
|
||||
{
|
||||
QString id;
|
||||
if (lastHelpItemIdentified().isValid())
|
||||
id = lastHelpItemIdentified().helpId();
|
||||
|
||||
widget->setContextHelpId(id);
|
||||
callback(id);
|
||||
}
|
||||
|
||||
void BaseHoverHandler::process(TextEditorWidget *widget, int pos, ReportPriority report)
|
||||
{
|
||||
m_toolTip.clear();
|
||||
|
@@ -28,6 +28,8 @@
|
||||
#include "texteditor_global.h"
|
||||
#include "helpitem.h"
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@@ -43,7 +45,9 @@ class TEXTEDITOR_EXPORT BaseHoverHandler
|
||||
public:
|
||||
virtual ~BaseHoverHandler();
|
||||
|
||||
QString contextHelpId(TextEditorWidget *widget, int pos);
|
||||
void contextHelpId(TextEditorWidget *widget,
|
||||
int pos,
|
||||
const Core::IContext::HelpIdCallback &callback);
|
||||
|
||||
using ReportPriority = std::function<void(int priority)>;
|
||||
void checkPriority(TextEditorWidget *widget, int pos, ReportPriority report);
|
||||
@@ -67,6 +71,8 @@ protected:
|
||||
void setLastHelpItemIdentified(const HelpItem &help);
|
||||
const HelpItem &lastHelpItemIdentified() const;
|
||||
|
||||
void propagateHelpId(TextEditorWidget *widget, const Core::IContext::HelpIdCallback &callback);
|
||||
|
||||
// identifyMatch() is required to report a priority by using the "report" callback.
|
||||
// It is recommended to use e.g.
|
||||
// Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
|
@@ -7925,8 +7925,9 @@ void BaseTextEditor::setContextHelpId(const QString &id)
|
||||
void TextEditorWidget::contextHelpId(const IContext::HelpIdCallback &callback)
|
||||
{
|
||||
if (d->m_contextHelpId.isEmpty() && !d->m_hoverHandlers.isEmpty())
|
||||
d->m_contextHelpId = d->m_hoverHandlers.first()->contextHelpId(this, textCursor().position());
|
||||
callback(d->m_contextHelpId);
|
||||
d->m_hoverHandlers.first()->contextHelpId(this, textCursor().position(), callback);
|
||||
else
|
||||
callback(d->m_contextHelpId);
|
||||
}
|
||||
|
||||
void TextEditorWidget::setContextHelpId(const QString &id)
|
||||
|
Reference in New Issue
Block a user