forked from qt-creator/qt-creator
Wizards: Register commands for wizards
Change-Id: Ida28b91c97980cb1391ddad7291151b4e8615615 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -32,7 +32,6 @@
|
|||||||
#include "ui_newdialog.h"
|
#include "ui_newdialog.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/documentmanager.h>
|
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -452,22 +451,7 @@ void NewDialog::okButtonClicked()
|
|||||||
|
|
||||||
IWizardFactory *wizard = currentWizardFactory();
|
IWizardFactory *wizard = currentWizardFactory();
|
||||||
QTC_ASSERT(wizard, accept(); return);
|
QTC_ASSERT(wizard, accept(); return);
|
||||||
QString path = m_defaultLocation;
|
QString path = wizard->runPath(m_defaultLocation);
|
||||||
if (path.isEmpty()) {
|
|
||||||
switch (wizard->kind()) {
|
|
||||||
case IWizardFactory::ProjectWizard:
|
|
||||||
// Project wizards: Check for projects directory or
|
|
||||||
// use last visited directory of file dialog. Never start
|
|
||||||
// at current.
|
|
||||||
path = DocumentManager::useProjectsDirectory() ?
|
|
||||||
DocumentManager::projectsDirectory() :
|
|
||||||
DocumentManager::fileDialogLastVisitedDirectory();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
path = DocumentManager::fileDialogInitialDirectory();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wizard->runWizard(path, ICore::dialogParent(), selectedPlatform(), m_extraVariables);
|
wizard->runWizard(path, ICore::dialogParent(), selectedPlatform(), m_extraVariables);
|
||||||
|
|
||||||
close();
|
close();
|
||||||
|
|||||||
@@ -29,8 +29,11 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "iwizardfactory.h"
|
#include "iwizardfactory.h"
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <coreplugin/featureprovider.h>
|
#include "actionmanager/actionmanager.h"
|
||||||
|
#include "documentmanager.h"
|
||||||
|
#include "icore.h"
|
||||||
|
#include "featureprovider.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginspec.h>
|
#include <extensionsystem/pluginspec.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
@@ -38,7 +41,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QAction>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class Core::IWizardFactory
|
\class Core::IWizardFactory
|
||||||
@@ -169,6 +172,11 @@ template <class Predicate>
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Id actionId(const IWizardFactory *factory)
|
||||||
|
{
|
||||||
|
return factory->id().withPrefix("Wizard.Impl.");
|
||||||
|
}
|
||||||
|
|
||||||
QList<IWizardFactory*> IWizardFactory::allWizardFactories()
|
QList<IWizardFactory*> IWizardFactory::allWizardFactories()
|
||||||
{
|
{
|
||||||
if (!s_areFactoriesLoaded) {
|
if (!s_areFactoriesLoaded) {
|
||||||
@@ -191,6 +199,15 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTC_ASSERT(!newFactory->m_action, continue);
|
||||||
|
newFactory->m_action = new QAction(newFactory->displayName(), newFactory);
|
||||||
|
ActionManager::registerAction(newFactory->m_action, actionId(newFactory));
|
||||||
|
|
||||||
|
connect(newFactory->m_action, &QAction::triggered, newFactory, [newFactory]() {
|
||||||
|
QString path = newFactory->runPath(QString());
|
||||||
|
newFactory->runWizard(path, ICore::dialogParent(), QString(), QVariantMap());
|
||||||
|
});
|
||||||
|
|
||||||
sanityCheck.insert(newFactory->id(), newFactory);
|
sanityCheck.insert(newFactory->id(), newFactory);
|
||||||
s_allFactories << newFactory;
|
s_allFactories << newFactory;
|
||||||
}
|
}
|
||||||
@@ -215,6 +232,27 @@ QList<IWizardFactory*> IWizardFactory::wizardFactoriesOfKind(WizardKind kind)
|
|||||||
return findWizardFactories(WizardKindPredicate(kind));
|
return findWizardFactories(WizardKindPredicate(kind));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString IWizardFactory::runPath(const QString &defaultPath)
|
||||||
|
{
|
||||||
|
QString path = defaultPath;
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
switch (kind()) {
|
||||||
|
case IWizardFactory::ProjectWizard:
|
||||||
|
// Project wizards: Check for projects directory or
|
||||||
|
// use last visited directory of file dialog. Never start
|
||||||
|
// at current.
|
||||||
|
path = DocumentManager::useProjectsDirectory() ?
|
||||||
|
DocumentManager::projectsDirectory() :
|
||||||
|
DocumentManager::fileDialogLastVisitedDirectory();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
path = DocumentManager::fileDialogInitialDirectory();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
bool IWizardFactory::isAvailable(const QString &platformName) const
|
bool IWizardFactory::isAvailable(const QString &platformName) const
|
||||||
{
|
{
|
||||||
FeatureSet availableFeatures = pluginFeatures();
|
FeatureSet availableFeatures = pluginFeatures();
|
||||||
@@ -274,6 +312,17 @@ void IWizardFactory::destroyFeatureProvider()
|
|||||||
s_providerList.clear();
|
s_providerList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IWizardFactory::clearWizardFactories()
|
||||||
|
{
|
||||||
|
foreach (IWizardFactory *factory, s_allFactories)
|
||||||
|
ActionManager::unregisterAction(factory->m_action, actionId(factory));
|
||||||
|
|
||||||
|
qDeleteAll(s_allFactories);
|
||||||
|
s_allFactories.clear();
|
||||||
|
|
||||||
|
s_areFactoriesLoaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
FeatureSet IWizardFactory::pluginFeatures() const
|
FeatureSet IWizardFactory::pluginFeatures() const
|
||||||
{
|
{
|
||||||
static FeatureSet plugins;
|
static FeatureSet plugins;
|
||||||
@@ -291,6 +340,5 @@ FeatureSet IWizardFactory::pluginFeatures() const
|
|||||||
|
|
||||||
void IWizardFactory::initialize()
|
void IWizardFactory::initialize()
|
||||||
{
|
{
|
||||||
connect(ICore::instance(), &ICore::coreAboutToClose,
|
connect(ICore::instance(), &ICore::coreAboutToClose, &IWizardFactory::clearWizardFactories);
|
||||||
ICore::instance(), []() { qDeleteAll(s_allFactories); s_allFactories.clear(); });
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
namespace Internal { class CorePlugin; }
|
namespace Internal { class CorePlugin; }
|
||||||
@@ -84,6 +86,8 @@ public:
|
|||||||
void addRequiredFeature(const Feature &feature) { m_requiredFeatures |= feature; }
|
void addRequiredFeature(const Feature &feature) { m_requiredFeatures |= feature; }
|
||||||
void setFlags(WizardFlags flags) { m_flags = flags; }
|
void setFlags(WizardFlags flags) { m_flags = flags; }
|
||||||
|
|
||||||
|
QString runPath(const QString &defaultPath);
|
||||||
|
|
||||||
virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &variables) = 0;
|
virtual void runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &variables) = 0;
|
||||||
|
|
||||||
bool isAvailable(const QString &platformName) const;
|
bool isAvailable(const QString &platformName) const;
|
||||||
@@ -108,6 +112,9 @@ private:
|
|||||||
static void initialize();
|
static void initialize();
|
||||||
static void destroyFeatureProvider();
|
static void destroyFeatureProvider();
|
||||||
|
|
||||||
|
static void clearWizardFactories();
|
||||||
|
|
||||||
|
QAction *m_action = 0;
|
||||||
IWizardFactory::WizardKind m_kind;
|
IWizardFactory::WizardKind m_kind;
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
|
|||||||
Reference in New Issue
Block a user