From 54602502810da9ec8b3b1764b57ee8a006f21845 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 20 Jan 2015 14:46:10 +0100 Subject: [PATCH] VcsBase: Make VcsConfiguration page more dynamic ... again making it more useful for the JSON wizard Change-Id: Ic7a454c4efc93eb48a44ab2a37ecd39f8c6f3ba7 Reviewed-by: Orgad Shaneh --- src/plugins/bazaar/clonewizard.cpp | 7 +- src/plugins/cvs/checkoutwizard.cpp | 7 +- src/plugins/git/clonewizard.cpp | 7 +- src/plugins/mercurial/clonewizard.cpp | 7 +- src/plugins/subversion/checkoutwizard.cpp | 7 +- .../vcsbase/wizard/vcsconfigurationpage.cpp | 72 +++++++++++++------ .../vcsbase/wizard/vcsconfigurationpage.h | 7 +- 7 files changed, 81 insertions(+), 33 deletions(-) diff --git a/src/plugins/bazaar/clonewizard.cpp b/src/plugins/bazaar/clonewizard.cpp index 941622eea13..9a24c8bb6a9 100644 --- a/src/plugins/bazaar/clonewizard.cpp +++ b/src/plugins/bazaar/clonewizard.cpp @@ -58,8 +58,11 @@ CloneWizard::CloneWizard(const Utils::FileName &path, QWidget *parent) : setStartedStatus(tr("Cloning started...")); const Core::IVersionControl *vc = BazaarPlugin::instance()->versionControl(); - if (!vc->isConfigured()) - addPage(new VcsConfigurationPage(vc)); + if (!vc->isConfigured()) { + VcsConfigurationPage *configPage = new VcsConfigurationPage; + configPage->setVersionControl(vc); + addPage(configPage); + } CloneWizardPage *page = new CloneWizardPage; page->setPath(path.toString()); addPage(page); diff --git a/src/plugins/cvs/checkoutwizard.cpp b/src/plugins/cvs/checkoutwizard.cpp index e5cbaeebb24..c06243a1116 100644 --- a/src/plugins/cvs/checkoutwizard.cpp +++ b/src/plugins/cvs/checkoutwizard.cpp @@ -51,8 +51,11 @@ CheckoutWizard::CheckoutWizard(const Utils::FileName &path, QWidget *parent) : BaseCheckoutWizard(path, parent) { const Core::IVersionControl *vc = CvsPlugin::instance()->versionControl(); - if (!vc->isConfigured()) - addPage(new VcsConfigurationPage(vc)); + if (!vc->isConfigured()) { + VcsConfigurationPage *configPage = new VcsConfigurationPage; + configPage->setVersionControl(vc); + addPage(configPage); + } CheckoutWizardPage *cwp = new CheckoutWizardPage; cwp->setPath(path.toString()); addPage(cwp); diff --git a/src/plugins/git/clonewizard.cpp b/src/plugins/git/clonewizard.cpp index 7ba8249a7e9..fd987989163 100644 --- a/src/plugins/git/clonewizard.cpp +++ b/src/plugins/git/clonewizard.cpp @@ -54,8 +54,11 @@ CloneWizard::CloneWizard(const Utils::FileName &path, QWidget *parent) : setStartedStatus(tr("Cloning started...")); const Internal::GitVersionControl *vc = Internal::GitPlugin::instance()->gitVersionControl(); - if (!vc->isConfigured()) - addPage(new VcsConfigurationPage(vc)); + if (!vc->isConfigured()) { + VcsConfigurationPage *configPage = new VcsConfigurationPage; + configPage->setVersionControl(vc); + addPage(configPage); + } CloneWizardPage *cwp = new CloneWizardPage; cwp->setPath(path.toString()); addPage(cwp); diff --git a/src/plugins/mercurial/clonewizard.cpp b/src/plugins/mercurial/clonewizard.cpp index 339bc244bd2..9648b7310ab 100644 --- a/src/plugins/mercurial/clonewizard.cpp +++ b/src/plugins/mercurial/clonewizard.cpp @@ -53,8 +53,11 @@ CloneWizard::CloneWizard(const Utils::FileName &path, QWidget *parent) : setStartedStatus(tr("Cloning started...")); const Core::IVersionControl *vc = MercurialPlugin::instance()->versionControl(); - if (!vc->isConfigured()) - addPage(new VcsConfigurationPage(vc)); + if (!vc->isConfigured()) { + VcsConfigurationPage *configPage = new VcsConfigurationPage; + configPage->setVersionControl(vc); + addPage(configPage); + } CloneWizardPage *page = new CloneWizardPage; page->setPath(path.toString()); addPage(page); diff --git a/src/plugins/subversion/checkoutwizard.cpp b/src/plugins/subversion/checkoutwizard.cpp index 45b7d439727..cfd50b03fe8 100644 --- a/src/plugins/subversion/checkoutwizard.cpp +++ b/src/plugins/subversion/checkoutwizard.cpp @@ -54,8 +54,11 @@ CheckoutWizard::CheckoutWizard(const FileName &path, QWidget *parent) : BaseCheckoutWizard(path, parent) { const Core::IVersionControl *vc = SubversionPlugin::instance()->versionControl(); - if (!vc->isConfigured()) - addPage(new VcsConfigurationPage(vc)); + if (!vc->isConfigured()) { + VcsConfigurationPage *configPage = new VcsConfigurationPage; + configPage->setVersionControl(vc); + addPage(configPage); + } CheckoutWizardPage *cwp = new CheckoutWizardPage; cwp->setPath(path.toString()); addPage(cwp); diff --git a/src/plugins/vcsbase/wizard/vcsconfigurationpage.cpp b/src/plugins/vcsbase/wizard/vcsconfigurationpage.cpp index 34c3ea7cd12..efd1cc9c838 100644 --- a/src/plugins/vcsbase/wizard/vcsconfigurationpage.cpp +++ b/src/plugins/vcsbase/wizard/vcsconfigurationpage.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -67,10 +68,10 @@ Utils::WizardPage *VcsConfigurationPageFactory::create(JsonWizard *wizard, Id ty 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); + VcsConfigurationPage *page = new VcsConfigurationPage; + page->setVersionControlId(vcsId); - return new VcsConfigurationPage(vc); + return page; } bool VcsConfigurationPageFactory::validateData(Id typeId, const QVariant &data, @@ -91,17 +92,6 @@ bool VcsConfigurationPageFactory::validateData(Id typeId, const QVariant &data, "\"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; } @@ -109,21 +99,19 @@ class VcsConfigurationPagePrivate { public: const IVersionControl *m_versionControl; + QString m_versionControlId; QPushButton *m_configureButton; }; } // namespace Internal -VcsConfigurationPage::VcsConfigurationPage(const IVersionControl *vc, QWidget *parent) : - Utils::WizardPage(parent), - d(new Internal::VcsConfigurationPagePrivate) +VcsConfigurationPage::VcsConfigurationPage() : d(new Internal::VcsConfigurationPagePrivate) { - QTC_ASSERT(vc, return); setTitle(tr("Configuration")); - setSubTitle(tr("Please configure %1 now.").arg(vc->displayName())); - d->m_versionControl = vc; + d->m_versionControl = 0; d->m_configureButton = new QPushButton(ICore::msgShowOptionsDialog(), this); + d->m_configureButton->setEnabled(false); QVBoxLayout *verticalLayout = new QVBoxLayout(this); verticalLayout->addWidget(d->m_configureButton); @@ -137,9 +125,51 @@ VcsConfigurationPage::~VcsConfigurationPage() delete d; } +void VcsConfigurationPage::setVersionControl(const IVersionControl *vc) +{ + if (vc) + d->m_versionControlId = vc->id().toString(); + else + d->m_versionControlId.clear(); + d->m_versionControl = 0; +} + +void VcsConfigurationPage::setVersionControlId(const QString &id) +{ + d->m_versionControlId = id; +} + +void VcsConfigurationPage::initializePage() +{ + if (!d->m_versionControlId.isEmpty()) { + auto jw = qobject_cast(wizard()); + if (!jw) + emit reportError(tr("No version control set on \"VcsConfiguration\" page.")); + + const QString vcsId = jw ? jw->expander()->expand(d->m_versionControlId) : d->m_versionControlId; + + d->m_versionControl = VcsManager::versionControl(Id::fromString(vcsId)); + if (!d->m_versionControl) { + emit reportError( + tr("\"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(", ")))); + } + } + + d->m_configureButton->setEnabled(d->m_versionControl); + if (d->m_versionControl) + setSubTitle(tr("Please configure %1 now.").arg(d->m_versionControl->displayName())); + else + setSubTitle(tr("No known version control selected.")); +} + bool VcsConfigurationPage::isComplete() const { - return d->m_versionControl->isConfigured(); + return d->m_versionControl ? d->m_versionControl->isConfigured() : false; } void VcsConfigurationPage::openConfiguration() diff --git a/src/plugins/vcsbase/wizard/vcsconfigurationpage.h b/src/plugins/vcsbase/wizard/vcsconfigurationpage.h index 1a0b6059267..d881e3cf375 100644 --- a/src/plugins/vcsbase/wizard/vcsconfigurationpage.h +++ b/src/plugins/vcsbase/wizard/vcsconfigurationpage.h @@ -61,10 +61,13 @@ 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(); ~VcsConfigurationPage(); + void setVersionControl(const Core::IVersionControl *vc); + void setVersionControlId(const QString &id); + + void initializePage(); bool isComplete() const; private slots: