summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpptoolseditorsupport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cpptools/cpptoolseditorsupport.cpp')
-rw-r--r--src/plugins/cpptools/cpptoolseditorsupport.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp
index 631b1c1a44..e9ec1d23a0 100644
--- a/src/plugins/cpptools/cpptoolseditorsupport.cpp
+++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp
@@ -115,6 +115,7 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
, m_textEditor(textEditor)
, m_updateDocumentInterval(UpdateDocumentDefaultInterval)
, m_revision(0)
+ , m_editorVisible(textEditor->widget()->isVisible())
, m_cachedContentsEditorRevision(-1)
, m_fileIsBeingReloaded(false)
, m_initialized(false)
@@ -152,6 +153,13 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
connect(m_textEditor->document(), SIGNAL(reloadFinished(bool)),
this, SLOT(onReloadFinished()));
+ connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor *)),
+ this, SLOT(onCurrentEditorChanged()));
+ m_editorGCTimer = new QTimer(this);
+ m_editorGCTimer->setSingleShot(true);
+ m_editorGCTimer->setInterval(EditorHiddenGCTimeout);
+ connect(m_editorGCTimer, SIGNAL(timeout()), this, SLOT(releaseResources()));
+
updateDocument();
}
@@ -460,6 +468,30 @@ void CppEditorSupport::updateEditorNow()
editorWidget->setIfdefedOutBlocks(m_editorUpdates.ifdefedOutBlocks);
}
+void CppEditorSupport::onCurrentEditorChanged()
+{
+ bool editorVisible = m_textEditor->widget()->isVisible();
+
+ if (m_editorVisible != editorVisible) {
+ m_editorVisible = editorVisible;
+ if (editorVisible) {
+ m_editorGCTimer->stop();
+ QMutexLocker locker(&m_lastSemanticInfoLock);
+ if (!m_lastSemanticInfo.doc)
+ updateDocumentNow();
+ } else {
+ m_editorGCTimer->start(EditorHiddenGCTimeout);
+ }
+ }
+}
+
+void CppEditorSupport::releaseResources()
+{
+ snapshotUpdater()->releaseSnapshot();
+ QMutexLocker semanticLocker(&m_lastSemanticInfoLock);
+ m_lastSemanticInfo = SemanticInfo();
+}
+
SemanticInfo::Source CppEditorSupport::currentSource(bool force)
{
int line = 0, column = 0;