From 72f0b52555d40d83b1f795ceccdd59cbf4493ec6 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 15 Oct 2014 14:23:00 +0200 Subject: [PATCH] JsonWizard: Add page to query for project parameters Change-Id: I76fad7fd563af6c33b117f1256fa06c22c4240df Reviewed-by: Daniel Teske --- .../jsonwizard/jsonprojectpage.cpp | 92 +++++++++++++++++++ .../jsonwizard/jsonprojectpage.h | 53 +++++++++++ .../projectexplorer/jsonwizard/jsonwizard.pri | 2 + .../jsonwizard/jsonwizardpagefactory_p.cpp | 29 ++++++ .../jsonwizard/jsonwizardpagefactory_p.h | 9 ++ .../projectexplorer/projectexplorer.cpp | 1 + .../projectexplorer/projectexplorer.qbs | 1 + 7 files changed, 187 insertions(+) create mode 100644 src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp create mode 100644 src/plugins/projectexplorer/jsonwizard/jsonprojectpage.h diff --git a/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp new file mode 100644 index 00000000000..ce6e1f79d0f --- /dev/null +++ b/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.cpp @@ -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 + +#include +#include + +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(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 diff --git a/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.h b/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.h new file mode 100644 index 00000000000..6b542ee34b6 --- /dev/null +++ b/src/plugins/projectexplorer/jsonwizard/jsonprojectpage.h @@ -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 + +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 diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri b/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri index 8e8346e54ff..69d53e9e377 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri @@ -1,5 +1,6 @@ HEADERS += $$PWD/jsonfieldpage.h \ $$PWD/jsonfilepage.h \ + $$PWD/jsonprojectpage.h \ $$PWD/jsonsummarypage.h \ $$PWD/jsonwizard.h \ $$PWD/jsonwizardfactory.h \ @@ -10,6 +11,7 @@ HEADERS += $$PWD/jsonfieldpage.h \ SOURCES += $$PWD/jsonfieldpage.cpp \ $$PWD/jsonfilepage.cpp \ + $$PWD/jsonprojectpage.cpp \ $$PWD/jsonsummarypage.cpp \ $$PWD/jsonwizard.cpp \ $$PWD/jsonwizardfactory.cpp \ diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp index 7cf4d3fa04c..4be83b743e5 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp @@ -32,6 +32,7 @@ #include "jsonfieldpage.h" #include "jsonfilepage.h" +#include "jsonprojectpage.h" #include "jsonsummarypage.h" #include "jsonwizardfactory.h" @@ -122,6 +123,34 @@ bool FilePageFactory::validateData(Core::Id typeId, const QVariant &data, QStrin 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: // -------------------------------------------------------------------- diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.h index 44a5c0e44d8..ce134be7317 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.h @@ -54,6 +54,15 @@ public: 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 { public: diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 11a3206a5bd..7bf11e8a72b 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -448,6 +448,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er // For JsonWizard: JsonWizardFactory::registerPageFactory(new FieldPageFactory); JsonWizardFactory::registerPageFactory(new FilePageFactory); + JsonWizardFactory::registerPageFactory(new ProjectPageFactory); JsonWizardFactory::registerPageFactory(new SummaryPageFactory); JsonWizardFactory::registerGeneratorFactory(new FileGeneratorFactory); diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index d3c29e7d6b5..4a145e57c96 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -171,6 +171,7 @@ QtcPlugin { files: [ "jsonfieldpage.cpp", "jsonfieldpage.h", "jsonfilepage.cpp", "jsonfilepage.h", + "jsonprojectpage.cpp", "jsonprojectpage.h", "jsonsummarypage.cpp", "jsonsummarypage.h", "jsonwizard.cpp", "jsonwizard.h", "jsonwizardfactory.cpp", "jsonwizardfactory.h",