forked from qt-creator/qt-creator
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:
@@ -27,11 +27,11 @@ using namespace Utils;
|
||||
|
||||
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();
|
||||
for (int i = 0; i < size; ++i)
|
||||
if (f.at(i).path() == path)
|
||||
if (f.at(i).filePath() == path)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
@@ -166,9 +166,10 @@ bool BaseFileWizardFactory::postGenerateOpenEditors(const GeneratedFiles &l, QSt
|
||||
{
|
||||
for (const GeneratedFile &file : qAsConst(l)) {
|
||||
if (file.attributes() & GeneratedFile::OpenEditorAttribute) {
|
||||
if (!EditorManager::openEditor(FilePath::fromString(file.path()), file.editorId())) {
|
||||
if (!EditorManager::openEditor(file.filePath(), file.editorId())) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -197,9 +198,9 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge
|
||||
static const QString symLinkMsg = tr("[symbolic link]");
|
||||
|
||||
for (const GeneratedFile &file : qAsConst(*files)) {
|
||||
const QString path = file.path();
|
||||
if (QFileInfo::exists(path))
|
||||
existingFiles.append(path);
|
||||
const FilePath path = file.filePath();
|
||||
if (path.exists())
|
||||
existingFiles.append(path.toString());
|
||||
}
|
||||
if (existingFiles.isEmpty())
|
||||
return OverwriteOk;
|
||||
@@ -244,7 +245,7 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge
|
||||
overwriteDialog.setFiles(existingFiles);
|
||||
for (const GeneratedFile &file : qAsConst(*files))
|
||||
if (file.attributes() & GeneratedFile::CustomGeneratorAttribute)
|
||||
overwriteDialog.setFileEnabled(file.path(), false);
|
||||
overwriteDialog.setFileEnabled(file.filePath().toString(), false);
|
||||
if (overwriteDialog.exec() != QDialog::Accepted)
|
||||
return OverwriteCanceled;
|
||||
const QStringList existingFilesToKeep = overwriteDialog.uncheckedFiles();
|
||||
@@ -252,7 +253,7 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge
|
||||
return OverwriteCanceled;
|
||||
// Set 'keep' attribute in files
|
||||
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);
|
||||
GeneratedFile &file = (*files)[i];
|
||||
file.setAttributes(file.attributes() | GeneratedFile::KeepExistingFileAttribute);
|
||||
|
@@ -16,6 +16,8 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
|
||||
// TODO: Port to Utils::FilePaths
|
||||
|
||||
// Documentation inside.
|
||||
class CORE_EXPORT PromptOverwriteDialog : public QDialog
|
||||
{
|
||||
|
@@ -96,22 +96,11 @@ GeneratedFile &GeneratedFile::operator=(const GeneratedFile &rhs)
|
||||
|
||||
GeneratedFile::~GeneratedFile() = default;
|
||||
|
||||
QString GeneratedFile::path() const
|
||||
{
|
||||
return m_d->path.toString();
|
||||
}
|
||||
|
||||
FilePath GeneratedFile::filePath() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_d->path = p;
|
||||
|
@@ -42,8 +42,6 @@ public:
|
||||
~GeneratedFile();
|
||||
|
||||
// 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);
|
||||
Utils::FilePath filePath() const;
|
||||
|
||||
|
@@ -126,7 +126,7 @@ void BaseProjectWizardDialog::slotAccepted()
|
||||
bool BaseProjectWizardDialog::validateCurrentPage()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ public:
|
||||
void setForceSubProject(bool force);
|
||||
|
||||
signals:
|
||||
void projectParametersChanged(const QString &projectName, const QString &path);
|
||||
void projectParametersChanged(const QString &projectName, const Utils::FilePath &path);
|
||||
|
||||
protected:
|
||||
Utils::ProjectIntroPage *introPage() const;
|
||||
|
@@ -183,7 +183,7 @@ static bool createFile(CustomWizardFile cwFile,
|
||||
return false;
|
||||
|
||||
GeneratedFile generatedFile;
|
||||
generatedFile.setPath(targetPath);
|
||||
generatedFile.setFilePath(FilePath::fromString(targetPath).cleanPath());
|
||||
if (cwFile.binary) {
|
||||
// Binary file: Set data.
|
||||
generatedFile.setBinary(true);
|
||||
@@ -279,9 +279,10 @@ bool CustomWizard::writeFiles(const GeneratedFiles &files, QString *errorMessage
|
||||
// Paranoia: Check on the files generated by the script:
|
||||
for (const GeneratedFile &generatedFile : files) {
|
||||
if (generatedFile.attributes() & GeneratedFile::CustomGeneratorAttribute)
|
||||
if (!QFileInfo(generatedFile.path()).isFile()) {
|
||||
if (!generatedFile.filePath().isFile()) {
|
||||
*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;
|
||||
}
|
||||
}
|
||||
@@ -511,7 +512,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w,
|
||||
w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath));
|
||||
|
||||
connect(w, &BaseProjectWizardDialog::projectParametersChanged,
|
||||
this, &CustomProjectWizard::projectParametersChanged);
|
||||
this, &CustomProjectWizard::handleProjectParametersChanged);
|
||||
|
||||
if (CustomWizardPrivate::verbose)
|
||||
qDebug() << "initProjectWizardDialog" << w << w->pageIds();
|
||||
@@ -563,12 +564,13 @@ bool CustomProjectWizard::postGenerateFiles(const QWizard *, const GeneratedFile
|
||||
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.
|
||||
context()->baseReplacements.insert(QLatin1String("ProjectName"), project);
|
||||
context()->baseReplacements.insert(QLatin1String("ProjectName"), name);
|
||||
|
||||
emit projectLocationChanged(path + QLatin1Char('/') + project);
|
||||
emit projectLocationChanged(path / name);
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -110,7 +110,7 @@ public:
|
||||
static bool postGenerateOpen(const Core::GeneratedFiles &l, QString *errorMessage = nullptr);
|
||||
|
||||
signals:
|
||||
void projectLocationChanged(const QString &path);
|
||||
void projectLocationChanged(const Utils::FilePath &path);
|
||||
|
||||
protected:
|
||||
Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const override;
|
||||
@@ -123,7 +123,7 @@ protected:
|
||||
const QList<QWizardPage *> &extensionPages) const;
|
||||
|
||||
private:
|
||||
void projectParametersChanged(const QString &project, const QString &path);
|
||||
void handleProjectParametersChanged(const QString &project, const Utils::FilePath &path);
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -157,7 +157,7 @@ Core::GeneratedFiles
|
||||
fileInfo.isAbsolute() ?
|
||||
token :
|
||||
(targetPath + QLatin1Char('/') + token);
|
||||
file.setPath(fullPath);
|
||||
file.setFilePath(FilePath::fromString(fullPath).cleanPath());
|
||||
}
|
||||
}
|
||||
file.setAttributes(attributes);
|
||||
@@ -168,7 +168,7 @@ Core::GeneratedFiles
|
||||
QDebug nospace = qDebug().nospace();
|
||||
nospace << script << " generated:\n";
|
||||
for (const Core::GeneratedFile &f : qAsConst(files))
|
||||
nospace << ' ' << f.path() << f.attributes() << '\n';
|
||||
nospace << ' ' << f.filePath() << f.attributes() << '\n';
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
@@ -223,8 +223,9 @@ Node *JsonSummaryPage::findWizardContextNode(Node *contextNode) const
|
||||
void JsonSummaryPage::updateFileList()
|
||||
{
|
||||
m_fileList = m_wizard->generateFileList();
|
||||
QStringList filePaths
|
||||
= Utils::transform(m_fileList, [](const JsonWizard::GeneratorFile &f) { return f.file.path(); });
|
||||
const FilePaths filePaths =
|
||||
Utils::transform(m_fileList,
|
||||
[](const JsonWizard::GeneratorFile &f) { return f.file.filePath(); });
|
||||
setFiles(filePaths);
|
||||
}
|
||||
|
||||
|
@@ -58,7 +58,7 @@ private:
|
||||
{
|
||||
if (column != 0 || role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
return QDir::toNativeSeparators(m_candidate->file.path());
|
||||
return m_candidate->file.filePath().toUserOutput();
|
||||
}
|
||||
|
||||
JsonWizard::GeneratorFile * const m_candidate;
|
||||
@@ -167,15 +167,18 @@ JsonWizard::GeneratorFiles JsonWizard::generateFileList()
|
||||
QString errorMessage;
|
||||
GeneratorFiles list;
|
||||
|
||||
QString targetPath = stringValue(QLatin1String("TargetPath"));
|
||||
const Utils::FilePath targetPath =
|
||||
Utils::FilePath::fromString(stringValue(QLatin1String("TargetPath")));
|
||||
if (targetPath.isEmpty())
|
||||
errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page.");
|
||||
|
||||
if (m_files.isEmpty() && errorMessage.isEmpty()) {
|
||||
emit preGenerateFiles();
|
||||
for (JsonWizardGenerator *gen : qAsConst(m_generators)) {
|
||||
Core::GeneratedFiles tmp = gen->fileList(&m_expander, stringValue(QStringLiteral("WizardDir")),
|
||||
targetPath, &errorMessage);
|
||||
const Utils::FilePath wizardDir =
|
||||
Utils::FilePath::fromString(stringValue(QLatin1String("WizardDir")));
|
||||
const Core::GeneratedFiles tmp =
|
||||
gen->fileList(&m_expander, wizardDir, targetPath, &errorMessage);
|
||||
if (!errorMessage.isEmpty())
|
||||
break;
|
||||
list.append(Utils::transform(tmp, [&gen](const Core::GeneratedFile &f)
|
||||
@@ -423,7 +426,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
|
||||
bool openedSomething = false;
|
||||
for (const JsonWizard::GeneratorFile &f : files) {
|
||||
const Core::GeneratedFile &file = f.file;
|
||||
if (!QFileInfo::exists(file.path())) {
|
||||
if (!file.filePath().exists()) {
|
||||
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
|
||||
"\"%1\" does not exist in the file system.")
|
||||
.arg(file.filePath().toUserOutput());
|
||||
@@ -445,8 +448,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
|
||||
openedSomething = true;
|
||||
}
|
||||
if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) {
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(Utils::FilePath::fromString(
|
||||
file.path()),
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(file.filePath(),
|
||||
file.editorId());
|
||||
if (!editor) {
|
||||
errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
|
||||
|
@@ -41,8 +41,8 @@ bool JsonWizardFileGenerator::setup(const QVariant &data, QString *errorMessage)
|
||||
File f;
|
||||
|
||||
const QVariantMap tmp = d.toMap();
|
||||
f.source = tmp.value(QLatin1String("source")).toString();
|
||||
f.target = tmp.value(QLatin1String("target")).toString();
|
||||
f.source = Utils::FilePath::fromVariant(tmp.value(QLatin1String("source")));
|
||||
f.target = Utils::FilePath::fromVariant(tmp.value(QLatin1String("target")));
|
||||
f.condition = tmp.value(QLatin1String("condition"), true);
|
||||
f.isBinary = tmp.value(QLatin1String("isBinary"), 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);
|
||||
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(Utils::FilePath::fromString(file.source), openMode, errorMessage))
|
||||
if (!reader.fetch(file.source, openMode, errorMessage))
|
||||
return Core::GeneratedFile();
|
||||
|
||||
// Generate file information:
|
||||
Core::GeneratedFile gf;
|
||||
gf.setPath(file.target);
|
||||
gf.setFilePath(file.target);
|
||||
|
||||
if (!file.keepExisting) {
|
||||
if (file.isBinary.toBool()) {
|
||||
@@ -114,7 +114,7 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
|
||||
errorMessage));
|
||||
if (!errorMessage->isEmpty()) {
|
||||
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "When processing \"%1\":<br>%2")
|
||||
.arg(file.source, *errorMessage);
|
||||
.arg(file.source.toUserOutput(), *errorMessage);
|
||||
return Core::GeneratedFile();
|
||||
}
|
||||
}
|
||||
@@ -138,14 +138,11 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
|
||||
}
|
||||
|
||||
Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *expander,
|
||||
const QString &wizardDir, const QString &projectDir,
|
||||
const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
|
||||
QString *errorMessage)
|
||||
{
|
||||
errorMessage->clear();
|
||||
|
||||
QDir wizard(wizardDir);
|
||||
QDir project(projectDir);
|
||||
|
||||
const QList<File> enabledFiles
|
||||
= Utils::filtered(m_fileList, [&expander](const File &f) {
|
||||
return JsonWizard::boolFromVariant(f.condition, expander);
|
||||
@@ -153,14 +150,15 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
||||
|
||||
const QList<File> concreteFiles
|
||||
= 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:
|
||||
File file = f;
|
||||
|
||||
file.keepExisting = file.source.isEmpty();
|
||||
file.target = project.absoluteFilePath(expander->expand(file.target));
|
||||
file.source = file.keepExisting ? file.target : wizard.absoluteFilePath(
|
||||
expander->expand(file.source));
|
||||
file.target = projectDir / expander->expand(file.target.toString());
|
||||
file.source = file.keepExisting
|
||||
? file.target
|
||||
: wizardDir / expander->expand(file.source.toString());
|
||||
file.isBinary = JsonWizard::boolFromVariant(file.isBinary, expander);
|
||||
|
||||
return file;
|
||||
@@ -169,18 +167,18 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
||||
QList<File> fileList;
|
||||
QList<File> 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)) {
|
||||
QDir sourceDir(dir.source);
|
||||
QDirIterator it(dir.source, QDir::NoDotAndDotDot | QDir::Files| QDir::Hidden,
|
||||
QDirIterator::Subdirectories);
|
||||
Utils::FilePath sourceDir(dir.source);
|
||||
const Utils::FilePaths entries =
|
||||
sourceDir.dirEntries(QDir::NoDotAndDotDot | QDir::Files| QDir::Hidden);
|
||||
|
||||
while (it.hasNext()) {
|
||||
const QString relativeFilePath = sourceDir.relativeFilePath(it.next());
|
||||
const QString targetPath = dir.target + QLatin1Char('/') + relativeFilePath;
|
||||
for (const Utils::FilePath &entry : entries) {
|
||||
const Utils::FilePath relativeFilePath = sourceDir.relativeChildPath(entry);
|
||||
const Utils::FilePath targetPath = dir.target / relativeFilePath.toString();
|
||||
|
||||
if (knownFiles.contains(targetPath))
|
||||
continue;
|
||||
@@ -188,7 +186,7 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
||||
// initialize each new file with properties (isBinary etc)
|
||||
// from the current directory json entry
|
||||
File newFile = dir;
|
||||
newFile.source = dir.source + QLatin1Char('/') + relativeFilePath;
|
||||
newFile.source = dir.source / relativeFilePath.toString();
|
||||
newFile.target = targetPath;
|
||||
fileList.append(newFile);
|
||||
}
|
||||
@@ -200,7 +198,8 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp
|
||||
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 result;
|
||||
|
@@ -17,7 +17,7 @@ public:
|
||||
bool setup(const QVariant &data, QString *errorMessage);
|
||||
|
||||
Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
|
||||
const QString &wizardDir, const QString &projectDir,
|
||||
const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
|
||||
QString *errorMessage) override;
|
||||
|
||||
bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) override;
|
||||
@@ -26,8 +26,8 @@ private:
|
||||
class File {
|
||||
public:
|
||||
bool keepExisting = false;
|
||||
QString source;
|
||||
QString target;
|
||||
Utils::FilePath source;
|
||||
Utils::FilePath target;
|
||||
QVariant condition = true;
|
||||
QVariant isBinary = false;
|
||||
QVariant overwrite = false;
|
||||
|
@@ -140,11 +140,10 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso
|
||||
bool oddStuffFound = false;
|
||||
|
||||
for (const JsonWizard::GeneratorFile &f : qAsConst(*files)) {
|
||||
const QFileInfo fi(f.file.path());
|
||||
if (fi.exists()
|
||||
if (f.file.filePath().exists()
|
||||
&& !(f.file.attributes() & GeneratedFile::ForceOverwrite)
|
||||
&& !(f.file.attributes() & GeneratedFile::KeepExistingFileAttribute))
|
||||
existingFiles.append(f.file.path());
|
||||
existingFiles.append(f.file.filePath().toString());
|
||||
}
|
||||
if (existingFiles.isEmpty())
|
||||
return OverwriteOk;
|
||||
@@ -190,7 +189,7 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso
|
||||
overwriteDialog.setFiles(existingFiles);
|
||||
for (const JsonWizard::GeneratorFile &file : qAsConst(*files))
|
||||
if (!file.generator->canKeepExistingFiles())
|
||||
overwriteDialog.setFileEnabled(file.file.path(), false);
|
||||
overwriteDialog.setFileEnabled(file.file.filePath().toString(), false);
|
||||
if (overwriteDialog.exec() != QDialog::Accepted)
|
||||
return OverwriteCanceled;
|
||||
|
||||
@@ -200,7 +199,7 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso
|
||||
|
||||
// Set 'keep' attribute in files
|
||||
for (JsonWizard::GeneratorFile &file : *files) {
|
||||
if (!existingFilesToKeep.contains(file.file.path()))
|
||||
if (!existingFilesToKeep.contains(file.file.filePath().toString()))
|
||||
continue;
|
||||
|
||||
file.file.setAttributes(file.file.attributes() | GeneratedFile::KeepExistingFileAttribute);
|
||||
|
@@ -22,7 +22,7 @@ public:
|
||||
virtual ~JsonWizardGenerator() = default;
|
||||
|
||||
virtual Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
|
||||
const QString &baseDir, const QString &projectDir,
|
||||
const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
|
||||
QString *errorMessage) = 0;
|
||||
virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
|
||||
virtual bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
|
||||
|
@@ -51,14 +51,13 @@ bool JsonWizardScannerGenerator::setup(const QVariant &data, QString *errorMessa
|
||||
}
|
||||
|
||||
Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *expander,
|
||||
const QString &wizardDir,
|
||||
const QString &projectDir,
|
||||
const Utils::FilePath &wizardDir,
|
||||
const Utils::FilePath &projectDir,
|
||||
QString *errorMessage)
|
||||
{
|
||||
Q_UNUSED(wizardDir)
|
||||
errorMessage->clear();
|
||||
|
||||
QDir project(projectDir);
|
||||
Core::GeneratedFiles result;
|
||||
|
||||
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();
|
||||
for (auto it = result.begin(); it != result.end(); ++it) {
|
||||
const QString relPath = project.relativeFilePath(it->path());
|
||||
it->setBinary(binaryPattern.match(relPath).hasMatch());
|
||||
bool found = ProjectManager::canOpenProjectForMimeType(Utils::mimeTypeForFile(
|
||||
Utils::FilePath::fromString(relPath)));
|
||||
const Utils::FilePath relPath = projectDir.relativePath(it->filePath());
|
||||
it->setBinary(binaryPattern.match(relPath.toString()).hasMatch());
|
||||
bool found = ProjectManager::canOpenProjectForMimeType(Utils::mimeTypeForFile(relPath));
|
||||
if (found) {
|
||||
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.
|
||||
for (Core::GeneratedFile &f : result) {
|
||||
if (f.attributes().testFlag(Core::GeneratedFile::OpenProjectAttribute)
|
||||
&& getDepth(f.path()) > minDepth) {
|
||||
&& getDepth(f.filePath()) > minDepth) {
|
||||
f.setAttributes(f.attributes().setFlag(Core::GeneratedFile::OpenProjectAttribute,
|
||||
false));
|
||||
}
|
||||
@@ -100,31 +99,31 @@ Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *
|
||||
return result;
|
||||
}
|
||||
|
||||
bool JsonWizardScannerGenerator::matchesSubdirectoryPattern(const QString &path)
|
||||
bool JsonWizardScannerGenerator::matchesSubdirectoryPattern(const Utils::FilePath &path)
|
||||
{
|
||||
for (const QRegularExpression ®exp : qAsConst(m_subDirectoryExpressions)) {
|
||||
if (regexp.match(path).hasMatch())
|
||||
if (regexp.match(path.path()).hasMatch())
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
QDir directory(dir);
|
||||
|
||||
if (!directory.exists())
|
||||
if (!dir.exists())
|
||||
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);
|
||||
for (const QFileInfo &fi : entries) {
|
||||
const QString relativePath = base.relativeFilePath(fi.absoluteFilePath());
|
||||
for (const Utils::FilePath &fi : entries) {
|
||||
const Utils::FilePath relativePath = base.relativePath(fi);
|
||||
if (fi.isDir() && matchesSubdirectoryPattern(relativePath)) {
|
||||
result += scan(fi.absoluteFilePath(), base);
|
||||
result += scan(fi, base);
|
||||
} else {
|
||||
Core::GeneratedFile f(fi.absoluteFilePath());
|
||||
Core::GeneratedFile f(fi);
|
||||
f.setAttributes(f.attributes() | Core::GeneratedFile::KeepExistingFileAttribute);
|
||||
|
||||
result.append(f);
|
||||
|
@@ -19,11 +19,11 @@ public:
|
||||
bool setup(const QVariant &data, QString *errorMessage);
|
||||
|
||||
Core::GeneratedFiles fileList(Utils::MacroExpander *expander,
|
||||
const QString &wizardDir, const QString &projectDir,
|
||||
const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir,
|
||||
QString *errorMessage) override;
|
||||
private:
|
||||
Core::GeneratedFiles scan(const QString &dir, const QDir &base);
|
||||
bool matchesSubdirectoryPattern(const QString &path);
|
||||
Core::GeneratedFiles scan(const Utils::FilePath &dir, const Utils::FilePath &base);
|
||||
bool matchesSubdirectoryPattern(const Utils::FilePath &path);
|
||||
|
||||
QString m_binaryPattern;
|
||||
QList<QRegularExpression> m_subDirectoryExpressions;
|
||||
|
@@ -97,7 +97,7 @@ void ProjectFileWizardExtension::firstExtensionPageShown(
|
||||
if (debugExtension)
|
||||
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);
|
||||
|
||||
FilePaths filePaths;
|
||||
|
@@ -123,14 +123,14 @@ Qt::ItemFlags AddNewTree::flags(int) const
|
||||
class BestNodeSelector
|
||||
{
|
||||
public:
|
||||
BestNodeSelector(const QString &commonDirectory, const FilePaths &files);
|
||||
BestNodeSelector(const FilePath &commonDirectory, const FilePaths &files);
|
||||
void inspect(AddNewTree *tree, bool isContextNode);
|
||||
AddNewTree *bestChoice() const;
|
||||
bool deploys();
|
||||
QString deployingProjects() const;
|
||||
|
||||
private:
|
||||
QString m_commonDirectory;
|
||||
FilePath m_commonDirectory;
|
||||
FilePaths m_files;
|
||||
bool m_deploys = false;
|
||||
QString m_deployText;
|
||||
@@ -139,7 +139,7 @@ private:
|
||||
int m_bestMatchPriority = -1;
|
||||
};
|
||||
|
||||
BestNodeSelector::BestNodeSelector(const QString &commonDirectory, const FilePaths &files) :
|
||||
BestNodeSelector::BestNodeSelector(const FilePath &commonDirectory, const FilePaths &files) :
|
||||
m_commonDirectory(commonDirectory),
|
||||
m_files(files),
|
||||
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();
|
||||
if (node->isProjectNodeType()) {
|
||||
if (static_cast<ProjectNode *>(node)->deploysFolder(m_commonDirectory)) {
|
||||
if (static_cast<ProjectNode *>(node)->deploysFolder(m_commonDirectory.toString())) {
|
||||
m_deploys = true;
|
||||
m_deployText += tree->displayName() + QLatin1Char('\n');
|
||||
}
|
||||
@@ -162,10 +162,11 @@ void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode)
|
||||
if (m_deploys)
|
||||
return;
|
||||
|
||||
const QString projectDirectory = node->directory().toString();
|
||||
const int projectDirectorySize = projectDirectory.size();
|
||||
const FilePath projectDirectory = node->directory();
|
||||
const int projectDirectorySize = projectDirectory.toString().size();
|
||||
if (m_commonDirectory != projectDirectory
|
||||
&& !m_commonDirectory.startsWith(projectDirectory + QLatin1Char('/'))
|
||||
&& !m_commonDirectory.toString().startsWith(
|
||||
projectDirectory.toString() + QLatin1Char('/')) // TODO: still required?
|
||||
&& !isContextNode)
|
||||
return;
|
||||
|
||||
@@ -384,7 +385,7 @@ void ProjectWizardPage::initializeVersionControls()
|
||||
QStringList versionControlChoices = QStringList(tr("<None>"));
|
||||
if (!m_commonDirectory.isEmpty()) {
|
||||
IVersionControl *managingControl =
|
||||
VcsManager::findVersionControlForDirectory(FilePath::fromString(m_commonDirectory));
|
||||
VcsManager::findVersionControlForDirectory(m_commonDirectory);
|
||||
if (managingControl) {
|
||||
// Under VCS
|
||||
if (managingControl->supportsOperation(IVersionControl::AddOperation)) {
|
||||
@@ -427,8 +428,10 @@ bool ProjectWizardPage::runVersionControl(const QList<GeneratedFile> &files, QSt
|
||||
// Create repository?
|
||||
if (!m_repositoryExists) {
|
||||
QTC_ASSERT(versionControl->supportsOperation(IVersionControl::CreateRepositoryOperation), return false);
|
||||
if (!versionControl->vcsCreateRepository(FilePath::fromString(m_commonDirectory))) {
|
||||
*errorMessage = tr("A version control system repository could not be created in \"%1\".").arg(m_commonDirectory);
|
||||
if (!versionControl->vcsCreateRepository(m_commonDirectory)) {
|
||||
*errorMessage =
|
||||
tr("A version control system repository could not be created in \"%1\".").
|
||||
arg(m_commonDirectory.toUserOutput());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -436,7 +439,8 @@ bool ProjectWizardPage::runVersionControl(const QList<GeneratedFile> &files, QSt
|
||||
if (versionControl->supportsOperation(IVersionControl::AddOperation)) {
|
||||
for (const GeneratedFile &generatedFile : files) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -517,12 +521,9 @@ IVersionControl *ProjectWizardPage::currentVersionControl()
|
||||
return m_activeVersionControls.at(index);
|
||||
}
|
||||
|
||||
void ProjectWizardPage::setFiles(const QStringList &fileNames)
|
||||
void ProjectWizardPage::setFiles(const FilePaths &files)
|
||||
{
|
||||
if (fileNames.count() == 1)
|
||||
m_commonDirectory = QFileInfo(fileNames.first()).absolutePath();
|
||||
else
|
||||
m_commonDirectory = Utils::commonPath(fileNames);
|
||||
m_commonDirectory = FileUtils::commonPath(files);
|
||||
QString fileMessage;
|
||||
{
|
||||
QTextStream str(&fileMessage);
|
||||
@@ -532,14 +533,13 @@ void ProjectWizardPage::setFiles(const QStringList &fileNames)
|
||||
|
||||
QStringList formattedFiles;
|
||||
if (m_commonDirectory.isEmpty()) {
|
||||
formattedFiles = fileNames;
|
||||
formattedFiles = Utils::transform(files, &FilePath::toString);
|
||||
} else {
|
||||
str << QDir::toNativeSeparators(m_commonDirectory) << ":\n\n";
|
||||
int prefixSize = m_commonDirectory.size();
|
||||
if (!m_commonDirectory.endsWith('/'))
|
||||
++prefixSize;
|
||||
formattedFiles = Utils::transform(fileNames, [prefixSize](const QString &f)
|
||||
{ return f.mid(prefixSize); });
|
||||
str << m_commonDirectory.toUserOutput() << ":\n\n";
|
||||
int prefixSize = m_commonDirectory.toUserOutput().size();
|
||||
formattedFiles = Utils::transform(files, [prefixSize] (const FilePath &f) {
|
||||
return f.toUserOutput().mid(prefixSize + 1); // +1 skips the initial dir separator
|
||||
});
|
||||
}
|
||||
// Alphabetically, and files in sub-directories first
|
||||
Utils::sort(formattedFiles, [](const QString &filePath1, const QString &filePath2) -> bool {
|
||||
@@ -549,8 +549,7 @@ void ProjectWizardPage::setFiles(const QStringList &fileNames)
|
||||
if (filePath1HasDir == filePath2HasDir)
|
||||
return FilePath::fromString(filePath1) < FilePath::fromString(filePath2);
|
||||
return filePath1HasDir;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
for (const QString &f : qAsConst(formattedFiles))
|
||||
str << QDir::toNativeSeparators(f) << '\n';
|
||||
|
@@ -44,7 +44,7 @@ public:
|
||||
Core::IVersionControl *currentVersionControl();
|
||||
|
||||
// Returns the common path
|
||||
void setFiles(const QStringList &files);
|
||||
void setFiles(const Utils::FilePaths &files);
|
||||
|
||||
bool runVersionControl(const QList<Core::GeneratedFile> &files, QString *errorMessage);
|
||||
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
Utils::TreeModel<> m_model;
|
||||
|
||||
QList<Core::IVersionControl*> m_activeVersionControls;
|
||||
QString m_commonDirectory;
|
||||
Utils::FilePath m_commonDirectory;
|
||||
bool m_repositoryExists = false;
|
||||
|
||||
QLabel *m_projectLabel;
|
||||
|
@@ -253,7 +253,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
|
||||
const Core::GeneratedFile iconFile = generateIconFile(Utils::FilePath::fromFileInfo(qfi),
|
||||
newIcon,
|
||||
errorMessage);
|
||||
if (iconFile.path().isEmpty())
|
||||
if (iconFile.filePath().isEmpty())
|
||||
return QList<Core::GeneratedFile>();
|
||||
rc.push_back(iconFile);
|
||||
icon = qfi.fileName();
|
||||
|
@@ -70,7 +70,7 @@ bool QtWizard::qt4ProjectPostGenerateFiles(const QWizard *w,
|
||||
// Generate user settings
|
||||
for (const Core::GeneratedFile &file : generatedFiles)
|
||||
if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
|
||||
dialog->writeUserFile(file.path());
|
||||
dialog->writeUserFile(file.filePath());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -181,12 +181,12 @@ int BaseQmakeProjectWizardDialog::addTargetSetupPage(int id)
|
||||
return id;
|
||||
}
|
||||
|
||||
bool BaseQmakeProjectWizardDialog::writeUserFile(const QString &proFileName) const
|
||||
bool BaseQmakeProjectWizardDialog::writeUserFile(const Utils::FilePath &proFile) const
|
||||
{
|
||||
if (!m_targetSetupPage)
|
||||
return false;
|
||||
|
||||
QmakeProject *pro = new QmakeProject(Utils::FilePath::fromString(proFileName));
|
||||
QmakeProject *pro = new QmakeProject(proFile);
|
||||
bool success = m_targetSetupPage->setupProject(pro);
|
||||
if (success)
|
||||
pro->saveSettings();
|
||||
@@ -201,14 +201,15 @@ QList<Utils::Id> BaseQmakeProjectWizardDialog::selectedKits() const
|
||||
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)
|
||||
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
|
||||
|
@@ -91,11 +91,11 @@ public:
|
||||
|
||||
int addTargetSetupPage(int id = -1);
|
||||
|
||||
bool writeUserFile(const QString &proFileName) const;
|
||||
bool writeUserFile(const Utils::FilePath &proFile) const;
|
||||
QList<Utils::Id> selectedKits() const;
|
||||
|
||||
private:
|
||||
void generateProfileName(const QString &name, const QString &path);
|
||||
void generateProfileName(const QString &name, const Utils::FilePath &path);
|
||||
|
||||
ProjectExplorer::TargetSetupPage *m_targetSetupPage = nullptr;
|
||||
QList<Utils::Id> m_profileIds;
|
||||
|
Reference in New Issue
Block a user