forked from qt-creator/qt-creator
CppTools: Garbage collect if the last CppEditor is closed
Task-number: QTCREATORBUG-9828 Change-Id: Ie0ef9757cedb772702e49542b58d5b589506aa9e Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -618,21 +618,22 @@ void CppModelManager::deleteEditorSupport(TextEditor::BaseTextEditor *textEditor
|
||||
return;
|
||||
|
||||
CppEditorSupport *editorSupport;
|
||||
int numberOfOpenEditors = 0;
|
||||
|
||||
{ // only lock the operations on m_editorSupport
|
||||
QMutexLocker locker(&m_editorSupportMutex);
|
||||
editorSupport = m_editorSupport.value(textEditor, 0);
|
||||
m_editorSupport.remove(textEditor);
|
||||
numberOfOpenEditors = m_editorSupport.size();
|
||||
}
|
||||
|
||||
delete editorSupport;
|
||||
|
||||
++numberOfClosedEditors;
|
||||
if (numberOfClosedEditors == 5) {
|
||||
if (numberOfOpenEditors == 0 || numberOfClosedEditors == 5) {
|
||||
numberOfClosedEditors = 0;
|
||||
GC();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CppModelManager::isCppEditor(Core::IEditor *editor) const
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include "cpppreprocessor.h"
|
||||
#include "modelmanagertesthelper.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
@@ -413,3 +414,33 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
||||
sm->removeProject(project);
|
||||
ModelManagerTestHelper::verifyClean();
|
||||
}
|
||||
|
||||
/// QTCREATORBUG-9828: Locator shows symbols of closed files
|
||||
/// Check: The garbage collector should be run if the last CppEditor is closed.
|
||||
void CppToolsPlugin::test_modelmanager_gc_if_last_cppeditor_closed()
|
||||
{
|
||||
TestDataDirectory testDataDirectory(QLatin1String("testdata_guiproject1"));
|
||||
const QString file = testDataDirectory.file(QLatin1String("main.cpp"));
|
||||
|
||||
Core::EditorManager *em = Core::EditorManager::instance();
|
||||
CppModelManager *mm = CppModelManager::instance();
|
||||
|
||||
// Open a file in the editor
|
||||
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 0);
|
||||
Core::IEditor *editor = em->openEditor(file);
|
||||
QVERIFY(editor);
|
||||
QCOMPARE(Core::EditorManager::documentModel()->openedDocuments().size(), 1);
|
||||
QVERIFY(mm->isCppEditor(editor));
|
||||
QVERIFY(mm->workingCopy().contains(file));
|
||||
|
||||
// Check: File is in the snapshot
|
||||
QVERIFY(mm->snapshot().contains(file));
|
||||
|
||||
// Close file/editor
|
||||
const QList<Core::IEditor*> editorsToClose = QList<Core::IEditor*>() << editor;
|
||||
em->closeEditors(editorsToClose, /*askAboutModifiedEditors=*/ false);
|
||||
|
||||
// Check: File is removed from the snapshpt
|
||||
QVERIFY(!mm->workingCopy().contains(file));
|
||||
QVERIFY(!mm->snapshot().contains(file));
|
||||
}
|
||||
|
@@ -187,6 +187,7 @@ private slots:
|
||||
void test_modelmanager_refresh_2();
|
||||
void test_modelmanager_snapshot_after_two_projects();
|
||||
void test_modelmanager_extraeditorsupport_uiFiles();
|
||||
void test_modelmanager_gc_if_last_cppeditor_closed();
|
||||
|
||||
private:
|
||||
void test_completion();
|
||||
|
Reference in New Issue
Block a user