From 35aafdcdd9e21b28fa88cd4c757313ab24d08911 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 23 Apr 2015 15:02:59 +0200 Subject: [PATCH] JsonWizard: Add a polish phase Add a signal/method to polish the generated files: This phase happens after all files are written to disk and are ready. It is intended for tasks not directly related to the project setup: E.g. generation of config files, etc. Use this to generate our config files. Change-Id: I9bb5d296bec19f163b70c5ec8d43d5b8e3a52d79 Reviewed-by: Tobias Hunger --- src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp | 2 +- src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp | 7 ++++++- src/plugins/projectexplorer/jsonwizard/jsonwizard.h | 1 + .../jsonwizard/jsonwizardfilegenerator.cpp | 8 ++++++++ .../projectexplorer/jsonwizard/jsonwizardfilegenerator.h | 1 + .../jsonwizard/jsonwizardgeneratorfactory.cpp | 9 +++++++++ .../jsonwizard/jsonwizardgeneratorfactory.h | 2 ++ 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp index e93aeeeccad..65737f55932 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp @@ -55,7 +55,7 @@ void JsonKitsPage::initializePage() JsonWizard *wiz = qobject_cast(wizard()); QTC_ASSERT(wiz, return); - connect(wiz, &JsonWizard::allDone, this, &JsonKitsPage::setupProjectFiles); + connect(wiz, &JsonWizard::filesPolished, this, &JsonKitsPage::setupProjectFiles); const QString platform = wiz->stringValue(QLatin1String("Platform")); const Core::FeatureSet preferred = Core::FeatureSet::fromStringList(wiz->value(QLatin1String("PreferredFeatures")).toStringList()); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp index d14c40348e9..a4c20993306 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp @@ -209,12 +209,17 @@ void JsonWizard::accept() return; } emit filesReady(m_files); + if (!JsonWizardGenerator::polish(this, &m_files, &errorMessage)) { + if (!errorMessage.isEmpty()) + QMessageBox::warning(this, tr("Failed to polish Files"), errorMessage); + return; + } + emit filesPolished(m_files); if (!JsonWizardGenerator::allDone(this, &m_files, &errorMessage)) { if (!errorMessage.isEmpty()) QMessageBox::warning(this, tr("Failed to Open Files"), errorMessage); return; } - emit allDone(m_files); } diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h index 37362a2cfeb..6311facca8a 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h @@ -90,6 +90,7 @@ signals: void preWriteFiles(const JsonWizard::GeneratorFiles &files); // emitted before files are written to disk. void postProcessFiles(const JsonWizard::GeneratorFiles &files); // emitted before files are post-processed. void filesReady(const JsonWizard::GeneratorFiles &files); // emitted just after files are in final state on disk. + void filesPolished(const JsonWizard::GeneratorFiles &files); // emitted just after additional files (e.g. settings) not directly related to the project were created. void allDone(const JsonWizard::GeneratorFiles &files); // emitted just after the wizard is done with the files. They are ready to be opened. public slots: diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp index 873ff04c719..14c5e46d7d5 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp @@ -199,6 +199,14 @@ bool JsonWizardFileGenerator::postWrite(const JsonWizard *wizard, Core::Generate return true; } +bool JsonWizardFileGenerator::polish(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) +{ + Q_UNUSED(wizard); + Q_UNUSED(file); + Q_UNUSED(errorMessage); + return true; +} + bool JsonWizardFileGenerator::allDone(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) { Q_UNUSED(wizard); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.h index c5e3e35fbe3..5ecabb19159 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.h @@ -50,6 +50,7 @@ public: bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); bool postWrite(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); + bool polish(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); bool allDone(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); private: diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp index ec643baf794..781a1eedfa5 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp @@ -227,6 +227,15 @@ bool JsonWizardGenerator::postWrite(const JsonWizard *wizard, JsonWizard::Genera return true; } +bool JsonWizardGenerator::polish(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage) +{ + for (auto i = files->begin(); i != files->end(); ++i) { + if (!i->generator->polish(wizard, &(i->file), errorMessage)) + return false; + } + return true; +} + bool JsonWizardGenerator::allDone(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage) { for (auto i = files->begin(); i != files->end(); ++i) { diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h index 08dff686d75..2d0502df6e7 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h @@ -55,6 +55,7 @@ public: virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); virtual bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0; virtual bool postWrite(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0; + virtual bool polish(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0; virtual bool allDone(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0; virtual bool canKeepExistingFiles() const { return true; } @@ -65,6 +66,7 @@ public: static bool formatFiles(const JsonWizard *wizard, QList *files, QString *errorMessage); static bool writeFiles(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage); static bool postWrite(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage); + static bool polish(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage); static bool allDone(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage); };