forked from qt-creator/qt-creator
EditorManager: add optional uniqueId parameter
to return existent IEditor matching this uniqueId Change-Id: I8199c39182d88d5496b0277d08896dfe32a52790 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user