forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -1052,25 +1052,19 @@ bool Qt4PriFileNode::priFileWritable(const QString &path)
|
||||
|
||||
bool Qt4PriFileNode::saveModifiedEditors()
|
||||
{
|
||||
QList<Core::IDocument*> modifiedDocuments;
|
||||
Core::IDocument *document
|
||||
= Core::EditorManager::documentModel()->documentForFilePath(m_projectFilePath);
|
||||
if (!document || !document->isModified())
|
||||
return true;
|
||||
|
||||
foreach (Core::IEditor *editor, Core::ICore::editorManager()->editorsForFileName(m_projectFilePath)) {
|
||||
if (Core::IDocument *editorDocument = editor->document()) {
|
||||
if (editorDocument->isModified())
|
||||
modifiedDocuments << editorDocument;
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user