2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectfilewizardextension.h"
|
|
|
|
|
#include "projectexplorer.h"
|
2009-09-25 11:35:44 +02:00
|
|
|
#include "session.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectnodes.h"
|
|
|
|
|
#include "nodesvisitor.h"
|
|
|
|
|
#include "projectwizardpage.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/basefilewizard.h>
|
|
|
|
|
#include <coreplugin/dialogs/iwizard.h>
|
|
|
|
|
#include <coreplugin/filemanager.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/iversioncontrol.h>
|
|
|
|
|
#include <coreplugin/vcsmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QVariant>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QMultiMap>
|
|
|
|
|
|
|
|
|
|
enum { debugExtension = 0 };
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
typedef QList<ProjectNode *> ProjectNodeList;
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
// --------- AllProjectNodesVisitor. Figure out all projects.
|
|
|
|
|
// No sooner said then done.
|
|
|
|
|
class AllProjectNodesVisitor : public NodesVisitor
|
|
|
|
|
{
|
|
|
|
|
AllProjectNodesVisitor(ProjectNodeList &l) : m_projectNodes(l) {}
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
static ProjectNodeList allProjects(const ProjectExplorerPlugin *pe);
|
|
|
|
|
|
|
|
|
|
virtual void visitProjectNode(ProjectNode *node);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ProjectNodeList &m_projectNodes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ProjectNodeList AllProjectNodesVisitor::allProjects(const ProjectExplorerPlugin *pe)
|
|
|
|
|
{
|
|
|
|
|
ProjectNodeList rc;
|
|
|
|
|
AllProjectNodesVisitor visitor(rc);
|
|
|
|
|
pe->session()->sessionNode()->accept(&visitor);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AllProjectNodesVisitor::visitProjectNode(ProjectNode *node)
|
|
|
|
|
{
|
|
|
|
|
if (node->supportedActions().contains(ProjectNode::AddFile))
|
|
|
|
|
m_projectNodes << node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------- ProjectWizardContext
|
2009-01-20 15:31:33 +01:00
|
|
|
struct ProjectWizardContext
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
Core::IVersionControl *versionControl;
|
|
|
|
|
ProjectNodeList projects;
|
|
|
|
|
ProjectWizardPage *page;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ---- ProjectFileWizardExtension
|
2009-01-20 15:31:33 +01:00
|
|
|
ProjectFileWizardExtension::ProjectFileWizardExtension()
|
|
|
|
|
: m_context(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectFileWizardExtension::~ProjectFileWizardExtension()
|
|
|
|
|
{
|
|
|
|
|
delete m_context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectFileWizardExtension::firstExtensionPageShown(const QList<Core::GeneratedFile> &files)
|
|
|
|
|
{
|
|
|
|
|
if (debugExtension)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << files.size();
|
|
|
|
|
// Setup files display and version control depending on path
|
|
|
|
|
QStringList fileNames;
|
|
|
|
|
foreach (const Core::GeneratedFile &f, files)
|
|
|
|
|
fileNames.push_back(f.path());
|
|
|
|
|
|
|
|
|
|
const QString directory = QFileInfo(fileNames.front()).absolutePath();
|
2009-01-20 15:31:33 +01:00
|
|
|
m_context->versionControl = Core::ICore::instance()->vcsManager()->findVersionControlForDirectory(directory);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_context->page->setFilesDisplay(fileNames);
|
2008-12-03 15:04:51 +01:00
|
|
|
|
|
|
|
|
const bool canAddToVCS = m_context->versionControl && m_context->versionControl->supportsOperation(Core::IVersionControl::AddOperation);
|
|
|
|
|
if (m_context->versionControl)
|
|
|
|
|
m_context->page->setVCSDisplay(m_context->versionControl->name());
|
|
|
|
|
m_context->page->setAddToVersionControlEnabled(canAddToVCS);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ProjectNode *currentProject()
|
|
|
|
|
{
|
|
|
|
|
if (Node *currentNode = ProjectExplorerPlugin::instance()->currentNode())
|
|
|
|
|
if (ProjectNode *currentProjectNode = qobject_cast<ProjectNode *>(currentNode))
|
|
|
|
|
return currentProjectNode;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QWizardPage *> ProjectFileWizardExtension::extensionPages(const Core::IWizard *wizard)
|
|
|
|
|
{
|
|
|
|
|
if (!m_context)
|
|
|
|
|
m_context = new ProjectWizardContext;
|
|
|
|
|
// Init context with page and projects
|
|
|
|
|
m_context->page = new ProjectWizardPage;
|
|
|
|
|
m_context->versionControl = 0;
|
|
|
|
|
m_context->projects = AllProjectNodesVisitor::allProjects(ProjectExplorerPlugin::instance());
|
|
|
|
|
// Set up project list which remains the same over duration of wizard execution
|
|
|
|
|
// Disable "add project to project"
|
|
|
|
|
const bool hasProjects = !m_context->projects.empty();
|
|
|
|
|
if (hasProjects) {
|
2009-07-17 18:06:08 +10:00
|
|
|
m_context->page->setProjects(m_context->projects);
|
|
|
|
|
m_context->page->setCurrentProject(currentProject());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
m_context->page->setAddToProjectEnabled(hasProjects && wizard->kind() != Core::IWizard::ProjectWizard);
|
|
|
|
|
|
|
|
|
|
return QList<QWizardPage *>() << m_context->page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProjectFileWizardExtension::process(const QList<Core::GeneratedFile> &files, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
typedef QMultiMap<FileType, QString> TypeFileMap;
|
|
|
|
|
// Add files to project && version control
|
|
|
|
|
if (m_context->page->addToProject()) {
|
2009-07-17 18:06:08 +10:00
|
|
|
ProjectNode *project = m_context->page->currentProject();
|
2008-12-02 12:01:29 +01:00
|
|
|
// Split into lists by file type and add
|
|
|
|
|
TypeFileMap typeFileMap;
|
|
|
|
|
foreach (const Core::GeneratedFile &generatedFile, files) {
|
|
|
|
|
const QString path = generatedFile.path();
|
2009-01-20 15:31:33 +01:00
|
|
|
typeFileMap.insert(typeForFileName(Core::ICore::instance()->mimeDatabase(), path), path);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
foreach (FileType type, typeFileMap.uniqueKeys()) {
|
|
|
|
|
const QStringList files = typeFileMap.values(type);
|
|
|
|
|
if (!project->addFiles(type, files)) {
|
|
|
|
|
*errorMessage = tr("Failed to add one or more files to project\n'%1' (%2).").
|
|
|
|
|
arg(project->path(), files.join(QLatin1String(",")));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Add files to version control
|
|
|
|
|
if (m_context->page->addToVersionControl()) {
|
|
|
|
|
foreach (const Core::GeneratedFile &generatedFile, files) {
|
|
|
|
|
if (!m_context->versionControl->vcsAdd(generatedFile.path())) {
|
|
|
|
|
*errorMessage = tr("Failed to add '%1' to the version control system.").arg(generatedFile.path());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|