forked from qt-creator/qt-creator
JsonWizard: Add page to query for project parameters
Change-Id: I76fad7fd563af6c33b117f1256fa06c22c4240df Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
92
src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp
Normal file
92
src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** 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
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "jsonprojectpage.h"
|
||||||
|
#include "jsonwizard.h"
|
||||||
|
|
||||||
|
#include <coreplugin/documentmanager.h>
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
|
JsonProjectPage::JsonProjectPage(QWidget *parent) :
|
||||||
|
Utils::ProjectIntroPage(parent)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void JsonProjectPage::initializePage()
|
||||||
|
{
|
||||||
|
if (Core::DocumentManager::useProjectsDirectory()) {
|
||||||
|
setPath(Core::DocumentManager::projectsDirectory());
|
||||||
|
} else {
|
||||||
|
if (JsonWizard *wiz = qobject_cast<JsonWizard *>(wizard()))
|
||||||
|
setPath(wiz->value(QLatin1String("InitialPath")).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
setProjectName(uniqueProjectName(path()));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JsonProjectPage::validatePage()
|
||||||
|
{
|
||||||
|
if (isComplete() && useAsDefaultPath()) {
|
||||||
|
// Store the path as default path for new projects if desired.
|
||||||
|
Core::DocumentManager::setProjectsDirectory(path());
|
||||||
|
Core::DocumentManager::setUseProjectsDirectory(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString target = path();
|
||||||
|
if (!target.endsWith(QLatin1Char('/')))
|
||||||
|
target += QLatin1Char('/');
|
||||||
|
target += projectName();
|
||||||
|
|
||||||
|
wizard()->setProperty("ProjectDirectory", target);
|
||||||
|
wizard()->setProperty("TargetPath", target);
|
||||||
|
|
||||||
|
return Utils::ProjectIntroPage::validatePage();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString JsonProjectPage::uniqueProjectName(const QString &path)
|
||||||
|
{
|
||||||
|
const QDir pathDir(path);
|
||||||
|
//: File path suggestion for a new project. If you choose
|
||||||
|
//: to translate it, make sure it is a valid path name without blanks
|
||||||
|
//: and using only ascii chars.
|
||||||
|
const QString prefix = tr("untitled");
|
||||||
|
for (unsigned i = 0; ; ++i) {
|
||||||
|
QString name = prefix;
|
||||||
|
if (i)
|
||||||
|
name += QString::number(i);
|
||||||
|
if (!pathDir.exists(name))
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ProjectExplorer
|
53
src/plugins/projectexplorer/jsonwizard/jsonprojectpage.h
Normal file
53
src/plugins/projectexplorer/jsonwizard/jsonprojectpage.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** 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
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef JSONPROJECTPAGE_H
|
||||||
|
#define JSONPROJECTPAGE_H
|
||||||
|
|
||||||
|
#include <utils/projectintropage.h>
|
||||||
|
|
||||||
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
|
// Documentation inside.
|
||||||
|
class JsonProjectPage : public Utils::ProjectIntroPage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
JsonProjectPage(QWidget *parent = 0);
|
||||||
|
|
||||||
|
void initializePage();
|
||||||
|
bool validatePage();
|
||||||
|
|
||||||
|
static QString uniqueProjectName(const QString &path);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
|
#endif // JSONPROJECTPAGE_H
|
@@ -1,5 +1,6 @@
|
|||||||
HEADERS += $$PWD/jsonfieldpage.h \
|
HEADERS += $$PWD/jsonfieldpage.h \
|
||||||
$$PWD/jsonfilepage.h \
|
$$PWD/jsonfilepage.h \
|
||||||
|
$$PWD/jsonprojectpage.h \
|
||||||
$$PWD/jsonsummarypage.h \
|
$$PWD/jsonsummarypage.h \
|
||||||
$$PWD/jsonwizard.h \
|
$$PWD/jsonwizard.h \
|
||||||
$$PWD/jsonwizardfactory.h \
|
$$PWD/jsonwizardfactory.h \
|
||||||
@@ -10,6 +11,7 @@ HEADERS += $$PWD/jsonfieldpage.h \
|
|||||||
|
|
||||||
SOURCES += $$PWD/jsonfieldpage.cpp \
|
SOURCES += $$PWD/jsonfieldpage.cpp \
|
||||||
$$PWD/jsonfilepage.cpp \
|
$$PWD/jsonfilepage.cpp \
|
||||||
|
$$PWD/jsonprojectpage.cpp \
|
||||||
$$PWD/jsonsummarypage.cpp \
|
$$PWD/jsonsummarypage.cpp \
|
||||||
$$PWD/jsonwizard.cpp \
|
$$PWD/jsonwizard.cpp \
|
||||||
$$PWD/jsonwizardfactory.cpp \
|
$$PWD/jsonwizardfactory.cpp \
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "jsonfieldpage.h"
|
#include "jsonfieldpage.h"
|
||||||
#include "jsonfilepage.h"
|
#include "jsonfilepage.h"
|
||||||
|
#include "jsonprojectpage.h"
|
||||||
#include "jsonsummarypage.h"
|
#include "jsonsummarypage.h"
|
||||||
#include "jsonwizardfactory.h"
|
#include "jsonwizardfactory.h"
|
||||||
|
|
||||||
@@ -122,6 +123,34 @@ bool FilePageFactory::validateData(Core::Id typeId, const QVariant &data, QStrin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
// ProjectPageFactory:
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
ProjectPageFactory::ProjectPageFactory()
|
||||||
|
{
|
||||||
|
setTypeIdsSuffix(QLatin1String("Project"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::WizardPage *ProjectPageFactory::create(JsonWizard *wizard, Core::Id typeId, const QVariant &data)
|
||||||
|
{
|
||||||
|
Q_UNUSED(data);
|
||||||
|
QTC_ASSERT(canCreate(typeId), return 0);
|
||||||
|
|
||||||
|
JsonProjectPage *page = new JsonProjectPage;
|
||||||
|
page->setPath(wizard->value(QStringLiteral("GivenPath")).toString());
|
||||||
|
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProjectPageFactory::validateData(Core::Id typeId, const QVariant &data, QString *errorMessage)
|
||||||
|
{
|
||||||
|
Q_UNUSED(errorMessage);
|
||||||
|
|
||||||
|
QTC_ASSERT(canCreate(typeId), return false);
|
||||||
|
return data.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// SummaryPageFactory:
|
// SummaryPageFactory:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
@@ -54,6 +54,15 @@ public:
|
|||||||
bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage);
|
bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ProjectPageFactory : public JsonWizardPageFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ProjectPageFactory();
|
||||||
|
|
||||||
|
Utils::WizardPage *create(JsonWizard *wizard, Core::Id typeId, const QVariant &data);
|
||||||
|
bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage);
|
||||||
|
};
|
||||||
|
|
||||||
class SummaryPageFactory : public JsonWizardPageFactory
|
class SummaryPageFactory : public JsonWizardPageFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -448,6 +448,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
// For JsonWizard:
|
// For JsonWizard:
|
||||||
JsonWizardFactory::registerPageFactory(new FieldPageFactory);
|
JsonWizardFactory::registerPageFactory(new FieldPageFactory);
|
||||||
JsonWizardFactory::registerPageFactory(new FilePageFactory);
|
JsonWizardFactory::registerPageFactory(new FilePageFactory);
|
||||||
|
JsonWizardFactory::registerPageFactory(new ProjectPageFactory);
|
||||||
JsonWizardFactory::registerPageFactory(new SummaryPageFactory);
|
JsonWizardFactory::registerPageFactory(new SummaryPageFactory);
|
||||||
|
|
||||||
JsonWizardFactory::registerGeneratorFactory(new FileGeneratorFactory);
|
JsonWizardFactory::registerGeneratorFactory(new FileGeneratorFactory);
|
||||||
|
@@ -171,6 +171,7 @@ QtcPlugin {
|
|||||||
files: [
|
files: [
|
||||||
"jsonfieldpage.cpp", "jsonfieldpage.h",
|
"jsonfieldpage.cpp", "jsonfieldpage.h",
|
||||||
"jsonfilepage.cpp", "jsonfilepage.h",
|
"jsonfilepage.cpp", "jsonfilepage.h",
|
||||||
|
"jsonprojectpage.cpp", "jsonprojectpage.h",
|
||||||
"jsonsummarypage.cpp", "jsonsummarypage.h",
|
"jsonsummarypage.cpp", "jsonsummarypage.h",
|
||||||
"jsonwizard.cpp", "jsonwizard.h",
|
"jsonwizard.cpp", "jsonwizard.h",
|
||||||
"jsonwizardfactory.cpp", "jsonwizardfactory.h",
|
"jsonwizardfactory.cpp", "jsonwizardfactory.h",
|
||||||
|
Reference in New Issue
Block a user