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

Fix usage of EditorManager::editorsForFileName

And move to using the corresponding method in document model.

Change-Id: I80b12ceab8a91c5393b9c0422d660a8896ae09d8
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent bc88c0b8
...@@ -1333,14 +1333,14 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action) ...@@ -1333,14 +1333,14 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action)
OpenWithEntry entry = qvariant_cast<OpenWithEntry>(data); OpenWithEntry entry = qvariant_cast<OpenWithEntry>(data);
if (entry.editorFactory) { if (entry.editorFactory) {
// close any open editors that have this file open, but have a different type. // close any open editors that have this file open, but have a different type.
EditorManager *em = EditorManager::instance(); QList<IEditor *> editorsOpenForFile
QList<IEditor *> editorsOpenForFile = em->editorsForFileName(entry.fileName); = EditorManager::documentModel()->editorsForFilePath(entry.fileName);
if (!editorsOpenForFile.isEmpty()) { if (!editorsOpenForFile.isEmpty()) {
foreach (IEditor *openEditor, editorsOpenForFile) { foreach (IEditor *openEditor, editorsOpenForFile) {
if (entry.editorFactory->id() == openEditor->id()) if (entry.editorFactory->id() == openEditor->id())
editorsOpenForFile.removeAll(openEditor); 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; return;
} }
......
...@@ -627,17 +627,6 @@ SplitterOrView *EditorManager::findRoot(const EditorView *view, int *rootIndex) ...@@ -627,17 +627,6 @@ SplitterOrView *EditorManager::findRoot(const EditorView *view, int *rootIndex)
return 0; 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() IDocument *EditorManager::currentDocument()
{ {
return d->m_currentEditor ? d->m_currentEditor->document() : 0; return d->m_currentEditor ? d->m_currentEditor->document() : 0;
...@@ -1558,7 +1547,7 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri ...@@ -1558,7 +1547,7 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
if (newEditor) if (newEditor)
*newEditor = false; *newEditor = false;
const QList<IEditor *> editors = editorsForFileName(fn); const QList<IEditor *> editors = d->m_documentModel->editorsForFilePath(fn);
if (!editors.isEmpty()) { if (!editors.isEmpty()) {
IEditor *editor = editors.first(); IEditor *editor = editors.first();
if (flags & EditorManager::CanContainLineNumber) if (flags & EditorManager::CanContainLineNumber)
...@@ -1797,9 +1786,9 @@ bool EditorManager::saveDocumentAs(IDocument *documentParam) ...@@ -1797,9 +1786,9 @@ bool EditorManager::saveDocumentAs(IDocument *documentParam)
if (absoluteFilePath != document->filePath()) { if (absoluteFilePath != document->filePath()) {
// close existing editors for the new file name // close existing editors for the new file name
const QList<IEditor *> existList = editorsForFileName(absoluteFilePath); IDocument *otherDocument = d->m_documentModel->documentForFilePath(absoluteFilePath);
if (!existList.isEmpty()) if (otherDocument)
closeEditors(existList, false); closeDocuments(QList<IDocument *>() << otherDocument, false);
} }
const bool success = DocumentManager::saveDocument(document, absoluteFilePath); const bool success = DocumentManager::saveDocument(document, absoluteFilePath);
...@@ -2069,9 +2058,9 @@ DocumentModel *EditorManager::documentModel() ...@@ -2069,9 +2058,9 @@ DocumentModel *EditorManager::documentModel()
return d->m_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) void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState)
......
...@@ -122,8 +122,6 @@ public: ...@@ -122,8 +122,6 @@ public:
QStringList getOpenFileNames() const; QStringList getOpenFileNames() const;
Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const; Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
QList<IEditor *> editorsForFileName(const QString &filename) const;
static IDocument *currentDocument(); static IDocument *currentDocument();
static IEditor *currentEditor(); static IEditor *currentEditor();
QList<IEditor *> visibleEditors() const; QList<IEditor *> visibleEditors() const;
...@@ -135,7 +133,7 @@ public: ...@@ -135,7 +133,7 @@ public:
IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0); IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0);
static DocumentModel *documentModel(); 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 closeEditor(DocumentModel::Entry *entry);
void closeOtherEditors(IDocument *document); void closeOtherEditors(IDocument *document);
......
...@@ -353,9 +353,8 @@ void QmlInspectorAdapter::updatePendingPreviewDocuments(QmlJS::Document::Ptr doc ...@@ -353,9 +353,8 @@ void QmlInspectorAdapter::updatePendingPreviewDocuments(QmlJS::Document::Ptr doc
if (idx == -1) if (idx == -1)
return; return;
Core::EditorManager *em = Core::EditorManager::instance();
QList<Core::IEditor *> editors QList<Core::IEditor *> editors
= em->editorsForFileName(doc->fileName()); = Core::EditorManager::documentModel()->editorsForFilePath(doc->fileName());
if (editors.isEmpty()) if (editors.isEmpty())
return; return;
......
...@@ -1998,12 +1998,7 @@ void QmlV8DebuggerClient::highlightExceptionCode(int lineNumber, ...@@ -1998,12 +1998,7 @@ void QmlV8DebuggerClient::highlightExceptionCode(int lineNumber,
const QString &filePath, const QString &filePath,
const QString &errorMessage) const QString &errorMessage)
{ {
DocumentModel *documentModel = EditorManager::documentModel(); QList<IEditor *> editors = EditorManager::documentModel()->editorsForFilePath(filePath);
int index = documentModel->indexOfFilePath(filePath);
if (index < 0 || !documentModel->documents().at(index)->document)
return;
QList<IEditor *> editors = documentModel->editorsForDocument(
documentModel->documents().at(index)->document);
// set up the format for the errors // set up the format for the errors
QTextCharFormat errorFormat; QTextCharFormat errorFormat;
......
...@@ -1250,16 +1250,11 @@ void GitPlugin::updateSubmodules() ...@@ -1250,16 +1250,11 @@ void GitPlugin::updateSubmodules()
// If the file is modified in an editor, make sure it is saved. // If the file is modified in an editor, make sure it is saved.
static bool ensureFileSaved(const QString &fileName) static bool ensureFileSaved(const QString &fileName)
{ {
const QList<Core::IEditor*> editors = Core::EditorManager::instance()->editorsForFileName(fileName); Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(fileName);
if (editors.isEmpty())
return true;
Core::IDocument *document = editors.front()->document();
if (!document || !document->isModified()) if (!document || !document->isModified())
return true; return true;
bool canceled; bool canceled;
QList<Core::IDocument *> documents; Core::DocumentManager::saveModifiedDocuments(QList<Core::IDocument *>() << document, &canceled);
documents << document;
Core::DocumentManager::saveModifiedDocuments(documents, &canceled);
return !canceled; return !canceled;
} }
......
...@@ -998,9 +998,9 @@ void FindReferences::onReplaceButtonClicked(const QString &text, const QList<Fin ...@@ -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 // files that are opened in an editor are changed, but not saved
QStringList changedOnDisk; QStringList changedOnDisk;
QStringList changedUnsavedEditors; QStringList changedUnsavedEditors;
Core::EditorManager *editorManager = Core::EditorManager::instance(); Core::DocumentModel *documentModel = Core::EditorManager::documentModel();
foreach (const QString &fileName, fileNames) { foreach (const QString &fileName, fileNames) {
if (editorManager->editorsForFileName(fileName).isEmpty()) if (documentModel->documentForFilePath(fileName))
changedOnDisk += fileName; changedOnDisk += fileName;
else else
changedUnsavedEditors += fileName; changedUnsavedEditors += fileName;
......
...@@ -1052,25 +1052,19 @@ bool Qt4PriFileNode::priFileWritable(const QString &path) ...@@ -1052,25 +1052,19 @@ bool Qt4PriFileNode::priFileWritable(const QString &path)
bool Qt4PriFileNode::saveModifiedEditors() bool Qt4PriFileNode::saveModifiedEditors()
{ {
QList<Core::IDocument*> modifiedDocuments; Core::IDocument *document
= Core::EditorManager::documentModel()->documentForFilePath(m_projectFilePath);
foreach (Core::IEditor *editor, Core::ICore::editorManager()->editorsForFileName(m_projectFilePath)) { if (!document || !document->isModified())
if (Core::IDocument *editorDocument = editor->document()) { return true;
if (editorDocument->isModified())
modifiedDocuments << editorDocument;
}
}
if (!modifiedDocuments.isEmpty()) { bool cancelled;
bool cancelled; Core::DocumentManager::saveModifiedDocuments(QList<Core::IDocument *>() << document, &cancelled,
Core::DocumentManager::saveModifiedDocuments(modifiedDocuments, &cancelled, tr("There are unsaved changes for project file %1.").arg(m_projectFilePath));
tr("There are unsaved changes for project file %1.").arg(m_projectFilePath)); if (cancelled)
if (cancelled) return false;
return false; // force instant reload of ourselves
// force instant reload of ourselves QtSupport::ProFileCacheManager::instance()->discardFile(m_projectFilePath);
QtSupport::ProFileCacheManager::instance()->discardFile(m_projectFilePath); m_project->qt4ProjectManager()->notifyChanged(m_projectFilePath);
m_project->qt4ProjectManager()->notifyChanged(m_projectFilePath);
}
return true; return true;
} }
...@@ -1182,12 +1176,11 @@ void Qt4PriFileNode::changeFiles(const QString &mimeType, ...@@ -1182,12 +1176,11 @@ void Qt4PriFileNode::changeFiles(const QString &mimeType,
// We manually tell each editor to reload it's file. // We manually tell each editor to reload it's file.
// (The .pro files are notified by the file system watcher.) // (The .pro files are notified by the file system watcher.)
QStringList errorStrings; QStringList errorStrings;
foreach (Core::IEditor *editor, Core::ICore::editorManager()->editorsForFileName(m_projectFilePath)) { Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(m_projectFilePath);
if (Core::IDocument *editorDocument= editor->document()) { if (document) {
QString errorString; QString errorString;
if (!editorDocument->reload(&errorString, Core::IDocument::FlagReload, Core::IDocument::TypeContents)) if (!document->reload(&errorString, Core::IDocument::FlagReload, Core::IDocument::TypeContents))
errorStrings << errorString; errorStrings << errorString;
}
} }
if (!errorStrings.isEmpty()) if (!errorStrings.isEmpty())
QMessageBox::warning(Core::ICore::mainWindow(), tr("File Error"), QMessageBox::warning(Core::ICore::mainWindow(), tr("File Error"),
......
...@@ -58,13 +58,14 @@ BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent) ...@@ -58,13 +58,14 @@ BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent)
void BaseTextMarkRegistry::add(BaseTextMark *mark) void BaseTextMarkRegistry::add(BaseTextMark *mark)
{ {
m_marks[Utils::FileName::fromString(mark->fileName())].insert(mark); m_marks[Utils::FileName::fromString(mark->fileName())].insert(mark);
Core::EditorManager *em = Core::EditorManager::instance(); Core::DocumentModel *documentModel = Core::EditorManager::documentModel();
foreach (Core::IEditor *editor, em->editorsForFileName(mark->fileName())) { Core::IDocument *document = documentModel->documentForFilePath(mark->fileName());
if (ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor)) { if (!document)
ITextMarkable *markableInterface = textEditor->markableInterface(); return;
if (markableInterface->addMark(mark)) // TODO: markableInterface should be moved to ITextEditorDocument
break; if (ITextEditor *textEditor
} = qobject_cast<ITextEditor *>(documentModel->editorsForDocument(document).first())) {
textEditor->markableInterface()->addMark(mark);
} }
} }
......
...@@ -1226,17 +1226,9 @@ const VcsBaseEditorParameters *VcsBaseEditorWidget::findType(const VcsBaseEditor ...@@ -1226,17 +1226,9 @@ const VcsBaseEditorParameters *VcsBaseEditorWidget::findType(const VcsBaseEditor
// Find the codec used for a file querying the editor. // Find the codec used for a file querying the editor.
static QTextCodec *findFileCodec(const QString &source) static QTextCodec *findFileCodec(const QString &source)
{ {
typedef QList<Core::IEditor *> EditorList; Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(source);
if (Core::TextDocument *textDocument = qobject_cast<Core::TextDocument *>(document))
const EditorList editors = Core::EditorManager::instance()->editorsForFileName(source); return const_cast<QTextCodec *>(textDocument->codec());
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;
}
}
return 0; return 0;
} }
......
...@@ -219,9 +219,9 @@ StateListener::StateListener(QObject *parent) : ...@@ -219,9 +219,9 @@ StateListener::StateListener(QObject *parent) :
static inline QString displayNameOfEditor(const QString &fileName) static inline QString displayNameOfEditor(const QString &fileName)
{ {
const QList<Core::IEditor*> editors = Core::EditorManager::instance()->editorsForFileName(fileName); Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(fileName);
if (!editors.isEmpty()) if (document)
return editors.front()->document()->displayName(); return document->displayName();
return QString(); return QString();
} }
......
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