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"
|
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>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.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
|
|
|
|
2018-09-07 08:27:44 +02:00
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QStandardItem>
|
|
|
|
|
|
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 {
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
const char M_CURRENT_FILE[] = "CurrentFile";
|
2018-09-07 08:27:44 +02:00
|
|
|
const char CURRENT_FILE[] = QT_TRANSLATE_NOOP("QmlManager", "<Current File>");
|
|
|
|
|
|
|
|
|
|
static bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
|
|
|
|
|
{
|
|
|
|
|
return s1.toLower() < s2.toLower();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MainQmlFileAspect
|
|
|
|
|
|
2018-09-13 15:48:16 +02:00
|
|
|
class MainQmlFileAspect : public ProjectConfigurationAspect
|
2018-09-07 08:27:44 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2019-10-25 09:55:32 +02:00
|
|
|
explicit MainQmlFileAspect(Target *target);
|
2018-11-24 13:08:29 +01:00
|
|
|
~MainQmlFileAspect() override { delete m_fileListCombo; }
|
2018-09-07 08:27:44 +02:00
|
|
|
|
|
|
|
|
enum MainScriptSource {
|
|
|
|
|
FileInEditor,
|
|
|
|
|
FileInProjectFile,
|
|
|
|
|
FileInSettings
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-15 17:20:51 +02:00
|
|
|
void addToLayout(LayoutBuilder &builder) final;
|
2018-09-07 08:27:44 +02:00
|
|
|
void toMap(QVariantMap &map) const final;
|
|
|
|
|
void fromMap(const QVariantMap &map) final;
|
|
|
|
|
|
|
|
|
|
void updateFileComboBox();
|
|
|
|
|
MainScriptSource mainScriptSource() const;
|
|
|
|
|
void setMainScript(int index);
|
|
|
|
|
|
|
|
|
|
void setScriptSource(MainScriptSource source, const QString &settingsPath = QString());
|
|
|
|
|
|
|
|
|
|
QString mainScript() const;
|
|
|
|
|
void changeCurrentFile(IEditor *editor = nullptr);
|
|
|
|
|
bool isQmlFilePresent();
|
|
|
|
|
|
|
|
|
|
public:
|
2019-10-25 09:55:32 +02:00
|
|
|
QmlBuildSystem *qmlBuildSystem() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<QmlBuildSystem *>(m_target->buildSystem());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Target *m_target = nullptr;
|
2018-09-07 08:27:44 +02:00
|
|
|
QPointer<QComboBox> m_fileListCombo;
|
|
|
|
|
QStandardItemModel m_fileListModel;
|
|
|
|
|
QString m_scriptFile;
|
|
|
|
|
// absolute path to current file (if being used)
|
|
|
|
|
QString m_currentFileFilename;
|
|
|
|
|
// absolute path to selected main script (if being used)
|
|
|
|
|
QString m_mainScriptFilename;
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
MainQmlFileAspect::MainQmlFileAspect(Target *target)
|
|
|
|
|
: m_target(target)
|
2018-11-24 13:08:29 +01:00
|
|
|
, m_scriptFile(M_CURRENT_FILE)
|
2018-09-07 08:27:44 +02:00
|
|
|
{
|
|
|
|
|
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
|
|
|
|
this, &MainQmlFileAspect::changeCurrentFile);
|
|
|
|
|
connect(EditorManager::instance(), &EditorManager::currentDocumentStateChanged,
|
|
|
|
|
this, [this] { changeCurrentFile(); });
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 17:20:51 +02:00
|
|
|
void MainQmlFileAspect::addToLayout(LayoutBuilder &builder)
|
2018-09-07 08:27:44 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!m_fileListCombo, delete m_fileListCombo);
|
|
|
|
|
m_fileListCombo = new QComboBox;
|
|
|
|
|
m_fileListCombo->setModel(&m_fileListModel);
|
|
|
|
|
|
|
|
|
|
updateFileComboBox();
|
|
|
|
|
|
|
|
|
|
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::fileListChanged,
|
|
|
|
|
this, &MainQmlFileAspect::updateFileComboBox);
|
2019-02-26 09:40:49 +01:00
|
|
|
connect(m_fileListCombo, QOverload<int>::of(&QComboBox::activated),
|
2018-09-07 08:27:44 +02:00
|
|
|
this, &MainQmlFileAspect::setMainScript);
|
|
|
|
|
|
2019-11-07 12:22:29 +01:00
|
|
|
builder.addItems(QmlProjectRunConfiguration::tr("Main QML file:"), m_fileListCombo.data());
|
2018-09-07 08:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainQmlFileAspect::toMap(QVariantMap &map) const
|
|
|
|
|
{
|
|
|
|
|
map.insert(QLatin1String(Constants::QML_MAINSCRIPT_KEY), m_scriptFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainQmlFileAspect::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
m_scriptFile = map.value(QLatin1String(Constants::QML_MAINSCRIPT_KEY),
|
|
|
|
|
QLatin1String(M_CURRENT_FILE)).toString();
|
|
|
|
|
|
|
|
|
|
if (m_scriptFile == QLatin1String(M_CURRENT_FILE))
|
|
|
|
|
setScriptSource(FileInEditor);
|
|
|
|
|
else if (m_scriptFile.isEmpty())
|
|
|
|
|
setScriptSource(FileInProjectFile);
|
|
|
|
|
else
|
|
|
|
|
setScriptSource(FileInSettings, m_scriptFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainQmlFileAspect::updateFileComboBox()
|
|
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
QDir projectDir(m_target->project()->projectDirectory().toString());
|
2018-09-07 08:27:44 +02:00
|
|
|
|
|
|
|
|
if (mainScriptSource() == FileInProjectFile) {
|
|
|
|
|
const QString mainScriptInFilePath = projectDir.relativeFilePath(mainScript());
|
|
|
|
|
m_fileListModel.clear();
|
|
|
|
|
m_fileListModel.appendRow(new QStandardItem(mainScriptInFilePath));
|
|
|
|
|
if (m_fileListCombo)
|
|
|
|
|
m_fileListCombo->setEnabled(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_fileListCombo)
|
|
|
|
|
m_fileListCombo->setEnabled(true);
|
|
|
|
|
m_fileListModel.clear();
|
|
|
|
|
m_fileListModel.appendRow(new QStandardItem(QLatin1String(CURRENT_FILE)));
|
|
|
|
|
QModelIndex currentIndex;
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList sortedFiles = Utils::transform(m_target->project()->files(Project::SourceFiles),
|
2019-05-28 13:49:26 +02:00
|
|
|
&Utils::FilePath::toString);
|
2018-09-07 08:27:44 +02:00
|
|
|
|
|
|
|
|
// make paths relative to project directory
|
|
|
|
|
QStringList relativeFiles;
|
|
|
|
|
for (const QString &fn : qAsConst(sortedFiles))
|
|
|
|
|
relativeFiles += projectDir.relativeFilePath(fn);
|
|
|
|
|
sortedFiles = relativeFiles;
|
|
|
|
|
|
|
|
|
|
std::stable_sort(sortedFiles.begin(), sortedFiles.end(), caseInsensitiveLessThan);
|
|
|
|
|
|
|
|
|
|
QString mainScriptPath;
|
|
|
|
|
if (mainScriptSource() != FileInEditor)
|
|
|
|
|
mainScriptPath = projectDir.relativeFilePath(mainScript());
|
|
|
|
|
|
|
|
|
|
for (const QString &fn : qAsConst(sortedFiles)) {
|
|
|
|
|
QFileInfo fileInfo(fn);
|
|
|
|
|
if (fileInfo.suffix() != QLatin1String("qml"))
|
|
|
|
|
continue;
|
|
|
|
|
|
2018-11-24 13:08:29 +01:00
|
|
|
auto item = new QStandardItem(fn);
|
2018-09-07 08:27:44 +02:00
|
|
|
m_fileListModel.appendRow(item);
|
|
|
|
|
|
|
|
|
|
if (mainScriptPath == fn)
|
|
|
|
|
currentIndex = item->index();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_fileListCombo) {
|
|
|
|
|
if (currentIndex.isValid())
|
|
|
|
|
m_fileListCombo->setCurrentIndex(currentIndex.row());
|
|
|
|
|
else
|
|
|
|
|
m_fileListCombo->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainQmlFileAspect::MainScriptSource MainQmlFileAspect::mainScriptSource() const
|
|
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
if (!qmlBuildSystem()->mainFile().isEmpty())
|
2018-09-07 08:27:44 +02:00
|
|
|
return FileInProjectFile;
|
|
|
|
|
if (!m_mainScriptFilename.isEmpty())
|
|
|
|
|
return FileInSettings;
|
|
|
|
|
return FileInEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainQmlFileAspect::setMainScript(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
setScriptSource(FileInEditor);
|
|
|
|
|
} else {
|
|
|
|
|
const QString path = m_fileListModel.data(m_fileListModel.index(index, 0)).toString();
|
|
|
|
|
setScriptSource(FileInSettings, path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainQmlFileAspect::setScriptSource(MainScriptSource source, const QString &settingsPath)
|
|
|
|
|
{
|
|
|
|
|
if (source == FileInEditor) {
|
|
|
|
|
m_scriptFile = QLatin1String(M_CURRENT_FILE);
|
|
|
|
|
m_mainScriptFilename.clear();
|
|
|
|
|
} else if (source == FileInProjectFile) {
|
|
|
|
|
m_scriptFile.clear();
|
|
|
|
|
m_mainScriptFilename.clear();
|
|
|
|
|
} else { // FileInSettings
|
|
|
|
|
m_scriptFile = settingsPath;
|
2019-10-25 09:55:32 +02:00
|
|
|
m_mainScriptFilename = m_target->project()->projectDirectory().toString() + '/' + m_scriptFile;
|
2018-09-07 08:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-10 13:54:04 +02:00
|
|
|
emit changed();
|
2018-09-07 08:27:44 +02:00
|
|
|
updateFileComboBox();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Returns absolute path to main script file.
|
|
|
|
|
*/
|
|
|
|
|
QString MainQmlFileAspect::mainScript() const
|
|
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
if (!qmlBuildSystem()->mainFile().isEmpty()) {
|
|
|
|
|
const QString pathInProject = qmlBuildSystem()->mainFile();
|
2018-09-07 08:27:44 +02:00
|
|
|
if (QFileInfo(pathInProject).isAbsolute())
|
|
|
|
|
return pathInProject;
|
|
|
|
|
else
|
2019-10-25 09:55:32 +02:00
|
|
|
return QDir(qmlBuildSystem()->canonicalProjectDir().toString()).absoluteFilePath(pathInProject);
|
2018-09-07 08:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!m_mainScriptFilename.isEmpty())
|
|
|
|
|
return m_mainScriptFilename;
|
|
|
|
|
|
|
|
|
|
return m_currentFileFilename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainQmlFileAspect::changeCurrentFile(IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (!editor)
|
|
|
|
|
editor = EditorManager::currentEditor();
|
|
|
|
|
|
|
|
|
|
if (editor)
|
|
|
|
|
m_currentFileFilename = editor->document()->filePath().toString();
|
|
|
|
|
|
2018-09-10 13:54:04 +02:00
|
|
|
emit changed();
|
2018-09-07 08:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// QmlProjectRunConfiguration
|
2010-11-29 09:45:30 +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
|
|
|
{
|
2019-03-07 09:08:40 +01:00
|
|
|
auto envAspect = addAspect<EnvironmentAspect>();
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
auto envModifier = [this](Environment env) {
|
|
|
|
|
if (auto bs = dynamic_cast<const QmlBuildSystem *>(activeBuildSystem()))
|
|
|
|
|
env.modify(bs->environment());
|
2019-03-07 09:08:40 +01:00
|
|
|
return env;
|
2019-03-07 10:10:22 +01:00
|
|
|
};
|
2019-03-07 09:08:40 +01:00
|
|
|
|
2019-03-07 10:10:22 +01:00
|
|
|
const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit());
|
|
|
|
|
if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
|
2019-04-05 16:45:53 +02:00
|
|
|
envAspect->addPreferredBaseEnvironment(tr("System Environment"), [envModifier] {
|
2019-03-07 10:10:22 +01:00
|
|
|
return envModifier(Environment::systemEnvironment());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 16:45:53 +02:00
|
|
|
envAspect->addSupportedBaseEnvironment(tr("Clean Environment"), [envModifier] {
|
2019-03-07 10:10:22 +01:00
|
|
|
return envModifier(Environment());
|
|
|
|
|
});
|
2019-03-07 09:08:40 +01:00
|
|
|
|
2018-09-03 09:41:07 +02:00
|
|
|
m_qmlViewerAspect = addAspect<BaseStringAspect>();
|
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());
|
2018-09-03 09:41:07 +02:00
|
|
|
m_qmlViewerAspect->setDisplayStyle(BaseStringAspect::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] {
|
|
|
|
|
return CommandLine(FilePath::fromString(theExecutable()),
|
|
|
|
|
commandLineArguments(),
|
|
|
|
|
CommandLine::Raw);
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
m_mainQmlFileAspect = addAspect<MainQmlFileAspect>(target);
|
2018-09-10 13:54:04 +02:00
|
|
|
connect(m_mainQmlFileAspect, &MainQmlFileAspect::changed,
|
|
|
|
|
this, &QmlProjectRunConfiguration::updateEnabledState);
|
2018-09-07 08:27:44 +02:00
|
|
|
|
2017-09-01 13:23:02 +02:00
|
|
|
connect(target, &Target::kitChanged,
|
|
|
|
|
this, &QmlProjectRunConfiguration::updateEnabledState);
|
|
|
|
|
|
2017-11-27 11:48:43 +01:00
|
|
|
setDisplayName(tr("QML Scene", "QMLRunConfiguration display name."));
|
2017-09-01 13:23:02 +02:00
|
|
|
updateEnabledState();
|
|
|
|
|
}
|
|
|
|
|
|
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-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-06-11 14:39:39 +02:00
|
|
|
&& !commandLine().executable().exists()) {
|
2017-11-27 11:48:43 +01:00
|
|
|
return tr("No qmlscene found.");
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
2019-06-11 14:39:39 +02:00
|
|
|
if (commandLine().executable().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-05-23 18:10:34 +02:00
|
|
|
QString QmlProjectRunConfiguration::theExecutable() 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())
|
|
|
|
|
return qmlViewer;
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
BaseQtVersion *version = QtKitAspect::qtVersion(target()->kit());
|
2017-11-28 15:57:15 +01:00
|
|
|
if (!version) // No Qt version in Kit. Don't try to run qmlscene.
|
|
|
|
|
return QString();
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
const Id deviceType = DeviceTypeKitAspect::deviceTypeId(target()->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.
|
|
|
|
|
return version->type() == QtSupport::Constants::DESKTOPQT
|
2019-08-15 09:28:32 +02:00
|
|
|
? version->qmlsceneCommand() : QString("qmlscene");
|
2017-11-28 15:57:15 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
IDevice::ConstPtr dev = DeviceKitAspect::device(target()->kit());
|
2017-11-28 15:57:15 +01:00
|
|
|
if (dev.isNull()) // No device set. We don't know where to run qmlscene.
|
2010-10-04 15:03:01 +02:00
|
|
|
return QString();
|
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.
|
|
|
|
|
return 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());
|
2017-11-28 15:57:15 +01:00
|
|
|
const Utils::OsType osType = device ? device->osType() : Utils::HostOsInfo::hostOs();
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
|
// arguments from .qmlproject file
|
2019-10-25 09:55:32 +02:00
|
|
|
const QmlBuildSystem *bs = static_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())) {
|
2017-11-28 15:57:15 +01:00
|
|
|
Utils::QtcProcess::addArg(&args, QLatin1String("-I"), osType);
|
|
|
|
|
Utils::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-04-08 17:02:20 +02:00
|
|
|
Utils::QtcProcess::addArg(&args, QLatin1String("-S"), osType);
|
|
|
|
|
Utils::QtcProcess::addArg(&args, fileSelector, 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())
|
|
|
|
|
Utils::QtcProcess::addArg(&args, main, 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
|
|
|
{
|
2019-06-11 14:39:39 +02:00
|
|
|
if (m_mainQmlFileAspect->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
|
|
|
bool MainQmlFileAspect::isQmlFilePresent()
|
2010-03-05 11:11:05 +01:00
|
|
|
{
|
2010-08-19 16:51:27 +02:00
|
|
|
bool qmlFileFound = false;
|
2012-01-02 11:53:37 +01:00
|
|
|
if (mainScriptSource() == FileInEditor) {
|
2013-08-30 16:38:57 +02:00
|
|
|
IDocument *document = EditorManager::currentDocument();
|
2017-03-02 12:07:11 +01:00
|
|
|
Utils::MimeType mainScriptMimeType = Utils::mimeTypeForFile(mainScript());
|
2013-07-09 11:52:44 +02:00
|
|
|
if (document) {
|
2014-12-21 21:54:30 +02:00
|
|
|
m_currentFileFilename = document->filePath().toString();
|
2017-10-17 18:53:28 +02:00
|
|
|
if (mainScriptMimeType.matchesName(
|
|
|
|
|
QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE))
|
|
|
|
|
|| mainScriptMimeType.matchesName(
|
|
|
|
|
QLatin1String(ProjectExplorer::Constants::QMLUI_MIMETYPE))) {
|
2010-08-19 16:51:27 +02:00
|
|
|
qmlFileFound = true;
|
2017-10-17 18:53:28 +02:00
|
|
|
}
|
2010-06-10 09:10:11 +02:00
|
|
|
}
|
2013-07-09 11:52:44 +02:00
|
|
|
if (!document
|
2015-08-05 15:16:27 +02:00
|
|
|
|| mainScriptMimeType.matchesName(QLatin1String(QmlJSTools::Constants::QMLPROJECT_MIMETYPE))) {
|
2010-11-29 09:45:30 +01:00
|
|
|
// find a qml file with lowercase filename. This is slow, but only done
|
|
|
|
|
// in initialization/other border cases.
|
2019-10-25 09:55:32 +02:00
|
|
|
const auto files = m_target->project()->files(Project::SourceFiles);
|
2019-05-28 13:49:26 +02:00
|
|
|
for (const Utils::FilePath &filename : files) {
|
2017-12-06 10:27:27 +01:00
|
|
|
const QFileInfo fi = filename.toFileInfo();
|
2010-03-08 14:36:44 +01:00
|
|
|
|
2019-01-17 02:09:05 +01:00
|
|
|
if (!filename.isEmpty() && fi.baseName().at(0).isLower()) {
|
2017-10-17 18:53:28 +02:00
|
|
|
Utils::MimeType type = Utils::mimeTypeForFile(fi);
|
|
|
|
|
if (type.matchesName(QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE))
|
|
|
|
|
|| type.matchesName(
|
|
|
|
|
QLatin1String(ProjectExplorer::Constants::QMLUI_MIMETYPE))) {
|
2017-12-06 10:27:27 +01:00
|
|
|
m_currentFileFilename = filename.toString();
|
2017-10-17 18:53:28 +02:00
|
|
|
qmlFileFound = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-03-08 14:36:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-03-05 11:11:05 +01:00
|
|
|
}
|
2010-08-19 16:51:27 +02:00
|
|
|
} else { // use default one
|
2010-12-03 17:04:29 +01:00
|
|
|
qmlFileFound = !mainScript().isEmpty();
|
2010-08-19 16:51:27 +02:00
|
|
|
}
|
2018-09-07 08:27:44 +02:00
|
|
|
return qmlFileFound;
|
|
|
|
|
}
|
2010-08-19 16:51:27 +02:00
|
|
|
|
2018-09-07 08:27:44 +02:00
|
|
|
QString QmlProjectRunConfiguration::mainScript() const
|
|
|
|
|
{
|
|
|
|
|
return m_mainQmlFileAspect->mainScript();
|
2010-03-05 11:11:05 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-06 14:55:56 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
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
|