diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 48e55385583..facbe70e19a 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -599,6 +599,13 @@ QString DocumentManager::filePathKey(const QString &filePath, ResolveMode resolv return s; } +FilePath DocumentManager::filePathKey(const Utils::FilePath &filePath, ResolveMode resolveMode) +{ + if (resolveMode == ResolveLinks) + return filePath.canonicalPath().absoluteFilePath(); + return filePath.absoluteFilePath(); +} + /*! Returns the list of IDocuments that have been modified. */ diff --git a/src/plugins/coreplugin/documentmanager.h b/src/plugins/coreplugin/documentmanager.h index cdfecb0fd66..6aa8a18a629 100644 --- a/src/plugins/coreplugin/documentmanager.h +++ b/src/plugins/coreplugin/documentmanager.h @@ -78,6 +78,7 @@ public: // helper functions static QString cleanAbsoluteFilePath(const QString &filePath, ResolveMode resolveMode); static QString filePathKey(const QString &filePath, ResolveMode resolveMode); + static Utils::FilePath filePathKey(const Utils::FilePath &filePath, ResolveMode resolveMode); static bool saveDocument(IDocument *document, const Utils::FilePath &filePath = Utils::FilePath(), diff --git a/src/plugins/coreplugin/editormanager/documentmodel.cpp b/src/plugins/coreplugin/editormanager/documentmodel.cpp index 5c7b624d30e..24d265813d0 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel.cpp +++ b/src/plugins/coreplugin/editormanager/documentmodel.cpp @@ -103,13 +103,10 @@ int DocumentModelPrivate::rowCount(const QModelIndex &parent) const void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry) { - const Utils::FilePath fileName = entry->fileName(); - QString fixedPath; - if (!fileName.isEmpty()) - fixedPath = DocumentManager::filePathKey(fileName.toString(), DocumentManager::ResolveLinks); + const Utils::FilePath filePath = entry->fileName(); // replace a non-loaded entry (aka 'suspended') if possible - DocumentModel::Entry *previousEntry = DocumentModel::entryForFilePath(fileName); + DocumentModel::Entry *previousEntry = DocumentModel::entryForFilePath(filePath); if (previousEntry) { const bool replace = !entry->isSuspended && previousEntry->isSuspended; if (replace) { @@ -133,6 +130,7 @@ void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry) beginInsertRows(QModelIndex(), row, row); m_entries.insert(positions.second, entry); disambiguateDisplayNames(entry); + FilePath fixedPath = DocumentManager::filePathKey(filePath, DocumentManager::ResolveLinks); if (!fixedPath.isEmpty()) m_entryByFixedPath[fixedPath] = entry; connect(entry->document, &IDocument::changed, this, [this, document = entry->document] { @@ -231,8 +229,7 @@ Utils::optional DocumentModelPrivate::indexOfFilePath(const Utils::FilePath { if (filePath.isEmpty()) return Utils::nullopt; - const QString fixedPath = DocumentManager::filePathKey(filePath.toString(), - DocumentManager::ResolveLinks); + const FilePath fixedPath = DocumentManager::filePathKey(filePath, DocumentManager::ResolveLinks); const int index = m_entries.indexOf(m_entryByFixedPath.value(fixedPath)); if (index < 0) return Utils::nullopt; @@ -249,12 +246,10 @@ void DocumentModelPrivate::removeDocument(int idx) DocumentModel::Entry *entry = m_entries.takeAt(idx); endRemoveRows(); - const QString fileName = entry->fileName().toString(); - if (!fileName.isEmpty()) { - const QString fixedPath = DocumentManager::filePathKey(fileName, - DocumentManager::ResolveLinks); + const FilePath fixedPath = DocumentManager::filePathKey(entry->fileName(), + DocumentManager::ResolveLinks); + if (!fixedPath.isEmpty()) m_entryByFixedPath.remove(fixedPath); - } disconnect(entry->document, &IDocument::changed, this, nullptr); disambiguateDisplayNames(entry); delete entry; @@ -350,10 +345,8 @@ void DocumentModelPrivate::itemChanged(IDocument *document) const Utils::optional idx = indexOfDocument(document); if (!idx) return; - const QString fileName = document->filePath().toString(); - QString fixedPath; - if (!fileName.isEmpty()) - fixedPath = DocumentManager::filePathKey(fileName, DocumentManager::ResolveLinks); + const FilePath fixedPath = DocumentManager::filePathKey(document->filePath(), + DocumentManager::ResolveLinks); DocumentModel::Entry *entry = m_entries.at(idx.value()); bool found = false; // The entry's fileName might have changed, so find the previous fileName that was associated diff --git a/src/plugins/coreplugin/editormanager/documentmodel_p.h b/src/plugins/coreplugin/editormanager/documentmodel_p.h index a8c9f65ac36..ce39f939ce0 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel_p.h +++ b/src/plugins/coreplugin/editormanager/documentmodel_p.h @@ -97,7 +97,7 @@ public: QList m_entries; QMap > m_editors; - QHash m_entryByFixedPath; + QHash m_entryByFixedPath; }; } // Internal