From 339db00f8563c7fc865a6166114e684021ac260e Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 2 Sep 2020 12:06:51 +0200 Subject: [PATCH] Core: replace QString with Utils::FilePath to get documents Change-Id: I01777c227398be8bd3bf877c5429b84a75aa361b Reviewed-by: Eike Ziller --- .../coreplugin/editormanager/documentmodel.cpp | 6 +++--- .../coreplugin/editormanager/documentmodel.h | 4 ++-- .../coreplugin/editormanager/editormanager.cpp | 15 ++++++--------- src/plugins/cppeditor/cppeditorwidget.cpp | 6 +++--- src/plugins/debugger/qml/qmlengineutils.cpp | 3 ++- src/plugins/diffeditor/diffeditorplugin.cpp | 4 ++-- .../diffeditor/diffeditorwidgetcontroller.cpp | 2 +- src/plugins/git/gitplugin.cpp | 3 ++- .../qmakeprojectmanager/qmakeparsernodes.cpp | 5 ++--- src/plugins/qmljseditor/qmljsfindreferences.cpp | 2 +- src/plugins/qmlprojectmanager/qmlproject.cpp | 8 ++++---- src/plugins/texteditor/refactoringchanges.cpp | 2 +- src/plugins/texteditor/textdocument.cpp | 2 +- src/plugins/vcsbase/vcsbaseeditor.cpp | 3 ++- src/plugins/vcsbase/vcsbaseplugin.cpp | 2 +- 15 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/documentmodel.cpp b/src/plugins/coreplugin/editormanager/documentmodel.cpp index 181dae6ce15..259448cc394 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel.cpp +++ b/src/plugins/coreplugin/editormanager/documentmodel.cpp @@ -633,15 +633,15 @@ QList DocumentModel::openedDocuments() return d->m_editors.keys(); } -IDocument *DocumentModel::documentForFilePath(const QString &filePath) +IDocument *DocumentModel::documentForFilePath(const Utils::FilePath &filePath) { - const Utils::optional index = d->indexOfFilePath(Utils::FilePath::fromString(filePath)); + const Utils::optional index = d->indexOfFilePath(filePath); if (!index) return nullptr; return d->m_entries.at(*index)->document; } -QList DocumentModel::editorsForFilePath(const QString &filePath) +QList DocumentModel::editorsForFilePath(const Utils::FilePath &filePath) { IDocument *document = documentForFilePath(filePath); if (document) diff --git a/src/plugins/coreplugin/editormanager/documentmodel.h b/src/plugins/coreplugin/editormanager/documentmodel.h index 46045d76f40..e5261326548 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel.h +++ b/src/plugins/coreplugin/editormanager/documentmodel.h @@ -84,8 +84,8 @@ public: static Entry *entryForFilePath(const Utils::FilePath &filePath); static QList openedDocuments(); - static IDocument *documentForFilePath(const QString &filePath); - static QList editorsForFilePath(const QString &filePath); + static IDocument *documentForFilePath(const Utils::FilePath &filePath); + static QList editorsForFilePath(const Utils::FilePath &filePath); static QList editorsForDocument(IDocument *document); static QList editorsForDocuments(const QList &entries); static QList editorsForOpenedDocuments(); diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index afb4404878d..1586bf8c023 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -104,8 +104,6 @@ #include #endif -using namespace Utils; - enum { debugEditorManager=0 }; static const char kCurrentDocumentPrefix[] = "CurrentDocument"; @@ -654,7 +652,7 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN if (newEditor) *newEditor = false; - const QList editors = DocumentModel::editorsForFilePath(fn); + const QList editors = DocumentModel::editorsForFilePath(FilePath::fromString(fn)); if (!editors.isEmpty()) { IEditor *editor = editors.first(); if (flags & EditorManager::SwitchSplitIfAlreadyVisible) { @@ -812,8 +810,8 @@ IEditor *EditorManagerPrivate::openEditorWith(const QString &fileName, Utils::Id // close any open editors that have this file open // remember the views to open new editors in there QList views; - QList editorsOpenForFile - = DocumentModel::editorsForFilePath(fileName); + QList editorsOpenForFile = DocumentModel::editorsForFilePath( + FilePath::fromString(fileName)); foreach (IEditor *openEditor, editorsOpenForFile) { EditorView *view = EditorManagerPrivate::viewForEditor(openEditor); if (view && view->currentEditor() == openEditor) // visible @@ -2295,13 +2293,12 @@ bool EditorManagerPrivate::saveDocumentAs(IDocument *document) if (!document) return false; - const QString &absoluteFilePath = - DocumentManager::getSaveAsFileName(document); + const auto &absoluteFilePath = FilePath::fromString(DocumentManager::getSaveAsFileName(document)); if (absoluteFilePath.isEmpty()) return false; - if (absoluteFilePath != document->filePath().toString()) { + if (absoluteFilePath != document->filePath()) { // close existing editors for the new file name IDocument *otherDocument = DocumentModel::documentForFilePath(absoluteFilePath); if (otherDocument) @@ -2309,7 +2306,7 @@ bool EditorManagerPrivate::saveDocumentAs(IDocument *document) } emit m_instance->aboutToSave(document); - const bool success = DocumentManager::saveDocument(document, absoluteFilePath); + const bool success = DocumentManager::saveDocument(document, absoluteFilePath.toString()); document->checkPermissions(); // TODO: There is an issue to be treated here. The new file might be of a different mime diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index ddc0a09630c..38083da56f7 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -388,7 +388,7 @@ static void onReplaceUsagesClicked(const QString &text, static QTextDocument *getOpenDocument(const QString &path) { - const IDocument *document = DocumentModel::documentForFilePath(path); + const IDocument *document = DocumentModel::documentForFilePath(FilePath::fromString(path)); if (document) return qobject_cast(document)->document(); @@ -1104,7 +1104,7 @@ void CppEditorWidget::onFunctionDeclDefLinkFound(QSharedPointerm_declDefLink = link; IDocument *targetDocument = DocumentModel::documentForFilePath( - d->m_declDefLink->targetFile->fileName()); + FilePath::fromString(d->m_declDefLink->targetFile->fileName())); if (textDocument() != targetDocument) { if (auto textDocument = qobject_cast(targetDocument)) connect(textDocument, @@ -1137,7 +1137,7 @@ void CppEditorWidget::abortDeclDefLink() return; IDocument *targetDocument = DocumentModel::documentForFilePath( - d->m_declDefLink->targetFile->fileName()); + FilePath::fromString(d->m_declDefLink->targetFile->fileName())); if (textDocument() != targetDocument) { if (auto textDocument = qobject_cast(targetDocument)) disconnect(textDocument, diff --git a/src/plugins/debugger/qml/qmlengineutils.cpp b/src/plugins/debugger/qml/qmlengineutils.cpp index d659f2c79b9..eb0652fbc6e 100644 --- a/src/plugins/debugger/qml/qmlengineutils.cpp +++ b/src/plugins/debugger/qml/qmlengineutils.cpp @@ -241,7 +241,8 @@ void clearExceptionSelection() QStringList highlightExceptionCode(int lineNumber, const QString &filePath, const QString &errorMessage) { QStringList messages; - const QList editors = DocumentModel::editorsForFilePath(filePath); + const QList editors = DocumentModel::editorsForFilePath( + Utils::FilePath::fromString(filePath)); const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings(); QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR); diff --git a/src/plugins/diffeditor/diffeditorplugin.cpp b/src/plugins/diffeditor/diffeditorplugin.cpp index c3898a52963..36203d3fefb 100644 --- a/src/plugins/diffeditor/diffeditorplugin.cpp +++ b/src/plugins/diffeditor/diffeditorplugin.cpp @@ -199,7 +199,7 @@ QList DiffCurrentFileController::reloadInputList() const QList result; auto textDocument = qobject_cast( - DocumentModel::documentForFilePath(m_fileName)); + DocumentModel::documentForFilePath(Utils::FilePath::fromString(m_fileName))); if (textDocument && textDocument->isModified()) { QString errorString; @@ -313,7 +313,7 @@ QList DiffModifiedFilesController::reloadInputList() const for (const QString &fileName : m_fileNames) { auto textDocument = qobject_cast( - DocumentModel::documentForFilePath(fileName)); + DocumentModel::documentForFilePath(Utils::FilePath::fromString(fileName))); if (textDocument && textDocument->isModified()) { QString errorString; diff --git a/src/plugins/diffeditor/diffeditorwidgetcontroller.cpp b/src/plugins/diffeditor/diffeditorwidgetcontroller.cpp index a5757f42d26..3cddcdf55d0 100644 --- a/src/plugins/diffeditor/diffeditorwidgetcontroller.cpp +++ b/src/plugins/diffeditor/diffeditorwidgetcontroller.cpp @@ -178,7 +178,7 @@ void DiffEditorWidgetController::patch(bool revert, int fileIndex, int chunkInde m_document->reload(); } else { // PatchEditor auto textDocument = qobject_cast( - DocumentModel::documentForFilePath(absFileName)); + DocumentModel::documentForFilePath(Utils::FilePath::fromString(absFileName))); if (!textDocument) return; diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 9da466b6dc9..7a41ba16393 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -1588,7 +1588,8 @@ void GitPluginPrivate::updateSubmodules() // If the file is modified in an editor, make sure it is saved. static bool ensureFileSaved(const QString &fileName) { - return DocumentManager::saveModifiedDocument(DocumentModel::documentForFilePath(fileName)); + return DocumentManager::saveModifiedDocument( + DocumentModel::documentForFilePath(FilePath::fromString(fileName))); } void GitPluginPrivate::applyCurrentFilePatch() diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp index 37c9103c6ec..fec1da97553 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp @@ -722,8 +722,7 @@ bool QmakePriFile::addDependencies(const QStringList &dependencies) bool QmakePriFile::saveModifiedEditors() { - Core::IDocument *document - = Core::DocumentModel::documentForFilePath(filePath().toString()); + Core::IDocument *document = Core::DocumentModel::documentForFilePath(filePath()); if (!document || !document->isModified()) return true; @@ -976,7 +975,7 @@ void QmakePriFile::save(const QStringList &lines) // We manually tell each editor to reload it's file. // (The .pro files are notified by the file system watcher.) QStringList errorStrings; - Core::IDocument *document = Core::DocumentModel::documentForFilePath(filePath().toString()); + Core::IDocument *document = Core::DocumentModel::documentForFilePath(filePath()); if (document) { QString errorString; if (!document->reload(&errorString, Core::IDocument::FlagReload, Core::IDocument::TypeContents)) diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp index d6f85ef26c7..e5152be4f5a 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.cpp +++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp @@ -1043,7 +1043,7 @@ void FindReferences::onReplaceButtonClicked(const QString &text, const QListprojectFilePath().toString(); - Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath); + const Utils::FilePath qmlProjectFilePath = project()->projectFilePath(); + Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath.toString()); const QList editors = Core::DocumentModel::editorsForFilePath(qmlProjectFilePath); TextEditor::TextDocument *document = nullptr; if (!editors.isEmpty()) { @@ -489,7 +489,7 @@ bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const Q QString error; Utils::TextFileFormat textFileFormat; const QTextCodec *codec = QTextCodec::codecForName("UTF-8"); // qml files are defined to be utf-8 - if (Utils::TextFileFormat::readFile(qmlProjectFilePath, codec, &fileContent, &textFileFormat, &error) + if (Utils::TextFileFormat::readFile(qmlProjectFilePath.toString(), codec, &fileContent, &textFileFormat, &error) != Utils::TextFileFormat::ReadSuccess) { qWarning() << "Failed to read file" << qmlProjectFilePath << ":" << error; } @@ -502,7 +502,7 @@ bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const Q fileContent.replace(match.capturedStart(1), match.capturedLength(1), QFileInfo(newFilePath).fileName()); - if (!textFileFormat.writeFile(qmlProjectFilePath, fileContent, &error)) + if (!textFileFormat.writeFile(qmlProjectFilePath.toString(), fileContent, &error)) qWarning() << "Failed to write file" << qmlProjectFilePath << ":" << error; refresh(Everything); diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index a79d28bfafd..ea8ed79005f 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -164,7 +164,7 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer editors = DocumentModel::editorsForFilePath(fileName); + QList editors = DocumentModel::editorsForFilePath(Utils::FilePath::fromString(fileName)); if (!editors.isEmpty()) { auto editorWidget = TextEditorWidget::fromEditor(editors.first()); if (editorWidget && !editorWidget->isReadOnly()) diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index ee8d95736c3..70e5f2c5d8c 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -351,7 +351,7 @@ TextDocument *TextDocument::currentTextDocument() TextDocument *TextDocument::textDocumentForFilePath(const Utils::FilePath &filePath) { - return qobject_cast(DocumentModel::documentForFilePath(filePath.toString())); + return qobject_cast(DocumentModel::documentForFilePath(filePath)); } QString TextDocument::plainText() const diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp index 37fc44bacd4..752be68db26 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.cpp +++ b/src/plugins/vcsbase/vcsbaseeditor.cpp @@ -1260,7 +1260,8 @@ const VcsBaseEditorParameters *VcsBaseEditor::findType(const VcsBaseEditorParame // Find the codec used for a file querying the editor. static QTextCodec *findFileCodec(const QString &source) { - Core::IDocument *document = Core::DocumentModel::documentForFilePath(source); + Core::IDocument *document = Core::DocumentModel::documentForFilePath( + Utils::FilePath::fromString(source)); if (auto textDocument = qobject_cast(document)) return const_cast(textDocument->codec()); return nullptr; diff --git a/src/plugins/vcsbase/vcsbaseplugin.cpp b/src/plugins/vcsbase/vcsbaseplugin.cpp index 713d15ac618..aa077410a15 100644 --- a/src/plugins/vcsbase/vcsbaseplugin.cpp +++ b/src/plugins/vcsbase/vcsbaseplugin.cpp @@ -246,7 +246,7 @@ QString StateListener::windowTitleVcsTopic(const QString &filePath) static inline QString displayNameOfEditor(const QString &fileName) { - IDocument *document = DocumentModel::documentForFilePath(fileName); + IDocument *document = DocumentModel::documentForFilePath(FilePath::fromString(fileName)); if (document) return document->displayName(); return QString();