forked from qt-creator/qt-creator
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:
committed by
Orgad Shaneh
parent
81ce096719
commit
c225216b93
@@ -48,6 +48,7 @@
|
||||
#include <clangsupport/filecontainer.h>
|
||||
#include <clangsupport/clangcodemodelservermessages.h>
|
||||
|
||||
#include <utils/globalfilechangeblocker.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDateTime>
|
||||
@@ -104,6 +105,10 @@ BackendCommunicator::BackendCommunicator()
|
||||
this, &BackendCommunicator::onEditorAboutToClose);
|
||||
connect(Core::ICore::instance(), &Core::ICore::coreAboutToClose,
|
||||
this, &BackendCommunicator::setupDummySender);
|
||||
auto globalFCB = ::Utils::GlobalFileChangeBlocker::instance();
|
||||
m_postponeBackendJobs = globalFCB->isBlocked();
|
||||
connect(globalFCB, &::Utils::GlobalFileChangeBlocker::stateChanged,
|
||||
this, &BackendCommunicator::setBackendJobsPostponed);
|
||||
|
||||
initializeBackend();
|
||||
}
|
||||
@@ -210,14 +215,11 @@ bool BackendCommunicator::isNotWaitingForCompletion() const
|
||||
void BackendCommunicator::setBackendJobsPostponed(bool postponed)
|
||||
{
|
||||
if (postponed) {
|
||||
if (!m_postponeBackendJobs)
|
||||
documentVisibilityChanged(Utf8String(), {});
|
||||
++m_postponeBackendJobs;
|
||||
documentVisibilityChanged(Utf8String(), {});
|
||||
m_postponeBackendJobs = postponed;
|
||||
} else {
|
||||
if (QTC_GUARD(m_postponeBackendJobs > 0))
|
||||
--m_postponeBackendJobs;
|
||||
if (!m_postponeBackendJobs)
|
||||
documentVisibilityChanged();
|
||||
m_postponeBackendJobs = postponed;
|
||||
documentVisibilityChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ private:
|
||||
QTimer m_backendStartTimeOut;
|
||||
QScopedPointer<ClangBackEnd::ClangCodeModelServerInterface> m_sender;
|
||||
int m_connectedCount = 0;
|
||||
int m_postponeBackendJobs = 1; // Initial application state is inactive, so no jobs should be run.
|
||||
bool m_postponeBackendJobs = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -76,8 +76,6 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
||||
QTC_CHECK(!m_instance);
|
||||
m_instance = this;
|
||||
|
||||
QApplication::instance()->installEventFilter(this);
|
||||
|
||||
CppTools::CppModelManager::instance()->setCurrentDocumentFilter(
|
||||
std::make_unique<ClangCurrentDocumentFilter>());
|
||||
|
||||
@@ -141,11 +139,6 @@ std::unique_ptr<CppTools::AbstractOverviewModel> ClangModelManagerSupport::creat
|
||||
return std::make_unique<OverviewModel>();
|
||||
}
|
||||
|
||||
void ClangModelManagerSupport::setBackendJobsPostponed(bool postponed)
|
||||
{
|
||||
m_communicator.setBackendJobsPostponed(postponed);
|
||||
}
|
||||
|
||||
CppTools::BaseEditorDocumentProcessor *ClangModelManagerSupport::createEditorDocumentProcessor(
|
||||
TextEditor::TextDocument *baseTextDocument)
|
||||
{
|
||||
@@ -219,20 +212,6 @@ void ClangModelManagerSupport::connectToWidgetsMarkContextMenuRequested(QWidget
|
||||
}
|
||||
}
|
||||
|
||||
bool ClangModelManagerSupport::eventFilter(QObject *obj, QEvent *e)
|
||||
{
|
||||
if (obj == QApplication::instance() && e->type() == QEvent::ApplicationStateChange) {
|
||||
switch (QApplication::applicationState()) {
|
||||
case Qt::ApplicationInactive: setBackendJobsPostponed(true); break;
|
||||
case Qt::ApplicationActive: setBackendJobsPostponed(false); break;
|
||||
default:
|
||||
QTC_CHECK(false && "Unexpected Qt::ApplicationState");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)
|
||||
{
|
||||
QTC_ASSERT(editor, return);
|
||||
|
||||
@@ -72,7 +72,6 @@ public:
|
||||
CppTools::FollowSymbolInterface &followSymbolInterface() override;
|
||||
CppTools::RefactoringEngineInterface &refactoringEngineInterface() override;
|
||||
std::unique_ptr<CppTools::AbstractOverviewModel> createOverviewModel() override;
|
||||
void setBackendJobsPostponed(bool postponed) override;
|
||||
|
||||
BackendCommunicator &communicator();
|
||||
QString dummyUiHeaderOnDiskDirPath() const;
|
||||
@@ -83,8 +82,6 @@ public:
|
||||
static ClangModelManagerSupport *instance();
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject *obj, QEvent *e) override;
|
||||
|
||||
void onEditorOpened(Core::IEditor *editor);
|
||||
void onEditorClosed(const QList<Core::IEditor *> &editors);
|
||||
void onCurrentEditorChanged(Core::IEditor *newCurrent);
|
||||
|
||||
Reference in New Issue
Block a user