diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp index b718058de91c526e050355922c923db4515f1620..7d2f670701100e79f0d0d7c925c5ed526a2eb4fc 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp @@ -32,6 +32,10 @@ #include "jsonwizardgeneratorfactory.h" +#include "../project.h" +#include "../projectexplorer.h" + +#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/messagemanager.h> #include <utils/algorithm.h> @@ -223,6 +227,8 @@ void JsonWizard::accept() return; } emit allDone(m_files); + + openFiles(m_files); } void JsonWizard::handleNewPages(int pageId) @@ -239,4 +245,59 @@ void JsonWizard::handleError(const QString &message) Core::MessageManager::write(message, Core::MessageManager::ModeSwitch); } +void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files) +{ + QString errorMessage; + bool openedSomething = false; + foreach (const JsonWizard::GeneratorFile &f, files) { + const Core::GeneratedFile &file = f.file; + if (!QFileInfo(file.path()).exists()) { + errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", + "\"%1\" does not exist in the file system.") + .arg(QDir::toNativeSeparators(file.path())); + break; + } + if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) { + Project *project = ProjectExplorerPlugin::instance()->openProject(file.path(), &errorMessage); + if (!project) { + if (errorMessage.isEmpty()) { + errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", + "Failed to open \"%1\" as a project.") + .arg(QDir::toNativeSeparators(file.path())); + } + break; + } + openedSomething = true; + } + if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) { + if (!Core::EditorManager::openEditor(file.path(), file.editorId())) { + errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", + "Failed to open an editor for \"%1\".") + .arg(QDir::toNativeSeparators(file.path())); + break; + } + openedSomething = true; + } + } + + const QString path + = QDir::toNativeSeparators(m_expander.expand(value(QLatin1String("TargetPath")).toString())); + + // Now try to find the project file and open + if (!openedSomething) { + errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", + "No file to open found in \"%1\".") + .arg(path); + } + + if (!errorMessage.isEmpty()) { + const QString text = path.isEmpty() ? tr("Failed to open project.") + : tr("Failed to open project in \"%1\".").arg(path); + QMessageBox msgBox(QMessageBox::Warning, tr("Cannot Open Project"), text); + msgBox.setDetailedText(errorMessage); + msgBox.addButton(QMessageBox::Ok); + msgBox.exec(); + } +} + } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h index 6311facca8a4071d715e8aa44d539f55d52cf6da..d72bc934affee421cc7b1ecdfffacca53e4f1d25 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h @@ -101,6 +101,8 @@ private slots: void handleError(const QString &message); private: + void openFiles(const GeneratorFiles &files); + QList<JsonWizardGenerator *> m_generators; GeneratorFiles m_files; diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp index 14c5e46d7d5ec8fbc552ad66e763350d75ec8684..bf56c3f35467b8bb68846a058fcacc84609af075 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp @@ -210,25 +210,8 @@ bool JsonWizardFileGenerator::polish(const JsonWizard *wizard, Core::GeneratedFi bool JsonWizardFileGenerator::allDone(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) { Q_UNUSED(wizard); - if (file->attributes() & Core::GeneratedFile::OpenProjectAttribute) { - Project *project = ProjectExplorerPlugin::instance()->openProject(file->path(), errorMessage); - if (!project) { - *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", - "Failed to open \"%1\" as a project.") - .arg(QDir::toNativeSeparators(file->path())); - - return false; - } - } - if (file->attributes() & Core::GeneratedFile::OpenEditorAttribute) { - if (!Core::EditorManager::openEditor(file->path(), file->editorId())) { - if (errorMessage) - *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", - "Failed to open an editor for \"%1\".") - .arg(QDir::toNativeSeparators(file->path())); - return false; - } - } + Q_UNUSED(file); + Q_UNUSED(errorMessage); return true; }