forked from qt-creator/qt-creator
QmlProjectManager: Prepare special aspects for auto-registration
Change-Id: I9b5e019dfeaf394107a190e78e8880b4f16b9ee9 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -37,8 +37,8 @@ static bool caseInsensitiveLessThan(const FilePath &s1, const FilePath &s2)
|
|||||||
return s1.toString().toCaseFolded() < s2.toString().toCaseFolded();
|
return s1.toString().toCaseFolded() < s2.toString().toCaseFolded();
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlMainFileAspect::QmlMainFileAspect(Target *target)
|
QmlMainFileAspect::QmlMainFileAspect(AspectContainer *container)
|
||||||
: m_target(target)
|
: BaseAspect(container)
|
||||||
, m_scriptFile(M_CURRENT_FILE)
|
, m_scriptFile(M_CURRENT_FILE)
|
||||||
{
|
{
|
||||||
addDataExtractor(this, &QmlMainFileAspect::mainScript, &Data::mainScript);
|
addDataExtractor(this, &QmlMainFileAspect::mainScript, &Data::mainScript);
|
||||||
@@ -158,6 +158,11 @@ void QmlMainFileAspect::setMainScript(int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlMainFileAspect::setTarget(ProjectExplorer::Target *target)
|
||||||
|
{
|
||||||
|
m_target = target;
|
||||||
|
}
|
||||||
|
|
||||||
void QmlMainFileAspect::setScriptSource(MainScriptSource source, const QString &settingsPath)
|
void QmlMainFileAspect::setScriptSource(MainScriptSource source, const QString &settingsPath)
|
||||||
{
|
{
|
||||||
if (source == FileInEditor) {
|
if (source == FileInEditor) {
|
||||||
|
@@ -27,7 +27,7 @@ class QMLPROJECTMANAGER_EXPORT QmlMainFileAspect : public Utils::BaseAspect
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QmlMainFileAspect(ProjectExplorer::Target *target);
|
explicit QmlMainFileAspect(Utils::AspectContainer *container = nullptr);
|
||||||
~QmlMainFileAspect() override;
|
~QmlMainFileAspect() override;
|
||||||
|
|
||||||
enum MainScriptSource {
|
enum MainScriptSource {
|
||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
MainScriptSource mainScriptSource() const;
|
MainScriptSource mainScriptSource() const;
|
||||||
void setMainScript(int index);
|
void setMainScript(int index);
|
||||||
|
|
||||||
|
void setTarget(ProjectExplorer::Target *target);
|
||||||
void setScriptSource(MainScriptSource source, const QString &settingsPath = QString());
|
void setScriptSource(MainScriptSource source, const QString &settingsPath = QString());
|
||||||
|
|
||||||
Utils::FilePath mainScript() const;
|
Utils::FilePath mainScript() const;
|
||||||
|
@@ -14,6 +14,11 @@
|
|||||||
#include <projectexplorer/runcontrol.h>
|
#include <projectexplorer/runcontrol.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace QmlProjectManager {
|
||||||
|
|
||||||
static bool isMultilanguagePresent()
|
static bool isMultilanguagePresent()
|
||||||
{
|
{
|
||||||
const QVector<ExtensionSystem::PluginSpec *> &specs = ExtensionSystem::PluginManager::plugins();
|
const QVector<ExtensionSystem::PluginSpec *> &specs = ExtensionSystem::PluginManager::plugins();
|
||||||
@@ -24,7 +29,7 @@ static bool isMultilanguagePresent()
|
|||||||
!= specs.cend();
|
!= specs.cend();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Utils::FilePath getMultilanguageDatabaseFilePath(ProjectExplorer::Target *target)
|
static FilePath getMultilanguageDatabaseFilePath(ProjectExplorer::Target *target)
|
||||||
{
|
{
|
||||||
if (target) {
|
if (target) {
|
||||||
auto filePath = target->project()->projectDirectory().pathAppended("translations.db");
|
auto filePath = target->project()->projectDirectory().pathAppended("translations.db");
|
||||||
@@ -48,11 +53,8 @@ static QObject *getPreviewPlugin()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QmlMultiLanguageAspect::QmlMultiLanguageAspect(AspectContainer *container)
|
||||||
namespace QmlProjectManager {
|
: BoolAspect(container)
|
||||||
|
|
||||||
QmlMultiLanguageAspect::QmlMultiLanguageAspect(ProjectExplorer::Target *target)
|
|
||||||
: m_target(target)
|
|
||||||
{
|
{
|
||||||
setVisible(isMultilanguagePresent());
|
setVisible(isMultilanguagePresent());
|
||||||
setSettingsKey(Constants::USE_MULTILANGUAGE_KEY);
|
setSettingsKey(Constants::USE_MULTILANGUAGE_KEY);
|
||||||
@@ -66,8 +68,7 @@ QmlMultiLanguageAspect::QmlMultiLanguageAspect(ProjectExplorer::Target *target)
|
|||||||
addDataExtractor(this, &QmlMultiLanguageAspect::origin, &Data::origin);
|
addDataExtractor(this, &QmlMultiLanguageAspect::origin, &Data::origin);
|
||||||
|
|
||||||
connect(this, &BoolAspect::changed, this, [this] {
|
connect(this, &BoolAspect::changed, this, [this] {
|
||||||
for (ProjectExplorer::RunControl *runControl :
|
for (RunControl *runControl : ProjectExplorerPlugin::allRunControls()) {
|
||||||
ProjectExplorer::ProjectExplorerPlugin::allRunControls()) {
|
|
||||||
if (runControl->aspect<QmlMultiLanguageAspect>()->origin == this)
|
if (runControl->aspect<QmlMultiLanguageAspect>()->origin == this)
|
||||||
runControl->initiateStop();
|
runControl->initiateStop();
|
||||||
}
|
}
|
||||||
@@ -78,6 +79,11 @@ QmlMultiLanguageAspect::~QmlMultiLanguageAspect()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlMultiLanguageAspect::setTarget(Target *target)
|
||||||
|
{
|
||||||
|
m_target = target;
|
||||||
|
}
|
||||||
|
|
||||||
void QmlMultiLanguageAspect::setCurrentLocale(const QString &locale)
|
void QmlMultiLanguageAspect::setCurrentLocale(const QString &locale)
|
||||||
{
|
{
|
||||||
if (m_currentLocale == locale)
|
if (m_currentLocale == locale)
|
||||||
@@ -114,19 +120,19 @@ void QmlMultiLanguageAspect::fromMap(const QVariantMap &map)
|
|||||||
|
|
||||||
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current()
|
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current()
|
||||||
{
|
{
|
||||||
if (auto project = ProjectExplorer::ProjectManager::startupProject())
|
if (auto project = ProjectManager::startupProject())
|
||||||
return current(project);
|
return current(project);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current(ProjectExplorer::Project *project)
|
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current(Project *project)
|
||||||
{
|
{
|
||||||
if (auto target = project->activeTarget())
|
if (auto target = project->activeTarget())
|
||||||
return current(target);
|
return current(target);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current(ProjectExplorer::Target *target)
|
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current(Target *target)
|
||||||
{
|
{
|
||||||
if (!target)
|
if (!target)
|
||||||
return {};
|
return {};
|
||||||
|
@@ -15,9 +15,11 @@ class QMLPROJECTMANAGER_EXPORT QmlMultiLanguageAspect : public Utils::BoolAspect
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit QmlMultiLanguageAspect(ProjectExplorer::Target *target);
|
explicit QmlMultiLanguageAspect(Utils::AspectContainer *container = nullptr);
|
||||||
~QmlMultiLanguageAspect() override;
|
~QmlMultiLanguageAspect() override;
|
||||||
|
|
||||||
|
void setTarget(ProjectExplorer::Target *target);
|
||||||
|
|
||||||
QString currentLocale() const;
|
QString currentLocale() const;
|
||||||
void setCurrentLocale(const QString &locale);
|
void setCurrentLocale(const QString &locale);
|
||||||
Utils::FilePath databaseFilePath() const;
|
Utils::FilePath databaseFilePath() const;
|
||||||
|
@@ -120,14 +120,16 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
|||||||
return cmd;
|
return cmd;
|
||||||
});
|
});
|
||||||
|
|
||||||
m_qmlMainFileAspect = addAspect<QmlMainFileAspect>(target);
|
m_qmlMainFileAspect = addAspect<QmlMainFileAspect>();
|
||||||
|
m_qmlMainFileAspect->setTarget(target);
|
||||||
connect(m_qmlMainFileAspect, &QmlMainFileAspect::changed, this, &RunConfiguration::update);
|
connect(m_qmlMainFileAspect, &QmlMainFileAspect::changed, this, &RunConfiguration::update);
|
||||||
|
|
||||||
createQtVersionAspect();
|
createQtVersionAspect();
|
||||||
|
|
||||||
connect(target, &Target::kitChanged, this, &RunConfiguration::update);
|
connect(target, &Target::kitChanged, this, &RunConfiguration::update);
|
||||||
|
|
||||||
m_multiLanguageAspect = addAspect<QmlMultiLanguageAspect>(target);
|
m_multiLanguageAspect = addAspect<QmlMultiLanguageAspect>();
|
||||||
|
m_multiLanguageAspect->setTarget(target);
|
||||||
auto buildSystem = qobject_cast<const QmlBuildSystem *>(activeBuildSystem());
|
auto buildSystem = qobject_cast<const QmlBuildSystem *>(activeBuildSystem());
|
||||||
if (buildSystem)
|
if (buildSystem)
|
||||||
m_multiLanguageAspect->setValue(buildSystem->multilanguageSupport());
|
m_multiLanguageAspect->setValue(buildSystem->multilanguageSupport());
|
||||||
|
Reference in New Issue
Block a user