Centralize a PluginManager::isShuttingDown() status

Instead of keeping track of this in plugins individually.

Change-Id: Ia2650f0f647d4a63d2010cef688aa56f6020c338
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2023-05-22 13:21:57 +02:00
parent 323c58fd20
commit ee6789c523
14 changed files with 29 additions and 43 deletions

View File

@@ -1034,6 +1034,7 @@ void PluginManagerPrivate::readSettings()
*/
void PluginManagerPrivate::stopAll()
{
m_isShuttingDown = true;
if (delayedInitializeTimer && delayedInitializeTimer->isActive()) {
delayedInitializeTimer->stop();
delete delayedInitializeTimer;
@@ -1839,6 +1840,11 @@ bool PluginManager::isInitializationDone()
return d->m_isInitializationDone;
}
bool PluginManager::isShuttingDown()
{
return d->m_isShuttingDown;
}
/*!
Retrieves one object with \a name from the object pool.
\sa addObject()

View File

@@ -129,6 +129,7 @@ public:
static QString platformName();
static bool isInitializationDone();
static bool isShuttingDown();
static void remoteArguments(const QString &serializedArguments, QObject *socket);
static void shutdown();

View File

@@ -124,6 +124,7 @@ public:
bool m_isInitializationDone = false;
bool enableCrashCheck = true;
bool m_isShuttingDown = false;
QHash<QString, std::function<bool()>> m_scenarios;
QString m_requestedScenario;

View File

@@ -26,6 +26,8 @@
#include "../settingsdatabase.h"
#include "../statusbarmanager.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/async.h>
#include <utils/qtcassert.h>
@@ -147,7 +149,6 @@ bool Locator::delayedInitialize()
void Locator::aboutToShutdown()
{
m_shuttingDown = true;
m_refreshTimer.stop();
m_taskTree.reset();
}
@@ -373,7 +374,7 @@ void Locator::setUseCenteredPopupForShortcut(bool center)
void Locator::refresh(const QList<ILocatorFilter *> &filters)
{
if (m_shuttingDown)
if (ExtensionSystem::PluginManager::isShuttingDown())
return;
m_taskTree.reset(); // Superfluous, just for clarity. The next reset() below is enough.

View File

@@ -67,7 +67,6 @@ private:
bool useCenteredPopup = false;
};
bool m_shuttingDown = false;
bool m_settingsInitialized = false;
Settings m_settings;
QList<ILocatorFilter *> m_filters;

View File

@@ -686,7 +686,6 @@ public:
EngineManager m_engineManager;
QTimer m_shutdownTimer;
bool m_shuttingDown = false;
Console m_console; // ensure Debugger Console is created before settings are taken into account
DebuggerSettings m_debuggerSettings;
@@ -1392,7 +1391,7 @@ static QVariant configValue(const QString &name)
void DebuggerPluginPrivate::updatePresetState()
{
if (m_shuttingDown)
if (PluginManager::isShuttingDown())
return;
Project *startupProject = ProjectManager::startupProject();
@@ -1996,8 +1995,6 @@ void DebuggerPluginPrivate::dumpLog()
void DebuggerPluginPrivate::aboutToShutdown()
{
m_shuttingDown = true;
disconnect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, this, nullptr);
m_shutdownTimer.setInterval(0);
@@ -2081,7 +2078,7 @@ QWidget *addSearch(BaseTreeView *treeView)
void openTextEditor(const QString &titlePattern0, const QString &contents)
{
if (dd->m_shuttingDown)
if (PluginManager::isShuttingDown())
return;
QString titlePattern = titlePattern0;
IEditor *editor = EditorManager::openEditorWithContents(

View File

@@ -135,11 +135,6 @@ void EmacsKeysPlugin::extensionsInitialized()
{
}
ExtensionSystem::IPlugin::ShutdownFlag EmacsKeysPlugin::aboutToShutdown()
{
return SynchronousShutdown;
}
void EmacsKeysPlugin::editorAboutToClose(IEditor *editor)
{
auto w = qobject_cast<QPlainTextEdit*>(editor->widget());

View File

@@ -57,7 +57,6 @@ public:
void initialize() override;
void extensionsInitialized() override;
ShutdownFlag aboutToShutdown() override;
private:
void editorAboutToClose(Core::IEditor *editor);

View File

@@ -28,6 +28,8 @@
#include <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <languageserverprotocol/completion.h>
#include <languageserverprotocol/diagnostics.h>
#include <languageserverprotocol/initializemessages.h>
@@ -194,7 +196,7 @@ public:
// temporary container needed since m_resetAssistProvider is changed in resetAssistProviders
for (TextDocument *document : m_resetAssistProvider.keys())
resetAssistProviders(document);
if (!LanguageClientManager::isShuttingDown()) {
if (!ExtensionSystem::PluginManager::isShuttingDown()) {
// prevent accessing deleted editors on Creator shutdown
const QList<Core::IEditor *> &editors = Core::DocumentModel::editorsForOpenedDocuments();
for (Core::IEditor *editor : editors) {

View File

@@ -14,6 +14,8 @@
#include <coreplugin/icore.h>
#include <coreplugin/navigationwidget.h>
#include <extensionsystem/pluginmanager.h>
#include <languageserverprotocol/messages.h>
#include <languageserverprotocol/progresssupport.h>
@@ -32,6 +34,7 @@
#include <QTimer>
using namespace ExtensionSystem;
using namespace LanguageServerProtocol;
namespace LanguageClient {
@@ -39,7 +42,6 @@ namespace LanguageClient {
static Q_LOGGING_CATEGORY(Log, "qtc.languageclient.manager", QtWarningMsg)
static LanguageClientManager *managerInstance = nullptr;
static bool g_shuttingDown = false;
class LanguageClientManagerPrivate
{
@@ -139,7 +141,7 @@ void LanguageClientManager::clientStarted(Client *client)
QTC_ASSERT(client, return);
if (client->state() != Client::Uninitialized) // do not proceed if we already received an error
return;
if (g_shuttingDown) {
if (PluginManager::isShuttingDown()) {
clientFinished(client);
return;
}
@@ -165,7 +167,7 @@ void LanguageClientManager::clientFinished(Client *client)
&& client->state() != Client::ShutdownRequested;
if (unexpectedFinish) {
if (!g_shuttingDown) {
if (!PluginManager::isShuttingDown()) {
const QList<TextEditor::TextDocument *> &clientDocs
= managerInstance->m_clientForDocument.keys(client);
if (client->reset()) {
@@ -187,7 +189,7 @@ void LanguageClientManager::clientFinished(Client *client)
}
}
deleteClient(client);
if (g_shuttingDown && managerInstance->m_clients.isEmpty())
if (PluginManager::isShuttingDown() && managerInstance->m_clients.isEmpty())
emit managerInstance->shutdownFinished();
}
@@ -236,17 +238,14 @@ void LanguageClientManager::deleteClient(Client *client)
for (QList<Client *> &clients : managerInstance->m_clientsForSetting)
clients.removeAll(client);
client->deleteLater();
if (!g_shuttingDown)
if (!PluginManager::isShuttingDown())
emit instance()->clientRemoved(client);
}
void LanguageClientManager::shutdown()
{
QTC_ASSERT(managerInstance, return);
if (g_shuttingDown)
return;
qCDebug(Log) << "shutdown manager";
g_shuttingDown = true;
const auto clients = managerInstance->clients();
for (Client *client : clients)
shutdownClient(client);
@@ -258,11 +257,6 @@ void LanguageClientManager::shutdown()
});
}
bool LanguageClientManager::isShuttingDown()
{
return g_shuttingDown;
}
LanguageClientManager *LanguageClientManager::instance()
{
return managerInstance;

View File

@@ -48,7 +48,6 @@ public:
static void deleteClient(Client *client);
static void shutdown();
static bool isShuttingDown();
static LanguageClientManager *instance();

View File

@@ -177,6 +177,7 @@
*/
using namespace Core;
using namespace ExtensionSystem;
using namespace ProjectExplorer::Internal;
using namespace Utils;
@@ -600,7 +601,6 @@ public:
BuildPropertiesSettings m_buildPropertiesSettings;
QList<CustomParserSettings> m_customParsers;
bool m_shouldHaveRunConfiguration = false;
bool m_shuttingDown = false;
Id m_runMode = Constants::NO_RUN_MODE;
ToolChainManager *m_toolChainManager = nullptr;
@@ -1632,11 +1632,11 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
connect(ICore::instance(), &ICore::saveSettingsRequested,
dd, &ProjectExplorerPluginPrivate::savePersistentSettings);
connect(EditorManager::instance(), &EditorManager::autoSaved, this, [] {
if (!dd->m_shuttingDown && !SessionManager::loadingSession())
if (!PluginManager::isShuttingDown() && !SessionManager::loadingSession())
SessionManager::saveSession();
});
connect(qApp, &QApplication::applicationStateChanged, this, [](Qt::ApplicationState state) {
if (!dd->m_shuttingDown && state == Qt::ApplicationActive)
if (!PluginManager::isShuttingDown() && state == Qt::ApplicationActive)
dd->updateWelcomePage();
});
@@ -2173,7 +2173,7 @@ void ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu()
m_runWithoutDeployAction->setVisible(m_projectExplorerSettings.deployBeforeRun);
}
ExtensionSystem::IPlugin::ShutdownFlag ProjectExplorerPlugin::aboutToShutdown()
IPlugin::ShutdownFlag ProjectExplorerPlugin::aboutToShutdown()
{
disconnect(ModeManager::instance(), &ModeManager::currentModeChanged,
dd, &ProjectExplorerPluginPrivate::currentModeChanged);
@@ -2181,8 +2181,6 @@ ExtensionSystem::IPlugin::ShutdownFlag ProjectExplorerPlugin::aboutToShutdown()
ToolChainManager::aboutToShutdown();
ProjectManager::closeAllProjects();
dd->m_shuttingDown = true;
// Attempt to synchronously shutdown all run controls.
// If that fails, fall back to asynchronous shutdown (Debugger run controls
// might shutdown asynchronously).
@@ -2251,7 +2249,7 @@ bool ProjectExplorerPluginPrivate::closeAllFilesInProject(const Project *project
void ProjectExplorerPluginPrivate::savePersistentSettings()
{
if (dd->m_shuttingDown)
if (PluginManager::isShuttingDown())
return;
if (!SessionManager::loadingSession()) {
@@ -2560,7 +2558,7 @@ void ProjectExplorerPluginPrivate::checkForShutdown()
{
--m_activeRunControlCount;
QTC_ASSERT(m_activeRunControlCount >= 0, m_activeRunControlCount = 0);
if (m_shuttingDown && m_activeRunControlCount == 0)
if (PluginManager::isShuttingDown() && m_activeRunControlCount == 0)
emit m_instance->asynchronousShutdownFinished();
}

View File

@@ -210,11 +210,6 @@ void QmlJSEditorPlugin::extensionsInitialized()
QmllsSettingsManager::instance()->setupAutoupdate();
}
ExtensionSystem::IPlugin::ShutdownFlag QmlJSEditorPlugin::aboutToShutdown()
{
return IPlugin::aboutToShutdown();
}
Utils::JsonSchemaManager *QmlJSEditorPlugin::jsonManager()
{
return &m_instance->d->m_jsonManager;

View File

@@ -29,7 +29,6 @@ public:
private:
void initialize() final;
void extensionsInitialized() final;
ShutdownFlag aboutToShutdown() final;
class QmlJSEditorPluginPrivate *d = nullptr;
};