ProjectExplorer: Use more FilePath in wizards, mostly JsonWizard*

JsonWizardFileGenerator's path member variables become FilePath and
GeneratedFile gets the QString based file setter and getter removed.

Also, a couple of other function parameters become FilePath. TODOs notes
added for further changes.

Change-Id: Ic4b791ed71c3c03adb8f15771e2dfa9af593abd8
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Alessandro Portale
2022-06-17 17:10:51 +02:00
parent 40a1a719fe
commit 389b1eceb9
23 changed files with 130 additions and 138 deletions

View File

@@ -27,11 +27,11 @@ using namespace Utils;
namespace Core { namespace Core {
static int indexOfFile(const GeneratedFiles &f, const QString &path) static int indexOfFile(const GeneratedFiles &f, const FilePath &path)
{ {
const int size = f.size(); const int size = f.size();
for (int i = 0; i < size; ++i) for (int i = 0; i < size; ++i)
if (f.at(i).path() == path) if (f.at(i).filePath() == path)
return i; return i;
return -1; return -1;
} }
@@ -166,9 +166,10 @@ bool BaseFileWizardFactory::postGenerateOpenEditors(const GeneratedFiles &l, QSt
{ {
for (const GeneratedFile &file : qAsConst(l)) { for (const GeneratedFile &file : qAsConst(l)) {
if (file.attributes() & GeneratedFile::OpenEditorAttribute) { if (file.attributes() & GeneratedFile::OpenEditorAttribute) {
if (!EditorManager::openEditor(FilePath::fromString(file.path()), file.editorId())) { if (!EditorManager::openEditor(file.filePath(), file.editorId())) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("Failed to open an editor for \"%1\".").arg(QDir::toNativeSeparators(file.path())); *errorMessage = tr("Failed to open an editor for \"%1\".").
arg(file.filePath().toUserOutput());
return false; return false;
} }
} }
@@ -197,9 +198,9 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge
static const QString symLinkMsg = tr("[symbolic link]"); static const QString symLinkMsg = tr("[symbolic link]");
for (const GeneratedFile &file : qAsConst(*files)) { for (const GeneratedFile &file : qAsConst(*files)) {
const QString path = file.path(); const FilePath path = file.filePath();
if (QFileInfo::exists(path)) if (path.exists())
existingFiles.append(path); existingFiles.append(path.toString());
} }
if (existingFiles.isEmpty()) if (existingFiles.isEmpty())
return OverwriteOk; return OverwriteOk;
@@ -244,7 +245,7 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge
overwriteDialog.setFiles(existingFiles); overwriteDialog.setFiles(existingFiles);
for (const GeneratedFile &file : qAsConst(*files)) for (const GeneratedFile &file : qAsConst(*files))
if (file.attributes() & GeneratedFile::CustomGeneratorAttribute) if (file.attributes() & GeneratedFile::CustomGeneratorAttribute)
overwriteDialog.setFileEnabled(file.path(), false); overwriteDialog.setFileEnabled(file.filePath().toString(), false);
if (overwriteDialog.exec() != QDialog::Accepted) if (overwriteDialog.exec() != QDialog::Accepted)
return OverwriteCanceled; return OverwriteCanceled;
const QStringList existingFilesToKeep = overwriteDialog.uncheckedFiles(); const QStringList existingFilesToKeep = overwriteDialog.uncheckedFiles();
@@ -252,7 +253,7 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge
return OverwriteCanceled; return OverwriteCanceled;
// Set 'keep' attribute in files // Set 'keep' attribute in files
for (const QString &keepFile : qAsConst(existingFilesToKeep)) { for (const QString &keepFile : qAsConst(existingFilesToKeep)) {
const int i = indexOfFile(*files, keepFile); const int i = indexOfFile(*files, FilePath::fromString(keepFile).cleanPath());
QTC_ASSERT(i != -1, return OverwriteCanceled); QTC_ASSERT(i != -1, return OverwriteCanceled);
GeneratedFile &file = (*files)[i]; GeneratedFile &file = (*files)[i];
file.setAttributes(file.attributes() | GeneratedFile::KeepExistingFileAttribute); file.setAttributes(file.attributes() | GeneratedFile::KeepExistingFileAttribute);

View File

@@ -16,6 +16,8 @@ QT_END_NAMESPACE
namespace Core { namespace Core {
// TODO: Port to Utils::FilePaths
// Documentation inside. // Documentation inside.
class CORE_EXPORT PromptOverwriteDialog : public QDialog class CORE_EXPORT PromptOverwriteDialog : public QDialog
{ {

View File

@@ -96,22 +96,11 @@ GeneratedFile &GeneratedFile::operator=(const GeneratedFile &rhs)
GeneratedFile::~GeneratedFile() = default; GeneratedFile::~GeneratedFile() = default;
QString GeneratedFile::path() const
{
return m_d->path.toString();
}
FilePath GeneratedFile::filePath() const FilePath GeneratedFile::filePath() const
{ {
return m_d->path; return m_d->path;
} }
void GeneratedFile::setPath(const QString &p)
{
m_d->path = Utils::FilePath::fromString(p).cleanPath();
}
void GeneratedFile::setFilePath(const Utils::FilePath &p) void GeneratedFile::setFilePath(const Utils::FilePath &p)
{ {
m_d->path = p; m_d->path = p;

View File

@@ -42,8 +42,6 @@ public:
~GeneratedFile(); ~GeneratedFile();
// Full path of the file should be created, or the suggested file name // Full path of the file should be created, or the suggested file name
QString path() const;
void setPath(const QString &p);
void setFilePath(const Utils::FilePath &p); void setFilePath(const Utils::FilePath &p);
Utils::FilePath filePath() const; Utils::FilePath filePath() const;

View File

@@ -126,7 +126,7 @@ void BaseProjectWizardDialog::slotAccepted()
bool BaseProjectWizardDialog::validateCurrentPage() bool BaseProjectWizardDialog::validateCurrentPage()
{ {
if (currentId() == d->introPageId) if (currentId() == d->introPageId)
emit projectParametersChanged(d->introPage->projectName(), d->introPage->filePath().toString()); emit projectParametersChanged(d->introPage->projectName(), d->introPage->filePath());
return Core::BaseFileWizard::validateCurrentPage(); return Core::BaseFileWizard::validateCurrentPage();
} }

View File

@@ -49,7 +49,7 @@ public:
void setForceSubProject(bool force); void setForceSubProject(bool force);
signals: signals:
void projectParametersChanged(const QString &projectName, const QString &path); void projectParametersChanged(const QString &projectName, const Utils::FilePath &path);
protected: protected:
Utils::ProjectIntroPage *introPage() const; Utils::ProjectIntroPage *introPage() const;

View File

@@ -183,7 +183,7 @@ static bool createFile(CustomWizardFile cwFile,
return false; return false;
GeneratedFile generatedFile; GeneratedFile generatedFile;
generatedFile.setPath(targetPath); generatedFile.setFilePath(FilePath::fromString(targetPath).cleanPath());
if (cwFile.binary) { if (cwFile.binary) {
// Binary file: Set data. // Binary file: Set data.
generatedFile.setBinary(true); generatedFile.setBinary(true);
@@ -279,9 +279,10 @@ bool CustomWizard::writeFiles(const GeneratedFiles &files, QString *errorMessage
// Paranoia: Check on the files generated by the script: // Paranoia: Check on the files generated by the script:
for (const GeneratedFile &generatedFile : files) { for (const GeneratedFile &generatedFile : files) {
if (generatedFile.attributes() & GeneratedFile::CustomGeneratorAttribute) if (generatedFile.attributes() & GeneratedFile::CustomGeneratorAttribute)
if (!QFileInfo(generatedFile.path()).isFile()) { if (!generatedFile.filePath().isFile()) {
*errorMessage = QString::fromLatin1("%1 failed to generate %2"). *errorMessage = QString::fromLatin1("%1 failed to generate %2").
arg(d->m_parameters->filesGeneratorScript.back(), generatedFile.path()); arg(d->m_parameters->filesGeneratorScript.back()).
arg(generatedFile.filePath().toString());
return false; return false;
} }
} }
@@ -511,7 +512,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w,
w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath)); w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath));
connect(w, &BaseProjectWizardDialog::projectParametersChanged, connect(w, &BaseProjectWizardDialog::projectParametersChanged,
this, &CustomProjectWizard::projectParametersChanged); this, &CustomProjectWizard::handleProjectParametersChanged);
if (CustomWizardPrivate::verbose) if (CustomWizardPrivate::verbose)
qDebug() << "initProjectWizardDialog" << w << w->pageIds(); qDebug() << "initProjectWizardDialog" << w << w->pageIds();
@@ -563,12 +564,13 @@ bool CustomProjectWizard::postGenerateFiles(const QWizard *, const GeneratedFile
return CustomProjectWizard::postGenerateOpen(l, errorMessage); return CustomProjectWizard::postGenerateOpen(l, errorMessage);
} }
void CustomProjectWizard::projectParametersChanged(const QString &project, const QString & path) void CustomProjectWizard::handleProjectParametersChanged(const QString &name,
const Utils::FilePath &path)
{ {
// Make '%ProjectName%' available in base replacements. // Make '%ProjectName%' available in base replacements.
context()->baseReplacements.insert(QLatin1String("ProjectName"), project); context()->baseReplacements.insert(QLatin1String("ProjectName"), name);
emit projectLocationChanged(path + QLatin1Char('/') + project); emit projectLocationChanged(path / name);
} }
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -110,7 +110,7 @@ public:
static bool postGenerateOpen(const Core::GeneratedFiles &l, QString *errorMessage = nullptr); static bool postGenerateOpen(const Core::GeneratedFiles &l, QString *errorMessage = nullptr);
signals: signals:
void projectLocationChanged(const QString &path); void projectLocationChanged(const Utils::FilePath &path);
protected: protected:
Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters &parameters) const override; Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters &parameters) const override;
@@ -123,7 +123,7 @@ protected:
const QList<QWizardPage *> &extensionPages) const; const QList<QWizardPage *> &extensionPages) const;
private: private:
void projectParametersChanged(const QString &project, const QString &path); void handleProjectParametersChanged(const QString &project, const Utils::FilePath &path);
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -157,7 +157,7 @@ Core::GeneratedFiles
fileInfo.isAbsolute() ? fileInfo.isAbsolute() ?
token : token :
(targetPath + QLatin1Char('/') + token); (targetPath + QLatin1Char('/') + token);
file.setPath(fullPath); file.setFilePath(FilePath::fromString(fullPath).cleanPath());
} }
} }
file.setAttributes(attributes); file.setAttributes(attributes);
@@ -168,7 +168,7 @@ Core::GeneratedFiles
QDebug nospace = qDebug().nospace(); QDebug nospace = qDebug().nospace();
nospace << script << " generated:\n"; nospace << script << " generated:\n";
for (const Core::GeneratedFile &f : qAsConst(files)) for (const Core::GeneratedFile &f : qAsConst(files))
nospace << ' ' << f.path() << f.attributes() << '\n'; nospace << ' ' << f.filePath() << f.attributes() << '\n';
} }
return files; return files;
} }

View File

@@ -223,8 +223,9 @@ Node *JsonSummaryPage::findWizardContextNode(Node *contextNode) const
void JsonSummaryPage::updateFileList() void JsonSummaryPage::updateFileList()
{ {
m_fileList = m_wizard->generateFileList(); m_fileList = m_wizard->generateFileList();
QStringList filePaths const FilePaths filePaths =
= Utils::transform(m_fileList, [](const JsonWizard::GeneratorFile &f) { return f.file.path(); }); Utils::transform(m_fileList,
[](const JsonWizard::GeneratorFile &f) { return f.file.filePath(); });
setFiles(filePaths); setFiles(filePaths);
} }

View File

@@ -58,7 +58,7 @@ private:
{ {
if (column != 0 || role != Qt::DisplayRole) if (column != 0 || role != Qt::DisplayRole)
return QVariant(); return QVariant();
return QDir::toNativeSeparators(m_candidate->file.path()); return m_candidate->file.filePath().toUserOutput();
} }
JsonWizard::GeneratorFile * const m_candidate; JsonWizard::GeneratorFile * const m_candidate;
@@ -167,15 +167,18 @@ JsonWizard::GeneratorFiles JsonWizard::generateFileList()
QString errorMessage; QString errorMessage;
GeneratorFiles list; GeneratorFiles list;
QString targetPath = stringValue(QLatin1String("TargetPath")); const Utils::FilePath targetPath =
Utils::FilePath::fromString(stringValue(QLatin1String("TargetPath")));
if (targetPath.isEmpty()) if (targetPath.isEmpty())
errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page."); errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page.");
if (m_files.isEmpty() && errorMessage.isEmpty()) { if (m_files.isEmpty() && errorMessage.isEmpty()) {
emit preGenerateFiles(); emit preGenerateFiles();
for (JsonWizardGenerator *gen : qAsConst(m_generators)) { for (JsonWizardGenerator *gen : qAsConst(m_generators)) {
Core::GeneratedFiles tmp = gen->fileList(&m_expander, stringValue(QStringLiteral("WizardDir")), const Utils::FilePath wizardDir =
targetPath, &errorMessage); Utils::FilePath::fromString(stringValue(QLatin1String("WizardDir")));
const Core::GeneratedFiles tmp =
gen->fileList(&m_expander, wizardDir, targetPath, &errorMessage);
if (!errorMessage.isEmpty()) if (!errorMessage.isEmpty())
break; break;
list.append(Utils::transform(tmp, [&gen](const Core::GeneratedFile &f) list.append(Utils::transform(tmp, [&gen](const Core::GeneratedFile &f)
@@ -423,7 +426,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
bool openedSomething = false; bool openedSomething = false;
for (const JsonWizard::GeneratorFile &f : files) { for (const JsonWizard::GeneratorFile &f : files) {
const Core::GeneratedFile &file = f.file; const Core::GeneratedFile &file = f.file;
if (!QFileInfo::exists(file.path())) { if (!file.filePath().exists()) {
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"\"%1\" does not exist in the file system.") "\"%1\" does not exist in the file system.")
.arg(file.filePath().toUserOutput()); .arg(file.filePath().toUserOutput());
@@ -445,8 +448,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
openedSomething = true; openedSomething = true;
} }
if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) { if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) {
Core::IEditor *editor = Core::EditorManager::openEditor(Utils::FilePath::fromString( Core::IEditor *editor = Core::EditorManager::openEditor(file.filePath(),
file.path()),
file.editorId()); file.editorId());
if (!editor) { if (!editor) {
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",

View File

@@ -41,8 +41,8 @@ bool JsonWizardFileGenerator::setup(const QVariant &data, QString *errorMessage)
File f; File f;
const QVariantMap tmp = d.toMap(); const QVariantMap tmp = d.toMap();
f.source = tmp.value(QLatin1String("source")).toString(); f.source = Utils::FilePath::fromVariant(tmp.value(QLatin1String("source")));
f.target = tmp.value(QLatin1String("target")).toString(); f.target = Utils::FilePath::fromVariant(tmp.value(QLatin1String("target")));
f.condition = tmp.value(QLatin1String("condition"), true); f.condition = tmp.value(QLatin1String("condition"), true);
f.isBinary = tmp.value(QLatin1String("isBinary"), false); f.isBinary = tmp.value(QLatin1String("isBinary"), false);
f.overwrite = tmp.value(QLatin1String("overwrite"), false); f.overwrite = tmp.value(QLatin1String("overwrite"), false);
@@ -77,12 +77,12 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text); QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text);
Utils::FileReader reader; Utils::FileReader reader;
if (!reader.fetch(Utils::FilePath::fromString(file.source), openMode, errorMessage)) if (!reader.fetch(file.source, openMode, errorMessage))
return Core::GeneratedFile(); return Core::GeneratedFile();
// Generate file information: // Generate file information:
Core::GeneratedFile gf; Core::GeneratedFile gf;
gf.setPath(file.target); gf.setFilePath(file.target);
if (!file.keepExisting) { if (!file.keepExisting) {
if (file.isBinary.toBool()) { if (file.isBinary.toBool()) {
@@ -114,7 +114,7 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
errorMessage)); errorMessage));
if (!errorMessage->isEmpty()) { if (!errorMessage->isEmpty()) {
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "When processing \"%1\":<br>%2") *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "When processing \"%1\":<br>%2")
.arg(file.source, *errorMessage); .arg(file.source.toUserOutput(), *errorMessage);
return Core::GeneratedFile(); return Core::GeneratedFile();
} }
} }
@@ -138,14 +138,11 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
} }
Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *expander, Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *expander,
const QString &wizardDir, const QString &projectDir, const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
QString *errorMessage) QString *errorMessage)
{ {
errorMessage->clear(); errorMessage->clear();
QDir wizard(wizardDir);
QDir project(projectDir);
const QList<File> enabledFiles const QList<File> enabledFiles
= Utils::filtered(m_fileList, [&expander](const File &f) { = Utils::filtered(m_fileList, [&expander](const File &f) {
return JsonWizard::boolFromVariant(f.condition, expander); return JsonWizard::boolFromVariant(f.condition, expander);
@@ -153,14 +150,15 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
const QList<File> concreteFiles const QList<File> concreteFiles
= Utils::transform(enabledFiles, = Utils::transform(enabledFiles,
[&expander, &wizard, &project](const File &f) -> File { [&expander, &wizardDir, &projectDir](const File &f) -> File {
// Return a new file with concrete values based on input file: // Return a new file with concrete values based on input file:
File file = f; File file = f;
file.keepExisting = file.source.isEmpty(); file.keepExisting = file.source.isEmpty();
file.target = project.absoluteFilePath(expander->expand(file.target)); file.target = projectDir / expander->expand(file.target.toString());
file.source = file.keepExisting ? file.target : wizard.absoluteFilePath( file.source = file.keepExisting
expander->expand(file.source)); ? file.target
: wizardDir / expander->expand(file.source.toString());
file.isBinary = JsonWizard::boolFromVariant(file.isBinary, expander); file.isBinary = JsonWizard::boolFromVariant(file.isBinary, expander);
return file; return file;
@@ -169,18 +167,18 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
QList<File> fileList; QList<File> fileList;
QList<File> dirList; QList<File> dirList;
std::tie(fileList, dirList) std::tie(fileList, dirList)
= Utils::partition(concreteFiles, [](const File &f) { return !QFileInfo(f.source).isDir(); }); = Utils::partition(concreteFiles, [](const File &f) { return !f.source.isDir(); });
const QSet<QString> knownFiles = Utils::transform<QSet>(fileList, &File::target); const QSet<Utils::FilePath> knownFiles = Utils::transform<QSet>(fileList, &File::target);
for (const File &dir : qAsConst(dirList)) { for (const File &dir : qAsConst(dirList)) {
QDir sourceDir(dir.source); Utils::FilePath sourceDir(dir.source);
QDirIterator it(dir.source, QDir::NoDotAndDotDot | QDir::Files| QDir::Hidden, const Utils::FilePaths entries =
QDirIterator::Subdirectories); sourceDir.dirEntries(QDir::NoDotAndDotDot | QDir::Files| QDir::Hidden);
while (it.hasNext()) { for (const Utils::FilePath &entry : entries) {
const QString relativeFilePath = sourceDir.relativeFilePath(it.next()); const Utils::FilePath relativeFilePath = sourceDir.relativeChildPath(entry);
const QString targetPath = dir.target + QLatin1Char('/') + relativeFilePath; const Utils::FilePath targetPath = dir.target / relativeFilePath.toString();
if (knownFiles.contains(targetPath)) if (knownFiles.contains(targetPath))
continue; continue;
@@ -188,7 +186,7 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
// initialize each new file with properties (isBinary etc) // initialize each new file with properties (isBinary etc)
// from the current directory json entry // from the current directory json entry
File newFile = dir; File newFile = dir;
newFile.source = dir.source + QLatin1Char('/') + relativeFilePath; newFile.source = dir.source / relativeFilePath.toString();
newFile.target = targetPath; newFile.target = targetPath;
fileList.append(newFile); fileList.append(newFile);
} }
@@ -200,7 +198,8 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
return generateFile(f, expander, errorMessage); return generateFile(f, expander, errorMessage);
}); });
if (Utils::contains(result, [](const Core::GeneratedFile &gf) { return gf.path().isEmpty(); })) if (Utils::contains(result,
[](const Core::GeneratedFile &gf) { return gf.filePath().isEmpty(); }))
return Core::GeneratedFiles(); return Core::GeneratedFiles();
return result; return result;

View File

@@ -17,7 +17,7 @@ public:
bool setup(const QVariant &data, QString *errorMessage); bool setup(const QVariant &data, QString *errorMessage);
Core::GeneratedFiles fileList(Utils::MacroExpander *expander, Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
const QString &wizardDir, const QString &projectDir, const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
QString *errorMessage) override; QString *errorMessage) override;
bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) override; bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) override;
@@ -26,8 +26,8 @@ private:
class File { class File {
public: public:
bool keepExisting = false; bool keepExisting = false;
QString source; Utils::FilePath source;
QString target; Utils::FilePath target;
QVariant condition = true; QVariant condition = true;
QVariant isBinary = false; QVariant isBinary = false;
QVariant overwrite = false; QVariant overwrite = false;

View File

@@ -140,11 +140,10 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso
bool oddStuffFound = false; bool oddStuffFound = false;
for (const JsonWizard::GeneratorFile &f : qAsConst(*files)) { for (const JsonWizard::GeneratorFile &f : qAsConst(*files)) {
const QFileInfo fi(f.file.path()); if (f.file.filePath().exists()
if (fi.exists()
&& !(f.file.attributes() & GeneratedFile::ForceOverwrite) && !(f.file.attributes() & GeneratedFile::ForceOverwrite)
&& !(f.file.attributes() & GeneratedFile::KeepExistingFileAttribute)) && !(f.file.attributes() & GeneratedFile::KeepExistingFileAttribute))
existingFiles.append(f.file.path()); existingFiles.append(f.file.filePath().toString());
} }
if (existingFiles.isEmpty()) if (existingFiles.isEmpty())
return OverwriteOk; return OverwriteOk;
@@ -190,7 +189,7 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso
overwriteDialog.setFiles(existingFiles); overwriteDialog.setFiles(existingFiles);
for (const JsonWizard::GeneratorFile &file : qAsConst(*files)) for (const JsonWizard::GeneratorFile &file : qAsConst(*files))
if (!file.generator->canKeepExistingFiles()) if (!file.generator->canKeepExistingFiles())
overwriteDialog.setFileEnabled(file.file.path(), false); overwriteDialog.setFileEnabled(file.file.filePath().toString(), false);
if (overwriteDialog.exec() != QDialog::Accepted) if (overwriteDialog.exec() != QDialog::Accepted)
return OverwriteCanceled; return OverwriteCanceled;
@@ -200,7 +199,7 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso
// Set 'keep' attribute in files // Set 'keep' attribute in files
for (JsonWizard::GeneratorFile &file : *files) { for (JsonWizard::GeneratorFile &file : *files) {
if (!existingFilesToKeep.contains(file.file.path())) if (!existingFilesToKeep.contains(file.file.filePath().toString()))
continue; continue;
file.file.setAttributes(file.file.attributes() | GeneratedFile::KeepExistingFileAttribute); file.file.setAttributes(file.file.attributes() | GeneratedFile::KeepExistingFileAttribute);

View File

@@ -22,7 +22,7 @@ public:
virtual ~JsonWizardGenerator() = default; virtual ~JsonWizardGenerator() = default;
virtual Core::GeneratedFiles fileList(Utils::MacroExpander *expander, virtual Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
const QString &baseDir, const QString &projectDir, const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
QString *errorMessage) = 0; QString *errorMessage) = 0;
virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
virtual bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); virtual bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);

View File

@@ -51,14 +51,13 @@ bool JsonWizardScannerGenerator::setup(const QVariant &data, QString *errorMessa
} }
Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *expander, Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *expander,
const QString &wizardDir, const Utils::FilePath &wizardDir,
const QString &projectDir, const Utils::FilePath &projectDir,
QString *errorMessage) QString *errorMessage)
{ {
Q_UNUSED(wizardDir) Q_UNUSED(wizardDir)
errorMessage->clear(); errorMessage->clear();
QDir project(projectDir);
Core::GeneratedFiles result; Core::GeneratedFiles result;
QRegularExpression binaryPattern; QRegularExpression binaryPattern;
@@ -72,18 +71,18 @@ Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *
} }
} }
result = scan(project.absolutePath(), project); result = scan(projectDir, projectDir);
static const auto getDepth = [](const QString &filePath) { return int(filePath.count('/')); }; static const auto getDepth =
[](const Utils::FilePath &filePath) { return int(filePath.path().count('/')); };
int minDepth = std::numeric_limits<int>::max(); int minDepth = std::numeric_limits<int>::max();
for (auto it = result.begin(); it != result.end(); ++it) { for (auto it = result.begin(); it != result.end(); ++it) {
const QString relPath = project.relativeFilePath(it->path()); const Utils::FilePath relPath = projectDir.relativePath(it->filePath());
it->setBinary(binaryPattern.match(relPath).hasMatch()); it->setBinary(binaryPattern.match(relPath.toString()).hasMatch());
bool found = ProjectManager::canOpenProjectForMimeType(Utils::mimeTypeForFile( bool found = ProjectManager::canOpenProjectForMimeType(Utils::mimeTypeForFile(relPath));
Utils::FilePath::fromString(relPath)));
if (found) { if (found) {
it->setAttributes(it->attributes() | Core::GeneratedFile::OpenProjectAttribute); it->setAttributes(it->attributes() | Core::GeneratedFile::OpenProjectAttribute);
minDepth = std::min(minDepth, getDepth(it->path())); minDepth = std::min(minDepth, getDepth(it->filePath()));
} }
} }
@@ -91,7 +90,7 @@ Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *
// other project files are not candidates for opening. // other project files are not candidates for opening.
for (Core::GeneratedFile &f : result) { for (Core::GeneratedFile &f : result) {
if (f.attributes().testFlag(Core::GeneratedFile::OpenProjectAttribute) if (f.attributes().testFlag(Core::GeneratedFile::OpenProjectAttribute)
&& getDepth(f.path()) > minDepth) { && getDepth(f.filePath()) > minDepth) {
f.setAttributes(f.attributes().setFlag(Core::GeneratedFile::OpenProjectAttribute, f.setAttributes(f.attributes().setFlag(Core::GeneratedFile::OpenProjectAttribute,
false)); false));
} }
@@ -100,31 +99,31 @@ Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *
return result; return result;
} }
bool JsonWizardScannerGenerator::matchesSubdirectoryPattern(const QString &path) bool JsonWizardScannerGenerator::matchesSubdirectoryPattern(const Utils::FilePath &path)
{ {
for (const QRegularExpression &regexp : qAsConst(m_subDirectoryExpressions)) { for (const QRegularExpression &regexp : qAsConst(m_subDirectoryExpressions)) {
if (regexp.match(path).hasMatch()) if (regexp.match(path.path()).hasMatch())
return true; return true;
} }
return false; return false;
} }
Core::GeneratedFiles JsonWizardScannerGenerator::scan(const QString &dir, const QDir &base) Core::GeneratedFiles JsonWizardScannerGenerator::scan(const Utils::FilePath &dir,
const Utils::FilePath &base)
{ {
Core::GeneratedFiles result; Core::GeneratedFiles result;
QDir directory(dir);
if (!directory.exists()) if (!dir.exists())
return result; return result;
const QFileInfoList entries = directory.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, const Utils::FilePaths entries = dir.dirEntries({{}, QDir::AllEntries | QDir::NoDotAndDotDot},
QDir::DirsLast | QDir::Name); QDir::DirsLast | QDir::Name);
for (const QFileInfo &fi : entries) { for (const Utils::FilePath &fi : entries) {
const QString relativePath = base.relativeFilePath(fi.absoluteFilePath()); const Utils::FilePath relativePath = base.relativePath(fi);
if (fi.isDir() && matchesSubdirectoryPattern(relativePath)) { if (fi.isDir() && matchesSubdirectoryPattern(relativePath)) {
result += scan(fi.absoluteFilePath(), base); result += scan(fi, base);
} else { } else {
Core::GeneratedFile f(fi.absoluteFilePath()); Core::GeneratedFile f(fi);
f.setAttributes(f.attributes() | Core::GeneratedFile::KeepExistingFileAttribute); f.setAttributes(f.attributes() | Core::GeneratedFile::KeepExistingFileAttribute);
result.append(f); result.append(f);

View File

@@ -19,11 +19,11 @@ public:
bool setup(const QVariant &data, QString *errorMessage); bool setup(const QVariant &data, QString *errorMessage);
Core::GeneratedFiles fileList(Utils::MacroExpander *expander, Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
const QString &wizardDir, const QString &projectDir, const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
QString *errorMessage) override; QString *errorMessage) override;
private: private:
Core::GeneratedFiles scan(const QString &dir, const QDir &base); Core::GeneratedFiles scan(const Utils::FilePath &dir, const Utils::FilePath &base);
bool matchesSubdirectoryPattern(const QString &path); bool matchesSubdirectoryPattern(const Utils::FilePath &path);
QString m_binaryPattern; QString m_binaryPattern;
QList<QRegularExpression> m_subDirectoryExpressions; QList<QRegularExpression> m_subDirectoryExpressions;

View File

@@ -97,7 +97,7 @@ void ProjectFileWizardExtension::firstExtensionPageShown(
if (debugExtension) if (debugExtension)
qDebug() << Q_FUNC_INFO << files.size(); qDebug() << Q_FUNC_INFO << files.size();
QStringList fileNames = Utils::transform(files, &GeneratedFile::path); const FilePaths fileNames = Utils::transform(files, &GeneratedFile::filePath);
m_context->page->setFiles(fileNames); m_context->page->setFiles(fileNames);
FilePaths filePaths; FilePaths filePaths;

View File

@@ -123,14 +123,14 @@ Qt::ItemFlags AddNewTree::flags(int) const
class BestNodeSelector class BestNodeSelector
{ {
public: public:
BestNodeSelector(const QString &commonDirectory, const FilePaths &files); BestNodeSelector(const FilePath &commonDirectory, const FilePaths &files);
void inspect(AddNewTree *tree, bool isContextNode); void inspect(AddNewTree *tree, bool isContextNode);
AddNewTree *bestChoice() const; AddNewTree *bestChoice() const;
bool deploys(); bool deploys();
QString deployingProjects() const; QString deployingProjects() const;
private: private:
QString m_commonDirectory; FilePath m_commonDirectory;
FilePaths m_files; FilePaths m_files;
bool m_deploys = false; bool m_deploys = false;
QString m_deployText; QString m_deployText;
@@ -139,7 +139,7 @@ private:
int m_bestMatchPriority = -1; int m_bestMatchPriority = -1;
}; };
BestNodeSelector::BestNodeSelector(const QString &commonDirectory, const FilePaths &files) : BestNodeSelector::BestNodeSelector(const FilePath &commonDirectory, const FilePaths &files) :
m_commonDirectory(commonDirectory), m_commonDirectory(commonDirectory),
m_files(files), m_files(files),
m_deployText(QCoreApplication::translate("ProjectWizard", "The files are implicitly added to the projects:") + QLatin1Char('\n')) m_deployText(QCoreApplication::translate("ProjectWizard", "The files are implicitly added to the projects:") + QLatin1Char('\n'))
@@ -154,7 +154,7 @@ void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode)
{ {
FolderNode *node = tree->node(); FolderNode *node = tree->node();
if (node->isProjectNodeType()) { if (node->isProjectNodeType()) {
if (static_cast<ProjectNode *>(node)->deploysFolder(m_commonDirectory)) { if (static_cast<ProjectNode *>(node)->deploysFolder(m_commonDirectory.toString())) {
m_deploys = true; m_deploys = true;
m_deployText += tree->displayName() + QLatin1Char('\n'); m_deployText += tree->displayName() + QLatin1Char('\n');
} }
@@ -162,10 +162,11 @@ void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode)
if (m_deploys) if (m_deploys)
return; return;
const QString projectDirectory = node->directory().toString(); const FilePath projectDirectory = node->directory();
const int projectDirectorySize = projectDirectory.size(); const int projectDirectorySize = projectDirectory.toString().size();
if (m_commonDirectory != projectDirectory if (m_commonDirectory != projectDirectory
&& !m_commonDirectory.startsWith(projectDirectory + QLatin1Char('/')) && !m_commonDirectory.toString().startsWith(
projectDirectory.toString() + QLatin1Char('/')) // TODO: still required?
&& !isContextNode) && !isContextNode)
return; return;
@@ -384,7 +385,7 @@ void ProjectWizardPage::initializeVersionControls()
QStringList versionControlChoices = QStringList(tr("<None>")); QStringList versionControlChoices = QStringList(tr("<None>"));
if (!m_commonDirectory.isEmpty()) { if (!m_commonDirectory.isEmpty()) {
IVersionControl *managingControl = IVersionControl *managingControl =
VcsManager::findVersionControlForDirectory(FilePath::fromString(m_commonDirectory)); VcsManager::findVersionControlForDirectory(m_commonDirectory);
if (managingControl) { if (managingControl) {
// Under VCS // Under VCS
if (managingControl->supportsOperation(IVersionControl::AddOperation)) { if (managingControl->supportsOperation(IVersionControl::AddOperation)) {
@@ -427,8 +428,10 @@ bool ProjectWizardPage::runVersionControl(const QList<GeneratedFile> &files, QSt
// Create repository? // Create repository?
if (!m_repositoryExists) { if (!m_repositoryExists) {
QTC_ASSERT(versionControl->supportsOperation(IVersionControl::CreateRepositoryOperation), return false); QTC_ASSERT(versionControl->supportsOperation(IVersionControl::CreateRepositoryOperation), return false);
if (!versionControl->vcsCreateRepository(FilePath::fromString(m_commonDirectory))) { if (!versionControl->vcsCreateRepository(m_commonDirectory)) {
*errorMessage = tr("A version control system repository could not be created in \"%1\".").arg(m_commonDirectory); *errorMessage =
tr("A version control system repository could not be created in \"%1\".").
arg(m_commonDirectory.toUserOutput());
return false; return false;
} }
} }
@@ -436,7 +439,8 @@ bool ProjectWizardPage::runVersionControl(const QList<GeneratedFile> &files, QSt
if (versionControl->supportsOperation(IVersionControl::AddOperation)) { if (versionControl->supportsOperation(IVersionControl::AddOperation)) {
for (const GeneratedFile &generatedFile : files) { for (const GeneratedFile &generatedFile : files) {
if (!versionControl->vcsAdd(generatedFile.filePath())) { if (!versionControl->vcsAdd(generatedFile.filePath())) {
*errorMessage = tr("Failed to add \"%1\" to the version control system.").arg(generatedFile.path()); *errorMessage = tr("Failed to add \"%1\" to the version control system.").
arg(generatedFile.filePath().toUserOutput());
return false; return false;
} }
} }
@@ -517,12 +521,9 @@ IVersionControl *ProjectWizardPage::currentVersionControl()
return m_activeVersionControls.at(index); return m_activeVersionControls.at(index);
} }
void ProjectWizardPage::setFiles(const QStringList &fileNames) void ProjectWizardPage::setFiles(const FilePaths &files)
{ {
if (fileNames.count() == 1) m_commonDirectory = FileUtils::commonPath(files);
m_commonDirectory = QFileInfo(fileNames.first()).absolutePath();
else
m_commonDirectory = Utils::commonPath(fileNames);
QString fileMessage; QString fileMessage;
{ {
QTextStream str(&fileMessage); QTextStream str(&fileMessage);
@@ -532,14 +533,13 @@ void ProjectWizardPage::setFiles(const QStringList &fileNames)
QStringList formattedFiles; QStringList formattedFiles;
if (m_commonDirectory.isEmpty()) { if (m_commonDirectory.isEmpty()) {
formattedFiles = fileNames; formattedFiles = Utils::transform(files, &FilePath::toString);
} else { } else {
str << QDir::toNativeSeparators(m_commonDirectory) << ":\n\n"; str << m_commonDirectory.toUserOutput() << ":\n\n";
int prefixSize = m_commonDirectory.size(); int prefixSize = m_commonDirectory.toUserOutput().size();
if (!m_commonDirectory.endsWith('/')) formattedFiles = Utils::transform(files, [prefixSize] (const FilePath &f) {
++prefixSize; return f.toUserOutput().mid(prefixSize + 1); // +1 skips the initial dir separator
formattedFiles = Utils::transform(fileNames, [prefixSize](const QString &f) });
{ return f.mid(prefixSize); });
} }
// Alphabetically, and files in sub-directories first // Alphabetically, and files in sub-directories first
Utils::sort(formattedFiles, [](const QString &filePath1, const QString &filePath2) -> bool { Utils::sort(formattedFiles, [](const QString &filePath1, const QString &filePath2) -> bool {
@@ -549,8 +549,7 @@ void ProjectWizardPage::setFiles(const QStringList &fileNames)
if (filePath1HasDir == filePath2HasDir) if (filePath1HasDir == filePath2HasDir)
return FilePath::fromString(filePath1) < FilePath::fromString(filePath2); return FilePath::fromString(filePath1) < FilePath::fromString(filePath2);
return filePath1HasDir; return filePath1HasDir;
} });
);
for (const QString &f : qAsConst(formattedFiles)) for (const QString &f : qAsConst(formattedFiles))
str << QDir::toNativeSeparators(f) << '\n'; str << QDir::toNativeSeparators(f) << '\n';

View File

@@ -44,7 +44,7 @@ public:
Core::IVersionControl *currentVersionControl(); Core::IVersionControl *currentVersionControl();
// Returns the common path // Returns the common path
void setFiles(const QStringList &files); void setFiles(const Utils::FilePaths &files);
bool runVersionControl(const QList<Core::GeneratedFile> &files, QString *errorMessage); bool runVersionControl(const QList<Core::GeneratedFile> &files, QString *errorMessage);
@@ -75,7 +75,7 @@ private:
Utils::TreeModel<> m_model; Utils::TreeModel<> m_model;
QList<Core::IVersionControl*> m_activeVersionControls; QList<Core::IVersionControl*> m_activeVersionControls;
QString m_commonDirectory; Utils::FilePath m_commonDirectory;
bool m_repositoryExists = false; bool m_repositoryExists = false;
QLabel *m_projectLabel; QLabel *m_projectLabel;

View File

@@ -253,7 +253,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
const Core::GeneratedFile iconFile = generateIconFile(Utils::FilePath::fromFileInfo(qfi), const Core::GeneratedFile iconFile = generateIconFile(Utils::FilePath::fromFileInfo(qfi),
newIcon, newIcon,
errorMessage); errorMessage);
if (iconFile.path().isEmpty()) if (iconFile.filePath().isEmpty())
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
rc.push_back(iconFile); rc.push_back(iconFile);
icon = qfi.fileName(); icon = qfi.fileName();

View File

@@ -70,7 +70,7 @@ bool QtWizard::qt4ProjectPostGenerateFiles(const QWizard *w,
// Generate user settings // Generate user settings
for (const Core::GeneratedFile &file : generatedFiles) for (const Core::GeneratedFile &file : generatedFiles)
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) { if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
dialog->writeUserFile(file.path()); dialog->writeUserFile(file.filePath());
break; break;
} }
@@ -181,12 +181,12 @@ int BaseQmakeProjectWizardDialog::addTargetSetupPage(int id)
return id; return id;
} }
bool BaseQmakeProjectWizardDialog::writeUserFile(const QString &proFileName) const bool BaseQmakeProjectWizardDialog::writeUserFile(const Utils::FilePath &proFile) const
{ {
if (!m_targetSetupPage) if (!m_targetSetupPage)
return false; return false;
QmakeProject *pro = new QmakeProject(Utils::FilePath::fromString(proFileName)); QmakeProject *pro = new QmakeProject(proFile);
bool success = m_targetSetupPage->setupProject(pro); bool success = m_targetSetupPage->setupProject(pro);
if (success) if (success)
pro->saveSettings(); pro->saveSettings();
@@ -201,14 +201,15 @@ QList<Utils::Id> BaseQmakeProjectWizardDialog::selectedKits() const
return m_targetSetupPage->selectedKits(); return m_targetSetupPage->selectedKits();
} }
void BaseQmakeProjectWizardDialog::generateProfileName(const QString &name, const QString &path) void BaseQmakeProjectWizardDialog::generateProfileName(const QString &name,
const Utils::FilePath &path)
{ {
if (!m_targetSetupPage) if (!m_targetSetupPage)
return; return;
const QString proFile = QDir::cleanPath(path + '/' + name + '/' + name + ".pro"); const Utils::FilePath proFile = path / name / name + ".pro";
m_targetSetupPage->setProjectPath(Utils::FilePath::fromString(proFile)); m_targetSetupPage->setProjectPath(proFile);
} }
} // Internal } // Internal

View File

@@ -91,11 +91,11 @@ public:
int addTargetSetupPage(int id = -1); int addTargetSetupPage(int id = -1);
bool writeUserFile(const QString &proFileName) const; bool writeUserFile(const Utils::FilePath &proFile) const;
QList<Utils::Id> selectedKits() const; QList<Utils::Id> selectedKits() const;
private: private:
void generateProfileName(const QString &name, const QString &path); void generateProfileName(const QString &name, const Utils::FilePath &path);
ProjectExplorer::TargetSetupPage *m_targetSetupPage = nullptr; ProjectExplorer::TargetSetupPage *m_targetSetupPage = nullptr;
QList<Utils::Id> m_profileIds; QList<Utils::Id> m_profileIds;