2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-02-16 13:39:13 +01:00
|
|
|
|
2010-07-13 15:02:37 +02:00
|
|
|
#include "qmlprojectrunconfiguration.h"
|
2010-02-16 13:39:13 +01:00
|
|
|
#include "qmlproject.h"
|
|
|
|
|
#include "qmlprojectmanagerconstants.h"
|
2020-01-06 14:48:51 +01:00
|
|
|
#include "qmlmainfileaspect.h"
|
2020-06-18 08:49:29 +02:00
|
|
|
#include "qmlmultilanguageaspect.h"
|
2018-09-07 08:27:44 +02:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2018-09-07 08:27:44 +02:00
|
|
|
|
2019-03-07 09:08:40 +01:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2018-09-07 08:27:44 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2019-03-13 08:06:08 +01:00
|
|
|
#include <projectexplorer/runcontrol.h>
|
2020-01-06 14:48:51 +01:00
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2020-01-06 14:48:51 +01:00
|
|
|
#include <projectexplorer/environmentaspect.h>
|
|
|
|
|
#include <projectexplorer/projectconfigurationaspects.h>
|
2018-09-07 08:27:44 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2011-05-20 21:40:53 +02:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2010-11-29 09:45:30 +01:00
|
|
|
|
2019-03-07 09:08:40 +01:00
|
|
|
#include <utils/environment.h>
|
2013-10-23 22:07:46 +03:00
|
|
|
#include <utils/fileutils.h>
|
2015-02-04 09:32:46 +01:00
|
|
|
#include <utils/mimetypes/mimedatabase.h>
|
2013-10-23 22:07:46 +03:00
|
|
|
#include <utils/qtcprocess.h>
|
2011-01-05 14:44:52 +01:00
|
|
|
#include <utils/winutils.h>
|
2019-03-07 09:08:40 +01:00
|
|
|
|
2015-08-05 15:16:27 +02:00
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
2010-12-21 12:39:14 +01:00
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
using namespace Core;
|
2014-05-26 22:13:14 +03:00
|
|
|
using namespace ProjectExplorer;
|
2017-12-20 19:11:10 +01:00
|
|
|
using namespace QtSupport;
|
2019-03-07 09:08:40 +01:00
|
|
|
using namespace Utils;
|
2017-12-20 19:11:10 +01:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
namespace QmlProjectManager {
|
2020-06-18 08:49:29 +02:00
|
|
|
class QmlMultiLanguageAspect;
|
2020-02-11 11:18:18 +01:00
|
|
|
namespace Internal {
|
2010-02-16 13:39:13 +01:00
|
|
|
|
2018-09-07 08:27:44 +02:00
|
|
|
// QmlProjectRunConfiguration
|
2010-11-29 09:45:30 +01:00
|
|
|
|
2020-02-11 11:18:18 +01:00
|
|
|
class QmlProjectRunConfiguration final : public RunConfiguration
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(QmlProjectManager::QmlProjectRunConfiguration)
|
|
|
|
|
|
|
|
|
|
public:
|
2020-06-26 13:59:38 +02:00
|
|
|
QmlProjectRunConfiguration(Target *target, Utils::Id id);
|
2020-02-11 11:18:18 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Runnable runnable() const final;
|
|
|
|
|
QString disabledReason() const final;
|
|
|
|
|
bool isEnabled() const final;
|
|
|
|
|
|
|
|
|
|
QString mainScript() const;
|
|
|
|
|
Utils::FilePath qmlScenePath() const;
|
|
|
|
|
QString commandLineArguments() const;
|
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
StringAspect *m_qmlViewerAspect = nullptr;
|
2020-02-11 11:18:18 +01:00
|
|
|
QmlMainFileAspect *m_qmlMainFileAspect = nullptr;
|
2020-06-18 08:49:29 +02:00
|
|
|
QmlMultiLanguageAspect *m_multiLanguageAspect = nullptr;
|
2020-02-11 11:18:18 +01:00
|
|
|
};
|
|
|
|
|
|
2018-04-25 10:26:08 +02:00
|
|
|
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
|
|
|
|
: RunConfiguration(target, id)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2020-08-13 09:16:00 +02:00
|
|
|
m_qmlViewerAspect = addAspect<StringAspect>();
|
2018-10-19 15:58:40 +02:00
|
|
|
m_qmlViewerAspect->setLabelText(tr("QML Viewer:"));
|
2019-06-11 14:39:39 +02:00
|
|
|
m_qmlViewerAspect->setPlaceHolderText(commandLine().executable().toString());
|
2020-08-13 09:16:00 +02:00
|
|
|
m_qmlViewerAspect->setDisplayStyle(StringAspect::LineEditDisplay);
|
2019-04-08 13:43:26 +02:00
|
|
|
m_qmlViewerAspect->setHistoryCompleter("QmlProjectManager.viewer.history");
|
2018-09-03 09:41:07 +02:00
|
|
|
|
2018-09-07 08:27:44 +02:00
|
|
|
auto argumentAspect = addAspect<ArgumentsAspect>();
|
|
|
|
|
argumentAspect->setSettingsKey(Constants::QML_VIEWER_ARGUMENTS_KEY);
|
2013-11-01 14:13:41 +01:00
|
|
|
|
2019-06-11 14:39:39 +02:00
|
|
|
setCommandLineGetter([this] {
|
2019-11-15 17:32:29 +01:00
|
|
|
return CommandLine(qmlScenePath(), commandLineArguments(), CommandLine::Raw);
|
2019-06-11 14:39:39 +02:00
|
|
|
});
|
|
|
|
|
|
2020-01-06 14:48:51 +01:00
|
|
|
m_qmlMainFileAspect = addAspect<QmlMainFileAspect>(target);
|
|
|
|
|
connect(m_qmlMainFileAspect, &QmlMainFileAspect::changed, this, &RunConfiguration::update);
|
2018-09-07 08:27:44 +02:00
|
|
|
|
2019-12-04 09:19:50 +01:00
|
|
|
connect(target, &Target::kitChanged, this, &RunConfiguration::update);
|
2017-09-01 13:23:02 +02:00
|
|
|
|
2020-06-18 08:49:29 +02:00
|
|
|
m_multiLanguageAspect = addAspect<QmlMultiLanguageAspect>(target);
|
|
|
|
|
|
|
|
|
|
auto envAspect = addAspect<EnvironmentAspect>();
|
|
|
|
|
connect(m_multiLanguageAspect, &QmlMultiLanguageAspect::changed, envAspect, &EnvironmentAspect::environmentChanged);
|
|
|
|
|
|
|
|
|
|
auto envModifier = [this](Environment env) {
|
|
|
|
|
if (auto bs = dynamic_cast<const QmlBuildSystem *>(activeBuildSystem()))
|
|
|
|
|
env.modify(bs->environment());
|
|
|
|
|
|
|
|
|
|
if (m_multiLanguageAspect && m_multiLanguageAspect->value() && !m_multiLanguageAspect->databaseFilePath().isEmpty()) {
|
|
|
|
|
env.set("QT_MULTILANGUAGE_DATABASE", m_multiLanguageAspect->databaseFilePath().toString());
|
2020-07-20 20:45:08 +02:00
|
|
|
env.set("QT_MULTILANGUAGE_LANGUAGE", m_multiLanguageAspect->currentLocale());
|
2020-07-20 10:28:16 +02:00
|
|
|
} else {
|
|
|
|
|
env.unset("QT_MULTILANGUAGE_DATABASE");
|
|
|
|
|
env.unset("QT_MULTILANGUAGE_LANGUAGE");
|
2020-06-18 08:49:29 +02:00
|
|
|
}
|
|
|
|
|
return env;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit());
|
|
|
|
|
if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
|
|
|
|
envAspect->addPreferredBaseEnvironment(tr("System Environment"), [envModifier] {
|
|
|
|
|
return envModifier(Environment::systemEnvironment());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
envAspect->addSupportedBaseEnvironment(tr("Clean Environment"), [envModifier] {
|
|
|
|
|
Environment environment;
|
|
|
|
|
return envModifier(environment);
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-27 11:48:43 +01:00
|
|
|
setDisplayName(tr("QML Scene", "QMLRunConfiguration display name."));
|
2019-12-04 09:19:50 +01:00
|
|
|
update();
|
2017-09-01 13:23:02 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-25 15:00:20 +01:00
|
|
|
Runnable QmlProjectRunConfiguration::runnable() const
|
|
|
|
|
{
|
2018-05-16 15:42:03 +02:00
|
|
|
Runnable r;
|
2019-06-11 14:39:39 +02:00
|
|
|
r.setCommandLine(commandLine());
|
2019-03-07 09:08:40 +01:00
|
|
|
r.environment = aspect<EnvironmentAspect>()->environment();
|
2019-10-25 09:55:32 +02:00
|
|
|
const QmlBuildSystem *bs = static_cast<QmlBuildSystem *>(activeBuildSystem());
|
|
|
|
|
r.workingDirectory = bs->targetDirectory().toString();
|
2016-01-25 15:00:20 +01:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-26 16:30:35 +02:00
|
|
|
QString QmlProjectRunConfiguration::disabledReason() const
|
|
|
|
|
{
|
2017-07-17 14:34:05 +02:00
|
|
|
if (mainScript().isEmpty())
|
|
|
|
|
return tr("No script file to execute.");
|
2019-11-15 17:32:29 +01:00
|
|
|
|
|
|
|
|
const FilePath viewer = qmlScenePath();
|
2019-02-06 12:50:51 +01:00
|
|
|
if (DeviceTypeKitAspect::deviceTypeId(target()->kit())
|
2017-11-28 15:57:15 +01:00
|
|
|
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE
|
2019-11-15 17:32:29 +01:00
|
|
|
&& !viewer.exists()) {
|
2017-11-27 11:48:43 +01:00
|
|
|
return tr("No qmlscene found.");
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
2019-11-15 17:32:29 +01:00
|
|
|
if (viewer.isEmpty())
|
2017-11-28 15:57:15 +01:00
|
|
|
return tr("No qmlscene binary specified for target device.");
|
2017-07-17 14:34:05 +02:00
|
|
|
return RunConfiguration::disabledReason();
|
2011-05-26 16:30:35 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 17:32:29 +01:00
|
|
|
FilePath QmlProjectRunConfiguration::qmlScenePath() const
|
2010-09-28 17:26:27 +02:00
|
|
|
{
|
2018-09-03 09:41:07 +02:00
|
|
|
const QString qmlViewer = m_qmlViewerAspect->value();
|
|
|
|
|
if (!qmlViewer.isEmpty())
|
2019-11-15 17:32:29 +01:00
|
|
|
return FilePath::fromString(qmlViewer);
|
2018-09-03 09:41:07 +02:00
|
|
|
|
2019-11-15 17:32:29 +01:00
|
|
|
Kit *kit = target()->kit();
|
|
|
|
|
BaseQtVersion *version = QtKitAspect::qtVersion(kit);
|
2017-11-28 15:57:15 +01:00
|
|
|
if (!version) // No Qt version in Kit. Don't try to run qmlscene.
|
2019-11-15 17:32:29 +01:00
|
|
|
return {};
|
2017-11-28 15:57:15 +01:00
|
|
|
|
2019-11-15 17:32:29 +01:00
|
|
|
const Id deviceType = DeviceTypeKitAspect::deviceTypeId(kit);
|
2017-11-28 15:57:15 +01:00
|
|
|
if (deviceType == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
|
|
|
|
// If not given explicitly by Qt Version, try to pick it from $PATH.
|
2019-11-15 17:32:29 +01:00
|
|
|
const bool isDesktop = version->type() == QtSupport::Constants::DESKTOPQT;
|
|
|
|
|
return FilePath::fromString(isDesktop ? version->qmlsceneCommand() : QString("qmlscene"));
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 17:32:29 +01:00
|
|
|
IDevice::ConstPtr dev = DeviceKitAspect::device(kit);
|
2017-11-28 15:57:15 +01:00
|
|
|
if (dev.isNull()) // No device set. We don't know where to run qmlscene.
|
2019-11-15 17:32:29 +01:00
|
|
|
return {};
|
2012-08-23 14:53:03 +02:00
|
|
|
|
2017-11-28 15:57:15 +01:00
|
|
|
const QString qmlscene = dev->qmlsceneCommand();
|
|
|
|
|
// If not given explicitly by device, try to pick it from $PATH.
|
2019-11-15 17:32:29 +01:00
|
|
|
return FilePath::fromString(qmlscene.isEmpty() ? QString("qmlscene") : qmlscene);
|
2010-09-28 17:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-11 11:20:11 +02:00
|
|
|
QString QmlProjectRunConfiguration::commandLineArguments() const
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
|
// arguments in .user file
|
2018-09-07 13:29:45 +02:00
|
|
|
QString args = aspect<ArgumentsAspect>()->arguments(macroExpander());
|
2019-10-25 09:55:32 +02:00
|
|
|
const IDevice::ConstPtr device = DeviceKitAspect::device(target()->kit());
|
2019-11-15 17:32:29 +01:00
|
|
|
const OsType osType = device ? device->osType() : HostOsInfo::hostOs();
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
|
// arguments from .qmlproject file
|
2019-12-16 16:19:44 +01:00
|
|
|
const QmlBuildSystem *bs = qobject_cast<QmlBuildSystem *>(target()->buildSystem());
|
2018-02-22 10:42:13 +01:00
|
|
|
foreach (const QString &importPath,
|
2019-10-25 09:55:32 +02:00
|
|
|
QmlBuildSystem::makeAbsolute(bs->targetDirectory(), bs->customImportPaths())) {
|
2019-11-15 17:32:29 +01:00
|
|
|
QtcProcess::addArg(&args, "-I", osType);
|
|
|
|
|
QtcProcess::addArg(&args, importPath, osType);
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
for (const QString &fileSelector : bs->customFileSelectors()) {
|
2019-11-15 17:32:29 +01:00
|
|
|
QtcProcess::addArg(&args, "-S", osType);
|
|
|
|
|
QtcProcess::addArg(&args, fileSelector, osType);
|
2019-04-08 17:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-06 13:04:17 +02:00
|
|
|
if (Utils::HostOsInfo::isWindowsHost() && bs->forceFreeType()) {
|
2019-12-04 13:10:38 +01:00
|
|
|
Utils::QtcProcess::addArg(&args, "-platform", osType);
|
|
|
|
|
Utils::QtcProcess::addArg(&args, "windows:fontengine=freetype", osType);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
const QString main = bs->targetFile(FilePath::fromString(mainScript())).toString();
|
2017-11-28 15:57:15 +01:00
|
|
|
if (!main.isEmpty())
|
2019-11-15 17:32:29 +01:00
|
|
|
QtcProcess::addArg(&args, main, osType);
|
2020-06-18 08:49:29 +02:00
|
|
|
|
|
|
|
|
if (m_multiLanguageAspect && m_multiLanguageAspect->value())
|
|
|
|
|
QtcProcess::addArg(&args, "-qmljsdebugger=file:unused_if_debugger_arguments_added,services:DebugTranslation", osType);
|
|
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
bool QmlProjectRunConfiguration::isEnabled() const
|
2010-08-19 16:51:27 +02:00
|
|
|
{
|
2020-01-06 14:48:51 +01:00
|
|
|
if (m_qmlMainFileAspect->isQmlFilePresent() && !commandLine().executable().isEmpty()) {
|
2019-10-25 09:55:32 +02:00
|
|
|
BuildSystem *bs = activeBuildSystem();
|
|
|
|
|
return !bs->isParsing() && bs->hasParsingData();
|
2018-09-07 08:27:44 +02:00
|
|
|
}
|
2019-10-25 09:55:32 +02:00
|
|
|
return false;
|
2010-08-19 16:51:27 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-07 08:27:44 +02:00
|
|
|
QString QmlProjectRunConfiguration::mainScript() const
|
|
|
|
|
{
|
2020-01-06 14:48:51 +01:00
|
|
|
return m_qmlMainFileAspect->mainScript();
|
2010-03-05 11:11:05 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-11 11:18:18 +01:00
|
|
|
// QmlProjectRunConfigurationFactory
|
2018-04-06 14:55:56 +02:00
|
|
|
|
|
|
|
|
QmlProjectRunConfigurationFactory::QmlProjectRunConfigurationFactory()
|
|
|
|
|
: FixedRunConfigurationFactory(QmlProjectRunConfiguration::tr("QML Scene"), false)
|
|
|
|
|
{
|
2018-04-25 10:26:08 +02:00
|
|
|
registerRunConfiguration<QmlProjectRunConfiguration>
|
|
|
|
|
("QmlProjectManager.QmlRunConfiguration.QmlScene");
|
2018-04-06 14:55:56 +02:00
|
|
|
addSupportedProjectType(QmlProjectManager::Constants::QML_PROJECT_ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2010-02-16 13:39:13 +01:00
|
|
|
} // namespace QmlProjectManager
|