From 1cefde9e45bedecfce2b42ace29c5bf390a476b5 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 26 Aug 2010 18:33:16 +0200 Subject: [PATCH] Implement adding new project into opened subdirs project Reviewed-by: dt --- .../cmakeprojectmanager/cmakeprojectnodes.cpp | 6 ++ .../cmakeprojectmanager/cmakeprojectnodes.h | 3 + src/plugins/coreplugin/basefilewizard.cpp | 23 ++++- src/plugins/coreplugin/basefilewizard.h | 3 + src/plugins/coreplugin/ifilewizardextension.h | 11 ++- .../genericprojectmanager/genericprojectnodes.cpp | 6 ++ .../genericprojectmanager/genericprojectnodes.h | 2 + .../genericprojectmanager/genericprojectwizard.cpp | 11 +++ .../genericprojectmanager/genericprojectwizard.h | 2 + .../projectexplorer/customwizard/customwizard.cpp | 19 ++++ .../projectexplorer/customwizard/customwizard.h | 1 + .../projectexplorer/projectfilewizardextension.cpp | 102 ++++++++++++++------- .../projectexplorer/projectfilewizardextension.h | 13 ++- src/plugins/projectexplorer/projectnodes.h | 2 + src/plugins/qmlprojectmanager/qmlprojectnodes.cpp | 6 ++ src/plugins/qmlprojectmanager/qmlprojectnodes.h | 2 + .../customwidgetwizard/customwidgetwizard.cpp | 11 +++ .../customwidgetwizard/customwidgetwizard.h | 2 + src/plugins/qt4projectmanager/qt4nodes.cpp | 36 +++++++- src/plugins/qt4projectmanager/qt4nodes.h | 2 + .../qt4projectmanager/wizards/consoleappwizard.cpp | 9 ++ .../qt4projectmanager/wizards/consoleappwizard.h | 2 + .../wizards/emptyprojectwizard.cpp | 8 ++ .../qt4projectmanager/wizards/emptyprojectwizard.h | 2 + .../qt4projectmanager/wizards/guiappwizard.cpp | 9 ++ .../qt4projectmanager/wizards/guiappwizard.h | 2 + .../qt4projectmanager/wizards/librarywizard.cpp | 10 ++ .../qt4projectmanager/wizards/librarywizard.h | 2 + .../qt4projectmanager/wizards/testwizard.cpp | 9 ++ src/plugins/qt4projectmanager/wizards/testwizard.h | 1 + 30 files changed, 271 insertions(+), 46 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp index 6659d96ca4..356c6fca93 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp @@ -49,6 +49,12 @@ QList CMakeProjectNode::supportedAc return QList(); } +bool CMakeProjectNode::canAddSubProject(const QString &proFilePath) const +{ + Q_UNUSED(proFilePath) + return false; +} + bool CMakeProjectNode::addSubProjects(const QStringList &proFilePaths) { Q_UNUSED(proFilePaths) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h index eb96a46fdc..2ba10e47a0 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h @@ -43,6 +43,9 @@ public: CMakeProjectNode(const QString &fileName); virtual bool hasBuildTargets() const; virtual QList supportedActions(Node *node) const; + + virtual bool canAddSubProject(const QString &proFilePath) const; + virtual bool addSubProjects(const QStringList &proFilePaths); virtual bool removeSubProjects(const QStringList &proFilePaths); virtual bool addFiles(const ProjectExplorer::FileType fileType, diff --git a/src/plugins/coreplugin/basefilewizard.cpp b/src/plugins/coreplugin/basefilewizard.cpp index 14d7b213c9..9ab88b1911 100644 --- a/src/plugins/coreplugin/basefilewizard.cpp +++ b/src/plugins/coreplugin/basefilewizard.cpp @@ -530,7 +530,7 @@ QStringList BaseFileWizard::runWizard(const QString &path, QWidget *parent) } if (firstExtensionPageHit) foreach (IFileWizardExtension *ex, extensions) - ex->firstExtensionPageShown(files); + ex->firstExtensionPageShown(files, generatedProjectFilePath(wizard.data())); if (accepted) break; } @@ -558,12 +558,23 @@ QStringList BaseFileWizard::runWizard(const QString &path, QWidget *parent) return QStringList(); } } + bool removeOpenProjectAttribute = false; // Run the extensions - foreach (IFileWizardExtension *ex, extensions) - if (!ex->process(files, &errorMessage)) { + foreach (IFileWizardExtension *ex, extensions) { + bool remove; + if (!ex->process(files, generatedProjectFilePath(wizard.data()), &remove, &errorMessage)) { QMessageBox::critical(parent, tr("File Generation Failure"), errorMessage); return QStringList(); } + removeOpenProjectAttribute |= remove; + } + + if (removeOpenProjectAttribute) { + for (int i = 0; i < files.count(); i++) { + if (files[i].attributes() & Core::GeneratedFile::OpenProjectAttribute) + files[i].setAttributes(Core::GeneratedFile::OpenEditorAttribute); + } + } // Post generation handler if (!postGenerateFiles(wizard.data(), files, &errorMessage)) { @@ -596,6 +607,12 @@ void BaseFileWizard::applyExtensionPageShortTitle(Utils::Wizard *wizard, int pag item->setTitle(shortTitle); } +QString BaseFileWizard::generatedProjectFilePath(const QWizard *wizard) const +{ + Q_UNUSED(wizard) + return QString(); +} + bool BaseFileWizard::postGenerateFiles(const QWizard *, const GeneratedFiles &l, QString *errorMessage) { return BaseFileWizard::postGenerateOpenEditors(l, errorMessage); diff --git a/src/plugins/coreplugin/basefilewizard.h b/src/plugins/coreplugin/basefilewizard.h index e1f5a369d5..ac094bed7b 100644 --- a/src/plugins/coreplugin/basefilewizard.h +++ b/src/plugins/coreplugin/basefilewizard.h @@ -200,6 +200,9 @@ protected: virtual GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const = 0; + // Overwrite for ProjectWizard kind and return the path to the generated project file + virtual QString generatedProjectFilePath(const QWizard *wizard) const; + /* Overwrite to perform steps to be done after files are actually created. * The default implementation opens editors with the newly generated files. */ virtual bool postGenerateFiles(const QWizard *w, const GeneratedFiles &l, QString *errorMessage); diff --git a/src/plugins/coreplugin/ifilewizardextension.h b/src/plugins/coreplugin/ifilewizardextension.h index 237cf593f0..18172f5ba2 100644 --- a/src/plugins/coreplugin/ifilewizardextension.h +++ b/src/plugins/coreplugin/ifilewizardextension.h @@ -57,11 +57,18 @@ public: virtual QList extensionPages(const IWizard *wizard) = 0; /* Process the files using the extension parameters */ - virtual bool process(const QList &files, QString *errorMessage) = 0; + virtual bool process(const QList &files, + const QString &generatedProjectFilePath, + bool *removeOpenProjectAttribute, + QString *errorMessage) = 0; public slots: /* Notification about the first extension page being shown. */ - virtual void firstExtensionPageShown(const QList &) {} + virtual void firstExtensionPageShown(const QList &files, + const QString &generatedProjectFilePath) { + Q_UNUSED(files) + Q_UNUSED(generatedProjectFilePath) + } }; } // namespace Core diff --git a/src/plugins/genericprojectmanager/genericprojectnodes.cpp b/src/plugins/genericprojectmanager/genericprojectnodes.cpp index 61e43a8204..beda4a3489 100644 --- a/src/plugins/genericprojectmanager/genericprojectnodes.cpp +++ b/src/plugins/genericprojectmanager/genericprojectnodes.cpp @@ -179,6 +179,12 @@ QList GenericProjectNode::supported << RemoveFile; } +bool GenericProjectNode::canAddSubProject(const QString &proFilePath) const +{ + Q_UNUSED(proFilePath) + return false; +} + bool GenericProjectNode::addSubProjects(const QStringList &proFilePaths) { Q_UNUSED(proFilePaths) diff --git a/src/plugins/genericprojectmanager/genericprojectnodes.h b/src/plugins/genericprojectmanager/genericprojectnodes.h index edca4e2552..89a4a09cbd 100644 --- a/src/plugins/genericprojectmanager/genericprojectnodes.h +++ b/src/plugins/genericprojectmanager/genericprojectnodes.h @@ -57,6 +57,8 @@ public: virtual QList supportedActions(Node *node) const; + virtual bool canAddSubProject(const QString &proFilePath) const; + virtual bool addSubProjects(const QStringList &proFilePaths); virtual bool removeSubProjects(const QStringList &proFilePaths); diff --git a/src/plugins/genericprojectmanager/genericprojectwizard.cpp b/src/plugins/genericprojectmanager/genericprojectwizard.cpp index b7f184e3e4..6f53486db5 100644 --- a/src/plugins/genericprojectmanager/genericprojectwizard.cpp +++ b/src/plugins/genericprojectmanager/genericprojectwizard.cpp @@ -231,6 +231,17 @@ Core::GeneratedFiles GenericProjectWizard::generateFiles(const QWizard *w, return files; } +QString GenericProjectWizard::generatedProjectFilePath(const QWizard *w) const +{ + const GenericProjectWizardDialog *wizard = qobject_cast(w); + const QString projectPath = wizard->path(); + const QDir dir(projectPath); + const QString projectName = wizard->projectName(); + const QString creatorFileName = QFileInfo(dir, projectName + QLatin1String(".creator")).absoluteFilePath(); + + return creatorFileName; +} + bool GenericProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage) { Q_UNUSED(w); diff --git a/src/plugins/genericprojectmanager/genericprojectwizard.h b/src/plugins/genericprojectmanager/genericprojectwizard.h index 833d89ee1f..9925e92d13 100644 --- a/src/plugins/genericprojectmanager/genericprojectwizard.h +++ b/src/plugins/genericprojectmanager/genericprojectwizard.h @@ -81,6 +81,8 @@ protected: virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; + virtual QString generatedProjectFilePath(const QWizard *w) const; + virtual bool postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage); bool isValidDir(const QFileInfo &fileInfo) const; diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp index 34870de774..98f2eff927 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp @@ -451,6 +451,25 @@ bool CustomProjectWizard::postGenerateOpen(const Core::GeneratedFiles &l, QStrin return BaseFileWizard::postGenerateOpenEditors(l, errorMessage); } +QString CustomProjectWizard::generatedProjectFilePath(const QWizard *wizard) const +{ + const BaseProjectWizardDialog *dialog = qobject_cast(wizard); + QTC_ASSERT(dialog, return QString()) + const QString targetPath = dialog->path() + QLatin1Char('/') + dialog->projectName(); + const QChar slash = QLatin1Char('/'); + // take the first from parameters()->files list which have cwFile.openProject set + foreach(const Internal::CustomWizardFile &file, parameters()->files) { + if (file.openProject) { + FieldReplacementMap fieldReplacementMap = replacementMap(dialog); + fieldReplacementMap.insert(QLatin1String("ProjectName"), dialog->projectName()); + QString target = file.target; + Internal::CustomWizardContext::replaceFields(fieldReplacementMap, &target); + return QDir::toNativeSeparators(targetPath + slash + target); + } + } + return QString(); +} + bool CustomProjectWizard::postGenerateFiles(const QWizard *, const Core::GeneratedFiles &l, QString *errorMessage) { if (CustomWizardPrivate::verbose) diff --git a/src/plugins/projectexplorer/customwizard/customwizard.h b/src/plugins/projectexplorer/customwizard/customwizard.h index 5197004a24..2df8bda89e 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.h +++ b/src/plugins/projectexplorer/customwizard/customwizard.h @@ -162,6 +162,7 @@ signals: void projectLocationChanged(const QString &path); protected: + QString generatedProjectFilePath(const QWizard *wizard) const; virtual bool postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage); void initProjectWizardDialog(BaseProjectWizardDialog *w, const QString &defaultPath, diff --git a/src/plugins/projectexplorer/projectfilewizardextension.cpp b/src/plugins/projectexplorer/projectfilewizardextension.cpp index a432e5cfb1..5ff438bccf 100644 --- a/src/plugins/projectexplorer/projectfilewizardextension.cpp +++ b/src/plugins/projectexplorer/projectfilewizardextension.cpp @@ -38,7 +38,6 @@ #include #include -#include #include #include #include @@ -156,11 +155,13 @@ struct ProjectWizardContext ProjectWizardPage *page; bool repositoryExists; // Is VCS 'add' sufficient, or should a repository be created? QString commonDirectory; + const Core::IWizard *wizard; }; ProjectWizardContext::ProjectWizardContext() : page(0), - repositoryExists(false) + repositoryExists(false), + wizard(0) { } @@ -171,6 +172,7 @@ void ProjectWizardContext::clear() commonDirectory.clear(); page = 0; repositoryExists = false; + wizard = 0; } // ---- ProjectFileWizardExtension @@ -222,8 +224,12 @@ static int findMatchingProject(const QList &projects, return bestMatch; } -void ProjectFileWizardExtension::firstExtensionPageShown(const QList &files) +void ProjectFileWizardExtension::firstExtensionPageShown( + const QList &files, + const QString &generatedProjectFilePath) { + initProjectChoices(generatedProjectFilePath); + if (debugExtension) qDebug() << Q_FUNC_INFO << files.size(); // Parametrize wizard page: find best project to add to, set up files display and @@ -307,13 +313,11 @@ QList ProjectFileWizardExtension::extensionPages(const Core::IWiz } // Init context with page and projects m_context->page = new ProjectWizardPage; - // Project list remains the same over duration of wizard execution - // Note that projects cannot be added to projects. - initProjectChoices(wizard->kind() != Core::IWizard::ProjectWizard); + m_context->wizard = wizard; return QList() << m_context->page; } -void ProjectFileWizardExtension::initProjectChoices(bool enabled) +void ProjectFileWizardExtension::initProjectChoices(const QString &generatedProjectFilePath) { // Set up project list which remains the same over duration of wizard execution // As tooltip, set the directory for disambiguation (should someone have @@ -321,56 +325,84 @@ void ProjectFileWizardExtension::initProjectChoices(bool enabled) //: No project selected QStringList projectChoices(tr("")); QStringList projectToolTips((QString())); - if (enabled) { - typedef QMap ProjectEntryMap; - // Sort by base name and purge duplicated entries (resulting from dependencies) - // via Map. - ProjectEntryMap entryMap; - foreach(ProjectNode *n, AllProjectNodesVisitor::allProjects(ProjectNode::AddNewFile)) + typedef QMap ProjectEntryMap; + // Sort by base name and purge duplicated entries (resulting from dependencies) + // via Map. + ProjectEntryMap entryMap; + + ProjectNode::ProjectAction projectAction = + m_context->wizard->kind() == Core::IWizard::ProjectWizard + ? ProjectNode::AddSubProject : ProjectNode::AddNewFile; + foreach(ProjectNode *n, AllProjectNodesVisitor::allProjects(projectAction)) { + if (projectAction == ProjectNode::AddNewFile + || (projectAction == ProjectNode::AddSubProject + && n->canAddSubProject(generatedProjectFilePath))) entryMap.insert(ProjectEntry(n), true); - // Collect names - const ProjectEntryMap::const_iterator cend = entryMap.constEnd(); - for (ProjectEntryMap::const_iterator it = entryMap.constBegin(); it != cend; ++it) { - m_context->projects.push_back(it.key()); - projectChoices.push_back(it.key().fileName); - projectToolTips.push_back(it.key().nativeDirectory); - } } + + m_context->projects.clear(); + + // Collect names + const ProjectEntryMap::const_iterator cend = entryMap.constEnd(); + for (ProjectEntryMap::const_iterator it = entryMap.constBegin(); it != cend; ++it) { + m_context->projects.push_back(it.key()); + projectChoices.push_back(it.key().fileName); + projectToolTips.push_back(it.key().nativeDirectory); + } + m_context->page->setProjects(projectChoices); m_context->page->setProjectToolTips(projectToolTips); } -bool ProjectFileWizardExtension::process(const QList &files, QString *errorMessage) +bool ProjectFileWizardExtension::process( + const QList &files, + const QString &generatedProjectFilePath, + bool *removeOpenProjectAttribute, QString *errorMessage) { - return processProject(files, errorMessage) && + return processProject(files, generatedProjectFilePath, + removeOpenProjectAttribute, errorMessage) && processVersionControl(files, errorMessage); } // Add files to project && version control -bool ProjectFileWizardExtension::processProject(const QList &files, QString *errorMessage) +bool ProjectFileWizardExtension::processProject( + const QList &files, + const QString &generatedProjectFilePath, + bool *removeOpenProjectAttribute, QString *errorMessage) { typedef QMultiMap TypeFileMap; + *removeOpenProjectAttribute = false; + // Add files to project (Entry at 0 is 'None'). const int projectIndex = m_context->page->currentProjectIndex() - 1; if (projectIndex < 0 || projectIndex >= m_context->projects.size()) return true; ProjectNode *project = m_context->projects.at(projectIndex).node; - // Split into lists by file type and bulk-add them. - TypeFileMap typeFileMap; - const Core::MimeDatabase *mdb = Core::ICore::instance()->mimeDatabase(); - foreach (const Core::GeneratedFile &generatedFile, files) { - const QString path = generatedFile.path(); - typeFileMap.insert(typeForFileName(mdb, path), path); - } - foreach (FileType type, typeFileMap.uniqueKeys()) { - const QStringList typeFiles = typeFileMap.values(type); - if (!project->addFiles(type, typeFiles)) { - *errorMessage = tr("Failed to add one or more files to project\n'%1' (%2)."). - arg(project->path(), typeFiles.join(QString(QLatin1Char(',')))); + if (m_context->wizard->kind() == Core::IWizard::ProjectWizard) { + if (!project->addSubProjects(QStringList(generatedProjectFilePath))) { + *errorMessage = tr("Failed to add subproject '%1'\nto project '%2'.") + .arg(generatedProjectFilePath).arg(project->path()); return false; } + *removeOpenProjectAttribute = true; + } else { + // Split into lists by file type and bulk-add them. + TypeFileMap typeFileMap; + const Core::MimeDatabase *mdb = Core::ICore::instance()->mimeDatabase(); + foreach (const Core::GeneratedFile &generatedFile, files) { + const QString path = generatedFile.path(); + typeFileMap.insert(typeForFileName(mdb, path), path); + } + foreach (FileType type, typeFileMap.uniqueKeys()) { + const QStringList typeFiles = typeFileMap.values(type); + if (!project->addFiles(type, typeFiles)) { + *errorMessage = tr("Failed to add one or more files to project\n'%1' (%2)."). + arg(project->path(), typeFiles.join(QString(QLatin1Char(',')))); + return false; + } + } } return true; } diff --git a/src/plugins/projectexplorer/projectfilewizardextension.h b/src/plugins/projectexplorer/projectfilewizardextension.h index d7ba722c7c..5c9dbe0d62 100644 --- a/src/plugins/projectexplorer/projectfilewizardextension.h +++ b/src/plugins/projectexplorer/projectfilewizardextension.h @@ -50,15 +50,20 @@ public: virtual ~ProjectFileWizardExtension(); virtual QList extensionPages(const Core::IWizard *wizard); - virtual bool process(const QList &files, QString *errorMessage); + virtual bool process(const QList &files, + const QString &generatedProjectFilePath, + bool *removeOpenProjectAttribute, QString *errorMessage); public slots: - virtual void firstExtensionPageShown(const QList &); + virtual void firstExtensionPageShown(const QList &files, + const QString &generatedProjectFilePath); private: - void initProjectChoices(bool enabled); + void initProjectChoices(const QString &generatedProjectFilePath); void initializeVersionControlChoices(); - bool processProject(const QList &files, QString *errorMessage); + bool processProject(const QList &files, + const QString &generatedProjectFilePath, + bool *removeOpenProjectAttribute, QString *errorMessage); bool processVersionControl(const QList &files, QString *errorMessage); ProjectWizardContext *m_context; diff --git a/src/plugins/projectexplorer/projectnodes.h b/src/plugins/projectexplorer/projectnodes.h index 1545f33ccb..62a7f2970f 100644 --- a/src/plugins/projectexplorer/projectnodes.h +++ b/src/plugins/projectexplorer/projectnodes.h @@ -182,6 +182,8 @@ public: virtual QList supportedActions(Node *node) const = 0; + virtual bool canAddSubProject(const QString &proFilePath) const = 0; + virtual bool addSubProjects(const QStringList &proFilePaths) = 0; virtual bool removeSubProjects(const QStringList &proFilePaths) = 0; diff --git a/src/plugins/qmlprojectmanager/qmlprojectnodes.cpp b/src/plugins/qmlprojectmanager/qmlprojectnodes.cpp index 2be16f01eb..021c55d0db 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectnodes.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectnodes.cpp @@ -180,6 +180,12 @@ QList QmlProjectNode::supportedActi return actions; } +bool QmlProjectNode::canAddSubProject(const QString &proFilePath) const +{ + Q_UNUSED(proFilePath) + return false; +} + bool QmlProjectNode::addSubProjects(const QStringList &proFilePaths) { Q_UNUSED(proFilePaths) diff --git a/src/plugins/qmlprojectmanager/qmlprojectnodes.h b/src/plugins/qmlprojectmanager/qmlprojectnodes.h index 8413e9362e..2b6f7dc1ff 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectnodes.h +++ b/src/plugins/qmlprojectmanager/qmlprojectnodes.h @@ -58,6 +58,8 @@ public: virtual QList supportedActions(Node *node) const; + virtual bool canAddSubProject(const QString &proFilePath) const; + virtual bool addSubProjects(const QStringList &proFilePaths); virtual bool removeSubProjects(const QStringList &proFilePaths); diff --git a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.cpp b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.cpp index c59d5f321f..db7e72b44c 100644 --- a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.cpp +++ b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.cpp @@ -75,5 +75,16 @@ Core::GeneratedFiles CustomWidgetWizard::generateFiles(const QWizard *w, return PluginGenerator::generatePlugin(p, *(cw->pluginOptions()), errorMessage); } +QString CustomWidgetWizard::generatedProjectFilePath(const QWizard *w) const +{ + const CustomWidgetWizardDialog *cw = qobject_cast(w); + const QChar slash = QLatin1Char('/'); + QString baseDir = cw->path(); + baseDir += slash; + baseDir += cw->projectName(); + baseDir += slash; + return baseDir + cw->projectName() + QLatin1String(".pro"); +} + } // namespace Internal } // namespace Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.h b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.h index c458575a49..0762774967 100644 --- a/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.h +++ b/src/plugins/qt4projectmanager/customwidgetwizard/customwidgetwizard.h @@ -49,6 +49,8 @@ protected: virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; + + virtual QString generatedProjectFilePath(const QWizard *w) const; }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/qt4nodes.cpp b/src/plugins/qt4projectmanager/qt4nodes.cpp index 343a44a748..be01abe82b 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.cpp +++ b/src/plugins/qt4projectmanager/qt4nodes.cpp @@ -771,10 +771,39 @@ QList Qt4PriFileNode::supportedActions(Node *node) c return actions; } +bool Qt4PriFileNode::canAddSubProject(const QString &proFilePath) const +{ + QFileInfo fi(proFilePath); + if (fi.suffix() == QLatin1String("pro") + || fi.suffix() == QLatin1String("pri")) + return true; + return false; +} + bool Qt4PriFileNode::addSubProjects(const QStringList &proFilePaths) { - Q_UNUSED(proFilePaths) - return false; //changeIncludes(m_includeFile, proFilePaths, AddToProFile); + ProjectExplorer::FindAllFilesVisitor visitor; + accept(&visitor); + const QStringList &allFiles = visitor.filePaths(); + + QStringList uniqueProFilePaths; + foreach (const QString &proFile, proFilePaths) { + if (!allFiles.contains(proFile)) { + // if proFilePath is like: _path_/projectName/projectName.pro + // we simplify it to: _path_/projectName + QString proFilePath = proFile; + QFileInfo fi(proFile); + QFileInfo parentFi(fi.absolutePath()); + if (parentFi.fileName() == fi.baseName()) + proFilePath = parentFi.absoluteFilePath(); + uniqueProFilePaths.append(proFilePath); + } + } + + QStringList failedFiles; + changeFiles(ProjectExplorer::ProjectFileType, uniqueProFilePaths, &failedFiles, AddToProFile); + + return failedFiles.isEmpty(); } bool Qt4PriFileNode::removeSubProjects(const QStringList &proFilePaths) @@ -1085,6 +1114,9 @@ QStringList Qt4PriFileNode::varNames(ProjectExplorer::FileType type) case ProjectExplorer::FormType: vars << QLatin1String("FORMS"); break; + case ProjectExplorer::ProjectFileType: + vars << QLatin1String("SUBDIRS"); + break; case ProjectExplorer::QMLType: break; default: diff --git a/src/plugins/qt4projectmanager/qt4nodes.h b/src/plugins/qt4projectmanager/qt4nodes.h index 001c45c807..371de843b6 100644 --- a/src/plugins/qt4projectmanager/qt4nodes.h +++ b/src/plugins/qt4projectmanager/qt4nodes.h @@ -140,6 +140,8 @@ public: bool hasBuildTargets() const { return false; } + bool canAddSubProject(const QString &proFilePath) const; + bool addSubProjects(const QStringList &proFilePaths); bool removeSubProjects(const QStringList &proFilePaths); diff --git a/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp b/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp index fa8dc63840..091d49eb4b 100644 --- a/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/consoleappwizard.cpp @@ -104,5 +104,14 @@ Core::GeneratedFiles return Core::GeneratedFiles() << source << profile; } +QString ConsoleAppWizard::generatedProjectFilePath(const QWizard *w) const +{ + const ConsoleAppWizardDialog *wizard = qobject_cast< const ConsoleAppWizardDialog *>(w); + const QtProjectParameters params = wizard->parameters(); + const QString projectPath = params.projectPath(); + + return Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix()); +} + } // namespace Internal } // namespace Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/wizards/consoleappwizard.h b/src/plugins/qt4projectmanager/wizards/consoleappwizard.h index de21cda794..9ad1471869 100644 --- a/src/plugins/qt4projectmanager/wizards/consoleappwizard.h +++ b/src/plugins/qt4projectmanager/wizards/consoleappwizard.h @@ -51,6 +51,8 @@ protected: virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; + + QString generatedProjectFilePath(const QWizard *w) const; }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp index 63cbf6fe07..f5367d8462 100644 --- a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp @@ -74,5 +74,13 @@ Core::GeneratedFiles return Core::GeneratedFiles() << profile; } +QString EmptyProjectWizard::generatedProjectFilePath(const QWizard *w) const +{ + const EmptyProjectWizardDialog *wizard = qobject_cast< const EmptyProjectWizardDialog *>(w); + const QtProjectParameters params = wizard->parameters(); + const QString projectPath = params.projectPath(); + return Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix()); +} + } // namespace Internal } // namespace Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.h b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.h index 038b47a6bc..d951046c90 100644 --- a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.h +++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.h @@ -49,6 +49,8 @@ protected: virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; + + QString generatedProjectFilePath(const QWizard *w) const; }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp b/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp index 24e6344498..1b755b7f47 100644 --- a/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/guiappwizard.cpp @@ -237,6 +237,15 @@ Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w, return rc; } +QString GuiAppWizard::generatedProjectFilePath(const QWizard *w) const +{ + const GuiAppWizardDialog *dialog = qobject_cast(w); + const QtProjectParameters projectParams = dialog->projectParameters(); + const QString projectPath = projectParams.projectPath(); + + return buildFileName(projectPath, projectParams.fileName, profileSuffix()); +} + bool GuiAppWizard::parametrizeTemplate(const QString &templatePath, const QString &templateName, const GuiAppParameters ¶ms, QString *target, QString *errorMessage) diff --git a/src/plugins/qt4projectmanager/wizards/guiappwizard.h b/src/plugins/qt4projectmanager/wizards/guiappwizard.h index ae47a4c490..4432ecd815 100644 --- a/src/plugins/qt4projectmanager/wizards/guiappwizard.h +++ b/src/plugins/qt4projectmanager/wizards/guiappwizard.h @@ -61,6 +61,8 @@ protected: virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; + QString generatedProjectFilePath(const QWizard *w) const; + private: static bool parametrizeTemplate(const QString &templatePath, const QString &templateName, const GuiAppParameters ¶ms, diff --git a/src/plugins/qt4projectmanager/wizards/librarywizard.cpp b/src/plugins/qt4projectmanager/wizards/librarywizard.cpp index e86de20dcd..1c6e877566 100644 --- a/src/plugins/qt4projectmanager/wizards/librarywizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/librarywizard.cpp @@ -137,5 +137,15 @@ Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w, return rc; } +QString LibraryWizard::generatedProjectFilePath(const QWizard *w) const +{ + const LibraryWizardDialog *dialog = qobject_cast(w); + const QtProjectParameters projectParams = dialog->parameters(); + const QString projectPath = projectParams.projectPath(); + + return buildFileName(projectPath, projectParams.fileName, profileSuffix()); +} + + } // namespace Internal } // namespace Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/wizards/librarywizard.h b/src/plugins/qt4projectmanager/wizards/librarywizard.h index b0c1d869ae..9ce0228ddb 100644 --- a/src/plugins/qt4projectmanager/wizards/librarywizard.h +++ b/src/plugins/qt4projectmanager/wizards/librarywizard.h @@ -54,6 +54,8 @@ protected: virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; + + QString generatedProjectFilePath(const QWizard *w) const; }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/wizards/testwizard.cpp b/src/plugins/qt4projectmanager/wizards/testwizard.cpp index a493270e2b..7d38283242 100644 --- a/src/plugins/qt4projectmanager/wizards/testwizard.cpp +++ b/src/plugins/qt4projectmanager/wizards/testwizard.cpp @@ -184,5 +184,14 @@ Core::GeneratedFiles TestWizard::generateFiles(const QWizard *w, QString *errorM return Core::GeneratedFiles() << source << profile; } +QString TestWizard::generatedProjectFilePath(const QWizard *w) const +{ + const TestWizardDialog *wizardDialog = qobject_cast(w); + const QtProjectParameters projectParams = wizardDialog->projectParameters(); + const QString projectPath = projectParams.projectPath(); + + return buildFileName(projectPath, projectParams.fileName, profileSuffix()); +} + } // namespace Internal } // namespace Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/wizards/testwizard.h b/src/plugins/qt4projectmanager/wizards/testwizard.h index 71a9bb24ac..16aa5d80ca 100644 --- a/src/plugins/qt4projectmanager/wizards/testwizard.h +++ b/src/plugins/qt4projectmanager/wizards/testwizard.h @@ -50,6 +50,7 @@ protected: virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const; + QString generatedProjectFilePath(const QWizard *w) const; signals: public slots: -- 2.11.0