diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 603373af2da..f1db1acbda1 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -102,6 +102,8 @@ static const char reloadBehaviorKey[] = "EditorManager/ReloadBehavior"; static const char autoSaveEnabledKey[] = "EditorManager/AutoSaveEnabled"; static const char autoSaveIntervalKey[] = "EditorManager/AutoSaveInterval"; +static const char scratchBufferKey[] = "_q_emScratchBuffer"; + //===================EditorClosingCoreListener====================== namespace Core { @@ -2329,20 +2331,8 @@ QStringList EditorManager::getOpenFileNames() return DocumentManager::getOpenFileNames(fileFilters, QString(), &selectedFilter); } - -IEditor *EditorManager::openEditorWithContents(Id editorId, - QString *titlePattern, - const QByteArray &contents, - OpenEditorFlags flags) +static QString makeTitleUnique(QString *titlePattern) { - if (debugEditorManager) - qDebug() << Q_FUNC_INFO << editorId.name() << titlePattern << contents; - - if (flags & EditorManager::OpenInOtherSplit) - EditorManager::gotoOtherSplit(); - - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - QString title; if (titlePattern) { const QChar dollar = QLatin1Char('$'); @@ -2371,8 +2361,42 @@ IEditor *EditorManager::openEditorWithContents(Id editorId, } *titlePattern = title; } + return title; +} - IEditor *edt = EditorManagerPrivate::createEditor(editorId, title); +IEditor *EditorManager::openEditorWithContents(Id editorId, + QString *titlePattern, + const QByteArray &contents, + const QString &uniqueId, + OpenEditorFlags flags) +{ + if (debugEditorManager) + qDebug() << Q_FUNC_INFO << editorId.name() << titlePattern << uniqueId << contents; + + if (flags & EditorManager::OpenInOtherSplit) + EditorManager::gotoOtherSplit(); + + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + + const QString title = makeTitleUnique(titlePattern); + + IEditor *edt = 0; + if (!uniqueId.isEmpty()) { + foreach (IDocument *document, DocumentModel::openedDocuments()) + if (document->property(scratchBufferKey).toString() == uniqueId) { + edt = DocumentModel::editorsForDocument(document).first(); + + document->setContents(contents); + if (!title.isEmpty()) + edt->document()->setPreferredDisplayName(title); + + QApplication::restoreOverrideCursor(); + activateEditor(edt, flags); + return edt; + } + } + + edt = EditorManagerPrivate::createEditor(editorId, title); if (!edt) { QApplication::restoreOverrideCursor(); return 0; @@ -2385,10 +2409,12 @@ IEditor *EditorManager::openEditorWithContents(Id editorId, return 0; } + if (!uniqueId.isEmpty()) + edt->document()->setProperty(scratchBufferKey, uniqueId); + if (!title.isEmpty()) edt->document()->setPreferredDisplayName(title); - EditorManagerPrivate::addEditor(edt); QApplication::restoreOverrideCursor(); activateEditor(edt, flags); diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index 2a09104cbb7..f2b123c3baf 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -120,6 +120,7 @@ public: bool *newEditor = 0); static IEditor *openEditorWithContents(Id editorId, QString *titlePattern = 0, const QByteArray &contents = QByteArray(), + const QString &uniqueId = QString(), OpenEditorFlags flags = NoFlags); static bool openExternalEditor(const QString &fileName, Id editorId); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 432324a1b63..f9ea096e3f5 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -3157,7 +3157,7 @@ void openTextEditor(const QString &titlePattern0, const QString &contents) return; QString titlePattern = titlePattern0; IEditor *editor = EditorManager::openEditorWithContents( - CC::K_DEFAULT_TEXT_EDITOR_ID, &titlePattern, contents.toUtf8(), + CC::K_DEFAULT_TEXT_EDITOR_ID, &titlePattern, contents.toUtf8(), QString(), EditorManager::IgnoreNavigationHistory); QTC_ASSERT(editor, return); }