diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index d78db9cd855..d7dfc368261 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -1336,22 +1336,22 @@ void DocumentManager::checkForReload() } /*! - Adds the \a fileName to the list of recent files. Associates the file to + Adds the \a filePath to the list of recent files. Associates the file to be reopened with the editor that has the specified \a editorId, if possible. \a editorId defaults to the empty ID, which lets \QC figure out the best editor itself. */ -void DocumentManager::addToRecentFiles(const QString &fileName, Id editorId) +void DocumentManager::addToRecentFiles(const Utils::FilePath &filePath, Id editorId) { - if (fileName.isEmpty()) + if (filePath.isEmpty()) return; - const QString fileKey = filePathKey(fileName, KeepLinks); + const QString fileKey = filePathKey(filePath.toString(), KeepLinks); Utils::erase(d->m_recentFiles, [fileKey](const RecentFile &file) { - return fileKey == filePathKey(file.first, DocumentManager::KeepLinks); + return fileKey == filePathKey(file.first.toString(), DocumentManager::KeepLinks); }); while (d->m_recentFiles.count() >= EditorManagerPrivate::maxRecentFiles()) d->m_recentFiles.removeLast(); - d->m_recentFiles.prepend(RecentFile(fileName, editorId)); + d->m_recentFiles.prepend(RecentFile(filePath, editorId)); } /*! @@ -1373,10 +1373,10 @@ QList DocumentManager::recentFiles() void DocumentManager::saveSettings() { - QStringList recentFiles; + QVariantList recentFiles; QStringList recentEditorIds; foreach (const RecentFile &file, d->m_recentFiles) { - recentFiles.append(file.first); + recentFiles.append(file.first.toVariant()); recentEditorIds.append(file.second.toString()); } @@ -1400,18 +1400,17 @@ void readSettings() QSettings *s = ICore::settings(); d->m_recentFiles.clear(); s->beginGroup(QLatin1String(settingsGroupC)); - const QStringList recentFiles = s->value(QLatin1String(filesKeyC)).toStringList(); + const QVariantList recentFiles = s->value(QLatin1String(filesKeyC)).toList(); const QStringList recentEditorIds = s->value(QLatin1String(editorsKeyC)).toStringList(); s->endGroup(); // clean non-existing files for (int i = 0, n = recentFiles.size(); i < n; ++i) { - const QString &fileName = recentFiles.at(i); QString editorId; if (i < recentEditorIds.size()) // guard against old or weird settings editorId = recentEditorIds.at(i); - if (QFileInfo(fileName).isFile()) - d->m_recentFiles.append(DocumentManager::RecentFile(QDir::fromNativeSeparators(fileName), // from native to guard against old settings - Id::fromString(editorId))); + const Utils::FilePath &filePath = FilePath::fromVariant(recentFiles.at(i)); + if (filePath.exists() && !filePath.isDir()) + d->m_recentFiles.append({filePath, Id::fromString(editorId)}); } s->beginGroup(QLatin1String(directoryGroupC)); diff --git a/src/plugins/coreplugin/documentmanager.h b/src/plugins/coreplugin/documentmanager.h index 4072187ba8d..cdfecb0fd66 100644 --- a/src/plugins/coreplugin/documentmanager.h +++ b/src/plugins/coreplugin/documentmanager.h @@ -53,7 +53,7 @@ public: KeepLinks }; - using RecentFile = QPair; + using RecentFile = QPair; static DocumentManager *instance(); @@ -69,7 +69,7 @@ public: static void unexpectFileChange(const QString &fileName); // recent files - static void addToRecentFiles(const QString &fileName, Utils::Id editorId = {}); + static void addToRecentFiles(const Utils::FilePath &filePath, Utils::Id editorId = {}); Q_SLOT void clearRecentFiles(); static QList recentFiles(); diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 8cc8883e8ff..5213756975a 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1445,8 +1445,7 @@ void EditorManagerPrivate::addEditor(IEditor *editor) const bool addWatcher = !isTemporary; DocumentManager::addDocument(document, addWatcher); if (!isTemporary) - DocumentManager::addToRecentFiles(document->filePath().toString(), - document->id()); + DocumentManager::addToRecentFiles(document->filePath(), document->id()); emit m_instance->documentOpened(document); } emit m_instance->editorOpened(editor); @@ -1983,7 +1982,7 @@ void EditorManagerPrivate::addDocumentToRecentFiles(IDocument *document) DocumentModel::Entry *entry = DocumentModel::entryForDocument(document); if (!entry) return; - DocumentManager::addToRecentFiles(document->filePath().toString(), entry->id()); + DocumentManager::addToRecentFiles(document->filePath(), entry->id()); } void EditorManagerPrivate::updateAutoSave() diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index aaeef7e3b89..8255bd31d17 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -1200,8 +1200,7 @@ void MainWindow::aboutToShowRecentFiles() for (int i = 0; i < recentFiles.count(); ++i) { const DocumentManager::RecentFile file = recentFiles[i]; - const QString filePath - = Utils::quoteAmpersands(QDir::toNativeSeparators(withTildeHomePath(file.first))); + const QString filePath = Utils::quoteAmpersands(file.first.shortNativePath()); const QString actionText = ActionManager::withNumberAccelerator(filePath, i + 1); QAction *action = menu->addAction(actionText); connect(action, &QAction::triggered, this, [file] {