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 <qtc-committer@nokia.com>
Task-number: QTCREATORBUG-1601
parent cedf9e21
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/filewizarddialog.h> #include <utils/filewizarddialog.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QFile> #include <QtCore/QFile>
...@@ -540,7 +541,7 @@ QStringList BaseFileWizard::runWizard(const QString &path, QWidget *parent) ...@@ -540,7 +541,7 @@ QStringList BaseFileWizard::runWizard(const QString &path, QWidget *parent)
foreach (const GeneratedFile &generatedFile, files) foreach (const GeneratedFile &generatedFile, files)
result.push_back(generatedFile.path()); result.push_back(generatedFile.path());
switch (promptOverwrite(path, result, &errorMessage)) { switch (promptOverwrite(result, &errorMessage)) {
case OverwriteCanceled: case OverwriteCanceled:
return QStringList(); return QStringList();
case OverwriteError: case OverwriteError:
...@@ -615,29 +616,34 @@ bool BaseFileWizard::postGenerateOpenEditors(const GeneratedFiles &l, QString *e ...@@ -615,29 +616,34 @@ bool BaseFileWizard::postGenerateOpenEditors(const GeneratedFiles &l, QString *e
return true; return true;
} }
BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(const QString &location, BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(const QStringList &files,
const QStringList &files,
QString *errorMessage) const QString *errorMessage) const
{ {
if (debugWizard) if (debugWizard)
qDebug() << Q_FUNC_INFO << location << files; qDebug() << Q_FUNC_INFO << files;
bool existingFilesFound = false; QStringList existingFiles;
bool oddStuffFound = false; bool oddStuffFound = false;
static const QString readOnlyMsg = tr(" [read only]"); static const QString readOnlyMsg = tr(" [read only]");
static const QString directoryMsg = tr(" [directory]"); static const QString directoryMsg = tr(" [directory]");
static const QString symLinkMsg = tr(" [symbolic link]"); static const QString symLinkMsg = tr(" [symbolic link]");
foreach (const QString &fileName, files) {
const QFileInfo fi(fileName);
if (fi.exists())
existingFiles.append(fileName);
}
// 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]"). // Format a file list message as ( "<file1> [readonly], <file2> [directory]").
QString fileNamesMsgPart; QString fileNamesMsgPart;
foreach (const QString &fileName, files) { foreach (const QString &fileName, existingFiles) {
const QFileInfo fi(fileName); const QFileInfo fi(fileName);
if (fi.exists()) { if (fi.exists()) {
existingFilesFound = true;
if (!fileNamesMsgPart.isEmpty()) if (!fileNamesMsgPart.isEmpty())
fileNamesMsgPart += QLatin1String(", "); fileNamesMsgPart += QLatin1String(", ");
fileNamesMsgPart += fi.fileName(); fileNamesMsgPart += fileName.mid(commonExistingPath.size() + 1);
do { do {
if (fi.isDir()) { if (fi.isDir()) {
oddStuffFound = true; oddStuffFound = true;
...@@ -657,17 +663,17 @@ BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(const QString &l ...@@ -657,17 +663,17 @@ BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(const QString &l
} }
} }
if (!existingFilesFound) if (existingFiles.isEmpty())
return OverwriteOk; return OverwriteOk;
if (oddStuffFound) { 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; return OverwriteError;
} }
const QString messageFormat = tr("The following files already exist in the directory %1:\n" const QString messageFormat = tr("The following files already exist in the directory %1:\n"
"%2.\nWould you like to overwrite them?"); "%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(), const bool yes = (QMessageBox::question(Core::ICore::instance()->mainWindow(),
tr("Existing files"), message, tr("Existing files"), message,
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes | QMessageBox::No,
......
...@@ -210,8 +210,7 @@ protected: ...@@ -210,8 +210,7 @@ protected:
// Utility that performs an overwrite check on a set of files. It checks if // 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. // the file exists, can be overwritten at all and prompts the user.
enum OverwriteResult { OverwriteOk, OverwriteError, OverwriteCanceled }; enum OverwriteResult { OverwriteOk, OverwriteError, OverwriteCanceled };
OverwriteResult promptOverwrite(const QString &location, OverwriteResult promptOverwrite(const QStringList &files,
const QStringList &files,
QString *errorMessage) const; QString *errorMessage) const;
// Utility to open the editors for the files whose attribute is set accordingly. // Utility to open the editors for the files whose attribute is set accordingly.
......
Markdown is supported
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