forked from qt-creator/qt-creator
OpenDocumentsFilter: Reimplement matchers()
Change-Id: Ie458d74321286d720b3eef62b7b3273c5c222e44 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -3,11 +3,13 @@
|
|||||||
|
|
||||||
#include "opendocumentsfilter.h"
|
#include "opendocumentsfilter.h"
|
||||||
|
|
||||||
|
#include "../coreplugin.h"
|
||||||
#include "../coreplugintr.h"
|
#include "../coreplugintr.h"
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/asynctask.h>
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
#include <utils/link.h>
|
#include <utils/link.h>
|
||||||
#include <utils/tasktree.h>
|
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
@@ -25,6 +27,7 @@ OpenDocumentsFilter::OpenDocumentsFilter()
|
|||||||
setDefaultShortcutString("o");
|
setDefaultShortcutString("o");
|
||||||
setPriority(High);
|
setPriority(High);
|
||||||
setDefaultIncludedByDefault(true);
|
setDefaultIncludedByDefault(true);
|
||||||
|
// TODO: Remove the refresh recipe
|
||||||
setRefreshRecipe(Tasking::Sync([this] { refreshInternally(); return true; }));
|
setRefreshRecipe(Tasking::Sync([this] { refreshInternally(); return true; }));
|
||||||
|
|
||||||
connect(DocumentModel::model(), &QAbstractItemModel::dataChanged,
|
connect(DocumentModel::model(), &QAbstractItemModel::dataChanged,
|
||||||
@@ -35,6 +38,56 @@ OpenDocumentsFilter::OpenDocumentsFilter()
|
|||||||
this, &OpenDocumentsFilter::slotRowsRemoved);
|
this, &OpenDocumentsFilter::slotRowsRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void matchEditors(QPromise<void> &promise, const LocatorStorage &storage,
|
||||||
|
const QList<OpenDocumentsFilter::Entry> &editorsData)
|
||||||
|
{
|
||||||
|
const Link link = Link::fromString(storage.input(), true);
|
||||||
|
const QRegularExpression regexp = ILocatorFilter::createRegExp(link.targetFilePath.toString());
|
||||||
|
if (!regexp.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
LocatorFilterEntries goodEntries;
|
||||||
|
LocatorFilterEntries betterEntries;
|
||||||
|
|
||||||
|
for (const OpenDocumentsFilter::Entry &editorData : editorsData) {
|
||||||
|
if (promise.isCanceled())
|
||||||
|
return;
|
||||||
|
if (editorData.fileName.isEmpty())
|
||||||
|
continue;
|
||||||
|
const QRegularExpressionMatch match = regexp.match(editorData.displayName);
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
LocatorFilterEntry filterEntry;
|
||||||
|
filterEntry.displayName = editorData.displayName;
|
||||||
|
filterEntry.filePath = editorData.fileName;
|
||||||
|
filterEntry.extraInfo = filterEntry.filePath.shortNativePath();
|
||||||
|
filterEntry.highlightInfo = ILocatorFilter::highlightInfo(match);
|
||||||
|
filterEntry.linkForEditor = Link(filterEntry.filePath, link.targetLine,
|
||||||
|
link.targetColumn);
|
||||||
|
if (match.capturedStart() == 0)
|
||||||
|
betterEntries.append(filterEntry);
|
||||||
|
else
|
||||||
|
goodEntries.append(filterEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storage.reportOutput(betterEntries + goodEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
LocatorMatcherTasks OpenDocumentsFilter::matchers()
|
||||||
|
{
|
||||||
|
using namespace Tasking;
|
||||||
|
|
||||||
|
TreeStorage<LocatorStorage> storage;
|
||||||
|
|
||||||
|
const auto onSetup = [storage](AsyncTask<void> &async) {
|
||||||
|
const QList<Entry> editorsData = Utils::transform(DocumentModel::entries(),
|
||||||
|
[](const DocumentModel::Entry *e) { return Entry{e->filePath(), e->displayName()}; });
|
||||||
|
async.setFutureSynchronizer(CorePlugin::futureSynchronizer());
|
||||||
|
async.setConcurrentCallData(matchEditors, *storage, editorsData);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {{Async<void>(onSetup), storage}};
|
||||||
|
}
|
||||||
|
|
||||||
void OpenDocumentsFilter::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
void OpenDocumentsFilter::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||||
const QVector<int> &roles)
|
const QVector<int> &roles)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,13 +20,7 @@ public:
|
|||||||
OpenDocumentsFilter();
|
OpenDocumentsFilter();
|
||||||
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
|
QList<LocatorFilterEntry> matchesFor(QFutureInterface<LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
public slots:
|
// TODO: Move to cpp when matchesFor() is removed
|
||||||
void slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
|
||||||
const QVector<int> &roles);
|
|
||||||
void slotRowsInserted(const QModelIndex &, int first, int last);
|
|
||||||
void slotRowsRemoved(const QModelIndex &, int first, int last);
|
|
||||||
|
|
||||||
private:
|
|
||||||
class Entry
|
class Entry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -34,6 +28,14 @@ private:
|
|||||||
QString displayName;
|
QString displayName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||||
|
const QVector<int> &roles);
|
||||||
|
void slotRowsInserted(const QModelIndex &, int first, int last);
|
||||||
|
void slotRowsRemoved(const QModelIndex &, int first, int last);
|
||||||
|
|
||||||
|
private:
|
||||||
|
LocatorMatcherTasks matchers() final;
|
||||||
QList<Entry> editors() const;
|
QList<Entry> editors() const;
|
||||||
void refreshInternally();
|
void refreshInternally();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user