forked from qt-creator/qt-creator
Wizards: Simplify checking for plugins
Change-Id: Ifc63d075462562a2efef5208e37458a16ac640ca Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
"icon": "../../global/consoleapplication.png",
|
||||
"iconKind": "Themed",
|
||||
"featuresRequired": [ "QtSupport.Wizards.FeatureQt" ],
|
||||
"enabled": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0 || value('Plugins').indexOf('QbsProjectManager') >= 0 || value('Plugins').indexOf('CMakeProjectManager') >= 0 || value('Plugins').indexOf('MesonProjectManager') >= 0}",
|
||||
"enabled": "%{JS: isAnyPluginRunning(['qmakeprojectmanager', 'qbsprojectmanager', 'cmakeprojectmanager', 'mesonprojectmanager'])}",
|
||||
|
||||
"options":
|
||||
[
|
||||
@@ -51,27 +51,27 @@
|
||||
{
|
||||
"trKey": "qmake",
|
||||
"value": "qmake",
|
||||
"condition": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('qmakeprojectmanager')}"
|
||||
},
|
||||
{
|
||||
"trKey": "CMake",
|
||||
"value": "cmake",
|
||||
"condition": "%{JS: value('Plugins').indexOf('CMakeProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('cmakeprojectmanager')}"
|
||||
},
|
||||
{
|
||||
"trKey": "CMake for Qt 6.5 and Later",
|
||||
"value": "cmake-qt6",
|
||||
"condition": "%{JS: value('Plugins').indexOf('CMakeProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('cmakeprojectmanager')}"
|
||||
},
|
||||
{
|
||||
"trKey": "Qbs",
|
||||
"value": "qbs",
|
||||
"condition": "%{JS: value('Plugins').indexOf('QbsProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('qbsprojectmanager')}"
|
||||
},
|
||||
{
|
||||
"trKey": "Meson",
|
||||
"value": "meson",
|
||||
"condition": "%{JS: value('Plugins').indexOf('MesonProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('mesonprojectmanager')}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
"icon": "../../global/guiapplication.png",
|
||||
"iconKind": "Themed",
|
||||
"featuresRequired": [ "QtSupport.Wizards.FeatureQt" ],
|
||||
"enabled": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0 || value('Plugins').indexOf('CMakeProjectManager') >= 0 || value('Plugins').indexOf('QbsProjectManager') >= 0 || value('Plugins').indexOf('MesonProjectManager') >= 0}",
|
||||
"enabled": "%{JS: isAnyPluginRunning(['qmakeprojectmanager', 'qbsprojectmanager', 'cmakeprojectmanager', 'mesonprojectmanager'])}",
|
||||
|
||||
"options":
|
||||
[
|
||||
@@ -56,27 +56,27 @@
|
||||
{
|
||||
"trKey": "qmake",
|
||||
"value": "qmake",
|
||||
"condition": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('qmakeprojectmanager')}"
|
||||
},
|
||||
{
|
||||
"trKey": "CMake",
|
||||
"value": "cmake",
|
||||
"condition": "%{JS: value('Plugins').indexOf('CMakeProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('cmakeprojectmanager')}"
|
||||
},
|
||||
{
|
||||
"trKey": "CMake for Qt 6.5 and Later",
|
||||
"value": "cmake-qt6",
|
||||
"condition": "%{JS: value('Plugins').indexOf('CMakeProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('cmakeprojectmanager')}"
|
||||
},
|
||||
{
|
||||
"trKey": "Meson",
|
||||
"value": "meson",
|
||||
"condition": "%{JS: value('Plugins').indexOf('MesonProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('mesonprojectmanager')}"
|
||||
},
|
||||
{
|
||||
"trKey": "Qbs",
|
||||
"value": "qbs",
|
||||
"condition": "%{JS: value('Plugins').indexOf('QbsProjectManager') >= 0}"
|
||||
"condition": "%{JS: isPluginRunning('qbsprojectmanager')}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -16,6 +16,9 @@
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/itemviews.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -143,6 +146,9 @@ JsonWizard::JsonWizard(QWidget *parent)
|
||||
// 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.engine().evaluate("var isPluginRunning = Wizard.isPluginRunning");
|
||||
m_jsExpander.engine().evaluate("var isAnyPluginRunning = Wizard.isAnyPluginRunning");
|
||||
|
||||
m_jsExpander.registerForExpander(&m_expander);
|
||||
}
|
||||
|
||||
@@ -536,5 +542,24 @@ QVariant JsonWizardJsExtension::value(const QString &name) const
|
||||
return m_wizard->expander()->expandVariant(m_wizard->value(name));
|
||||
}
|
||||
|
||||
bool JsonWizardJsExtension::isPluginRunning(const QString &id) const
|
||||
{
|
||||
return Internal::isAnyPluginRunning({id});
|
||||
}
|
||||
bool JsonWizardJsExtension::isAnyPluginRunning(const QStringList &ids) const
|
||||
{
|
||||
return Internal::isAnyPluginRunning(ids);
|
||||
}
|
||||
|
||||
bool isAnyPluginRunning(const QStringList &ids)
|
||||
{
|
||||
QTC_CHECK(Utils::allOf(ids, [](const QString &id) { return id.isLower(); }));
|
||||
|
||||
return Utils::anyOf(
|
||||
ExtensionSystem::PluginManager::plugins(), [ids](const ExtensionSystem::PluginSpec *s) {
|
||||
return s->state() == ExtensionSystem::PluginSpec::Running && ids.contains(s->id());
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -22,6 +22,8 @@ class JsonWizardGenerator;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
bool isAnyPluginRunning(const QStringList &ids);
|
||||
|
||||
class JsonWizardJsExtension : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -29,6 +31,8 @@ public:
|
||||
JsonWizardJsExtension(JsonWizard *wizard);
|
||||
|
||||
Q_INVOKABLE QVariant value(const QString &name) const;
|
||||
Q_INVOKABLE bool isPluginRunning(const QString &id) const;
|
||||
Q_INVOKABLE bool isAnyPluginRunning(const QStringList &ids) const;
|
||||
|
||||
private:
|
||||
JsonWizard *m_wizard;
|
||||
|
@@ -109,6 +109,14 @@ public:
|
||||
return Id::toStringList(m_pluginFeatures);
|
||||
return {};
|
||||
}
|
||||
Q_INVOKABLE bool isPluginRunning(const QString &id) const
|
||||
{
|
||||
return Internal::isAnyPluginRunning({id});
|
||||
}
|
||||
Q_INVOKABLE bool isAnyPluginRunning(const QStringList &ids) const
|
||||
{
|
||||
return Internal::isAnyPluginRunning(ids);
|
||||
}
|
||||
|
||||
private:
|
||||
Id m_platformId;
|
||||
@@ -802,6 +810,9 @@ bool JsonWizardFactory::isAvailable(Id platformId) const
|
||||
platformId),
|
||||
pluginFeatures()));
|
||||
jsExpander.engine().evaluate("var value = Wizard.value");
|
||||
jsExpander.engine().evaluate("var isPluginRunning = Wizard.isPluginRunning");
|
||||
jsExpander.engine().evaluate("var isAnyPluginRunning = Wizard.isAnyPluginRunning");
|
||||
|
||||
jsExpander.registerForExpander(e);
|
||||
return JsonWizard::boolFromVariant(m_enabledExpression, &expander);
|
||||
}
|
||||
|
Reference in New Issue
Block a user