Commit 8a31388f authored by Eike Ziller's avatar Eike Ziller

EditorManager: Close documents instead of editors where appropriate

This is the first step in actually making "closeEditor(s)" close editors
instead of documents.

Change-Id: I02761e0cef950b8fc093f65a90df04a9a7550681
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 5a0a61bf
......@@ -2364,7 +2364,7 @@ public:
~TestCase()
{
Core::EditorManager::closeEditor(m_editor, false);
Core::EditorManager::closeDocument(m_editor->document(), false);
QCoreApplication::processEvents(); // process any pending events
QFile file(m_fileName);
......
......@@ -1576,7 +1576,7 @@ void EditorManagerPrivate::closeEditorFromContextMenu()
{
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
if (document)
EditorManager::closeEditors(DocumentModel::editorsForDocument(document));
EditorManager::closeDocument(document);
}
void EditorManagerPrivate::closeOtherDocumentsFromContextMenu()
......@@ -2327,6 +2327,11 @@ QList<IEditor*> EditorManager::visibleEditors()
return editors;
}
bool EditorManager::closeDocument(IDocument *document, bool askAboutModifiedEditors)
{
return closeDocuments(QList<IDocument *>() << document, askAboutModifiedEditors);
}
bool EditorManager::closeDocuments(const QList<IDocument *> &document, bool askAboutModifiedEditors)
{
return m_instance->closeEditors(DocumentModel::editorsForDocuments(document), askAboutModifiedEditors);
......
......@@ -132,6 +132,7 @@ public:
static void activateEditorForEntry(DocumentModel::Entry *entry, OpenEditorFlags flags = 0);
static IEditor *activateEditorForDocument(IDocument *document, OpenEditorFlags flags = 0);
static bool closeDocument(IDocument *document, bool askAboutModifiedEditors = true);
static bool closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true);
static void closeDocument(DocumentModel::Entry *entry);
static void closeOtherDocuments(IDocument *document);
......
......@@ -730,7 +730,7 @@ void CppToolsPlugin::test_modelmanager_gc_if_last_cppeditor_closed()
helper.waitForRefreshedSourceFiles();
// Close file/editor
Core::EditorManager::closeEditor(editor, /*askAboutModifiedEditors=*/ false);
Core::EditorManager::closeDocument(editor->document(), /*askAboutModifiedEditors=*/ false);
helper.waitForFinishedGc();
// Check: File is removed from the snapshpt
......@@ -769,7 +769,7 @@ void CppToolsPlugin::test_modelmanager_dont_gc_opened_files()
QVERIFY(mm->snapshot().contains(file));
// Close editor
Core::EditorManager::closeEditor(editor);
Core::EditorManager::closeDocument(editor->document());
helper.waitForFinishedGc();
QVERIFY(mm->snapshot().isEmpty());
}
......
......@@ -104,11 +104,11 @@ void MemoryAgent::closeEditors()
if (m_editors.isEmpty())
return;
QList<IEditor *> editors;
QSet<IDocument *> documents;
foreach (QPointer<IEditor> editor, m_editors)
if (editor)
editors.append(editor.data());
EditorManager::closeEditors(editors);
documents.insert(editor->document());
EditorManager::closeDocuments(documents.toList());
m_editors.clear();
}
......
......@@ -340,15 +340,15 @@ QmlEngine::QmlEngine(const DebuggerStartParameters &startParameters, DebuggerEng
QmlEngine::~QmlEngine()
{
QList<Core::IEditor *> editorsToClose;
QSet<Core::IDocument *> documentsToClose;
QHash<QString, QWeakPointer<TextEditor::BaseTextEditor> >::iterator iter;
for (iter = m_sourceEditors.begin(); iter != m_sourceEditors.end(); ++iter) {
QWeakPointer<TextEditor::BaseTextEditor> textEditPtr = iter.value();
if (textEditPtr)
editorsToClose << textEditPtr.data();
documentsToClose << textEditPtr.data()->document();
}
Core::EditorManager::closeEditors(editorsToClose);
Core::EditorManager::closeDocuments(documentsToClose.toList());
}
void QmlEngine::notifyInferiorSetupOk()
......
......@@ -77,7 +77,8 @@ SourceAgentPrivate::SourceAgentPrivate()
SourceAgentPrivate::~SourceAgentPrivate()
{
EditorManager::closeEditor(editor);
if (editor)
EditorManager::closeDocument(editor->document());
editor = 0;
delete locationMark;
}
......
......@@ -149,7 +149,7 @@ void Internal::TextEditorPlugin::testBlockSelectionTransformation()
}
QCOMPARE(textEditor->textDocument()->plainText(), transformedText);
}
Core::EditorManager::closeEditor(editor, false);
Core::EditorManager::closeDocument(editor->document(), false);
}
static const char text[] =
......@@ -364,7 +364,7 @@ void Internal::TextEditorPlugin::testBlockSelectionInsert()
QCOMPARE(textEditor->textDocument()->plainText(), transformedText);
}
Core::EditorManager::closeEditor(editor, false);
Core::EditorManager::closeDocument(editor->document(), false);
}
......@@ -442,7 +442,7 @@ void Internal::TextEditorPlugin::testBlockSelectionRemove()
QCOMPARE(textEditor->textDocument()->plainText(), transformedText);
}
Core::EditorManager::closeEditor(editor, false);
Core::EditorManager::closeDocument(editor->document(), false);
}
void Internal::TextEditorPlugin::testBlockSelectionCopy_data()
......@@ -497,7 +497,7 @@ void Internal::TextEditorPlugin::testBlockSelectionCopy()
QCOMPARE(qApp->clipboard()->text(), copiedText);
}
Core::EditorManager::closeEditor(editor, false);
Core::EditorManager::closeDocument(editor->document(), false);
}
#endif // ifdef WITH_TESTS
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment