forked from qt-creator/qt-creator
HelpIndexFilter: Reimplement matchers()
Change-Id: I47bf8eee25b91ac5ae7d8fd2c06a34370d5d433f Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
#include <coreplugin/helpmanager.h>
|
#include <coreplugin/helpmanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <utils/tasktree.h>
|
#include <utils/asynctask.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QHelpEngine>
|
#include <QHelpEngine>
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Help;
|
using namespace Help;
|
||||||
using namespace Help::Internal;
|
using namespace Help::Internal;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
HelpIndexFilter::HelpIndexFilter()
|
HelpIndexFilter::HelpIndexFilter()
|
||||||
{
|
{
|
||||||
@@ -42,6 +43,73 @@ HelpIndexFilter::HelpIndexFilter()
|
|||||||
this, &HelpIndexFilter::invalidateCache);
|
this, &HelpIndexFilter::invalidateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void matches(QPromise<QStringList> &promise, const LocatorStorage &storage,
|
||||||
|
const QStringList &cache, const QIcon &icon)
|
||||||
|
{
|
||||||
|
const QString input = storage.input();
|
||||||
|
const Qt::CaseSensitivity cs = ILocatorFilter::caseSensitivity(input);
|
||||||
|
QStringList bestKeywords;
|
||||||
|
QStringList worseKeywords;
|
||||||
|
bestKeywords.reserve(cache.size());
|
||||||
|
worseKeywords.reserve(cache.size());
|
||||||
|
for (const QString &keyword : cache) {
|
||||||
|
if (promise.isCanceled())
|
||||||
|
return;
|
||||||
|
if (keyword.startsWith(input, cs))
|
||||||
|
bestKeywords.append(keyword);
|
||||||
|
else if (keyword.contains(input, cs))
|
||||||
|
worseKeywords.append(keyword);
|
||||||
|
}
|
||||||
|
const QStringList lastIndicesCache = bestKeywords + worseKeywords;
|
||||||
|
|
||||||
|
LocatorFilterEntries entries;
|
||||||
|
for (const QString &key : lastIndicesCache) {
|
||||||
|
if (promise.isCanceled())
|
||||||
|
return;
|
||||||
|
const int index = key.indexOf(input, 0, cs);
|
||||||
|
LocatorFilterEntry filterEntry;
|
||||||
|
filterEntry.displayName = key;
|
||||||
|
filterEntry.acceptor = [key] {
|
||||||
|
HelpPlugin::showLinksInCurrentViewer(LocalHelpManager::linksForKeyword(key), key);
|
||||||
|
return AcceptResult();
|
||||||
|
};
|
||||||
|
filterEntry.displayIcon = icon;
|
||||||
|
filterEntry.highlightInfo = {index, int(input.length())};
|
||||||
|
entries.append(filterEntry);
|
||||||
|
}
|
||||||
|
storage.reportOutput(entries);
|
||||||
|
promise.addResult(lastIndicesCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
LocatorMatcherTasks HelpIndexFilter::matchers()
|
||||||
|
{
|
||||||
|
using namespace Tasking;
|
||||||
|
|
||||||
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
|
const auto onSetup = [this, storage](AsyncTask<QStringList> &async) {
|
||||||
|
if (m_needsUpdate) {
|
||||||
|
m_needsUpdate = false;
|
||||||
|
LocalHelpManager::setupGuiHelpEngine();
|
||||||
|
m_allIndicesCache = LocalHelpManager::filterEngine()->indices({});
|
||||||
|
m_lastIndicesCache.clear();
|
||||||
|
m_lastEntry.clear();
|
||||||
|
}
|
||||||
|
const QStringList cache = m_lastEntry.isEmpty() || !storage->input().contains(m_lastEntry)
|
||||||
|
? m_allIndicesCache : m_lastIndicesCache;
|
||||||
|
async.setFutureSynchronizer(HelpPlugin::futureSynchronizer());
|
||||||
|
async.setConcurrentCallData(matches, *storage, cache, m_icon);
|
||||||
|
};
|
||||||
|
const auto onDone = [this, storage](const AsyncTask<QStringList> &async) {
|
||||||
|
if (async.isResultAvailable()) {
|
||||||
|
m_lastIndicesCache = async.result();
|
||||||
|
m_lastEntry = storage->input();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {{Async<QStringList>(onSetup, onDone), storage}};
|
||||||
|
}
|
||||||
|
|
||||||
void HelpIndexFilter::prepareSearch(const QString &entry)
|
void HelpIndexFilter::prepareSearch(const QString &entry)
|
||||||
{
|
{
|
||||||
Q_UNUSED(entry)
|
Q_UNUSED(entry)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
private:
|
private:
|
||||||
|
Core::LocatorMatcherTasks matchers() final;
|
||||||
void invalidateCache();
|
void invalidateCache();
|
||||||
|
|
||||||
QStringList m_allIndicesCache;
|
QStringList m_allIndicesCache;
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/futuresynchronizer.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/styledbar.h>
|
#include <utils/styledbar.h>
|
||||||
@@ -97,7 +98,7 @@ class HelpPluginPrivate : public QObject
|
|||||||
public:
|
public:
|
||||||
HelpPluginPrivate();
|
HelpPluginPrivate();
|
||||||
|
|
||||||
void modeChanged(Utils::Id mode, Utils::Id old);
|
void modeChanged(Id mode, Id old);
|
||||||
|
|
||||||
void requestContextHelp();
|
void requestContextHelp();
|
||||||
void showContextHelp(const HelpItem &contextHelp);
|
void showContextHelp(const HelpItem &contextHelp);
|
||||||
@@ -142,6 +143,7 @@ public:
|
|||||||
LocalHelpManager m_localHelpManager;
|
LocalHelpManager m_localHelpManager;
|
||||||
|
|
||||||
HelpIndexFilter helpIndexFilter;
|
HelpIndexFilter helpIndexFilter;
|
||||||
|
FutureSynchronizer m_futureSynchronizer;
|
||||||
};
|
};
|
||||||
|
|
||||||
static HelpPluginPrivate *dd = nullptr;
|
static HelpPluginPrivate *dd = nullptr;
|
||||||
@@ -395,6 +397,12 @@ HelpWidget *HelpPlugin::modeHelpWidget()
|
|||||||
return dd->m_centralWidget;
|
return dd->m_centralWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureSynchronizer *HelpPlugin::futureSynchronizer()
|
||||||
|
{
|
||||||
|
QTC_ASSERT(dd, return nullptr);
|
||||||
|
return &dd->m_futureSynchronizer;
|
||||||
|
}
|
||||||
|
|
||||||
void HelpPluginPrivate::showLinksInCurrentViewer(const QMultiMap<QString, QUrl> &links, const QString &key)
|
void HelpPluginPrivate::showLinksInCurrentViewer(const QMultiMap<QString, QUrl> &links, const QString &key)
|
||||||
{
|
{
|
||||||
if (links.size() < 1)
|
if (links.size() < 1)
|
||||||
@@ -403,7 +411,7 @@ void HelpPluginPrivate::showLinksInCurrentViewer(const QMultiMap<QString, QUrl>
|
|||||||
widget->showLinks(links, key);
|
widget->showLinks(links, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpPluginPrivate::modeChanged(Utils::Id mode, Utils::Id old)
|
void HelpPluginPrivate::modeChanged(Id mode, Id old)
|
||||||
{
|
{
|
||||||
Q_UNUSED(old)
|
Q_UNUSED(old)
|
||||||
if (mode == m_mode.id()) {
|
if (mode == m_mode.id()) {
|
||||||
@@ -503,7 +511,7 @@ HelpViewer *HelpPluginPrivate::viewerForContextHelp()
|
|||||||
void HelpPluginPrivate::requestContextHelp()
|
void HelpPluginPrivate::requestContextHelp()
|
||||||
{
|
{
|
||||||
// Find out what to show
|
// Find out what to show
|
||||||
const QVariant tipHelpValue = Utils::ToolTip::contextHelp();
|
const QVariant tipHelpValue = ToolTip::contextHelp();
|
||||||
const HelpItem tipHelp = tipHelpValue.canConvert<HelpItem>()
|
const HelpItem tipHelp = tipHelpValue.canConvert<HelpItem>()
|
||||||
? tipHelpValue.value<HelpItem>()
|
? tipHelpValue.value<HelpItem>()
|
||||||
: HelpItem(tipHelpValue.toString());
|
: HelpItem(tipHelpValue.toString());
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QUrl;
|
class QUrl;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Utils { class FutureSynchronizer; }
|
||||||
|
|
||||||
namespace Help {
|
namespace Help {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -30,6 +32,7 @@ public:
|
|||||||
const QString &key);
|
const QString &key);
|
||||||
static HelpViewer *createHelpViewer();
|
static HelpViewer *createHelpViewer();
|
||||||
static HelpWidget *modeHelpWidget();
|
static HelpWidget *modeHelpWidget();
|
||||||
|
static Utils::FutureSynchronizer *futureSynchronizer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initialize() final;
|
void initialize() final;
|
||||||
|
|||||||
Reference in New Issue
Block a user