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 <david.schulz@qt.io>
This commit is contained in:
Alessandro Portale
2023-02-03 14:19:48 +01:00
parent 0d0ce383be
commit 801709f72e
2 changed files with 15 additions and 8 deletions

View File

@@ -3340,8 +3340,11 @@ void ProjectExplorerPluginPrivate::updateRecentProjectMenu()
if (filePath.endsWith(QLatin1String(".qws"))) if (filePath.endsWith(QLatin1String(".qws")))
continue; continue;
const QString actionText = ActionManager::withNumberAccelerator( const QString displayPath =
filePath.withTildeHomePath(), acceleratorKey); filePath.osType() == OsTypeWindows ? filePath.displayName()
: filePath.withTildeHomePath();
const QString actionText =
ActionManager::withNumberAccelerator(displayPath, acceleratorKey);
QAction *action = menu->addAction(actionText); QAction *action = menu->addAction(actionText);
connect(action, &QAction::triggered, this, [this, filePath] { connect(action, &QAction::triggered, this, [this, filePath] {
openRecentProject(filePath); openRecentProject(filePath);

View File

@@ -335,9 +335,11 @@ public:
yy += 18; yy += 18;
// Project path. // Project path.
QString pathWithTilde = projectPath.withTildeHomePath(); const QString displayPath =
projectPath.osType() == OsTypeWindows ? projectPath.displayName()
: projectPath.withTildeHomePath();
painter->setPen(foregroundPrimaryColor); 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; yy += 22;
} }
@@ -486,10 +488,12 @@ public:
painter->setPen(themeColor(Theme::Welcome_ForegroundPrimaryColor)); painter->setPen(themeColor(Theme::Welcome_ForegroundPrimaryColor));
painter->setFont(sizedFont(13, option.widget)); painter->setFont(sizedFont(13, option.widget));
QString pathWithTilde = projectPath.withTildeHomePath(); const QString displayPath =
const QString pathWithTildeElided = projectPath.osType() == OsTypeWindows ? projectPath.displayName()
painter->fontMetrics().elidedText(pathWithTilde, Qt::ElideMiddle, textSpace); : projectPath.withTildeHomePath();
painter->drawText(x + TEXT_OFFSET_HORIZONTAL, secondBase, pathWithTildeElided); 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 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &idx) const final