forked from qt-creator/qt-creator
qmlproject: add convenience method to QmlMultiLanguageAspect
Change-Id: I88799aa1c5caa5c967b7c680ef9ddcbdd4b01bf5 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
static bool isMultilanguagePresent()
|
||||
@@ -125,4 +126,27 @@ void QmlMultiLanguageAspect::fromMap(const QVariantMap &map)
|
||||
setLastUsedLanguage(map.value(Constants::LAST_USED_LANGUAGE, "en").toString());
|
||||
}
|
||||
|
||||
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current()
|
||||
{
|
||||
if (auto project = ProjectExplorer::SessionManager::startupProject())
|
||||
return current(project);
|
||||
return {};
|
||||
}
|
||||
|
||||
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current(ProjectExplorer::Project *project)
|
||||
{
|
||||
if (auto target = project->activeTarget())
|
||||
return current(target);
|
||||
return {};
|
||||
}
|
||||
|
||||
QmlMultiLanguageAspect *QmlMultiLanguageAspect::current(ProjectExplorer::Target *target)
|
||||
{
|
||||
if (auto runConfiguration = target->activeRunConfiguration()) {
|
||||
if (auto multiLanguageAspect = runConfiguration->aspect<QmlProjectManager::QmlMultiLanguageAspect>())
|
||||
return multiLanguageAspect;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace QmlProjectManager
|
||||
|
||||
@@ -45,6 +45,10 @@ public:
|
||||
void toMap(QVariantMap &map) const final;
|
||||
void fromMap(const QVariantMap &map) final;
|
||||
|
||||
static QmlMultiLanguageAspect *current();
|
||||
static QmlMultiLanguageAspect *current(ProjectExplorer::Project *project);
|
||||
static QmlMultiLanguageAspect *current(ProjectExplorer::Target *target);
|
||||
|
||||
public slots:
|
||||
void setLastUsedLanguage(const QString &language);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user