aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2019-04-16 16:46:36 +0200
committerEike Ziller <eike.ziller@qt.io>2019-05-09 11:19:43 +0000
commite0d38ae4140d6101b483fde25158fc94b34a3a64 (patch)
tree9137897e6cc85c195ff76ebedc9de0d9a447a168 /src
parent0c5837a1114ef526727748a0db956f0758597350 (diff)
Export Wizard values to JavaScript macro
Registers a new function "value('name')", available to the wizard json files, which returns the value of the variable "name" as a JavaScript object. So, variables with a string value are actual JavaScript strings, booleans are booleans, lists are lists, and dictionaries are dictionaries. The patch also makes it actually possible to assign JSON lists and dictionaries to values. This removes some hacks involving creating complex JavaScript objects through string substitution. Change-Id: I4ac6da22bc5bccc9fadee97694c2fa14d44c9307 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/libs/utils/macroexpander.cpp23
-rw-r--r--src/libs/utils/macroexpander.h1
-rw-r--r--src/libs/utils/wizardpage.h36
-rw-r--r--src/plugins/coreplugin/jsexpander.cpp59
-rw-r--r--src/plugins/coreplugin/jsexpander.h35
-rw-r--r--src/plugins/coreplugin/mainwindow.cpp39
-rw-r--r--src/plugins/cpptools/cpptoolsplugin.cpp2
-rw-r--r--src/plugins/designer/formtemplatewizardpage.cpp2
-rw-r--r--src/plugins/modeleditor/jsextension.h2
-rw-r--r--src/plugins/modeleditor/modeleditor_plugin.cpp2
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp12
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp22
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizard.h19
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp40
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h21
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp4
-rw-r--r--src/plugins/qtsupport/qtsupportplugin.cpp2
-rw-r--r--src/plugins/vcsbase/vcsplugin.cpp2
18 files changed, 256 insertions, 67 deletions
diff --git a/src/libs/utils/macroexpander.cpp b/src/libs/utils/macroexpander.cpp
index eb3f05e1750..de1459aae18 100644
--- a/src/libs/utils/macroexpander.cpp
+++ b/src/libs/utils/macroexpander.cpp
@@ -295,6 +295,29 @@ QByteArray MacroExpander::expand(const QByteArray &stringWithVariables) const
return expand(QString::fromLatin1(stringWithVariables)).toLatin1();
}
+QVariant MacroExpander::expandVariant(const QVariant &v) const
+{
+ const auto type = QMetaType::Type(v.type());
+ if (type == QMetaType::QString) {
+ return expand(v.toString());
+ } else if (type == QMetaType::QStringList) {
+ return Utils::transform(v.toStringList(),
+ [this](const QString &s) -> QVariant { return expand(s); });
+ } else if (type == QMetaType::QVariantList) {
+ return Utils::transform(v.toList(), [this](const QVariant &v) { return expandVariant(v); });
+ } else if (type == QMetaType::QVariantMap) {
+ const auto map = v.toMap();
+ QVariantMap result;
+ QMapIterator<QString, QVariant> it(map);
+ while (it.hasNext()) {
+ it.next();
+ result.insert(it.key(), expandVariant(it.value()));
+ }
+ return result;
+ }
+ return v;
+}
+
QString MacroExpander::expandProcessArgs(const QString &argsWithVariables) const
{
return QtcProcess::expandMacros(argsWithVariables, d);
diff --git a/src/libs/utils/macroexpander.h b/src/libs/utils/macroexpander.h
index f17ae86b8c2..30dcf06a4fb 100644
--- a/src/libs/utils/macroexpander.h
+++ b/src/libs/utils/macroexpander.h
@@ -56,6 +56,7 @@ public:
QString expand(const QString &stringWithVariables) const;
QByteArray expand(const QByteArray &stringWithVariables) const;
+ QVariant expandVariant(const QVariant &v) const;
QString expandProcessArgs(const QString &argsWithVariables) const;
diff --git a/src/libs/utils/wizardpage.h b/src/libs/utils/wizardpage.h
index fa8c60b052b..abeccfce137 100644
--- a/src/libs/utils/wizardpage.h
+++ b/src/libs/utils/wizardpage.h
@@ -29,6 +29,7 @@
#include <QSet>
#include <QString>
+#include <QVariant>
#include <QWizardPage>
#include <functional>
@@ -41,30 +42,30 @@ namespace Internal {
class QTCREATOR_UTILS_EXPORT ObjectToFieldWidgetConverter : public QWidget
{
Q_OBJECT
- Q_PROPERTY(QString text READ text NOTIFY textChanged)
+ Q_PROPERTY(QVariant value READ value NOTIFY valueChanged)
public:
- template <class T, typename... Arguments>
- static ObjectToFieldWidgetConverter *create(T *sender, void (T::*member)(Arguments...), const std::function<QString()> &toTextFunction)
+ template<class T, typename... Arguments>
+ static ObjectToFieldWidgetConverter *create(T *sender,
+ void (T::*member)(Arguments...),
+ const std::function<QVariant()> &toVariantFunction)
{
auto widget = new ObjectToFieldWidgetConverter();
- widget->toTextFunction = toTextFunction;
+ widget->toVariantFunction = toVariantFunction;
connect(sender, &QObject::destroyed, widget, &QObject::deleteLater);
- connect(sender, member, widget, [widget] () {
- emit widget->textChanged(widget->text());
- });
+ connect(sender, member, widget, [widget]() { emit widget->valueChanged(widget->value()); });
return widget;
}
signals:
- void textChanged(const QString&);
+ void valueChanged(const QVariant &);
private:
ObjectToFieldWidgetConverter () = default;
- // is used by the property text
- QString text() {return toTextFunction();}
- std::function<QString()> toTextFunction;
+ // is used by the property value
+ QVariant value() { return toVariantFunction(); }
+ std::function<QVariant()> toVariantFunction;
};
} // Internal
@@ -79,10 +80,17 @@ public:
virtual void pageWasAdded(); // called when this page was added to a Utils::Wizard
template<class T, typename... Arguments>
- void registerObjectAsFieldWithName(const QString &name, T *sender, void (T::*changeSignal)(Arguments...),
- const std::function<QString()> &senderToString)
+ void registerObjectAsFieldWithName(const QString &name,
+ T *sender,
+ void (T::*changeSignal)(Arguments...),
+ const std::function<QVariant()> &senderToVariant)
{
- registerFieldWithName(name, Internal::ObjectToFieldWidgetConverter::create(sender, changeSignal, senderToString), "text", SIGNAL(textChanged(QString)));
+ registerFieldWithName(name,
+ Internal::ObjectToFieldWidgetConverter::create(sender,
+ changeSignal,
+ senderToVariant),
+ "value",
+ SIGNAL(valueChanged(QValue)));
}
void registerFieldWithName(const QString &name, QWidget *widget,
diff --git a/src/plugins/coreplugin/jsexpander.cpp b/src/plugins/coreplugin/jsexpander.cpp
index effa3464cc7..5aa9279c7c6 100644
--- a/src/plugins/coreplugin/jsexpander.cpp
+++ b/src/plugins/coreplugin/jsexpander.cpp
@@ -34,8 +34,26 @@
#include <QDebug>
#include <QJSEngine>
-namespace Core {
+#include <unordered_map>
+
+namespace std {
+template<> struct hash<QString>
+{
+ using argument_type = QString;
+ using result_type = size_t;
+ result_type operator()(const argument_type &v) const
+ {
+ return hash<string>()(v.toStdString());
+ }
+};
+} // namespace std
+
+using ExtensionMap = std::unordered_map<QString, Core::JsExpander::ObjectFactory>;
+Q_GLOBAL_STATIC(ExtensionMap, globalJsExtensions);
+static Core::JsExpander *globalExpander = nullptr;
+
+namespace Core {
namespace Internal {
class JsExpanderPrivate {
@@ -45,9 +63,14 @@ public:
} // namespace Internal
-static Internal::JsExpanderPrivate *d;
+void JsExpander::registerGlobalObject(const QString &name, const ObjectFactory &factory)
+{
+ globalJsExtensions->insert({name, factory});
+ if (globalExpander)
+ globalExpander->registerObject(name, factory());
+}
-void JsExpander::registerQObjectForJs(const QString &name, QObject *obj)
+void JsExpander::registerObject(const QString &name, QObject *obj)
{
QJSValue jsObj = d->m_engine.newQObject(obj);
d->m_engine.globalObject().setProperty(name, jsObj);
@@ -77,16 +100,21 @@ QString JsExpander::evaluate(const QString &expression, QString *errorMessage)
return QString();
}
-JsExpander::JsExpander()
+QJSEngine &JsExpander::engine()
{
- d = new Internal::JsExpanderPrivate;
- Utils::globalMacroExpander()->registerPrefix("JS",
+ return d->m_engine;
+}
+
+void JsExpander::registerForExpander(Utils::MacroExpander *macroExpander)
+{
+ macroExpander->registerPrefix(
+ "JS",
QCoreApplication::translate("Core::JsExpander",
"Evaluate simple JavaScript statements.<br>"
"The statements may not contain '{' nor '}' characters."),
- [](QString in) -> QString {
+ [this](QString in) -> QString {
QString errorMessage;
- QString result = JsExpander::evaluate(in, &errorMessage);
+ QString result = evaluate(in, &errorMessage);
if (!errorMessage.isEmpty()) {
qWarning() << errorMessage;
return errorMessage;
@@ -94,8 +122,21 @@ JsExpander::JsExpander()
return result;
}
});
+}
- registerQObjectForJs(QLatin1String("Util"), new Internal::UtilsJsExtension);
+JsExpander *JsExpander::createGlobalJsExpander()
+{
+ globalExpander = new JsExpander();
+ registerGlobalObject<Internal::UtilsJsExtension>("Util");
+ globalExpander->registerForExpander(Utils::globalMacroExpander());
+ return globalExpander;
+}
+
+JsExpander::JsExpander()
+{
+ d = new Internal::JsExpanderPrivate;
+ for (const std::pair<const QString, ObjectFactory> &obj : *globalJsExtensions)
+ registerObject(obj.first, obj.second());
}
JsExpander::~JsExpander()
diff --git a/src/plugins/coreplugin/jsexpander.h b/src/plugins/coreplugin/jsexpander.h
index 087f494ac0b..df8c6bceeaa 100644
--- a/src/plugins/coreplugin/jsexpander.h
+++ b/src/plugins/coreplugin/jsexpander.h
@@ -27,26 +27,51 @@
#include "core_global.h"
+#include <functional>
+
QT_BEGIN_NAMESPACE
+class QJSEngine;
class QObject;
class QString;
QT_END_NAMESPACE
+namespace Utils {
+class MacroExpander;
+}
+
namespace Core {
-namespace Internal { class MainWindow; }
+namespace Internal {
+class MainWindow;
+class JsExpanderPrivate;
+} // namespace Internal
class CORE_EXPORT JsExpander
{
public:
- static void registerQObjectForJs(const QString &name, QObject *obj);
-
- static QString evaluate(const QString &expression, QString *errorMessage = nullptr);
+ using ObjectFactory = std::function<QObject *()>;
-private:
JsExpander();
~JsExpander();
+ template <class T>
+ static void registerGlobalObject(const QString &name)
+ {
+ registerGlobalObject(name, []{ return new T; });
+ }
+
+ static void registerGlobalObject(const QString &name, const ObjectFactory &factory);
+
+ void registerObject(const QString &name, QObject *obj);
+ QString evaluate(const QString &expression, QString *errorMessage = nullptr);
+
+ QJSEngine &engine();
+ void registerForExpander(Utils::MacroExpander *macroExpander);
+
+private:
+ static JsExpander *createGlobalJsExpander();
+
+ Internal::JsExpanderPrivate *d;
friend class Core::Internal::MainWindow;
};
diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp
index 2e8b5f2ad15..d35477f6b57 100644
--- a/src/plugins/coreplugin/mainwindow.cpp
+++ b/src/plugins/coreplugin/mainwindow.cpp
@@ -100,25 +100,26 @@ namespace Internal {
enum { debugMainWindow = 0 };
-MainWindow::MainWindow() :
- AppMainWindow(),
- m_coreImpl(new ICore(this)),
- m_lowPrioAdditionalContexts(Constants::C_GLOBAL),
- m_settingsDatabase(new SettingsDatabase(QFileInfo(PluginManager::settings()->fileName()).path(),
- QLatin1String(Constants::IDE_CASED_ID),
- this)),
- m_progressManager(new ProgressManagerPrivate),
- m_jsExpander(new JsExpander),
- m_vcsManager(new VcsManager),
- m_modeStack(new FancyTabWidget(this)),
- m_generalSettings(new GeneralSettings),
- m_systemSettings(new SystemSettings),
- m_shortcutSettings(new ShortcutSettings),
- m_toolSettings(new ToolSettings),
- m_mimeTypeSettings(new MimeTypeSettings),
- m_systemEditor(new SystemEditor),
- m_toggleLeftSideBarButton(new QToolButton),
- m_toggleRightSideBarButton(new QToolButton)
+MainWindow::MainWindow()
+ : AppMainWindow()
+ , m_coreImpl(new ICore(this))
+ , m_lowPrioAdditionalContexts(Constants::C_GLOBAL)
+ , m_settingsDatabase(
+ new SettingsDatabase(QFileInfo(PluginManager::settings()->fileName()).path(),
+ QLatin1String(Constants::IDE_CASED_ID),
+ this))
+ , m_progressManager(new ProgressManagerPrivate)
+ , m_jsExpander(JsExpander::createGlobalJsExpander())
+ , m_vcsManager(new VcsManager)
+ , m_modeStack(new FancyTabWidget(this))
+ , m_generalSettings(new GeneralSettings)
+ , m_systemSettings(new SystemSettings)
+ , m_shortcutSettings(new ShortcutSettings)
+ , m_toolSettings(new ToolSettings)
+ , m_mimeTypeSettings(new MimeTypeSettings)
+ , m_systemEditor(new SystemEditor)
+ , m_toggleLeftSideBarButton(new QToolButton)
+ , m_toggleRightSideBarButton(new QToolButton)
{
(void) new DocumentManager(this);
diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp
index d2ca6d5d0b8..4d7599b24bb 100644
--- a/src/plugins/cpptools/cpptoolsplugin.cpp
+++ b/src/plugins/cpptools/cpptoolsplugin.cpp
@@ -172,7 +172,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
d = new CppToolsPluginPrivate;
- JsExpander::registerQObjectForJs(QLatin1String("Cpp"), new CppToolsJsExtension);
+ JsExpander::registerGlobalObject<CppToolsJsExtension>("Cpp");
// Menus
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
diff --git a/src/plugins/designer/formtemplatewizardpage.cpp b/src/plugins/designer/formtemplatewizardpage.cpp
index ce5f3ddb8c2..fb01ddc5f43 100644
--- a/src/plugins/designer/formtemplatewizardpage.cpp
+++ b/src/plugins/designer/formtemplatewizardpage.cpp
@@ -117,7 +117,7 @@ bool FormTemplateWizardPage::validatePage()
QMessageBox::critical(this, tr("%1 - Error").arg(title()), errorMessage);
return false;
}
- wizard()->setProperty("FormContents", m_templateContents.split('\n'));
+ wizard()->setProperty("FormContents", m_templateContents);
return true;
}
diff --git a/src/plugins/modeleditor/jsextension.h b/src/plugins/modeleditor/jsextension.h
index 74c7cbc892c..6192636e3b7 100644
--- a/src/plugins/modeleditor/jsextension.h
+++ b/src/plugins/modeleditor/jsextension.h
@@ -35,7 +35,7 @@ class JsExtension : public QObject
Q_OBJECT
public:
- JsExtension(QObject *parent = nullptr) : QObject(parent) { }
+ JsExtension() {}
Q_INVOKABLE QString fileNameToElementName(const QString &file);
Q_INVOKABLE QString elementNameToFileName(const QString &element);
diff --git a/src/plugins/modeleditor/modeleditor_plugin.cpp b/src/plugins/modeleditor/modeleditor_plugin.cpp
index 7571703cbbd..8e08854f4db 100644
--- a/src/plugins/modeleditor/modeleditor_plugin.cpp
+++ b/src/plugins/modeleditor/modeleditor_plugin.cpp
@@ -92,7 +92,7 @@ bool ModelEditorPlugin::initialize(const QStringList &arguments, QString *errorS
d->modelFactory = new ModelEditorFactory(d->uiController, this);
d->settingsController = new SettingsController(this);
- Core::JsExpander::registerQObjectForJs(QLatin1String("Modeling"), new JsExtension(this));
+ Core::JsExpander::registerGlobalObject<JsExtension>("Modeling");
connect(d->settingsController, &SettingsController::saveSettings,
d->uiController, &UiController::saveSettings);
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
index 8048d4cc6df..b04ec95efc0 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp
@@ -810,7 +810,7 @@ std::unique_ptr<QStandardItem> createStandardItemFromListItem(const QVariant &it
if (item.type() == QVariant::Map) {
QVariantMap tmp = item.toMap();
const QString key = JsonWizardFactory::localizedString(consumeValue(tmp, "trKey", QString()).toString());
- const QString value = consumeValue(tmp, "value", key).toString();
+ const QVariant value = consumeValue(tmp, "value", key);
if (key.isNull() || key.isEmpty()) {
*errorMessage = QCoreApplication::translate("ProjectExplorer::JsonFieldPage",
@@ -920,7 +920,7 @@ void ListField::initializeData(MacroExpander *expander)
if (item.get() == currentItem)
currentItem = expandedValuesItem;
expandedValuesItem->setText(expander->expand(item->text()));
- expandedValuesItem->setData(expander->expand(item->data(ValueRole).toString()), ValueRole);
+ expandedValuesItem->setData(expander->expandVariant(item->data(ValueRole)), ValueRole);
expandedValuesItem->setData(expander->expand(item->data(IconStringRole).toString()), IconStringRole);
expandedValuesItem->setData(condition, ConditionRole);
@@ -1020,8 +1020,8 @@ void ComboBoxField::setup(JsonFieldPage *page, const QString &name)
page->registerObjectAsFieldWithName<QItemSelectionModel>(name, selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
const QModelIndex i = selectionModel()->currentIndex();
if (i.isValid())
- return i.data(ValueRole).toString();
- return QString();
+ return i.data(ValueRole);
+ return QVariant();
});
QObject::connect(selectionModel(), &QItemSelectionModel::selectionChanged, page, [page]() {
emit page->completeChanged();
@@ -1058,8 +1058,8 @@ void IconListField::setup(JsonFieldPage *page, const QString &name)
page->registerObjectAsFieldWithName<QItemSelectionModel>(name, selectionModel(), &QItemSelectionModel::selectionChanged, [this]() {
const QModelIndex i = selectionModel()->currentIndex();
if (i.isValid())
- return i.data(ValueRole).toString();
- return QString();
+ return i.data(ValueRole);
+ return QVariant();
});
QObject::connect(selectionModel(), &QItemSelectionModel::selectionChanged, page, [page]() {
emit page->completeChanged();
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
index 5db2186c46a..6939d0863ec 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp
@@ -45,6 +45,7 @@
#include <QDialogButtonBox>
#include <QDir>
#include <QFileInfo>
+#include <QJSEngine>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
@@ -143,7 +144,8 @@ private:
} // namespace Internal
-JsonWizard::JsonWizard(QWidget *parent) : Utils::Wizard(parent)
+JsonWizard::JsonWizard(QWidget *parent)
+ : Utils::Wizard(parent)
{
setMinimumSize(800, 500);
m_expander.registerExtraResolver([this](const QString &name, QString *ret) -> bool {
@@ -157,7 +159,10 @@ JsonWizard::JsonWizard(QWidget *parent) : Utils::Wizard(parent)
const QString key = QString::fromLatin1("%{") + value + QLatin1Char('}');
return m_expander.expand(key) == key ? QString() : QLatin1String("true");
});
-
+ // override default JS macro by custom one that adds Wizard specific features
+ m_jsExpander.registerObject("Wizard", new Internal::JsonWizardJsExtension(this));
+ m_jsExpander.engine().evaluate("var value = Wizard.value");
+ m_jsExpander.registerForExpander(&m_expander);
}
JsonWizard::~JsonWizard()
@@ -520,4 +525,17 @@ bool JsonWizard::OptionDefinition::condition(Utils::MacroExpander &expander) con
return JsonWizard::boolFromVariant(m_condition, &expander);
}
+namespace Internal {
+
+JsonWizardJsExtension::JsonWizardJsExtension(JsonWizard *wizard)
+ : m_wizard(wizard)
+{}
+
+QVariant JsonWizardJsExtension::value(const QString &name) const
+{
+ const QVariant value = m_wizard->value(name);
+ return m_wizard->expander()->expandVariant(m_wizard->value(name));
+}
+
+} // namespace Internal
} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h
index 1f8aca77414..99a9ce49527 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.h
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.h
@@ -29,6 +29,7 @@
#include <projectexplorer/projectnodes.h>
#include <coreplugin/generatedfile.h>
+#include <coreplugin/jsexpander.h>
#include <utils/wizard.h>
#include <utils/macroexpander.h>
@@ -37,8 +38,25 @@
namespace ProjectExplorer {
+class JsonWizard;
class JsonWizardGenerator;
+namespace Internal {
+
+class JsonWizardJsExtension : public QObject
+{
+ Q_OBJECT
+public:
+ JsonWizardJsExtension(JsonWizard *wizard);
+
+ Q_INVOKABLE QVariant value(const QString &name) const;
+
+private:
+ JsonWizard *m_wizard;
+};
+
+} // namespace Internal
+
// Documentation inside.
class PROJECTEXPLORER_EXPORT JsonWizard : public Utils::Wizard
{
@@ -126,6 +144,7 @@ private:
GeneratorFiles m_files;
Utils::MacroExpander m_expander;
+ Core::JsExpander m_jsExpander;
};
} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp
index 3a01d9e0454..6ef34d8ddc5 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.cpp
@@ -34,6 +34,7 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
+#include <coreplugin/jsexpander.h>
#include <coreplugin/messagemanager.h>
#include <extensionsystem/pluginmanager.h>
@@ -46,10 +47,11 @@
#include <QDebug>
#include <QDir>
-#include <QMap>
+#include <QJSEngine>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
+#include <QMap>
#include <QUuid>
namespace ProjectExplorer {
@@ -513,9 +515,17 @@ bool JsonWizardFactory::isAvailable(Core::Id platformId) const
[platformId]() { return platformId.toString(); });
expander.registerVariable("Features", tr("The features available to this wizard."),
[this, e, platformId]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(availableFeatures(platformId)), e); });
- expander.registerVariable("Plugins", tr("The plugins loaded."),
- [this, e]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(pluginFeatures()), e); });
-
+ expander.registerVariable("Plugins", tr("The plugins loaded."), [this, e]() {
+ return JsonWizard::stringListToArrayString(Core::Id::toStringList(pluginFeatures()), e);
+ });
+ Core::JsExpander jsExpander;
+ jsExpander.registerObject("Wizard",
+ new Internal::JsonWizardFactoryJsExtension(platformId,
+ availableFeatures(
+ platformId),
+ pluginFeatures()));
+ jsExpander.engine().evaluate("var value = Wizard.value");
+ jsExpander.registerForExpander(e);
return JsonWizard::boolFromVariant(m_enabledExpression, &expander);
}
@@ -660,4 +670,26 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir,
return errorMessage->isEmpty();
}
+namespace Internal {
+
+JsonWizardFactoryJsExtension::JsonWizardFactoryJsExtension(Core::Id platformId,
+ const QSet<Core::Id> &availableFeatures,
+ const QSet<Core::Id> &pluginFeatures)
+ : m_platformId(platformId)
+ , m_availableFeatures(availableFeatures)
+ , m_pluginFeatures(pluginFeatures)
+{}
+
+QVariant JsonWizardFactoryJsExtension::value(const QString &name) const
+{
+ if (name == "Platform")
+ return m_platformId.toString();
+ if (name == "Features")
+ return Core::Id::toStringList(m_availableFeatures);
+ if (name == "Plugins")
+ return Core::Id::toStringList(m_pluginFeatures);
+ return QVariant();
+}
+
+} // namespace Internal
} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h
index ead93f48412..06af1ebae80 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h
@@ -119,4 +119,23 @@ private:
friend class ProjectExplorerPluginPrivate;
};
-} //namespace ProjectExplorer
+namespace Internal {
+
+class JsonWizardFactoryJsExtension : public QObject
+{
+ Q_OBJECT
+public:
+ JsonWizardFactoryJsExtension(Core::Id platformId,
+ const QSet<Core::Id> &availableFeatures,
+ const QSet<Core::Id> &pluginFeatures);
+
+ Q_INVOKABLE QVariant value(const QString &name) const;
+
+private:
+ Core::Id m_platformId;
+ QSet<Core::Id> m_availableFeatures;
+ QSet<Core::Id> m_pluginFeatures;
+};
+
+} // namespace Internal
+} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp
index ee7da5b419c..a168fea084f 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp
@@ -127,7 +127,9 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
*ret = options.value(n);
return true;
});
- nested.registerExtraResolver([expander](QString n, QString *ret) { return expander->resolveMacro(n, ret); });
+ nested.registerExtraResolver([expander](QString n, QString *ret) {
+ return expander->resolveMacro(n, ret);
+ });
gf.setContents(Utils::TemplateEngine::processText(&nested, QString::fromUtf8(reader.data()),
errorMessage));
diff --git a/src/plugins/qtsupport/qtsupportplugin.cpp b/src/plugins/qtsupport/qtsupportplugin.cpp
index 7b98a146b9a..5faa9f7a1a2 100644
--- a/src/plugins/qtsupport/qtsupportplugin.cpp
+++ b/src/plugins/qtsupport/qtsupportplugin.cpp
@@ -85,7 +85,7 @@ bool QtSupportPlugin::initialize(const QStringList &arguments, QString *errorMes
ProFileEvaluator::initialize();
new ProFileCacheManager(this);
- JsExpander::registerQObjectForJs(QLatin1String("QtSupport"), new CodeGenerator);
+ JsExpander::registerGlobalObject<CodeGenerator>("QtSupport");
d = new QtSupportPluginPrivate;
diff --git a/src/plugins/vcsbase/vcsplugin.cpp b/src/plugins/vcsbase/vcsplugin.cpp
index 201f2a3b435..efb70f1696b 100644
--- a/src/plugins/vcsbase/vcsplugin.cpp
+++ b/src/plugins/vcsbase/vcsplugin.cpp
@@ -98,7 +98,7 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
JsonWizardFactory::registerPageFactory(new Internal::VcsConfigurationPageFactory);
JsonWizardFactory::registerPageFactory(new Internal::VcsCommandPageFactory);
- JsExpander::registerQObjectForJs(QLatin1String("Vcs"), new VcsJsExtension);
+ JsExpander::registerGlobalObject<VcsJsExtension>("Vcs");
Utils::MacroExpander *expander = Utils::globalMacroExpander();
expander->registerVariable(Constants::VAR_VCS_NAME,