Utils: Introduce GlobalFileChangeBlocker

Tracks application state, and signals when it is changed.

Supports forcing blocked state with reference counting.

Change-Id: Ic173d42446b1b08bd4a1e7c1acf38c68644d30b3
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Orgad Shaneh
2018-12-16 00:32:14 +02:00
committed by Orgad Shaneh
parent 81ce096719
commit c225216b93
15 changed files with 152 additions and 71 deletions

View File

@@ -44,6 +44,7 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/fileutils.h>
#include <utils/globalfilechangeblocker.h>
#include <utils/hostosinfo.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcassert.h>
@@ -229,7 +230,13 @@ DocumentManager::DocumentManager(QObject *parent)
{
d = new DocumentManagerPrivate;
m_instance = this;
qApp->installEventFilter(this);
connect(Utils::GlobalFileChangeBlocker::instance(), &Utils::GlobalFileChangeBlocker::stateChanged,
this, [this](bool blocked) {
d->m_postponeAutoReload = blocked;
if (!blocked)
QTimer::singleShot(500, m_instance, &DocumentManager::checkForReload);
});
readSettings();
@@ -597,13 +604,6 @@ void DocumentManager::unexpectFileChange(const QString &fileName)
updateExpectedState(filePathKey(fileName, ResolveLinks));
}
void DocumentManager::setAutoReloadPostponed(bool postponed)
{
d->m_postponeAutoReload = postponed;
if (!postponed)
QTimer::singleShot(500, m_instance, &DocumentManager::checkForReload);
}
static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
const QString &message, bool *cancelled, bool silently,
const QString &alwaysSaveMessage, bool *alwaysSave,
@@ -1470,14 +1470,6 @@ void DocumentManager::notifyFilesChangedInternally(const QStringList &files)
emit m_instance->filesChangedInternally(files);
}
bool DocumentManager::eventFilter(QObject *obj, QEvent *e)
{
if (obj == qApp && e->type() == QEvent::ApplicationStateChange) {
QTimer::singleShot(0, this, &DocumentManager::checkForReload);
}
return false;
}
// -------------- FileChangeBlocker
FileChangeBlocker::FileChangeBlocker(const QString &fileName)