forked from qt-creator/qt-creator
Locator: Do not block main event loop
There are multiple locator filters (SpotlightLocatorFilter,
JavaScriptFilter, HelpIndexFilter, the LanguageClient filters) that
depend on the main event loop, and might lock up if that does not run
anymore.
So we cannot use waitForFinished. Cancel a running locator search, and
tell the plugin manager that we need to wait for asynchronous events to
finish before shutting down.
Amends cb5977fbad
Change-Id: Id0b3dc75bc22f21b34be39c3bdbec915b60bdee6
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -443,7 +443,8 @@ QString CorePlugin::msgCrashpadInformation()
|
|||||||
ExtensionSystem::IPlugin::ShutdownFlag CorePlugin::aboutToShutdown()
|
ExtensionSystem::IPlugin::ShutdownFlag CorePlugin::aboutToShutdown()
|
||||||
{
|
{
|
||||||
Find::aboutToShutdown();
|
Find::aboutToShutdown();
|
||||||
m_locator->aboutToShutdown();
|
ExtensionSystem::IPlugin::ShutdownFlag shutdownFlag = m_locator->aboutToShutdown(
|
||||||
|
[this] { emit asynchronousShutdownFinished(); });
|
||||||
m_mainWindow->aboutToShutdown();
|
m_mainWindow->aboutToShutdown();
|
||||||
return SynchronousShutdown;
|
return shutdownFlag;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,7 +169,8 @@ bool Locator::delayedInitialize()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Locator::aboutToShutdown()
|
ExtensionSystem::IPlugin::ShutdownFlag Locator::aboutToShutdown(
|
||||||
|
const std::function<void()> &emitAsynchronousShutdownFinished)
|
||||||
{
|
{
|
||||||
m_shuttingDown = true;
|
m_shuttingDown = true;
|
||||||
m_refreshTimer.stop();
|
m_refreshTimer.stop();
|
||||||
@@ -177,7 +178,7 @@ void Locator::aboutToShutdown()
|
|||||||
m_refreshTask.cancel();
|
m_refreshTask.cancel();
|
||||||
m_refreshTask.waitForFinished();
|
m_refreshTask.waitForFinished();
|
||||||
}
|
}
|
||||||
emit aboutToShutdownOccurred();
|
return LocatorWidget::aboutToShutdown(emitAsynchronousShutdownFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Locator::loadSettings()
|
void Locator::loadSettings()
|
||||||
|
|||||||
@@ -29,11 +29,14 @@
|
|||||||
#include "locatorconstants.h"
|
#include "locatorconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -48,7 +51,8 @@ public:
|
|||||||
~Locator() override;
|
~Locator() override;
|
||||||
|
|
||||||
static Locator *instance();
|
static Locator *instance();
|
||||||
void aboutToShutdown();
|
ExtensionSystem::IPlugin::ShutdownFlag aboutToShutdown(
|
||||||
|
const std::function<void()> &emitAsynchronousShutdownFinished);
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
@@ -63,7 +67,6 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void filtersChanged();
|
void filtersChanged();
|
||||||
void aboutToShutdownOccurred();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void refresh(QList<ILocatorFilter *> filters);
|
void refresh(QList<ILocatorFilter *> filters);
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ const int LocatorEntryRole = int(HighlightingItemRole::User);
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@@ -619,13 +620,6 @@ LocatorWidget::LocatorWidget(Locator *locator) :
|
|||||||
connect(qApp, &QApplication::focusChanged, this, &LocatorWidget::updatePreviousFocusWidget);
|
connect(qApp, &QApplication::focusChanged, this, &LocatorWidget::updatePreviousFocusWidget);
|
||||||
|
|
||||||
connect(locator, &Locator::filtersChanged, this, &LocatorWidget::updateFilterList);
|
connect(locator, &Locator::filtersChanged, this, &LocatorWidget::updateFilterList);
|
||||||
connect(locator, &Locator::aboutToShutdownOccurred, this, [this]() {
|
|
||||||
m_shuttingDown = true;
|
|
||||||
if (m_entriesWatcher->isRunning()) {
|
|
||||||
m_entriesWatcher->cancel();
|
|
||||||
m_entriesWatcher->waitForFinished();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
updateFilterList();
|
updateFilterList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -912,6 +906,22 @@ void LocatorWidget::scheduleAcceptEntry(const QModelIndex &index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExtensionSystem::IPlugin::ShutdownFlag LocatorWidget::aboutToShutdown(
|
||||||
|
const std::function<void()> &emitAsynchronousShutdownFinished)
|
||||||
|
{
|
||||||
|
m_shuttingDown = true;
|
||||||
|
if (m_sharedFuture.isRunning()) {
|
||||||
|
Utils::onFinished(m_sharedFuture,
|
||||||
|
Locator::instance(),
|
||||||
|
[emitAsynchronousShutdownFinished](const QFuture<void> &) {
|
||||||
|
emitAsynchronousShutdownFinished();
|
||||||
|
});
|
||||||
|
m_sharedFuture.cancel();
|
||||||
|
return ExtensionSystem::IPlugin::AsynchronousShutdown;
|
||||||
|
}
|
||||||
|
return ExtensionSystem::IPlugin::SynchronousShutdown;
|
||||||
|
}
|
||||||
|
|
||||||
void LocatorWidget::acceptEntry(int row)
|
void LocatorWidget::acceptEntry(int row)
|
||||||
{
|
{
|
||||||
if (row < 0 || row >= m_locatorModel->rowCount())
|
if (row < 0 || row >= m_locatorModel->rowCount())
|
||||||
|
|||||||
@@ -27,12 +27,15 @@
|
|||||||
|
|
||||||
#include "locator.h"
|
#include "locator.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
#include <utils/optional.h>
|
#include <utils/optional.h>
|
||||||
|
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
class QAction;
|
class QAction;
|
||||||
@@ -63,6 +66,9 @@ public:
|
|||||||
|
|
||||||
void scheduleAcceptEntry(const QModelIndex &index);
|
void scheduleAcceptEntry(const QModelIndex &index);
|
||||||
|
|
||||||
|
static ExtensionSystem::IPlugin::ShutdownFlag aboutToShutdown(
|
||||||
|
const std::function<void()> &emitAsynchronousShutdownFinished);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void showCurrentItemToolTip();
|
void showCurrentItemToolTip();
|
||||||
void lostFocus();
|
void lostFocus();
|
||||||
@@ -91,16 +97,17 @@ private:
|
|||||||
|
|
||||||
LocatorModel *m_locatorModel = nullptr;
|
LocatorModel *m_locatorModel = nullptr;
|
||||||
|
|
||||||
|
static bool m_shuttingDown;
|
||||||
|
static QFuture<void> m_sharedFuture;
|
||||||
|
static LocatorWidget *m_sharedFutureOrigin;
|
||||||
|
|
||||||
QMenu *m_filterMenu = nullptr;
|
QMenu *m_filterMenu = nullptr;
|
||||||
QAction *m_refreshAction = nullptr;
|
QAction *m_refreshAction = nullptr;
|
||||||
QAction *m_configureAction = nullptr;
|
QAction *m_configureAction = nullptr;
|
||||||
Utils::FancyLineEdit *m_fileLineEdit = nullptr;
|
Utils::FancyLineEdit *m_fileLineEdit = nullptr;
|
||||||
QTimer m_showPopupTimer;
|
QTimer m_showPopupTimer;
|
||||||
QFutureWatcher<LocatorFilterEntry> *m_entriesWatcher = nullptr;
|
QFutureWatcher<LocatorFilterEntry> *m_entriesWatcher = nullptr;
|
||||||
static QFuture<void> m_sharedFuture;
|
|
||||||
static LocatorWidget *m_sharedFutureOrigin;
|
|
||||||
QString m_requestedCompletionText;
|
QString m_requestedCompletionText;
|
||||||
bool m_shuttingDown = false;
|
|
||||||
bool m_needsClearResult = true;
|
bool m_needsClearResult = true;
|
||||||
bool m_updateRequested = false;
|
bool m_updateRequested = false;
|
||||||
bool m_rerunAfterFinished = false;
|
bool m_rerunAfterFinished = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user