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 <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -452,22 +451,7 @@ void NewDialog::okButtonClicked()
|
||||
|
||||
IWizardFactory *wizard = currentWizardFactory();
|
||||
QTC_ASSERT(wizard, accept(); return);
|
||||
QString path = 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;
|
||||
}
|
||||
}
|
||||
QString path = wizard->runPath(m_defaultLocation);
|
||||
wizard->runWizard(path, ICore::dialogParent(), selectedPlatform(), m_extraVariables);
|
||||
|
||||
close();
|
||||
|
||||
@@ -29,8 +29,11 @@
|
||||
****************************************************************************/
|
||||
|
||||
#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/pluginmanager.h>
|
||||
@@ -38,7 +41,7 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QStringList>
|
||||
#include <QAction>
|
||||
|
||||
/*!
|
||||
\class Core::IWizardFactory
|
||||
@@ -169,6 +172,11 @@ template <class Predicate>
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Id actionId(const IWizardFactory *factory)
|
||||
{
|
||||
return factory->id().withPrefix("Wizard.Impl.");
|
||||
}
|
||||
|
||||
QList<IWizardFactory*> IWizardFactory::allWizardFactories()
|
||||
{
|
||||
if (!s_areFactoriesLoaded) {
|
||||
@@ -191,6 +199,15 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
|
||||
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);
|
||||
s_allFactories << newFactory;
|
||||
}
|
||||
@@ -215,6 +232,27 @@ QList<IWizardFactory*> IWizardFactory::wizardFactoriesOfKind(WizardKind 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
|
||||
{
|
||||
FeatureSet availableFeatures = pluginFeatures();
|
||||
@@ -274,6 +312,17 @@ void IWizardFactory::destroyFeatureProvider()
|
||||
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
|
||||
{
|
||||
static FeatureSet plugins;
|
||||
@@ -291,6 +340,5 @@ FeatureSet IWizardFactory::pluginFeatures() const
|
||||
|
||||
void IWizardFactory::initialize()
|
||||
{
|
||||
connect(ICore::instance(), &ICore::coreAboutToClose,
|
||||
ICore::instance(), []() { qDeleteAll(s_allFactories); s_allFactories.clear(); });
|
||||
connect(ICore::instance(), &ICore::coreAboutToClose, &IWizardFactory::clearWizardFactories);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||
|
||||
namespace Core {
|
||||
|
||||
namespace Internal { class CorePlugin; }
|
||||
@@ -84,6 +86,8 @@ public:
|
||||
void addRequiredFeature(const Feature &feature) { m_requiredFeatures |= feature; }
|
||||
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;
|
||||
|
||||
bool isAvailable(const QString &platformName) const;
|
||||
@@ -108,6 +112,9 @@ private:
|
||||
static void initialize();
|
||||
static void destroyFeatureProvider();
|
||||
|
||||
static void clearWizardFactories();
|
||||
|
||||
QAction *m_action = 0;
|
||||
IWizardFactory::WizardKind m_kind;
|
||||
QIcon m_icon;
|
||||
QString m_description;
|
||||
|
||||
Reference in New Issue
Block a user