forked from qt-creator/qt-creator
Core: replace QString with Utils::FilePath to get documents
Change-Id: I01777c227398be8bd3bf877c5429b84a75aa361b Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -633,15 +633,15 @@ QList<IDocument *> DocumentModel::openedDocuments()
|
||||
return d->m_editors.keys();
|
||||
}
|
||||
|
||||
IDocument *DocumentModel::documentForFilePath(const QString &filePath)
|
||||
IDocument *DocumentModel::documentForFilePath(const Utils::FilePath &filePath)
|
||||
{
|
||||
const Utils::optional<int> index = d->indexOfFilePath(Utils::FilePath::fromString(filePath));
|
||||
const Utils::optional<int> index = d->indexOfFilePath(filePath);
|
||||
if (!index)
|
||||
return nullptr;
|
||||
return d->m_entries.at(*index)->document;
|
||||
}
|
||||
|
||||
QList<IEditor *> DocumentModel::editorsForFilePath(const QString &filePath)
|
||||
QList<IEditor *> DocumentModel::editorsForFilePath(const Utils::FilePath &filePath)
|
||||
{
|
||||
IDocument *document = documentForFilePath(filePath);
|
||||
if (document)
|
||||
|
@@ -84,8 +84,8 @@ public:
|
||||
static Entry *entryForFilePath(const Utils::FilePath &filePath);
|
||||
static QList<IDocument *> openedDocuments();
|
||||
|
||||
static IDocument *documentForFilePath(const QString &filePath);
|
||||
static QList<IEditor *> editorsForFilePath(const QString &filePath);
|
||||
static IDocument *documentForFilePath(const Utils::FilePath &filePath);
|
||||
static QList<IEditor *> editorsForFilePath(const Utils::FilePath &filePath);
|
||||
static QList<IEditor *> editorsForDocument(IDocument *document);
|
||||
static QList<IEditor *> editorsForDocuments(const QList<IDocument *> &entries);
|
||||
static QList<IEditor *> editorsForOpenedDocuments();
|
||||
|
@@ -104,8 +104,6 @@
|
||||
#include <QTest>
|
||||
#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<IEditor *> editors = DocumentModel::editorsForFilePath(fn);
|
||||
const QList<IEditor *> 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<EditorView *> views;
|
||||
QList<IEditor *> editorsOpenForFile
|
||||
= DocumentModel::editorsForFilePath(fileName);
|
||||
QList<IEditor *> 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
|
||||
|
@@ -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<const TextDocument *>(document)->document();
|
||||
|
||||
@@ -1104,7 +1104,7 @@ void CppEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL
|
||||
abortDeclDefLink();
|
||||
d->m_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<BaseTextDocument *>(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<BaseTextDocument *>(targetDocument))
|
||||
disconnect(textDocument,
|
||||
|
@@ -241,7 +241,8 @@ void clearExceptionSelection()
|
||||
QStringList highlightExceptionCode(int lineNumber, const QString &filePath, const QString &errorMessage)
|
||||
{
|
||||
QStringList messages;
|
||||
const QList<IEditor *> editors = DocumentModel::editorsForFilePath(filePath);
|
||||
const QList<IEditor *> editors = DocumentModel::editorsForFilePath(
|
||||
Utils::FilePath::fromString(filePath));
|
||||
|
||||
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||
QTextCharFormat errorFormat = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
|
||||
|
@@ -199,7 +199,7 @@ QList<ReloadInput> DiffCurrentFileController::reloadInputList() const
|
||||
QList<ReloadInput> result;
|
||||
|
||||
auto textDocument = qobject_cast<TextEditor::TextDocument *>(
|
||||
DocumentModel::documentForFilePath(m_fileName));
|
||||
DocumentModel::documentForFilePath(Utils::FilePath::fromString(m_fileName)));
|
||||
|
||||
if (textDocument && textDocument->isModified()) {
|
||||
QString errorString;
|
||||
@@ -313,7 +313,7 @@ QList<ReloadInput> DiffModifiedFilesController::reloadInputList() const
|
||||
|
||||
for (const QString &fileName : m_fileNames) {
|
||||
auto textDocument = qobject_cast<TextEditor::TextDocument *>(
|
||||
DocumentModel::documentForFilePath(fileName));
|
||||
DocumentModel::documentForFilePath(Utils::FilePath::fromString(fileName)));
|
||||
|
||||
if (textDocument && textDocument->isModified()) {
|
||||
QString errorString;
|
||||
|
@@ -178,7 +178,7 @@ void DiffEditorWidgetController::patch(bool revert, int fileIndex, int chunkInde
|
||||
m_document->reload();
|
||||
} else { // PatchEditor
|
||||
auto textDocument = qobject_cast<TextEditor::TextDocument *>(
|
||||
DocumentModel::documentForFilePath(absFileName));
|
||||
DocumentModel::documentForFilePath(Utils::FilePath::fromString(absFileName)));
|
||||
if (!textDocument)
|
||||
return;
|
||||
|
||||
|
@@ -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()
|
||||
|
@@ -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))
|
||||
|
@@ -1043,7 +1043,7 @@ void FindReferences::onReplaceButtonClicked(const QString &text, const QList<Sea
|
||||
QStringList changedOnDisk;
|
||||
QStringList changedUnsavedEditors;
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
if (DocumentModel::documentForFilePath(fileName))
|
||||
if (DocumentModel::documentForFilePath(Utils::FilePath::fromString(fileName)))
|
||||
changedOnDisk += fileName;
|
||||
else
|
||||
changedUnsavedEditors += fileName;
|
||||
|
@@ -474,8 +474,8 @@ bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const Q
|
||||
setMainFile(newFilePath);
|
||||
|
||||
// make sure to change it also in the qmlproject file
|
||||
const QString qmlProjectFilePath = project()->projectFilePath().toString();
|
||||
Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath);
|
||||
const Utils::FilePath qmlProjectFilePath = project()->projectFilePath();
|
||||
Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath.toString());
|
||||
const QList<Core::IEditor *> 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);
|
||||
|
@@ -164,7 +164,7 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer<R
|
||||
: m_fileName(fileName)
|
||||
, m_data(data)
|
||||
{
|
||||
QList<IEditor *> editors = DocumentModel::editorsForFilePath(fileName);
|
||||
QList<IEditor *> editors = DocumentModel::editorsForFilePath(Utils::FilePath::fromString(fileName));
|
||||
if (!editors.isEmpty()) {
|
||||
auto editorWidget = TextEditorWidget::fromEditor(editors.first());
|
||||
if (editorWidget && !editorWidget->isReadOnly())
|
||||
|
@@ -351,7 +351,7 @@ TextDocument *TextDocument::currentTextDocument()
|
||||
|
||||
TextDocument *TextDocument::textDocumentForFilePath(const Utils::FilePath &filePath)
|
||||
{
|
||||
return qobject_cast<TextDocument *>(DocumentModel::documentForFilePath(filePath.toString()));
|
||||
return qobject_cast<TextDocument *>(DocumentModel::documentForFilePath(filePath));
|
||||
}
|
||||
|
||||
QString TextDocument::plainText() const
|
||||
|
@@ -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<Core::BaseTextDocument *>(document))
|
||||
return const_cast<QTextCodec *>(textDocument->codec());
|
||||
return nullptr;
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user