diff --git a/src/plugins/coreplugin/icontext.cpp b/src/plugins/coreplugin/icontext.cpp index d924dc3058b..1d52b9f2b94 100644 --- a/src/plugins/coreplugin/icontext.cpp +++ b/src/plugins/coreplugin/icontext.cpp @@ -9,6 +9,24 @@ namespace Core { +void IContext::contextHelp(const HelpCallback &callback) const +{ + if (m_contextHelpProvider) { + m_contextHelpProvider(callback); + } else { + // This is important as this triggers the continued iteration + // through other contexts that may provide items. + callback({}); + } +} + +void IContext::setContextHelp(const HelpItem &item) +{ + m_contextHelpProvider = [item](const HelpCallback &callback) { + callback(item); + }; +} + void IContext::attach(QWidget *widget, const Context &context, const HelpItem &help) { auto icontext = new IContext(widget); // As QObject parent. diff --git a/src/plugins/coreplugin/icontext.h b/src/plugins/coreplugin/icontext.h index 41b8e3a87ee..a774bc41dd5 100644 --- a/src/plugins/coreplugin/icontext.h +++ b/src/plugins/coreplugin/icontext.h @@ -60,9 +60,10 @@ public: void setContext(const Context &context) { m_context = context; } using HelpCallback = std::function; - virtual void contextHelp(const HelpCallback &callback) const { callback(m_contextHelp); } + using HelpProvider = std::function; - virtual void setContextHelp(const HelpItem &id) { m_contextHelp = id; } + virtual void contextHelp(const HelpCallback &callback) const; + void setContextHelp(const HelpItem &id); static void attach(QWidget *widget, const Context &context, @@ -71,7 +72,7 @@ public: protected: Context m_context; QPointer m_widget; - HelpItem m_contextHelp; + HelpProvider m_contextHelpProvider; }; } // namespace Core