Commit a3984dd7 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

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 @@ ...@@ -36,11 +36,13 @@
#include "nicknamedialog.h" #include "nicknamedialog.h"
#include "vcsoutputwindow.h" #include "vcsoutputwindow.h"
#include "corelistener.h" #include "corelistener.h"
#include "wizard/vcsconfigurationpage.h"
#include <coreplugin/iversioncontrol.h> #include <coreplugin/iversioncontrol.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <coreplugin/vcsmanager.h> #include <coreplugin/vcsmanager.h>
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projecttree.h> #include <projectexplorer/projecttree.h>
...@@ -89,6 +91,8 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage) ...@@ -89,6 +91,8 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
this, SLOT(slotSettingsChanged())); this, SLOT(slotSettingsChanged()));
slotSettingsChanged(); slotSettingsChanged();
JsonWizardFactory::registerPageFactory(new Internal::VcsConfigurationPageFactory);
Utils::MacroExpander *expander = Utils::globalMacroExpander(); Utils::MacroExpander *expander = Utils::globalMacroExpander();
expander->registerVariable(Constants::VAR_VCS_NAME, expander->registerVariable(Constants::VAR_VCS_NAME,
tr("Name of the version control system in use by the current project."), tr("Name of the version control system in use by the current project."),
......
...@@ -34,7 +34,11 @@ ...@@ -34,7 +34,11 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/iversioncontrol.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 <utils/qtcassert.h>
#include <QPushButton> #include <QPushButton>
...@@ -42,10 +46,65 @@ ...@@ -42,10 +46,65 @@
#include <QWizardPage> #include <QWizardPage>
using namespace Core; using namespace Core;
using namespace ProjectExplorer;
namespace VcsBase { namespace VcsBase {
namespace Internal { 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 class VcsConfigurationPagePrivate
{ {
public: public:
...@@ -56,7 +115,7 @@ public: ...@@ -56,7 +115,7 @@ public:
} // namespace Internal } // namespace Internal
VcsConfigurationPage::VcsConfigurationPage(const IVersionControl *vc, QWidget *parent) : VcsConfigurationPage::VcsConfigurationPage(const IVersionControl *vc, QWidget *parent) :
QWizardPage(parent), Utils::WizardPage(parent),
d(new Internal::VcsConfigurationPagePrivate) d(new Internal::VcsConfigurationPagePrivate)
{ {
QTC_ASSERT(vc, return); QTC_ASSERT(vc, return);
......
...@@ -33,7 +33,9 @@ ...@@ -33,7 +33,9 @@
#include "../vcsbase_global.h" #include "../vcsbase_global.h"
#include <QWizardPage> #include <projectexplorer/jsonwizard/jsonwizardpagefactory.h>
#include <utils/wizardpage.h>
namespace Core { class IVersionControl; } namespace Core { class IVersionControl; }
...@@ -41,11 +43,25 @@ namespace VcsBase { ...@@ -41,11 +43,25 @@ namespace VcsBase {
namespace Internal { class VcsConfigurationPagePrivate; } 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 Q_OBJECT
public: public:
// TODO: Make this set the VCS only in initializePage.
explicit VcsConfigurationPage(const Core::IVersionControl *, QWidget *parent = 0); explicit VcsConfigurationPage(const Core::IVersionControl *, QWidget *parent = 0);
~VcsConfigurationPage(); ~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