summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2013-07-18 12:26:23 +0200
committerEike Ziller <eike.ziller@digia.com>2013-07-18 14:51:39 +0200
commit8c2e3fd2cbaeb1178ae3991de794ee6d74c84d85 (patch)
tree475e76bac18c802197b74a8862bded017352c59d /src
parentbc88c0b89e8f61a50ba62c8319114330211337da (diff)
downloadqt-creator-8c2e3fd2cbaeb1178ae3991de794ee6d74c84d85.tar.gz
Fix usage of EditorManager::editorsForFileName
And move to using the corresponding method in document model. Change-Id: I80b12ceab8a91c5393b9c0422d660a8896ae09d8 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/coreplugin/documentmanager.cpp6
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp23
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.h4
-rw-r--r--src/plugins/debugger/qml/qmlinspectoradapter.cpp3
-rw-r--r--src/plugins/debugger/qml/qmlv8debuggerclient.cpp7
-rw-r--r--src/plugins/git/gitplugin.cpp9
-rw-r--r--src/plugins/qmljseditor/qmljsfindreferences.cpp4
-rw-r--r--src/plugins/qt4projectmanager/qt4nodes.cpp41
-rw-r--r--src/plugins/texteditor/basetextmark.cpp15
-rw-r--r--src/plugins/vcsbase/vcsbaseeditor.cpp14
-rw-r--r--src/plugins/vcsbase/vcsbaseplugin.cpp6
11 files changed, 47 insertions, 85 deletions
diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp
index dc81932f66..b9050460de 100644
--- a/src/plugins/coreplugin/documentmanager.cpp
+++ b/src/plugins/coreplugin/documentmanager.cpp
@@ -1333,14 +1333,14 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action)
OpenWithEntry entry = qvariant_cast<OpenWithEntry>(data);
if (entry.editorFactory) {
// close any open editors that have this file open, but have a different type.
- EditorManager *em = EditorManager::instance();
- QList<IEditor *> editorsOpenForFile = em->editorsForFileName(entry.fileName);
+ QList<IEditor *> editorsOpenForFile
+ = EditorManager::documentModel()->editorsForFilePath(entry.fileName);
if (!editorsOpenForFile.isEmpty()) {
foreach (IEditor *openEditor, editorsOpenForFile) {
if (entry.editorFactory->id() == openEditor->id())
editorsOpenForFile.removeAll(openEditor);
}
- if (!em->closeEditors(editorsOpenForFile)) // don't open if cancel was pressed
+ if (!EditorManager::instance()->closeEditors(editorsOpenForFile)) // don't open if cancel was pressed
return;
}
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 881efab588..4f1ed05f12 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -627,17 +627,6 @@ SplitterOrView *EditorManager::findRoot(const EditorView *view, int *rootIndex)
return 0;
}
-QList<IEditor *> EditorManager::editorsForFileName(const QString &filename) const
-{
- QList<IEditor *> found;
- QString fixedname = DocumentManager::fixFileName(filename, DocumentManager::KeepLinks);
- foreach (IEditor *editor, openedEditors()) {
- if (fixedname == DocumentManager::fixFileName(editor->document()->filePath(), DocumentManager::KeepLinks))
- found << editor;
- }
- return found;
-}
-
IDocument *EditorManager::currentDocument()
{
return d->m_currentEditor ? d->m_currentEditor->document() : 0;
@@ -1558,7 +1547,7 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
if (newEditor)
*newEditor = false;
- const QList<IEditor *> editors = editorsForFileName(fn);
+ const QList<IEditor *> editors = d->m_documentModel->editorsForFilePath(fn);
if (!editors.isEmpty()) {
IEditor *editor = editors.first();
if (flags & EditorManager::CanContainLineNumber)
@@ -1797,9 +1786,9 @@ bool EditorManager::saveDocumentAs(IDocument *documentParam)
if (absoluteFilePath != document->filePath()) {
// close existing editors for the new file name
- const QList<IEditor *> existList = editorsForFileName(absoluteFilePath);
- if (!existList.isEmpty())
- closeEditors(existList, false);
+ IDocument *otherDocument = d->m_documentModel->documentForFilePath(absoluteFilePath);
+ if (otherDocument)
+ closeDocuments(QList<IDocument *>() << otherDocument, false);
}
const bool success = DocumentManager::saveDocument(document, absoluteFilePath);
@@ -2069,9 +2058,9 @@ DocumentModel *EditorManager::documentModel()
return d->m_documentModel;
}
-void EditorManager::closeDocuments(const QList<IDocument *> &document, bool askAboutModifiedEditors)
+bool EditorManager::closeDocuments(const QList<IDocument *> &document, bool askAboutModifiedEditors)
{
- m_instance->closeEditors(d->m_documentModel->editorsForDocuments(document), askAboutModifiedEditors);
+ return m_instance->closeEditors(d->m_documentModel->editorsForDocuments(document), askAboutModifiedEditors);
}
void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState)
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index ad7a091821..57406c8f0e 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -122,8 +122,6 @@ public:
QStringList getOpenFileNames() const;
Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
- QList<IEditor *> editorsForFileName(const QString &filename) const;
-
static IDocument *currentDocument();
static IEditor *currentEditor();
QList<IEditor *> visibleEditors() const;
@@ -135,7 +133,7 @@ public:
IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0);
static DocumentModel *documentModel();
- static void closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true);
+ static bool closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true);
void closeEditor(DocumentModel::Entry *entry);
void closeOtherEditors(IDocument *document);
diff --git a/src/plugins/debugger/qml/qmlinspectoradapter.cpp b/src/plugins/debugger/qml/qmlinspectoradapter.cpp
index 7ded0f0fc8..ade2eedcf0 100644
--- a/src/plugins/debugger/qml/qmlinspectoradapter.cpp
+++ b/src/plugins/debugger/qml/qmlinspectoradapter.cpp
@@ -353,9 +353,8 @@ void QmlInspectorAdapter::updatePendingPreviewDocuments(QmlJS::Document::Ptr doc
if (idx == -1)
return;
- Core::EditorManager *em = Core::EditorManager::instance();
QList<Core::IEditor *> editors
- = em->editorsForFileName(doc->fileName());
+ = Core::EditorManager::documentModel()->editorsForFilePath(doc->fileName());
if (editors.isEmpty())
return;
diff --git a/src/plugins/debugger/qml/qmlv8debuggerclient.cpp b/src/plugins/debugger/qml/qmlv8debuggerclient.cpp
index dc03a2890b..1d51afb31f 100644
--- a/src/plugins/debugger/qml/qmlv8debuggerclient.cpp
+++ b/src/plugins/debugger/qml/qmlv8debuggerclient.cpp
@@ -1998,12 +1998,7 @@ void QmlV8DebuggerClient::highlightExceptionCode(int lineNumber,
const QString &filePath,
const QString &errorMessage)
{
- DocumentModel *documentModel = EditorManager::documentModel();
- int index = documentModel->indexOfFilePath(filePath);
- if (index < 0 || !documentModel->documents().at(index)->document)
- return;
- QList<IEditor *> editors = documentModel->editorsForDocument(
- documentModel->documents().at(index)->document);
+ QList<IEditor *> editors = EditorManager::documentModel()->editorsForFilePath(filePath);
// set up the format for the errors
QTextCharFormat errorFormat;
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp
index 2ee39cddf2..6801a97390 100644
--- a/src/plugins/git/gitplugin.cpp
+++ b/src/plugins/git/gitplugin.cpp
@@ -1250,16 +1250,11 @@ void GitPlugin::updateSubmodules()
// If the file is modified in an editor, make sure it is saved.
static bool ensureFileSaved(const QString &fileName)
{
- const QList<Core::IEditor*> editors = Core::EditorManager::instance()->editorsForFileName(fileName);
- if (editors.isEmpty())
- return true;
- Core::IDocument *document = editors.front()->document();
+ Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(fileName);
if (!document || !document->isModified())
return true;
bool canceled;
- QList<Core::IDocument *> documents;
- documents << document;
- Core::DocumentManager::saveModifiedDocuments(documents, &canceled);
+ Core::DocumentManager::saveModifiedDocuments(QList<Core::IDocument *>() << document, &canceled);
return !canceled;
}
diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp
index af0d7b461b..7c54a0d3d3 100644
--- a/src/plugins/qmljseditor/qmljsfindreferences.cpp
+++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp
@@ -998,9 +998,9 @@ void FindReferences::onReplaceButtonClicked(const QString &text, const QList<Fin
// files that are opened in an editor are changed, but not saved
QStringList changedOnDisk;
QStringList changedUnsavedEditors;
- Core::EditorManager *editorManager = Core::EditorManager::instance();
+ Core::DocumentModel *documentModel = Core::EditorManager::documentModel();
foreach (const QString &fileName, fileNames) {
- if (editorManager->editorsForFileName(fileName).isEmpty())
+ if (documentModel->documentForFilePath(fileName))
changedOnDisk += fileName;
else
changedUnsavedEditors += fileName;
diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp
index eeb393fb91..8899e2948a 100644
--- a/src/plugins/qt4projectmanager/qt4nodes.cpp
+++ b/src/plugins/qt4projectmanager/qt4nodes.cpp
@@ -1052,25 +1052,19 @@ bool Qt4PriFileNode::priFileWritable(const QString &path)
bool Qt4PriFileNode::saveModifiedEditors()
{
- QList<Core::IDocument*> modifiedDocuments;
-
- foreach (Core::IEditor *editor, Core::ICore::editorManager()->editorsForFileName(m_projectFilePath)) {
- if (Core::IDocument *editorDocument = editor->document()) {
- if (editorDocument->isModified())
- modifiedDocuments << editorDocument;
- }
- }
+ Core::IDocument *document
+ = Core::EditorManager::documentModel()->documentForFilePath(m_projectFilePath);
+ if (!document || !document->isModified())
+ return true;
- if (!modifiedDocuments.isEmpty()) {
- bool cancelled;
- Core::DocumentManager::saveModifiedDocuments(modifiedDocuments, &cancelled,
- tr("There are unsaved changes for project file %1.").arg(m_projectFilePath));
- if (cancelled)
- return false;
- // force instant reload of ourselves
- QtSupport::ProFileCacheManager::instance()->discardFile(m_projectFilePath);
- m_project->qt4ProjectManager()->notifyChanged(m_projectFilePath);
- }
+ bool cancelled;
+ Core::DocumentManager::saveModifiedDocuments(QList<Core::IDocument *>() << document, &cancelled,
+ tr("There are unsaved changes for project file %1.").arg(m_projectFilePath));
+ if (cancelled)
+ return false;
+ // force instant reload of ourselves
+ QtSupport::ProFileCacheManager::instance()->discardFile(m_projectFilePath);
+ m_project->qt4ProjectManager()->notifyChanged(m_projectFilePath);
return true;
}
@@ -1182,12 +1176,11 @@ void Qt4PriFileNode::changeFiles(const QString &mimeType,
// We manually tell each editor to reload it's file.
// (The .pro files are notified by the file system watcher.)
QStringList errorStrings;
- foreach (Core::IEditor *editor, Core::ICore::editorManager()->editorsForFileName(m_projectFilePath)) {
- if (Core::IDocument *editorDocument= editor->document()) {
- QString errorString;
- if (!editorDocument->reload(&errorString, Core::IDocument::FlagReload, Core::IDocument::TypeContents))
- errorStrings << errorString;
- }
+ Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(m_projectFilePath);
+ if (document) {
+ QString errorString;
+ if (!document->reload(&errorString, Core::IDocument::FlagReload, Core::IDocument::TypeContents))
+ errorStrings << errorString;
}
if (!errorStrings.isEmpty())
QMessageBox::warning(Core::ICore::mainWindow(), tr("File Error"),
diff --git a/src/plugins/texteditor/basetextmark.cpp b/src/plugins/texteditor/basetextmark.cpp
index 49dc658b1b..e4558341d4 100644
--- a/src/plugins/texteditor/basetextmark.cpp
+++ b/src/plugins/texteditor/basetextmark.cpp
@@ -58,13 +58,14 @@ BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent)
void BaseTextMarkRegistry::add(BaseTextMark *mark)
{
m_marks[Utils::FileName::fromString(mark->fileName())].insert(mark);
- Core::EditorManager *em = Core::EditorManager::instance();
- foreach (Core::IEditor *editor, em->editorsForFileName(mark->fileName())) {
- if (ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor)) {
- ITextMarkable *markableInterface = textEditor->markableInterface();
- if (markableInterface->addMark(mark))
- break;
- }
+ Core::DocumentModel *documentModel = Core::EditorManager::documentModel();
+ Core::IDocument *document = documentModel->documentForFilePath(mark->fileName());
+ if (!document)
+ return;
+ // TODO: markableInterface should be moved to ITextEditorDocument
+ if (ITextEditor *textEditor
+ = qobject_cast<ITextEditor *>(documentModel->editorsForDocument(document).first())) {
+ textEditor->markableInterface()->addMark(mark);
}
}
diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp
index c7a35604d8..df85102cf7 100644
--- a/src/plugins/vcsbase/vcsbaseeditor.cpp
+++ b/src/plugins/vcsbase/vcsbaseeditor.cpp
@@ -1226,17 +1226,9 @@ const VcsBaseEditorParameters *VcsBaseEditorWidget::findType(const VcsBaseEditor
// Find the codec used for a file querying the editor.
static QTextCodec *findFileCodec(const QString &source)
{
- typedef QList<Core::IEditor *> EditorList;
-
- const EditorList editors = Core::EditorManager::instance()->editorsForFileName(source);
- if (!editors.empty()) {
- const EditorList::const_iterator ecend = editors.constEnd();
- for (EditorList::const_iterator it = editors.constBegin(); it != ecend; ++it)
- if (TextEditor::BaseTextEditor *be = qobject_cast<TextEditor::BaseTextEditor *>(*it)) {
- QTextCodec *codec = const_cast<QTextCodec *>(be->textDocument()->codec());
- return codec;
- }
- }
+ Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(source);
+ if (Core::TextDocument *textDocument = qobject_cast<Core::TextDocument *>(document))
+ return const_cast<QTextCodec *>(textDocument->codec());
return 0;
}
diff --git a/src/plugins/vcsbase/vcsbaseplugin.cpp b/src/plugins/vcsbase/vcsbaseplugin.cpp
index 442df7946b..f3c33ec313 100644
--- a/src/plugins/vcsbase/vcsbaseplugin.cpp
+++ b/src/plugins/vcsbase/vcsbaseplugin.cpp
@@ -219,9 +219,9 @@ StateListener::StateListener(QObject *parent) :
static inline QString displayNameOfEditor(const QString &fileName)
{
- const QList<Core::IEditor*> editors = Core::EditorManager::instance()->editorsForFileName(fileName);
- if (!editors.isEmpty())
- return editors.front()->document()->displayName();
+ Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(fileName);
+ if (document)
+ return document->displayName();
return QString();
}