Project wizard summary page: Order the file list

Alphabetically, and files in sub-directories first

Change-Id: I65a29af7a952e8c3aa63cbac637c6a9395b9a846
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@nokia.com>
This commit is contained in:
Alessandro Portale
2012-03-08 19:51:33 +01:00
parent a5063e6ba4
commit a9a50faa23

View File

@@ -135,6 +135,18 @@ void ProjectWizardPage::changeEvent(QEvent *e)
} }
} }
// Alphabetically, and files in sub-directories first
static bool generatedFilePathLessThan(const QString &filePath1, const QString &filePath2)
{
const bool filePath1HasDir = filePath1.contains(QLatin1Char('/'));
const bool filePath2HasDir = filePath2.contains(QLatin1Char('/'));
if (filePath1HasDir == filePath2HasDir)
return filePath1 < filePath2;
else
return filePath1HasDir;
}
void ProjectWizardPage::setFilesDisplay(const QString &commonPath, const QStringList &files) void ProjectWizardPage::setFilesDisplay(const QString &commonPath, const QStringList &files)
{ {
QString fileMessage; QString fileMessage;
@@ -143,15 +155,21 @@ void ProjectWizardPage::setFilesDisplay(const QString &commonPath, const QString
str << "<qt>" str << "<qt>"
<< (commonPath.isEmpty() ? tr("Files to be added:") : tr("Files to be added in")) << (commonPath.isEmpty() ? tr("Files to be added:") : tr("Files to be added in"))
<< "<pre>"; << "<pre>";
QStringList formattedFiles;
if (commonPath.isEmpty()) { if (commonPath.isEmpty()) {
foreach(const QString &f, files) formattedFiles = files;
str << QDir::toNativeSeparators(f) << '\n';
} else { } else {
str << QDir::toNativeSeparators(commonPath) << ":\n\n"; str << QDir::toNativeSeparators(commonPath) << ":\n\n";
const int prefixSize = commonPath.size() + 1; const int prefixSize = commonPath.size() + 1;
foreach (const QString &f, files) foreach (const QString &f, files)
str << QDir::toNativeSeparators(f.right(f.size() - prefixSize)) << '\n'; formattedFiles.append(f.right(f.size() - prefixSize));
} }
qSort(formattedFiles.begin(), formattedFiles.end(), generatedFilePathLessThan);
foreach (const QString &f, formattedFiles)
str << QDir::toNativeSeparators(f) << '\n';
str << "</pre>"; str << "</pre>";
} }
m_ui->filesLabel->setText(fileMessage); m_ui->filesLabel->setText(fileMessage);