diff --git a/src/plugins/coreplugin/CMakeLists.txt b/src/plugins/coreplugin/CMakeLists.txt index a7d1e6cf20f..0869553d8c4 100644 --- a/src/plugins/coreplugin/CMakeLists.txt +++ b/src/plugins/coreplugin/CMakeLists.txt @@ -111,7 +111,6 @@ add_qtc_plugin(Core locator/locatorconstants.h locator/locatorfiltersfilter.cpp locator/locatorfiltersfilter.h locator/locatormanager.cpp locator/locatormanager.h - locator/locatorsearchutils.cpp locator/locatorsearchutils.h locator/locatorsettingspage.cpp locator/locatorsettingspage.h locator/locatorwidget.cpp locator/locatorwidget.h locator/opendocumentsfilter.cpp locator/opendocumentsfilter.h diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index 5d7524d8080..bf8e09b67b5 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -6,7 +6,6 @@ #include "designmode.h" #include "editmode.h" #include "foldernavigationwidget.h" -#include "helpmanager.h" #include "icore.h" #include "idocument.h" #include "iwizardfactory.h" @@ -472,8 +471,7 @@ QString CorePlugin::msgCrashpadInformation() ExtensionSystem::IPlugin::ShutdownFlag CorePlugin::aboutToShutdown() { Find::aboutToShutdown(); - ExtensionSystem::IPlugin::ShutdownFlag shutdownFlag = m_locator->aboutToShutdown( - [this] { emit asynchronousShutdownFinished(); }); + m_locator->aboutToShutdown(); m_mainWindow->aboutToShutdown(); - return shutdownFlag; + return SynchronousShutdown; } diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index 3adf5b461c2..654f2e6bcb6 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -350,8 +350,6 @@ Project { "locatormanager.h", "locator.cpp", "locator.h", - "locatorsearchutils.cpp", - "locatorsearchutils.h", "locatorsettingspage.cpp", "locatorsettingspage.h", "locatorwidget.cpp", diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.h b/src/plugins/coreplugin/locator/ilocatorfilter.h index 377dcd9eac1..9ded00c1d0a 100644 --- a/src/plugins/coreplugin/locator/ilocatorfilter.h +++ b/src/plugins/coreplugin/locator/ilocatorfilter.h @@ -229,7 +229,8 @@ public: virtual void prepareSearch(const QString &entry); - virtual QList matchesFor(QFutureInterface &future, const QString &entry) = 0; + virtual QList matchesFor(QFutureInterface &, + const QString &) { return {}; }; virtual QByteArray saveState() const; virtual void restoreState(const QByteArray &state); diff --git a/src/plugins/coreplugin/locator/locator.cpp b/src/plugins/coreplugin/locator/locator.cpp index 1072dc0eca0..30d996a08e8 100644 --- a/src/plugins/coreplugin/locator/locator.cpp +++ b/src/plugins/coreplugin/locator/locator.cpp @@ -145,13 +145,11 @@ bool Locator::delayedInitialize() return true; } -ExtensionSystem::IPlugin::ShutdownFlag Locator::aboutToShutdown( - const std::function &emitAsynchronousShutdownFinished) +void Locator::aboutToShutdown() { m_shuttingDown = true; m_refreshTimer.stop(); m_taskTree.reset(); - return LocatorWidget::aboutToShutdown(emitAsynchronousShutdownFinished); } void Locator::loadSettings() diff --git a/src/plugins/coreplugin/locator/locator.h b/src/plugins/coreplugin/locator/locator.h index 59da8767d8a..edf978e6973 100644 --- a/src/plugins/coreplugin/locator/locator.h +++ b/src/plugins/coreplugin/locator/locator.h @@ -30,8 +30,7 @@ public: ~Locator() override; static Locator *instance(); - ExtensionSystem::IPlugin::ShutdownFlag aboutToShutdown( - const std::function &emitAsynchronousShutdownFinished); + void aboutToShutdown(); void initialize(); void extensionsInitialized(); diff --git a/src/plugins/coreplugin/locator/locatorsearchutils.cpp b/src/plugins/coreplugin/locator/locatorsearchutils.cpp deleted file mode 100644 index a6a90107fe3..00000000000 --- a/src/plugins/coreplugin/locator/locatorsearchutils.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "locatorsearchutils.h" - -#include - -#include - -void Core::Internal::runSearch(QFutureInterface &future, - const QList &filters, const QString &searchText) -{ - std::unordered_set addedCache; - const bool checkDuplicates = (filters.size() > 1); - const auto duplicatesRemoved = [&](const QList &entries) { - if (!checkDuplicates) - return entries; - QList results; - results.reserve(entries.size()); - for (const LocatorFilterEntry &entry : entries) { - const auto &link = entry.linkForEditor; - if (!link || addedCache.emplace(*link).second) - results.append(entry); - } - return results; - }; - - for (ILocatorFilter *filter : filters) { - if (future.isCanceled()) - break; - const auto results = duplicatesRemoved(filter->matchesFor(future, searchText)); - if (!results.isEmpty()) - future.reportResults(results); - } -} diff --git a/src/plugins/coreplugin/locator/locatorsearchutils.h b/src/plugins/coreplugin/locator/locatorsearchutils.h deleted file mode 100644 index d863b580a67..00000000000 --- a/src/plugins/coreplugin/locator/locatorsearchutils.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include "ilocatorfilter.h" - -namespace Core { -namespace Internal { - -void CORE_EXPORT runSearch(QFutureInterface &future, - const QList &filters, - const QString &searchText); - -} // namespace Internal -} // namespace Core diff --git a/src/plugins/coreplugin/locator/locatorwidget.cpp b/src/plugins/coreplugin/locator/locatorwidget.cpp index 74b35abaf54..1384f7b5de0 100644 --- a/src/plugins/coreplugin/locator/locatorwidget.cpp +++ b/src/plugins/coreplugin/locator/locatorwidget.cpp @@ -7,7 +7,6 @@ #include "locator.h" #include "locatorconstants.h" #include "locatormanager.h" -#include "locatorsearchutils.h" #include "../actionmanager/actionmanager.h" #include "../coreplugintr.h" #include "../editormanager/editormanager.h" @@ -25,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -54,16 +52,6 @@ const int LocatorEntryRole = int(HighlightingItemRole::User); namespace Core { namespace Internal { -static bool isUsingLocatorMatcher() -{ - const QString value = qtcEnvironmentVariable("QTC_USE_MATCHER", "").toLower(); - return !(value == "false" || value == "off"); -} - -bool LocatorWidget::m_shuttingDown = false; -QFuture LocatorWidget::m_sharedFuture; -LocatorWidget *LocatorWidget::m_sharedFutureOrigin = nullptr; - /* A model to represent the Locator results. */ class LocatorModel : public QAbstractListModel { @@ -631,12 +619,6 @@ LocatorWidget::LocatorWidget(Locator *locator) connect(m_fileLineEdit, &QLineEdit::textChanged, this, &LocatorWidget::showPopupDelayed); - m_entriesWatcher = new QFutureWatcher(this); - connect(m_entriesWatcher, &QFutureWatcher::resultsReadyAt, - this, &LocatorWidget::addSearchResults); - connect(m_entriesWatcher, &QFutureWatcher::finished, - this, &LocatorWidget::handleSearchFinished); - m_showPopupTimer.setInterval(100); m_showPopupTimer.setSingleShot(true); connect(&m_showPopupTimer, &QTimer::timeout, this, &LocatorWidget::showPopupNow); @@ -664,12 +646,7 @@ LocatorWidget::LocatorWidget(Locator *locator) updateFilterList(); } -LocatorWidget::~LocatorWidget() -{ - // no need to completely finish a running search, cancel it - if (m_entriesWatcher->future().isRunning()) - m_entriesWatcher->future().cancel(); -} +LocatorWidget::~LocatorWidget() = default; void LocatorWidget::updatePlaceholderText(Command *command) { @@ -878,7 +855,7 @@ void LocatorWidget::showPopupDelayed() void LocatorWidget::showPopupNow() { m_showPopupTimer.stop(); - updateCompletionList(m_fileLineEdit->text()); + runMatcher(m_fileLineEdit->text()); emit showPopup(); } @@ -973,91 +950,6 @@ void LocatorWidget::runMatcher(const QString &text) m_locatorMatcher->start(); } -// TODO: Remove when switched the default into new implementation. -static void printMatcherInfo() -{ - static bool printed = false; - if (printed) - return; - printed = true; - if (isUsingLocatorMatcher()) { - qDebug() << "Using the new LocatorMatcher implementation (default). In order to switch " - "back to the old implementation, set QTC_USE_MATCHER=FALSE env var."; - return; - } - qDebug() << "QTC_USE_MATCHER env var set to FALSE, using the old matchesFor implementation."; -} - -void LocatorWidget::updateCompletionList(const QString &text) -{ - if (m_shuttingDown) - return; - - printMatcherInfo(); - - if (isUsingLocatorMatcher()) { - runMatcher(text); - return; - } - - m_updateRequested = true; - if (m_sharedFuture.isRunning()) { - // Cancel the old future. We may not just block the UI thread to wait for the search to - // actually cancel. - m_requestedCompletionText = text; - if (m_sharedFutureOrigin == this) { - // This locator widget is currently running. Make handleSearchFinished trigger another - // update. - m_rerunAfterFinished = true; - } else { - // Another locator widget is running. Trigger another update when that is finished. - Utils::onFinished(m_sharedFuture, this, [this](const QFuture &) { - const QString text = m_requestedCompletionText; - m_requestedCompletionText.clear(); - updateCompletionList(text); - }); - } - m_sharedFuture.cancel(); - return; - } - - m_showProgressTimer.start(); - m_needsClearResult = true; - QString searchText; - const QList filters = filtersFor(text, searchText); - - for (ILocatorFilter *filter : filters) - filter->prepareSearch(searchText); - QFuture future = Utils::runAsync(&runSearch, filters, searchText); - m_sharedFuture = QFuture(future); - m_sharedFutureOrigin = this; - m_entriesWatcher->setFuture(future); -} - -void LocatorWidget::handleSearchFinished() -{ - m_showProgressTimer.stop(); - setProgressIndicatorVisible(false); - m_updateRequested = false; - if (m_rowRequestedForAccept) { - acceptEntry(m_rowRequestedForAccept.value()); - m_rowRequestedForAccept.reset(); - return; - } - if (m_rerunAfterFinished) { - m_rerunAfterFinished = false; - const QString text = m_requestedCompletionText; - m_requestedCompletionText.clear(); - updateCompletionList(text); - return; - } - - if (m_needsClearResult) { - m_locatorModel->clear(); - m_needsClearResult = false; - } -} - void LocatorWidget::scheduleAcceptEntry(const QModelIndex &index) { if (m_updateRequested) { @@ -1065,31 +957,12 @@ void LocatorWidget::scheduleAcceptEntry(const QModelIndex &index) // accept will be called after the update finished m_rowRequestedForAccept = index.row(); // do not wait for the rest of the search to finish - if (isUsingLocatorMatcher()) - m_locatorMatcher.reset(); - else - m_entriesWatcher->future().cancel(); + m_locatorMatcher.reset(); } else { acceptEntry(index.row()); } } -ExtensionSystem::IPlugin::ShutdownFlag LocatorWidget::aboutToShutdown( - const std::function &emitAsynchronousShutdownFinished) -{ - m_shuttingDown = true; - if (m_sharedFuture.isRunning()) { - Utils::onFinished(m_sharedFuture, - Locator::instance(), - [emitAsynchronousShutdownFinished](const QFuture &) { - emitAsynchronousShutdownFinished(); - }); - m_sharedFuture.cancel(); - return ExtensionSystem::IPlugin::AsynchronousShutdown; - } - return ExtensionSystem::IPlugin::SynchronousShutdown; -} - void LocatorWidget::acceptEntry(int row) { if (row < 0 || row >= m_locatorModel->rowCount()) @@ -1150,24 +1023,6 @@ void LocatorWidget::showConfigureDialog() ICore::showOptionsDialog(Constants::FILTER_OPTIONS_PAGE); } -void LocatorWidget::addSearchResults(int firstIndex, int endIndex) -{ - if (m_needsClearResult) { - m_locatorModel->clear(); - m_needsClearResult = false; - } - const bool selectFirst = m_locatorModel->rowCount() == 0; - QList entries; - for (int i = firstIndex; i < endIndex; ++i) - entries.append(m_entriesWatcher->resultAt(i)); - m_locatorModel->addEntries(entries); - if (selectFirst) { - emit selectRow(0); - if (m_rowRequestedForAccept) - m_rowRequestedForAccept = 0; - } -} - LocatorWidget *createStaticLocatorWidget(Locator *locator) { auto widget = new LocatorWidget(locator); diff --git a/src/plugins/coreplugin/locator/locatorwidget.h b/src/plugins/coreplugin/locator/locatorwidget.h index 4f6c1560ce5..ec3eca56f89 100644 --- a/src/plugins/coreplugin/locator/locatorwidget.h +++ b/src/plugins/coreplugin/locator/locatorwidget.h @@ -44,9 +44,6 @@ public: void scheduleAcceptEntry(const QModelIndex &index); - static ExtensionSystem::IPlugin::ShutdownFlag aboutToShutdown( - const std::function &emitAsynchronousShutdownFinished); - signals: void showCurrentItemToolTip(); void lostFocus(); @@ -61,8 +58,6 @@ private: void showPopupNow(); void acceptEntry(int row); static void showConfigureDialog(); - void addSearchResults(int firstIndex, int endIndex); - void handleSearchFinished(); void updateFilterList(); bool isInMainWindow() const; @@ -70,27 +65,18 @@ private: bool eventFilter(QObject *obj, QEvent *event) override; void runMatcher(const QString &text); - void updateCompletionList(const QString &text); static QList filtersFor(const QString &text, QString &searchText); void setProgressIndicatorVisible(bool visible); LocatorModel *m_locatorModel = nullptr; - - static bool m_shuttingDown; - static QFuture m_sharedFuture; - static LocatorWidget *m_sharedFutureOrigin; - QMenu *m_filterMenu = nullptr; QAction *m_centeredPopupAction = nullptr; QAction *m_refreshAction = nullptr; QAction *m_configureAction = nullptr; Utils::FancyLineEdit *m_fileLineEdit = nullptr; QTimer m_showPopupTimer; - QFutureWatcher *m_entriesWatcher = nullptr; - QString m_requestedCompletionText; bool m_needsClearResult = true; bool m_updateRequested = false; - bool m_rerunAfterFinished = false; bool m_possibleToolTipRequest = false; QWidget *m_progressIndicator = nullptr; QTimer m_showProgressTimer;