From 801709f72ea78ade76f0710f930fa24dc50be0b3 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 3 Feb 2023 14:19:48 +0100 Subject: [PATCH] ProjectExplorer: Show recent projects with native paths The paths in the "Recent Projects" menu, in the recent projects list on the welcome screen and those in the sessions list on the welcome screen were shown with non-natice directory separators on Windows. This fixes it for project FilePaths with osType() == OsTypeWindows Change-Id: I26afd56a82e32992f04bb3f2f1e2c1e767208ce5 Reviewed-by: David Schulz --- src/plugins/projectexplorer/projectexplorer.cpp | 7 +++++-- .../projectexplorer/projectwelcomepage.cpp | 16 ++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 7e3388c440b..64d2c8962d4 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -3340,8 +3340,11 @@ void ProjectExplorerPluginPrivate::updateRecentProjectMenu() if (filePath.endsWith(QLatin1String(".qws"))) continue; - const QString actionText = ActionManager::withNumberAccelerator( - filePath.withTildeHomePath(), acceleratorKey); + const QString displayPath = + filePath.osType() == OsTypeWindows ? filePath.displayName() + : filePath.withTildeHomePath(); + const QString actionText = + ActionManager::withNumberAccelerator(displayPath, acceleratorKey); QAction *action = menu->addAction(actionText); connect(action, &QAction::triggered, this, [this, filePath] { openRecentProject(filePath); diff --git a/src/plugins/projectexplorer/projectwelcomepage.cpp b/src/plugins/projectexplorer/projectwelcomepage.cpp index cac15eabdb3..156212a5041 100644 --- a/src/plugins/projectexplorer/projectwelcomepage.cpp +++ b/src/plugins/projectexplorer/projectwelcomepage.cpp @@ -335,9 +335,11 @@ public: yy += 18; // Project path. - QString pathWithTilde = projectPath.withTildeHomePath(); + const QString displayPath = + projectPath.osType() == OsTypeWindows ? projectPath.displayName() + : projectPath.withTildeHomePath(); painter->setPen(foregroundPrimaryColor); - painter->drawText(x1, yy, fm.elidedText(pathWithTilde, Qt::ElideMiddle, textSpace)); + painter->drawText(x1, yy, fm.elidedText(displayPath, Qt::ElideMiddle, textSpace)); yy += 22; } @@ -486,10 +488,12 @@ public: painter->setPen(themeColor(Theme::Welcome_ForegroundPrimaryColor)); painter->setFont(sizedFont(13, option.widget)); - QString pathWithTilde = projectPath.withTildeHomePath(); - const QString pathWithTildeElided = - painter->fontMetrics().elidedText(pathWithTilde, Qt::ElideMiddle, textSpace); - painter->drawText(x + TEXT_OFFSET_HORIZONTAL, secondBase, pathWithTildeElided); + const QString displayPath = + projectPath.osType() == OsTypeWindows ? projectPath.displayName() + : projectPath.withTildeHomePath(); + const QString displayPathElided = + painter->fontMetrics().elidedText(displayPath, Qt::ElideMiddle, textSpace); + painter->drawText(x + TEXT_OFFSET_HORIZONTAL, secondBase, displayPathElided); } QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &idx) const final