Commit 769e67c3 authored by Jarek Kobus's avatar Jarek Kobus
Browse files

Fixed showing the proper path in prompt to overwrite msg box

Reviewed-by: default avatarFriedemann Kleint <>
Task-number: QTCREATORBUG-1601
parent cedf9e21
......@@ -38,6 +38,7 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/filewizarddialog.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <QtCore/QDir>
#include <QtCore/QFile>
......@@ -540,7 +541,7 @@ QStringList BaseFileWizard::runWizard(const QString &path, QWidget *parent)
foreach (const GeneratedFile &generatedFile, files)
switch (promptOverwrite(path, result, &errorMessage)) {
switch (promptOverwrite(result, &errorMessage)) {
case OverwriteCanceled:
return QStringList();
case OverwriteError:
......@@ -615,29 +616,34 @@ bool BaseFileWizard::postGenerateOpenEditors(const GeneratedFiles &l, QString *e
return true;
BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(const QString &location,
const QStringList &files,
BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(const QStringList &files,
QString *errorMessage) const
if (debugWizard)
qDebug() << Q_FUNC_INFO << location << files;
qDebug() << Q_FUNC_INFO << files;
bool existingFilesFound = false;
QStringList existingFiles;
bool oddStuffFound = false;
static const QString readOnlyMsg = tr(" [read only]");
static const QString directoryMsg = tr(" [directory]");
static const QString symLinkMsg = tr(" [symbolic link]");
foreach (const QString &fileName, files) {
const QFileInfo fi(fileName);
if (fi.exists())
// Note: Generated files are using native separators, no need to convert.
const QString commonExistingPath = Utils::commonPath(existingFiles);
// Format a file list message as ( "<file1> [readonly], <file2> [directory]").
QString fileNamesMsgPart;
foreach (const QString &fileName, files) {
foreach (const QString &fileName, existingFiles) {
const QFileInfo fi(fileName);
if (fi.exists()) {
existingFilesFound = true;
if (!fileNamesMsgPart.isEmpty())
fileNamesMsgPart += QLatin1String(", ");
fileNamesMsgPart += fi.fileName();
fileNamesMsgPart += fileName.mid(commonExistingPath.size() + 1);
do {
if (fi.isDir()) {
oddStuffFound = true;
......@@ -657,17 +663,17 @@ BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(const QString &l
if (!existingFilesFound)
if (existingFiles.isEmpty())
return OverwriteOk;
if (oddStuffFound) {
*errorMessage = tr("The project directory %1 contains files which cannot be overwritten:\n%2.").arg(location).arg(fileNamesMsgPart);
*errorMessage = tr("The project directory %1 contains files which cannot be overwritten:\n%2.").arg(commonExistingPath).arg(fileNamesMsgPart);
return OverwriteError;
const QString messageFormat = tr("The following files already exist in the directory %1:\n"
"%2.\nWould you like to overwrite them?");
const QString message = messageFormat.arg(location).arg(fileNamesMsgPart);
const QString message = messageFormat.arg(commonExistingPath).arg(fileNamesMsgPart);
const bool yes = (QMessageBox::question(Core::ICore::instance()->mainWindow(),
tr("Existing files"), message,
QMessageBox::Yes | QMessageBox::No,
......@@ -210,8 +210,7 @@ protected:
// Utility that performs an overwrite check on a set of files. It checks if
// the file exists, can be overwritten at all and prompts the user.
enum OverwriteResult { OverwriteOk, OverwriteError, OverwriteCanceled };
OverwriteResult promptOverwrite(const QString &location,
const QStringList &files,
OverwriteResult promptOverwrite(const QStringList &files,
QString *errorMessage) const;
// Utility to open the editors for the files whose attribute is set accordingly.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment