forked from qt-creator/qt-creator
Core: Return context help id by callback
...to support asynchronous providers. Change-Id: I483489c74e7886d5bc2bf00b65540c3d2c7afee0 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -61,7 +61,7 @@ namespace Internal {
|
||||
// CMakeEditor
|
||||
//
|
||||
|
||||
QString CMakeEditor::contextHelpId() const
|
||||
void CMakeEditor::contextHelpId(const HelpIdCallback &callback) const
|
||||
{
|
||||
int pos = position();
|
||||
|
||||
@@ -71,8 +71,10 @@ QString CMakeEditor::contextHelpId() const
|
||||
if (pos < 0)
|
||||
break;
|
||||
chr = characterAt(pos);
|
||||
if (chr == QLatin1Char('('))
|
||||
return QString();
|
||||
if (chr == QLatin1Char('(')) {
|
||||
callback(QString());
|
||||
return;
|
||||
}
|
||||
} while (chr.unicode() != QChar::ParagraphSeparator);
|
||||
|
||||
++pos;
|
||||
@@ -95,11 +97,13 @@ QString CMakeEditor::contextHelpId() const
|
||||
}
|
||||
|
||||
// Not a command
|
||||
if (chr != QLatin1Char('('))
|
||||
return QString();
|
||||
if (chr != QLatin1Char('(')) {
|
||||
callback(QString());
|
||||
return;
|
||||
}
|
||||
|
||||
QString command = textAt(begin, end - begin).toLower();
|
||||
return QLatin1String("command/") + command;
|
||||
callback(QLatin1String("command/") + command);
|
||||
}
|
||||
|
||||
//
|
||||
|
@@ -38,7 +38,7 @@ class CMakeEditor : public TextEditor::BaseTextEditor
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QString contextHelpId() const override;
|
||||
void contextHelpId(const HelpIdCallback &callback) const override;
|
||||
|
||||
friend class CMakeEditorWidget;
|
||||
};
|
||||
|
@@ -33,6 +33,8 @@
|
||||
#include <QPointer>
|
||||
#include <QWidget>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class CORE_EXPORT Context
|
||||
@@ -71,7 +73,8 @@ public:
|
||||
|
||||
virtual Context context() const { return m_context; }
|
||||
virtual QWidget *widget() const { return m_widget; }
|
||||
virtual QString contextHelpId() const { return m_contextHelpId; }
|
||||
using HelpIdCallback = std::function<void(const QString &id)>;
|
||||
virtual void contextHelpId(const HelpIdCallback &callback) const { callback(m_contextHelpId); }
|
||||
|
||||
virtual void setContext(const Context &context) { m_context = context; }
|
||||
virtual void setWidget(QWidget *widget) { m_widget = widget; }
|
||||
|
@@ -45,10 +45,10 @@ DesignerContext::DesignerContext(const Core::Context &context,
|
||||
setWidget(widget);
|
||||
}
|
||||
|
||||
QString DesignerContext::contextHelpId() const
|
||||
void DesignerContext::contextHelpId(const HelpIdCallback &callback) const
|
||||
{
|
||||
const QDesignerFormEditorInterface *core = FormEditorW::designerEditor();
|
||||
return core->integration()->contextHelpId();
|
||||
callback(core->integration()->contextHelpId());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -37,7 +37,7 @@ public:
|
||||
QWidget *widget,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
QString contextHelpId() const override;
|
||||
void contextHelpId(const HelpIdCallback &callback) const override;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -194,7 +194,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
Context(kToolTipHelpContext, Core::Constants::C_GLOBAL));
|
||||
ActionManager::actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
|
||||
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1));
|
||||
connect(action, &QAction::triggered, this, &HelpPlugin::showContextHelp);
|
||||
connect(action, &QAction::triggered, this, &HelpPlugin::requestContextHelp);
|
||||
|
||||
action = new QAction(tr("Technical Support"), this);
|
||||
cmd = ActionManager::registerAction(action, "Help.TechSupport");
|
||||
@@ -573,14 +573,19 @@ static QUrl findBestLink(const QMap<QString, QUrl> &links, QString *highlightId)
|
||||
return source;
|
||||
}
|
||||
|
||||
void HelpPlugin::showContextHelp()
|
||||
void HelpPlugin::requestContextHelp()
|
||||
{
|
||||
// Find out what to show
|
||||
QString contextHelpId = Utils::ToolTip::contextHelpId();
|
||||
IContext *context = ICore::currentContextObject();
|
||||
if (contextHelpId.isEmpty() && context)
|
||||
contextHelpId = context->contextHelpId();
|
||||
context->contextHelpId([this](const QString &id) { showContextHelp(id); });
|
||||
else
|
||||
showContextHelp(contextHelpId);
|
||||
}
|
||||
|
||||
void HelpPlugin::showContextHelp(const QString &contextHelpId)
|
||||
{
|
||||
// get the viewer after getting the help id,
|
||||
// because a new window might be opened and therefore focus be moved
|
||||
HelpViewer *viewer = viewerForContextHelp();
|
||||
|
@@ -76,7 +76,8 @@ public:
|
||||
private:
|
||||
void modeChanged(Core::Id mode, Core::Id old);
|
||||
|
||||
void showContextHelp();
|
||||
void requestContextHelp();
|
||||
void showContextHelp(const QString &contextHelpId);
|
||||
void activateIndex();
|
||||
void activateContents();
|
||||
|
||||
|
@@ -334,12 +334,12 @@ double FormEditorWidget::containerPadding() const
|
||||
}
|
||||
|
||||
|
||||
QString FormEditorWidget::contextHelpId() const
|
||||
void FormEditorWidget::contextHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
if (m_formEditorView)
|
||||
return m_formEditorView->contextHelpId();
|
||||
|
||||
return QString();
|
||||
m_formEditorView->contextHelpId(callback);
|
||||
else
|
||||
callback(QString());
|
||||
}
|
||||
|
||||
void FormEditorWidget::setRootItemRect(const QRectF &rect)
|
||||
|
@@ -26,6 +26,8 @@
|
||||
|
||||
#include <documentwarningwidget.h>
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
|
||||
@@ -62,7 +64,7 @@ public:
|
||||
double spacing() const;
|
||||
double containerPadding() const;
|
||||
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
|
||||
void setRootItemRect(const QRectF &rect);
|
||||
QRectF rootItemRect() const;
|
||||
|
@@ -651,12 +651,12 @@ void DesignDocument::updateCurrentProject()
|
||||
viewManager().setNodeInstanceViewProject(currentProject);
|
||||
}
|
||||
|
||||
QString DesignDocument::contextHelpId() const
|
||||
void DesignDocument::contextHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
if (view())
|
||||
return view()->contextHelpId();
|
||||
|
||||
return QString();
|
||||
view()->contextHelpId(callback);
|
||||
else
|
||||
callback(QString());
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -31,6 +31,8 @@
|
||||
#include <componenttextmodifier.h>
|
||||
#include <subcomponentmanager.h>
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
@@ -75,7 +77,7 @@ public:
|
||||
Model *currentModel() const;
|
||||
Model *documentModel() const;
|
||||
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
QList<DocumentMessage> qmlParseWarnings() const;
|
||||
bool hasQmlParseWarnings() const;
|
||||
QList<DocumentMessage> qmlParseErrors() const;
|
||||
|
@@ -130,12 +130,12 @@ QList<QToolButton *> NavigatorWidget::createToolBarWidgets()
|
||||
return buttons;
|
||||
}
|
||||
|
||||
QString NavigatorWidget::contextHelpId() const
|
||||
void NavigatorWidget::contextHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
if (navigatorView())
|
||||
return navigatorView()->contextHelpId();
|
||||
|
||||
return QString();
|
||||
navigatorView()->contextHelpId(callback);
|
||||
else
|
||||
callback(QString());
|
||||
}
|
||||
|
||||
NavigatorView *NavigatorWidget::navigatorView() const
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
|
||||
#include <QFrame>
|
||||
#include <QPointer>
|
||||
|
||||
@@ -46,7 +48,7 @@ public:
|
||||
void setTreeModel(QAbstractItemModel *model);
|
||||
QTreeView *treeView() const;
|
||||
QList<QToolButton *> createToolBarWidgets();
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
|
||||
signals:
|
||||
void leftButtonClicked();
|
||||
|
@@ -150,19 +150,17 @@ WidgetInfo TextEditorView::widgetInfo()
|
||||
return createWidgetInfo(m_widget.get(), 0, "TextEditor", WidgetInfo::CentralPane, 0, tr("Text Editor"), DesignerWidgetFlags::IgnoreErrors);
|
||||
}
|
||||
|
||||
QString TextEditorView::contextHelpId() const
|
||||
void TextEditorView::contextHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
return AbstractView::contextHelpId();
|
||||
AbstractView::contextHelpId(callback);
|
||||
}
|
||||
|
||||
QString TextEditorView::qmlJSEditorHelpId() const
|
||||
void TextEditorView::qmlJSEditorHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
if (m_widget->textEditor()) {
|
||||
QString contextHelpId = m_widget->textEditor()->contextHelpId();
|
||||
if (!contextHelpId.isEmpty())
|
||||
return m_widget->textEditor()->contextHelpId();
|
||||
}
|
||||
return QString();
|
||||
if (m_widget->textEditor())
|
||||
m_widget->textEditor()->contextHelpId(callback);
|
||||
else
|
||||
callback(QString());
|
||||
}
|
||||
|
||||
void TextEditorView::nodeIdChanged(const ModelNode& /*node*/, const QString &/*newId*/, const QString &/*oldId*/)
|
||||
|
@@ -24,6 +24,8 @@
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
|
||||
#include <abstractview.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -67,9 +69,9 @@ public:
|
||||
|
||||
// TextEditorView
|
||||
WidgetInfo widgetInfo() override;
|
||||
QString contextHelpId() const override;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const override;
|
||||
|
||||
QString qmlJSEditorHelpId() const;
|
||||
void qmlJSEditorHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
|
||||
TextEditor::BaseTextEditor *textEditor();
|
||||
|
||||
|
@@ -94,9 +94,9 @@ void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor)
|
||||
oldEditor->deleteLater();
|
||||
}
|
||||
|
||||
QString TextEditorWidget::contextHelpId() const
|
||||
void TextEditorWidget::contextHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
return m_textEditorView->contextHelpId();
|
||||
m_textEditorView->contextHelpId(callback);
|
||||
}
|
||||
|
||||
void TextEditorWidget::updateSelectionByCursorPosition()
|
||||
|
@@ -50,7 +50,7 @@ public:
|
||||
return m_textEditor.get();
|
||||
}
|
||||
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
void jumpTextCursorToSelectedModelNode();
|
||||
void gotoCursorPosition(int line, int column);
|
||||
|
||||
|
@@ -34,6 +34,8 @@
|
||||
#include <rewritertransaction.h>
|
||||
#include <commondefines.h>
|
||||
|
||||
#include <coreplugin/icontext.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
|
||||
@@ -255,7 +257,7 @@ public:
|
||||
virtual bool hasWidget() const;
|
||||
virtual WidgetInfo widgetInfo();
|
||||
|
||||
virtual QString contextHelpId() const;
|
||||
virtual void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
|
||||
void activateTimelineRecording(const ModelNode &mutator);
|
||||
void deactivateTimelineRecording();
|
||||
|
@@ -95,7 +95,7 @@ public:
|
||||
|
||||
void toggleStatesViewExpanded();
|
||||
|
||||
QString qmlJSEditorHelpId() const;
|
||||
void qmlJSEditorHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
DesignDocument *currentDesignDocument() const;
|
||||
|
||||
private: // functions
|
||||
|
@@ -561,14 +561,13 @@ WidgetInfo AbstractView::widgetInfo()
|
||||
return createWidgetInfo();
|
||||
}
|
||||
|
||||
QString AbstractView::contextHelpId() const
|
||||
void AbstractView::contextHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
QString helpId;
|
||||
|
||||
#ifndef QMLDESIGNER_TEST
|
||||
helpId = QmlDesignerPlugin::instance()->viewManager().qmlJSEditorHelpId();
|
||||
QmlDesignerPlugin::instance()->viewManager().qmlJSEditorHelpId(callback);
|
||||
#else
|
||||
callback(QString());
|
||||
#endif
|
||||
return helpId;
|
||||
}
|
||||
|
||||
void AbstractView::activateTimelineRecording(const ModelNode &mutator)
|
||||
|
@@ -411,9 +411,9 @@ void ViewManager::toggleStatesViewExpanded()
|
||||
d->statesEditorView.toggleStatesViewExpanded();
|
||||
}
|
||||
|
||||
QString ViewManager::qmlJSEditorHelpId() const
|
||||
void ViewManager::qmlJSEditorHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
return d->textEditorView.qmlJSEditorHelpId();
|
||||
d->textEditorView.qmlJSEditorHelpId(callback);
|
||||
}
|
||||
|
||||
Model *ViewManager::currentModel() const
|
||||
|
@@ -40,9 +40,9 @@ DesignModeContext::DesignModeContext(QWidget *widget)
|
||||
setContext(Core::Context(Constants::C_QMLDESIGNER, Constants::C_QT_QUICK_TOOLS_MENU));
|
||||
}
|
||||
|
||||
QString DesignModeContext::contextHelpId() const
|
||||
void DesignModeContext::contextHelpId(const HelpIdCallback &callback) const
|
||||
{
|
||||
return qobject_cast<DesignModeWidget *>(m_widget)->contextHelpId();
|
||||
qobject_cast<DesignModeWidget *>(m_widget)->contextHelpId(callback);
|
||||
}
|
||||
|
||||
FormEditorContext::FormEditorContext(QWidget *widget)
|
||||
@@ -52,9 +52,9 @@ FormEditorContext::FormEditorContext(QWidget *widget)
|
||||
setContext(Core::Context(Constants::C_QMLFORMEDITOR, Constants::C_QT_QUICK_TOOLS_MENU));
|
||||
}
|
||||
|
||||
QString FormEditorContext::contextHelpId() const
|
||||
void FormEditorContext::contextHelpId(const HelpIdCallback &callback) const
|
||||
{
|
||||
return qobject_cast<FormEditorWidget *>(m_widget)->contextHelpId();
|
||||
qobject_cast<FormEditorWidget *>(m_widget)->contextHelpId(callback);
|
||||
}
|
||||
|
||||
NavigatorContext::NavigatorContext(QWidget *widget)
|
||||
@@ -64,9 +64,9 @@ NavigatorContext::NavigatorContext(QWidget *widget)
|
||||
setContext(Core::Context(Constants::C_QMLNAVIGATOR, Constants::C_QT_QUICK_TOOLS_MENU));
|
||||
}
|
||||
|
||||
QString NavigatorContext::contextHelpId() const
|
||||
void NavigatorContext::contextHelpId(const HelpIdCallback &callback) const
|
||||
{
|
||||
return qobject_cast<NavigatorWidget *>(m_widget)->contextHelpId();
|
||||
qobject_cast<NavigatorWidget *>(m_widget)->contextHelpId(callback);
|
||||
}
|
||||
|
||||
TextEditorContext::TextEditorContext(QWidget *widget)
|
||||
@@ -76,9 +76,9 @@ TextEditorContext::TextEditorContext(QWidget *widget)
|
||||
setContext(Core::Context(Constants::C_QMLTEXTEDITOR, Constants::C_QT_QUICK_TOOLS_MENU));
|
||||
}
|
||||
|
||||
QString TextEditorContext::contextHelpId() const
|
||||
void TextEditorContext::contextHelpId(const HelpIdCallback &callback) const
|
||||
{
|
||||
return qobject_cast<TextEditorWidget *>(m_widget)->contextHelpId();
|
||||
qobject_cast<TextEditorWidget *>(m_widget)->contextHelpId(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ class DesignModeContext : public Core::IContext
|
||||
|
||||
public:
|
||||
DesignModeContext(QWidget *widget);
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
};
|
||||
|
||||
class FormEditorContext : public Core::IContext
|
||||
@@ -48,7 +48,7 @@ class FormEditorContext : public Core::IContext
|
||||
|
||||
public:
|
||||
FormEditorContext(QWidget *widget);
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
};
|
||||
|
||||
class NavigatorContext : public Core::IContext
|
||||
@@ -57,7 +57,7 @@ class NavigatorContext : public Core::IContext
|
||||
|
||||
public:
|
||||
NavigatorContext(QWidget *widget);
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
};
|
||||
|
||||
class TextEditorContext : public Core::IContext
|
||||
@@ -66,7 +66,7 @@ class TextEditorContext : public Core::IContext
|
||||
|
||||
public:
|
||||
TextEditorContext(QWidget *widget);
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -531,11 +531,12 @@ void DesignModeWidget::showInternalTextEditor()
|
||||
m_centralTabWidget->switchTo(viewManager().widget("TextEditor"));
|
||||
}
|
||||
|
||||
QString DesignModeWidget::contextHelpId() const
|
||||
void DesignModeWidget::contextHelpId(const Core::IContext::HelpIdCallback &callback) const
|
||||
{
|
||||
if (currentDesignDocument())
|
||||
return currentDesignDocument()->contextHelpId();
|
||||
return QString();
|
||||
currentDesignDocument()->contextHelpId(callback);
|
||||
else
|
||||
callback(QString());
|
||||
}
|
||||
|
||||
void DesignModeWidget::initialize()
|
||||
|
@@ -62,7 +62,7 @@ public:
|
||||
explicit DesignModeWidget(QWidget *parent = 0);
|
||||
|
||||
~DesignModeWidget();
|
||||
QString contextHelpId() const;
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback) const;
|
||||
|
||||
void initialize();
|
||||
|
||||
|
@@ -7913,9 +7913,9 @@ void TextEditorWidgetPrivate::updateCursorPosition()
|
||||
q->ensureCursorVisible();
|
||||
}
|
||||
|
||||
QString BaseTextEditor::contextHelpId() const
|
||||
void BaseTextEditor::contextHelpId(const HelpIdCallback &callback) const
|
||||
{
|
||||
return editorWidget()->contextHelpId();
|
||||
editorWidget()->contextHelpId(callback);
|
||||
}
|
||||
|
||||
void BaseTextEditor::setContextHelpId(const QString &id)
|
||||
@@ -7924,11 +7924,11 @@ void BaseTextEditor::setContextHelpId(const QString &id)
|
||||
editorWidget()->setContextHelpId(id);
|
||||
}
|
||||
|
||||
QString TextEditorWidget::contextHelpId()
|
||||
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());
|
||||
return d->m_contextHelpId;
|
||||
callback(d->m_contextHelpId);
|
||||
}
|
||||
|
||||
void TextEditorWidget::setContextHelpId(const QString &id)
|
||||
|
@@ -129,7 +129,7 @@ public:
|
||||
bool restoreState(const QByteArray &state) override;
|
||||
QWidget *toolBar() override;
|
||||
|
||||
QString contextHelpId() const override; // from IContext
|
||||
void contextHelpId(const HelpIdCallback &callback) const override; // from IContext
|
||||
void setContextHelpId(const QString &id) override;
|
||||
|
||||
int currentLine() const override;
|
||||
@@ -533,7 +533,7 @@ public:
|
||||
QChar characterAt(int pos) const;
|
||||
QString textAt(int from, int to) const;
|
||||
|
||||
QString contextHelpId();
|
||||
void contextHelpId(const Core::IContext::HelpIdCallback &callback);
|
||||
void setContextHelpId(const QString &id);
|
||||
|
||||
static TextEditorWidget *currentTextEditorWidget();
|
||||
|
Reference in New Issue
Block a user