2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02: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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02: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"
|
2014-05-13 13:06:30 +02:00
|
|
|
#include "addnewmodel.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-12 16:45:21 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/stringutils.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/basefilewizard.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/iversioncontrol.h>
|
|
|
|
|
#include <coreplugin/vcsmanager.h>
|
2011-08-05 09:59:28 +02:00
|
|
|
#include <coreplugin/mimedatabase.h>
|
2010-01-12 16:45:21 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2011-08-05 09:59:28 +02:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <texteditor/icodestylepreferences.h>
|
2011-08-05 09:59:28 +02:00
|
|
|
#include <texteditor/icodestylepreferencesfactory.h>
|
|
|
|
|
#include <texteditor/normalindenter.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <texteditor/tabsettings.h>
|
2013-08-07 10:19:24 +02:00
|
|
|
#include <texteditor/storagesettings.h>
|
2011-08-05 09:59:28 +02:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/editorconfiguration.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtAlgorithms>
|
2013-06-05 14:04:07 +02:00
|
|
|
#include <QPointer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMultiMap>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
#include <QTextCursor>
|
2013-03-17 16:09:01 +01:00
|
|
|
#include <QMessageBox>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
using namespace TextEditor;
|
|
|
|
|
using namespace Core;
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::Internal::ProjectFileWizardExtension
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The ProjectFileWizardExtension class implements the post-file
|
|
|
|
|
generating steps of a project wizard.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
This class provides the following functions:
|
2011-04-14 12:58:14 +02:00
|
|
|
\list
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Add to a project file (*.pri/ *.pro)
|
2013-09-10 17:16:10 +02:00
|
|
|
\li Initialize a version control system repository (unless the path is already
|
2011-04-14 12:58:14 +02:00
|
|
|
managed) and do 'add' if the VCS supports it.
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
\sa ProjectExplorer::Internal::ProjectWizardPage
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
enum { debugExtension = 0 };
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
class BestNodeSelector
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2014-05-19 10:51:42 +02:00
|
|
|
BestNodeSelector(const QString &commonDirectory, const QStringList &files);
|
2014-05-13 13:06:30 +02:00
|
|
|
void inspect(AddNewTree *tree);
|
|
|
|
|
AddNewTree *bestChoice() const;
|
|
|
|
|
QString deployingProjects() const;
|
2014-02-18 16:31:36 +01:00
|
|
|
private:
|
2014-05-13 13:06:30 +02:00
|
|
|
QString m_commonDirectory;
|
|
|
|
|
QStringList m_files;
|
|
|
|
|
bool m_deploys;
|
|
|
|
|
QString m_deployText;
|
|
|
|
|
AddNewTree *m_bestChoice;
|
|
|
|
|
int m_bestMatchLength;
|
|
|
|
|
int m_bestMatchPriority;
|
2014-02-18 16:31:36 +01:00
|
|
|
};
|
|
|
|
|
|
2014-05-19 10:51:42 +02:00
|
|
|
BestNodeSelector::BestNodeSelector(const QString &commonDirectory, const QStringList &files)
|
2014-05-13 13:06:30 +02:00
|
|
|
: m_commonDirectory(commonDirectory),
|
|
|
|
|
m_files(files),
|
|
|
|
|
m_deploys(false),
|
|
|
|
|
m_deployText(QCoreApplication::translate("ProjectWizard", "The files are implicitly added to the projects:") + QLatin1Char('\n')),
|
|
|
|
|
m_bestChoice(0),
|
|
|
|
|
m_bestMatchLength(-1),
|
|
|
|
|
m_bestMatchPriority(-1)
|
2014-02-18 16:31:36 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
// Find the project the new files should be added
|
|
|
|
|
// If any node deploys the files, then we don't want to add the files.
|
|
|
|
|
// Otherwise consider their common path. Either a direct match on the directory
|
|
|
|
|
// or the directory with the longest matching path (list containing"/project/subproject1"
|
|
|
|
|
// matching common path "/project/subproject1/newuserpath").
|
|
|
|
|
void BestNodeSelector::inspect(AddNewTree *tree)
|
2014-02-18 16:31:36 +01:00
|
|
|
{
|
2014-05-13 13:06:30 +02:00
|
|
|
FolderNode *node = tree->node();
|
|
|
|
|
if (node->nodeType() == ProjectNodeType) {
|
|
|
|
|
if (static_cast<ProjectNode *>(node)->deploysFolder(m_commonDirectory)) {
|
|
|
|
|
m_deploys = true;
|
|
|
|
|
m_deployText += tree->displayName() + QLatin1Char('\n');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (m_deploys)
|
|
|
|
|
return;
|
|
|
|
|
const QString projectDirectory = ProjectExplorerPlugin::directoryFor(node);
|
|
|
|
|
const int projectDirectorySize = projectDirectory.size();
|
|
|
|
|
if (!m_commonDirectory.startsWith(projectDirectory))
|
|
|
|
|
return;
|
|
|
|
|
bool betterMatch = projectDirectorySize > m_bestMatchLength
|
|
|
|
|
|| (projectDirectorySize == m_bestMatchLength && tree->priority() > m_bestMatchPriority);
|
|
|
|
|
if (betterMatch) {
|
|
|
|
|
m_bestMatchPriority = tree->priority();
|
|
|
|
|
m_bestMatchLength = projectDirectorySize;
|
|
|
|
|
m_bestChoice = tree;
|
|
|
|
|
}
|
2014-02-18 16:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
AddNewTree *BestNodeSelector::bestChoice() const
|
2014-02-18 16:31:36 +01:00
|
|
|
{
|
2014-05-13 13:06:30 +02:00
|
|
|
if (m_deploys)
|
|
|
|
|
return 0;
|
|
|
|
|
return m_bestChoice;
|
|
|
|
|
}
|
2014-02-18 16:31:36 +01:00
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
QString BestNodeSelector::deployingProjects() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-05-13 13:06:30 +02:00
|
|
|
if (m_deploys)
|
|
|
|
|
return m_deployText;
|
|
|
|
|
return QString();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
static inline AddNewTree *createNoneNode(BestNodeSelector *selector)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-05-13 13:06:30 +02:00
|
|
|
QString displayName = QCoreApplication::translate("ProjectWizard", "<Implicitly Add>");
|
|
|
|
|
if (selector->bestChoice())
|
|
|
|
|
displayName = QCoreApplication::translate("ProjectWizard", "<None>");
|
|
|
|
|
return new AddNewTree(displayName);
|
2010-01-12 16:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
static inline AddNewTree *buildAddProjectTree(ProjectNode *root, const QString &projectPath, Node *contextNode, BestNodeSelector *selector)
|
|
|
|
|
{
|
|
|
|
|
QList<AddNewTree *> children;
|
|
|
|
|
foreach (ProjectNode *pn, root->subProjectNodes()) {
|
|
|
|
|
AddNewTree *child = buildAddProjectTree(pn, projectPath, contextNode, selector);
|
|
|
|
|
if (child)
|
|
|
|
|
children.append(child);
|
|
|
|
|
}
|
2010-01-12 16:45:21 +01:00
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
const QList<ProjectExplorer::ProjectAction> &list = root->supportedActions(root);
|
|
|
|
|
if (list.contains(ProjectExplorer::AddSubProject) && !list.contains(ProjectExplorer::InheritedFromParent)) {
|
|
|
|
|
if (projectPath.isEmpty() || root->canAddSubProject(projectPath)) {
|
|
|
|
|
FolderNode::AddNewInformation info = root->addNewInformation(QStringList() << projectPath, contextNode);
|
|
|
|
|
AddNewTree *item = new AddNewTree(root, children, info);
|
|
|
|
|
selector->inspect(item);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-12 16:45:21 +01:00
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
if (children.isEmpty())
|
|
|
|
|
return 0;
|
|
|
|
|
return new AddNewTree(root, children, root->displayName());
|
|
|
|
|
}
|
2010-01-12 16:45:21 +01:00
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
static inline AddNewTree *buildAddProjectTree(SessionNode *root, const QString &projectPath, Node *contextNode, BestNodeSelector *selector)
|
2010-01-12 16:45:21 +01:00
|
|
|
{
|
2014-05-13 13:06:30 +02:00
|
|
|
QList<AddNewTree *> children;
|
|
|
|
|
foreach (ProjectNode *pn, root->projectNodes()) {
|
|
|
|
|
AddNewTree *child = buildAddProjectTree(pn, projectPath, contextNode, selector);
|
|
|
|
|
if (child)
|
|
|
|
|
children.append(child);
|
|
|
|
|
}
|
|
|
|
|
children.prepend(createNoneNode(selector));
|
|
|
|
|
return new AddNewTree(root, children, root->displayName());
|
2010-01-12 16:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
static inline AddNewTree *buildAddFilesTree(FolderNode *root, const QStringList &files, Node *contextNode, BestNodeSelector *selector)
|
2010-01-12 16:45:21 +01:00
|
|
|
{
|
2014-05-13 13:06:30 +02:00
|
|
|
QList<AddNewTree *> children;
|
|
|
|
|
foreach (FolderNode *fn, root->subFolderNodes()) {
|
|
|
|
|
AddNewTree *child = buildAddFilesTree(fn, files, contextNode, selector);
|
|
|
|
|
if (child)
|
|
|
|
|
children.append(child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QList<ProjectExplorer::ProjectAction> &list = root->supportedActions(root);
|
|
|
|
|
if (list.contains(ProjectExplorer::AddNewFile) && !list.contains(ProjectExplorer::InheritedFromParent)) {
|
|
|
|
|
FolderNode::AddNewInformation info = root->addNewInformation(files, contextNode);
|
|
|
|
|
AddNewTree *item = new AddNewTree(root, children, info);
|
|
|
|
|
selector->inspect(item);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
if (children.isEmpty())
|
|
|
|
|
return 0;
|
|
|
|
|
return new AddNewTree(root, children, root->displayName());
|
2010-01-12 16:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
static inline AddNewTree *buildAddFilesTree(SessionNode *root, const QStringList &files, Node *contextNode, BestNodeSelector *selector)
|
2010-01-12 16:45:21 +01:00
|
|
|
{
|
2014-05-13 13:06:30 +02:00
|
|
|
QList<AddNewTree *> children;
|
|
|
|
|
foreach (ProjectNode *pn, root->projectNodes()) {
|
|
|
|
|
AddNewTree *child = buildAddFilesTree(pn, files, contextNode, selector);
|
|
|
|
|
if (child)
|
|
|
|
|
children.append(child);
|
|
|
|
|
}
|
|
|
|
|
children.prepend(createNoneNode(selector));
|
|
|
|
|
return new AddNewTree(root, children, root->displayName());
|
2010-01-12 16:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
static inline AddNewTree *getChoices(const QStringList &generatedFiles,
|
2014-05-02 17:38:42 +02:00
|
|
|
IWizardFactory::WizardKind wizardKind,
|
2014-05-13 13:06:30 +02:00
|
|
|
Node *contextNode,
|
|
|
|
|
BestNodeSelector *selector)
|
2010-01-12 16:45:21 +01:00
|
|
|
{
|
2014-05-02 17:38:42 +02:00
|
|
|
if (wizardKind == IWizardFactory::ProjectWizard)
|
2014-05-13 13:06:30 +02:00
|
|
|
return buildAddProjectTree(SessionManager::sessionNode(), generatedFiles.first(), contextNode, selector);
|
|
|
|
|
else
|
|
|
|
|
return buildAddFilesTree(SessionManager::sessionNode(), generatedFiles, contextNode, selector);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------- ProjectWizardContext
|
2009-01-20 15:31:33 +01:00
|
|
|
struct ProjectWizardContext
|
|
|
|
|
{
|
2010-01-12 16:45:21 +01:00
|
|
|
ProjectWizardContext();
|
|
|
|
|
void clear();
|
|
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
QList<IVersionControl*> versionControls;
|
|
|
|
|
QList<IVersionControl*> activeVersionControls;
|
2013-06-05 13:41:47 +02:00
|
|
|
QPointer<ProjectWizardPage> page; // this is managed by the wizard!
|
2010-01-12 16:45:21 +01:00
|
|
|
bool repositoryExists; // Is VCS 'add' sufficient, or should a repository be created?
|
|
|
|
|
QString commonDirectory;
|
2014-05-02 17:38:42 +02:00
|
|
|
const IWizardFactory *wizard;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2010-01-12 16:45:21 +01:00
|
|
|
ProjectWizardContext::ProjectWizardContext() :
|
|
|
|
|
page(0),
|
2010-08-26 18:33:16 +02:00
|
|
|
repositoryExists(false),
|
|
|
|
|
wizard(0)
|
2010-01-12 16:45:21 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectWizardContext::clear()
|
|
|
|
|
{
|
2011-04-15 17:43:44 +02:00
|
|
|
activeVersionControls.clear();
|
2010-01-12 16:45:21 +01:00
|
|
|
commonDirectory.clear();
|
2013-06-05 14:04:07 +02:00
|
|
|
page = 0;
|
2010-01-12 16:45:21 +01:00
|
|
|
repositoryExists = false;
|
2010-08-26 18:33:16 +02:00
|
|
|
wizard = 0;
|
2010-01-12 16:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ---- 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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
static QString generatedProjectFilePath(const QList<GeneratedFile> &files)
|
2010-09-02 12:14:27 +02:00
|
|
|
{
|
2013-10-06 02:46:23 +02:00
|
|
|
foreach (const GeneratedFile &file, files)
|
|
|
|
|
if (file.attributes() & GeneratedFile::OpenProjectAttribute)
|
2010-09-02 12:14:27 +02:00
|
|
|
return file.path();
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-26 18:33:16 +02:00
|
|
|
void ProjectFileWizardExtension::firstExtensionPageShown(
|
2013-10-06 02:46:23 +02:00
|
|
|
const QList<GeneratedFile> &files,
|
2012-04-02 14:55:56 +02:00
|
|
|
const QVariantMap &extraValues)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
if (debugExtension)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << files.size();
|
2014-02-18 16:31:36 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QStringList fileNames;
|
2013-10-06 02:46:23 +02:00
|
|
|
foreach (const GeneratedFile &f, files)
|
2008-12-02 12:01:29 +01:00
|
|
|
fileNames.push_back(f.path());
|
2010-01-12 16:45:21 +01:00
|
|
|
m_context->commonDirectory = Utils::commonPath(fileNames);
|
|
|
|
|
m_context->page->setFilesDisplay(m_context->commonDirectory, fileNames);
|
2010-08-24 17:17:11 +02:00
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
QStringList filePaths;
|
|
|
|
|
ProjectExplorer::ProjectAction projectAction;
|
2014-05-02 17:38:42 +02:00
|
|
|
if (m_context->wizard->kind()== IWizardFactory::ProjectWizard) {
|
2014-05-13 13:06:30 +02:00
|
|
|
projectAction = ProjectExplorer::AddSubProject;
|
|
|
|
|
filePaths << generatedProjectFilePath(files);
|
2010-08-24 17:17:11 +02:00
|
|
|
} else {
|
2014-05-13 13:06:30 +02:00
|
|
|
projectAction = ProjectExplorer::AddNewFile;
|
|
|
|
|
foreach (const GeneratedFile &gf, files)
|
|
|
|
|
filePaths << gf.path();
|
2010-08-24 17:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
|
|
|
|
|
Node *contextNode = extraValues.value(QLatin1String(Constants::PREFERRED_PROJECT_NODE)).value<Node *>();
|
2014-05-19 10:51:42 +02:00
|
|
|
BestNodeSelector selector(m_context->commonDirectory, filePaths);
|
2014-05-13 13:06:30 +02:00
|
|
|
AddNewTree *tree = getChoices(filePaths, m_context->wizard->kind(), contextNode, &selector);
|
|
|
|
|
|
|
|
|
|
m_context->page->setAdditionalInfo(selector.deployingProjects());
|
|
|
|
|
|
|
|
|
|
AddNewModel *model = new AddNewModel(tree);
|
|
|
|
|
m_context->page->setModel(model);
|
|
|
|
|
m_context->page->setBestNode(selector.bestChoice());
|
|
|
|
|
m_context->page->setAddingSubProject(projectAction == ProjectExplorer::AddSubProject);
|
2011-04-15 17:43:44 +02:00
|
|
|
|
|
|
|
|
// Store all version controls for later use:
|
2011-07-27 12:36:29 +00:00
|
|
|
if (m_context->versionControls.isEmpty()) {
|
2013-10-06 02:46:23 +02:00
|
|
|
foreach (IVersionControl *vc, ExtensionSystem::PluginManager::getObjects<IVersionControl>()) {
|
2011-07-27 12:36:29 +00:00
|
|
|
m_context->versionControls.append(vc);
|
|
|
|
|
connect(vc, SIGNAL(configurationChanged()), this, SLOT(initializeVersionControlChoices()));
|
|
|
|
|
}
|
2011-04-15 17:43:44 +02:00
|
|
|
}
|
|
|
|
|
|
2010-01-12 16:45:21 +01:00
|
|
|
initializeVersionControlChoices();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-12 16:45:21 +01:00
|
|
|
void ProjectFileWizardExtension::initializeVersionControlChoices()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-06-05 13:41:47 +02:00
|
|
|
if (m_context->page.isNull())
|
|
|
|
|
return;
|
|
|
|
|
|
2010-01-12 16:45:21 +01:00
|
|
|
// Figure out version control situation:
|
|
|
|
|
// 1) Directory is managed and VCS supports "Add" -> List it
|
|
|
|
|
// 2) Directory is managed and VCS does not support "Add" -> None available
|
|
|
|
|
// 3) Directory is not managed -> Offer all VCS that support "CreateRepository"
|
2011-04-15 17:43:44 +02:00
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
IVersionControl *currentSelection = 0;
|
2011-04-15 17:43:44 +02:00
|
|
|
int currentIdx = m_context->page->versionControlIndex() - 1;
|
|
|
|
|
if (currentIdx >= 0 && currentIdx <= m_context->activeVersionControls.size() - 1)
|
|
|
|
|
currentSelection = m_context->activeVersionControls.at(currentIdx);
|
|
|
|
|
|
|
|
|
|
m_context->activeVersionControls.clear();
|
|
|
|
|
|
|
|
|
|
QStringList versionControlChoices = QStringList(tr("<None>"));
|
2010-01-12 16:45:21 +01:00
|
|
|
if (!m_context->commonDirectory.isEmpty()) {
|
2013-10-06 02:46:23 +02:00
|
|
|
IVersionControl *managingControl = VcsManager::findVersionControlForDirectory(m_context->commonDirectory);
|
2010-01-12 16:45:21 +01:00
|
|
|
if (managingControl) {
|
|
|
|
|
// Under VCS
|
2013-10-06 02:46:23 +02:00
|
|
|
if (managingControl->supportsOperation(IVersionControl::AddOperation)) {
|
2011-04-18 16:24:29 +02:00
|
|
|
versionControlChoices.append(managingControl->displayName());
|
2011-04-15 17:43:44 +02:00
|
|
|
m_context->activeVersionControls.push_back(managingControl);
|
2010-01-12 16:45:21 +01:00
|
|
|
m_context->repositoryExists = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Create
|
2013-10-06 02:46:23 +02:00
|
|
|
foreach (IVersionControl *vc, m_context->versionControls)
|
|
|
|
|
if (vc->supportsOperation(IVersionControl::CreateRepositoryOperation)) {
|
2011-04-15 17:43:44 +02:00
|
|
|
versionControlChoices.append(vc->displayName());
|
|
|
|
|
m_context->activeVersionControls.append(vc);
|
|
|
|
|
}
|
2010-01-12 16:45:21 +01:00
|
|
|
m_context->repositoryExists = false;
|
|
|
|
|
}
|
|
|
|
|
} // has a common root.
|
2011-04-15 17:43:44 +02:00
|
|
|
|
2010-01-12 16:45:21 +01:00
|
|
|
m_context->page->setVersionControls(versionControlChoices);
|
|
|
|
|
// Enable adding to version control by default.
|
|
|
|
|
if (m_context->repositoryExists && versionControlChoices.size() >= 2)
|
|
|
|
|
m_context->page->setVersionControlIndex(1);
|
2011-04-15 17:43:44 +02:00
|
|
|
if (!m_context->repositoryExists) {
|
|
|
|
|
int newIdx = m_context->activeVersionControls.indexOf(currentSelection) + 1;
|
|
|
|
|
m_context->page->setVersionControlIndex(newIdx);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
QList<QWizardPage *> ProjectFileWizardExtension::extensionPages(const IWizardFactory *wizard)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!m_context)
|
2008-12-02 12:01:29 +01:00
|
|
|
m_context = new ProjectWizardContext;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2010-01-12 16:45:21 +01:00
|
|
|
m_context->clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
// Init context with page and projects
|
|
|
|
|
m_context->page = new ProjectWizardPage;
|
2010-08-26 18:33:16 +02:00
|
|
|
m_context->wizard = wizard;
|
2010-01-12 16:45:21 +01:00
|
|
|
return QList<QWizardPage *>() << m_context->page;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-05 09:59:28 +02:00
|
|
|
bool ProjectFileWizardExtension::processFiles(
|
2013-10-06 02:46:23 +02:00
|
|
|
const QList<GeneratedFile> &files,
|
2010-08-26 18:33:16 +02:00
|
|
|
bool *removeOpenProjectAttribute, QString *errorMessage)
|
2010-01-12 16:45:21 +01:00
|
|
|
{
|
2013-03-17 16:09:01 +01:00
|
|
|
if (!processProject(files, removeOpenProjectAttribute, errorMessage))
|
|
|
|
|
return false;
|
|
|
|
|
if (!processVersionControl(files, errorMessage)) {
|
|
|
|
|
QString message;
|
|
|
|
|
if (errorMessage) {
|
|
|
|
|
message = *errorMessage;
|
|
|
|
|
message.append(QLatin1String("\n\n"));
|
|
|
|
|
errorMessage->clear();
|
|
|
|
|
}
|
|
|
|
|
message.append(tr("Open project anyway?"));
|
2013-10-06 02:46:23 +02:00
|
|
|
if (QMessageBox::question(ICore::mainWindow(), tr("Version Control Failure"), message,
|
2013-03-17 16:09:01 +01:00
|
|
|
QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2010-01-12 16:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add files to project && version control
|
2010-08-26 18:33:16 +02:00
|
|
|
bool ProjectFileWizardExtension::processProject(
|
2013-10-06 02:46:23 +02:00
|
|
|
const QList<GeneratedFile> &files,
|
2010-08-26 18:33:16 +02:00
|
|
|
bool *removeOpenProjectAttribute, QString *errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-08-26 18:33:16 +02:00
|
|
|
*removeOpenProjectAttribute = false;
|
|
|
|
|
|
2010-09-02 12:14:27 +02:00
|
|
|
QString generatedProject = generatedProjectFilePath(files);
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
FolderNode *folder = m_context->page->currentNode();
|
|
|
|
|
if (!folder)
|
2010-01-12 16:45:21 +01:00
|
|
|
return true;
|
2014-05-02 17:38:42 +02:00
|
|
|
if (m_context->wizard->kind() == IWizardFactory::ProjectWizard) {
|
2014-02-18 16:31:36 +01:00
|
|
|
if (!static_cast<ProjectNode *>(folder)->addSubProjects(QStringList(generatedProject))) {
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("Failed to add subproject \"%1\"\nto project \"%2\".")
|
2014-02-18 16:31:36 +01:00
|
|
|
.arg(generatedProject).arg(folder->path());
|
2010-01-12 16:45:21 +01:00
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-08-26 18:33:16 +02:00
|
|
|
*removeOpenProjectAttribute = true;
|
|
|
|
|
} else {
|
2013-07-01 16:13:48 +02:00
|
|
|
QStringList filePaths;
|
2013-10-06 02:46:23 +02:00
|
|
|
foreach (const GeneratedFile &generatedFile, files)
|
2013-07-01 16:13:48 +02:00
|
|
|
filePaths << generatedFile.path();
|
2014-02-18 16:31:36 +01:00
|
|
|
if (!folder->addFiles(filePaths)) {
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("Failed to add one or more files to project\n\"%1\" (%2).").
|
2014-02-18 16:31:36 +01:00
|
|
|
arg(folder->path(), filePaths.join(QString(QLatin1Char(','))));
|
2013-07-01 16:13:48 +02:00
|
|
|
return false;
|
2010-08-26 18:33:16 +02:00
|
|
|
}
|
2010-01-12 16:45:21 +01:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
bool ProjectFileWizardExtension::processVersionControl(const QList<GeneratedFile> &files, QString *errorMessage)
|
2010-01-12 16:45:21 +01:00
|
|
|
{
|
|
|
|
|
// Add files to version control (Entry at 0 is 'None').
|
|
|
|
|
const int vcsIndex = m_context->page->versionControlIndex() - 1;
|
2011-04-15 17:43:44 +02:00
|
|
|
if (vcsIndex < 0 || vcsIndex >= m_context->activeVersionControls.size())
|
2010-01-12 16:45:21 +01:00
|
|
|
return true;
|
|
|
|
|
QTC_ASSERT(!m_context->commonDirectory.isEmpty(), return false);
|
2013-10-06 02:46:23 +02:00
|
|
|
IVersionControl *versionControl = m_context->activeVersionControls.at(vcsIndex);
|
2010-01-12 16:45:21 +01:00
|
|
|
// Create repository?
|
|
|
|
|
if (!m_context->repositoryExists) {
|
2013-10-06 02:46:23 +02:00
|
|
|
QTC_ASSERT(versionControl->supportsOperation(IVersionControl::CreateRepositoryOperation), return false);
|
2010-01-12 16:45:21 +01:00
|
|
|
if (!versionControl->vcsCreateRepository(m_context->commonDirectory)) {
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("A version control system repository could not be created in \"%1\".").arg(m_context->commonDirectory);
|
2010-01-12 16:45:21 +01:00
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-12 16:45:21 +01:00
|
|
|
// Add files if supported.
|
2013-10-06 02:46:23 +02:00
|
|
|
if (versionControl->supportsOperation(IVersionControl::AddOperation)) {
|
|
|
|
|
foreach (const GeneratedFile &generatedFile, files) {
|
2010-01-12 16:45:21 +01:00
|
|
|
if (!versionControl->vcsAdd(generatedFile.path())) {
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("Failed to add \"%1\" to the version control system.").arg(generatedFile.path());
|
2008-12-02 12:01:29 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
static ICodeStylePreferences *codeStylePreferences(Project *project, Id languageId)
|
2011-08-05 09:59:28 +02:00
|
|
|
{
|
2012-11-21 21:47:17 +02:00
|
|
|
if (!languageId.isValid())
|
2011-08-05 09:59:28 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (project)
|
2011-08-16 10:45:23 +02:00
|
|
|
return project->editorConfiguration()->codeStyle(languageId);
|
2011-08-05 09:59:28 +02:00
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
return TextEditorSettings::codeStyle(languageId);
|
2011-08-05 09:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
void ProjectFileWizardExtension::applyCodeStyle(GeneratedFile *file) const
|
2011-08-05 09:59:28 +02:00
|
|
|
{
|
|
|
|
|
if (file->isBinary() || file->contents().isEmpty())
|
|
|
|
|
return; // nothing to do
|
|
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
MimeType mt = MimeDatabase::findByFile(QFileInfo(file->path()));
|
|
|
|
|
Id languageId = TextEditorSettings::languageId(mt.type());
|
2011-08-05 09:59:28 +02:00
|
|
|
|
2012-11-21 21:47:17 +02:00
|
|
|
if (!languageId.isValid())
|
2011-08-05 09:59:28 +02:00
|
|
|
return; // don't modify files like *.ui *.pro
|
|
|
|
|
|
2014-05-13 13:06:30 +02:00
|
|
|
FolderNode *folder = m_context->page->currentNode();
|
2014-02-18 16:31:36 +01:00
|
|
|
Project *baseProject = SessionManager::projectForNode(folder);
|
2011-08-05 09:59:28 +02:00
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
ICodeStylePreferencesFactory *factory = TextEditorSettings::codeStyleFactory(languageId);
|
2011-08-05 09:59:28 +02:00
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
Indenter *indenter = 0;
|
2011-08-05 09:59:28 +02:00
|
|
|
if (factory)
|
|
|
|
|
indenter = factory->createIndenter();
|
|
|
|
|
if (!indenter)
|
2013-10-06 02:46:23 +02:00
|
|
|
indenter = new NormalIndenter();
|
2011-08-05 09:59:28 +02:00
|
|
|
|
2013-10-06 02:46:23 +02:00
|
|
|
ICodeStylePreferences *codeStylePrefs = codeStylePreferences(baseProject, languageId);
|
2011-08-05 09:59:28 +02:00
|
|
|
indenter->setCodeStylePreferences(codeStylePrefs);
|
|
|
|
|
QTextDocument doc(file->contents());
|
|
|
|
|
QTextCursor cursor(&doc);
|
|
|
|
|
cursor.select(QTextCursor::Document);
|
2011-08-16 10:45:23 +02:00
|
|
|
indenter->indent(&doc, cursor, QChar::Null, codeStylePrefs->currentTabSettings());
|
2011-08-05 09:59:28 +02:00
|
|
|
delete indenter;
|
2013-10-06 02:46:23 +02:00
|
|
|
if (TextEditorSettings::storageSettings().m_cleanWhitespace) {
|
2013-08-07 10:19:24 +02:00
|
|
|
QTextBlock block = doc.firstBlock();
|
|
|
|
|
while (block.isValid()) {
|
|
|
|
|
codeStylePrefs->currentTabSettings().removeTrailingWhitespace(cursor, block);
|
|
|
|
|
block = block.next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
file->setContents(doc.toPlainText());
|
2011-08-05 09:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|