Commit a3984dd7 authored by Tobias Hunger's avatar Tobias Hunger

Vcs: Make VcsConfiguration page available to JSON wizards

Change-Id: I444d1d95b87fe5c1ede04e1ae9bbe4e1e2d89bd3
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 6b10466b
......@@ -36,11 +36,13 @@
#include "nicknamedialog.h"
#include "vcsoutputwindow.h"
#include "corelistener.h"
#include "wizard/vcsconfigurationpage.h"
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/vcsmanager.h>
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projecttree.h>
......@@ -89,6 +91,8 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
this, SLOT(slotSettingsChanged()));
slotSettingsChanged();
JsonWizardFactory::registerPageFactory(new Internal::VcsConfigurationPageFactory);
Utils::MacroExpander *expander = Utils::globalMacroExpander();
expander->registerVariable(Constants::VAR_VCS_NAME,
tr("Name of the version control system in use by the current project."),
......
......@@ -34,7 +34,11 @@
#include <coreplugin/icore.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QPushButton>
......@@ -42,10 +46,65 @@
#include <QWizardPage>
using namespace Core;
using namespace ProjectExplorer;
namespace VcsBase {
namespace Internal {
VcsConfigurationPageFactory::VcsConfigurationPageFactory()
{
setTypeIdsSuffix(QLatin1String("VcsConfiguration"));
}
Utils::WizardPage *VcsConfigurationPageFactory::create(JsonWizard *wizard, Id typeId,
const QVariant &data)
{
Q_UNUSED(wizard);
QTC_ASSERT(canCreate(typeId), return 0);
QVariantMap tmp = data.toMap();
const QString vcsId = tmp.value(QLatin1String("vcsId")).toString();
QTC_ASSERT(!vcsId.isEmpty(), return 0);
IVersionControl *vc = VcsManager::versionControl(Id::fromString(vcsId));
QTC_ASSERT(vc, return 0);
return new VcsConfigurationPage(vc);
}
bool VcsConfigurationPageFactory::validateData(Id typeId, const QVariant &data,
QString *errorMessage)
{
QTC_ASSERT(canCreate(typeId), return false);
if (data.isNull() || data.type() != QVariant::Map) {
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"\"data\" must be a JSON object for \"VcsConfiguration\" pages.");
return false;
}
QVariantMap tmp = data.toMap();
const QString vcsId = tmp.value(QLatin1String("vcsId")).toString();
if (vcsId.isEmpty()) {
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"\"VcsConfiguration\" page requires a \"vcsId\" set.");
return false;
}
if (!VcsManager::versionControl(Id::fromString(vcsId))) {
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard",
"\"vcsId\" (\"%1\") is invalid for \"VcsConfiguration\" page. "
"Possible values are: %2.")
.arg(vcsId)
.arg(QStringList(Utils::transform(VcsManager::versionControls(), [](const IVersionControl *vc) {
return vc->id().toString();
})).join(QLatin1String(", ")));
return false;
}
return true;
}
class VcsConfigurationPagePrivate
{
public:
......@@ -56,7 +115,7 @@ public:
} // namespace Internal
VcsConfigurationPage::VcsConfigurationPage(const IVersionControl *vc, QWidget *parent) :
QWizardPage(parent),
Utils::WizardPage(parent),
d(new Internal::VcsConfigurationPagePrivate)
{
QTC_ASSERT(vc, return);
......
......@@ -33,7 +33,9 @@
#include "../vcsbase_global.h"
#include <QWizardPage>
#include <projectexplorer/jsonwizard/jsonwizardpagefactory.h>
#include <utils/wizardpage.h>
namespace Core { class IVersionControl; }
......@@ -41,11 +43,25 @@ namespace VcsBase {
namespace Internal { class VcsConfigurationPagePrivate; }
class VCSBASE_EXPORT VcsConfigurationPage : public QWizardPage
namespace Internal {
class VcsConfigurationPageFactory : public ProjectExplorer::JsonWizardPageFactory
{
public:
VcsConfigurationPageFactory();
Utils::WizardPage *create(ProjectExplorer::JsonWizard *wizard, Core::Id typeId, const QVariant &data);
bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage);
};
} // namespace Internal
class VCSBASE_EXPORT VcsConfigurationPage : public Utils::WizardPage
{
Q_OBJECT
public:
// TODO: Make this set the VCS only in initializePage.
explicit VcsConfigurationPage(const Core::IVersionControl *, QWidget *parent = 0);
~VcsConfigurationPage();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment