forked from qt-creator/qt-creator
LocatorWidget: Reuse LocatorMatcher in LocatorWidget
Introduce QTC_USE_MATCHER env var temporarily. When this var is set, the locator will use LocatorMatcher internally. It's very hard to migrate all the matchesFor() implementations into the LocatorMatcherTask in one patch, so this var is going to be removed when all filters are migrated. Whenever a new patch providing the filter's migration is added, it may be tested by setting this env var. Add a temporary printout with info about which implementation is selected in runtime. Change-Id: If2d6006a89f3669ea4f6f8f171e59e00917419c4 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -22,7 +22,10 @@ namespace Utils::Tasking { class TaskItem; }
|
|||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
namespace Internal { class Locator; }
|
namespace Internal {
|
||||||
|
class Locator;
|
||||||
|
class LocatorWidget;
|
||||||
|
}
|
||||||
|
|
||||||
class ILocatorFilter;
|
class ILocatorFilter;
|
||||||
class LocatorStoragePrivate;
|
class LocatorStoragePrivate;
|
||||||
@@ -279,6 +282,7 @@ private:
|
|||||||
virtual LocatorMatcherTasks matchers() { return {}; }
|
virtual LocatorMatcherTasks matchers() { return {}; }
|
||||||
|
|
||||||
friend class Internal::Locator;
|
friend class Internal::Locator;
|
||||||
|
friend class Internal::LocatorWidget;
|
||||||
static const QList<ILocatorFilter *> allLocatorFilters();
|
static const QList<ILocatorFilter *> allLocatorFilters();
|
||||||
|
|
||||||
Utils::Id m_id;
|
Utils::Id m_id;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/asynctask.h>
|
#include <utils/asynctask.h>
|
||||||
#include <utils/appmainwindow.h>
|
#include <utils/appmainwindow.h>
|
||||||
|
#include <utils/environment.h>
|
||||||
#include <utils/fancylineedit.h>
|
#include <utils/fancylineedit.h>
|
||||||
#include <utils/fsengine/fileiconprovider.h>
|
#include <utils/fsengine/fileiconprovider.h>
|
||||||
#include <utils/highlightingitemdelegate.h>
|
#include <utils/highlightingitemdelegate.h>
|
||||||
@@ -53,6 +54,8 @@ const int LocatorEntryRole = int(HighlightingItemRole::User);
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
static bool isUsingLocatorMatcher() { return qtcEnvironmentVariableIsSet("QTC_USE_MATCHER"); }
|
||||||
|
|
||||||
bool LocatorWidget::m_shuttingDown = false;
|
bool LocatorWidget::m_shuttingDown = false;
|
||||||
QFuture<void> LocatorWidget::m_sharedFuture;
|
QFuture<void> LocatorWidget::m_sharedFuture;
|
||||||
LocatorWidget *LocatorWidget::m_sharedFutureOrigin = nullptr;
|
LocatorWidget *LocatorWidget::m_sharedFutureOrigin = nullptr;
|
||||||
@@ -917,11 +920,80 @@ void LocatorWidget::setProgressIndicatorVisible(bool visible)
|
|||||||
m_progressIndicator->show();
|
m_progressIndicator->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocatorWidget::runMatcher(const QString &text)
|
||||||
|
{
|
||||||
|
QString searchText;
|
||||||
|
const QList<ILocatorFilter *> filters = filtersFor(text, searchText);
|
||||||
|
|
||||||
|
LocatorMatcherTasks tasks;
|
||||||
|
for (ILocatorFilter *filter : filters)
|
||||||
|
tasks += filter->matchers();
|
||||||
|
|
||||||
|
m_locatorMatcher.reset(new LocatorMatcher);
|
||||||
|
m_locatorMatcher->setTasks(tasks);
|
||||||
|
m_locatorMatcher->setInputData(searchText);
|
||||||
|
|
||||||
|
connect(m_locatorMatcher.get(), &LocatorMatcher::done, this, [this] {
|
||||||
|
m_showProgressTimer.stop();
|
||||||
|
setProgressIndicatorVisible(false);
|
||||||
|
m_updateRequested = false;
|
||||||
|
m_locatorMatcher.release()->deleteLater();
|
||||||
|
if (m_rowRequestedForAccept) {
|
||||||
|
acceptEntry(m_rowRequestedForAccept.value());
|
||||||
|
m_rowRequestedForAccept.reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_needsClearResult) {
|
||||||
|
m_locatorModel->clear();
|
||||||
|
m_needsClearResult = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(m_locatorMatcher.get(), &LocatorMatcher::serialOutputDataReady,
|
||||||
|
this, [this](const LocatorFilterEntries &serialOutputData) {
|
||||||
|
if (m_needsClearResult) {
|
||||||
|
m_locatorModel->clear();
|
||||||
|
m_needsClearResult = false;
|
||||||
|
}
|
||||||
|
const bool selectFirst = m_locatorModel->rowCount() == 0;
|
||||||
|
m_locatorModel->addEntries(serialOutputData);
|
||||||
|
if (selectFirst) {
|
||||||
|
emit selectRow(0);
|
||||||
|
if (m_rowRequestedForAccept)
|
||||||
|
m_rowRequestedForAccept = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_showProgressTimer.start();
|
||||||
|
m_needsClearResult = true;
|
||||||
|
m_updateRequested = true;
|
||||||
|
m_locatorMatcher->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove when switched the default into new implementation.
|
||||||
|
static void printMatcherInfo()
|
||||||
|
{
|
||||||
|
static bool printed = false;
|
||||||
|
if (printed)
|
||||||
|
return;
|
||||||
|
if (isUsingLocatorMatcher())
|
||||||
|
qDebug() << "QTC_USE_MATCHER env var set, using new LocatorMatcher implementation.";
|
||||||
|
else
|
||||||
|
qDebug() << "QTC_USE_MATCHER env var not set, using old matchesFor implementation.";
|
||||||
|
printed = true;
|
||||||
|
}
|
||||||
|
|
||||||
void LocatorWidget::updateCompletionList(const QString &text)
|
void LocatorWidget::updateCompletionList(const QString &text)
|
||||||
{
|
{
|
||||||
if (m_shuttingDown)
|
if (m_shuttingDown)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
printMatcherInfo();
|
||||||
|
|
||||||
|
if (isUsingLocatorMatcher()) {
|
||||||
|
runMatcher(text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_updateRequested = true;
|
m_updateRequested = true;
|
||||||
if (m_sharedFuture.isRunning()) {
|
if (m_sharedFuture.isRunning()) {
|
||||||
// Cancel the old future. We may not just block the UI thread to wait for the search to
|
// Cancel the old future. We may not just block the UI thread to wait for the search to
|
||||||
@@ -987,6 +1059,9 @@ void LocatorWidget::scheduleAcceptEntry(const QModelIndex &index)
|
|||||||
// accept will be called after the update finished
|
// accept will be called after the update finished
|
||||||
m_rowRequestedForAccept = index.row();
|
m_rowRequestedForAccept = index.row();
|
||||||
// do not wait for the rest of the search to finish
|
// do not wait for the rest of the search to finish
|
||||||
|
if (isUsingLocatorMatcher())
|
||||||
|
m_locatorMatcher.reset();
|
||||||
|
else
|
||||||
m_entriesWatcher->future().cancel();
|
m_entriesWatcher->future().cancel();
|
||||||
} else {
|
} else {
|
||||||
acceptEntry(index.row());
|
acceptEntry(index.row());
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ private:
|
|||||||
void updatePreviousFocusWidget(QWidget *previous, QWidget *current);
|
void updatePreviousFocusWidget(QWidget *previous, QWidget *current);
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
|
||||||
|
void runMatcher(const QString &text);
|
||||||
void updateCompletionList(const QString &text);
|
void updateCompletionList(const QString &text);
|
||||||
static QList<ILocatorFilter*> filtersFor(const QString &text, QString &searchText);
|
static QList<ILocatorFilter*> filtersFor(const QString &text, QString &searchText);
|
||||||
void setProgressIndicatorVisible(bool visible);
|
void setProgressIndicatorVisible(bool visible);
|
||||||
@@ -95,6 +96,7 @@ private:
|
|||||||
QTimer m_showProgressTimer;
|
QTimer m_showProgressTimer;
|
||||||
std::optional<int> m_rowRequestedForAccept;
|
std::optional<int> m_rowRequestedForAccept;
|
||||||
QPointer<QWidget> m_previousFocusWidget;
|
QPointer<QWidget> m_previousFocusWidget;
|
||||||
|
std::unique_ptr<LocatorMatcher> m_locatorMatcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LocatorPopup : public QWidget
|
class LocatorPopup : public QWidget
|
||||||
|
|||||||
Reference in New Issue
Block a user