2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-29 11:42:58 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-11-29 11:42:58 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-29 11:42:58 +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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-11-29 11:42:58 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-11-29 11:42:58 +01:00
|
|
|
|
|
|
|
|
#include "qmlprojectrunconfigurationwidget.h"
|
|
|
|
|
#include "qmlprojectrunconfiguration.h"
|
|
|
|
|
#include "qmlproject.h"
|
|
|
|
|
|
2011-02-24 14:58:37 +01:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2010-11-29 11:42:58 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2011-01-13 11:41:45 +01:00
|
|
|
#include <projectexplorer/environmentwidget.h>
|
2010-11-29 11:42:58 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2011-09-15 19:20:50 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2010-11-29 11:42:58 +01:00
|
|
|
#include <utils/detailswidget.h>
|
2011-02-01 18:36:00 +01:00
|
|
|
#include <utils/environment.h>
|
2010-11-29 11:42:58 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QStandardItemModel>
|
2010-11-29 11:42:58 +01:00
|
|
|
|
|
|
|
|
using Core::ICore;
|
|
|
|
|
|
|
|
|
|
namespace QmlProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
QmlProjectRunConfigurationWidget::QmlProjectRunConfigurationWidget(QmlProjectRunConfiguration *rc) :
|
|
|
|
|
m_runConfiguration(rc),
|
|
|
|
|
m_fileListCombo(0),
|
2010-12-03 17:04:29 +01:00
|
|
|
m_fileListModel(new QStandardItemModel(this))
|
2010-11-29 11:42:58 +01:00
|
|
|
{
|
2010-11-29 12:50:44 +01:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Qt Version, Arguments
|
|
|
|
|
//
|
|
|
|
|
|
2010-11-29 11:42:58 +01:00
|
|
|
Utils::DetailsWidget *detailsWidget = new Utils::DetailsWidget();
|
|
|
|
|
detailsWidget->setState(Utils::DetailsWidget::NoSummary);
|
|
|
|
|
|
|
|
|
|
QWidget *formWidget = new QWidget(detailsWidget);
|
|
|
|
|
detailsWidget->setWidget(formWidget);
|
|
|
|
|
QFormLayout *form = new QFormLayout(formWidget);
|
|
|
|
|
form->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
|
|
|
|
|
|
|
|
|
m_fileListCombo = new QComboBox;
|
|
|
|
|
m_fileListCombo->setModel(m_fileListModel);
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
connect(m_fileListCombo, SIGNAL(activated(int)), this, SLOT(setMainScript(int)));
|
2010-11-29 11:42:58 +01:00
|
|
|
connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(fileListChanged()),
|
|
|
|
|
SLOT(updateFileComboBox()));
|
|
|
|
|
|
|
|
|
|
QLineEdit *qmlViewerArgs = new QLineEdit;
|
|
|
|
|
qmlViewerArgs->setText(rc->m_qmlViewerArgs);
|
|
|
|
|
connect(qmlViewerArgs, SIGNAL(textChanged(QString)), this, SLOT(onViewerArgsChanged()));
|
|
|
|
|
|
|
|
|
|
form->addRow(tr("Arguments:"), qmlViewerArgs);
|
2010-11-29 12:50:44 +01:00
|
|
|
form->addRow(tr("Main QML file:"), m_fileListCombo);
|
|
|
|
|
|
|
|
|
|
layout->addWidget(detailsWidget);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Environment
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
QLabel *environmentLabel = new QLabel(this);
|
|
|
|
|
environmentLabel->setText(tr("Run Environment"));
|
|
|
|
|
QFont f = environmentLabel->font();
|
|
|
|
|
f.setBold(true);
|
|
|
|
|
f.setPointSizeF(f.pointSizeF() *1.2);
|
|
|
|
|
environmentLabel->setFont(f);
|
|
|
|
|
|
|
|
|
|
layout->addWidget(environmentLabel);
|
|
|
|
|
|
|
|
|
|
QWidget *baseEnvironmentWidget = new QWidget;
|
|
|
|
|
QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
|
|
|
|
|
baseEnvironmentLayout->setMargin(0);
|
|
|
|
|
m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
|
|
|
|
|
m_environmentWidget->setBaseEnvironment(rc->baseEnvironment());
|
2010-11-29 14:16:38 +01:00
|
|
|
m_environmentWidget->setBaseEnvironmentText(tr("System Environment"));
|
2010-11-29 12:50:44 +01:00
|
|
|
m_environmentWidget->setUserChanges(rc->userEnvironmentChanges());
|
|
|
|
|
|
|
|
|
|
connect(m_environmentWidget, SIGNAL(userChangesChanged()),
|
|
|
|
|
this, SLOT(userChangesChanged()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
layout->addWidget(m_environmentWidget);
|
2011-07-28 18:23:01 +02:00
|
|
|
|
|
|
|
|
updateFileComboBox();
|
2010-11-29 11:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
|
|
|
|
|
{
|
|
|
|
|
return s1.toLower() < s2.toLower();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProjectRunConfigurationWidget::updateFileComboBox()
|
|
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
ProjectExplorer::Project *project = m_runConfiguration->target()->project();
|
|
|
|
|
QDir projectDir(project->projectDirectory());
|
2010-11-29 11:42:58 +01:00
|
|
|
|
2012-01-02 11:53:37 +01:00
|
|
|
if (m_runConfiguration->mainScriptSource() == QmlProjectRunConfiguration::FileInProjectFile) {
|
|
|
|
|
const QString mainScriptInFilePath
|
|
|
|
|
= projectDir.relativeFilePath(m_runConfiguration->mainScript());
|
|
|
|
|
m_fileListModel->clear();
|
|
|
|
|
m_fileListModel->appendRow(new QStandardItem(mainScriptInFilePath));
|
|
|
|
|
m_fileListCombo->setEnabled(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_fileListCombo->setEnabled(true);
|
2010-12-03 17:04:29 +01:00
|
|
|
m_fileListModel->clear();
|
2012-11-26 21:24:16 +02:00
|
|
|
m_fileListModel->appendRow(new QStandardItem(QLatin1String(CURRENT_FILE)));
|
2010-12-03 17:04:29 +01:00
|
|
|
QModelIndex currentIndex;
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList sortedFiles = project->files(ProjectExplorer::Project::AllFiles);
|
2010-12-03 17:04:29 +01:00
|
|
|
|
|
|
|
|
// make paths relative to project directory
|
|
|
|
|
QStringList relativeFiles;
|
|
|
|
|
foreach (const QString &fn, sortedFiles) {
|
|
|
|
|
relativeFiles += projectDir.relativeFilePath(fn);
|
|
|
|
|
}
|
|
|
|
|
sortedFiles = relativeFiles;
|
|
|
|
|
|
2010-11-29 11:42:58 +01:00
|
|
|
qStableSort(sortedFiles.begin(), sortedFiles.end(), caseInsensitiveLessThan);
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
QString mainScriptPath;
|
|
|
|
|
if (m_runConfiguration->mainScriptSource() != QmlProjectRunConfiguration::FileInEditor)
|
|
|
|
|
mainScriptPath = projectDir.relativeFilePath(m_runConfiguration->mainScript());
|
|
|
|
|
|
2010-11-29 11:42:58 +01:00
|
|
|
foreach (const QString &fn, sortedFiles) {
|
|
|
|
|
QFileInfo fileInfo(fn);
|
|
|
|
|
if (fileInfo.suffix() != QLatin1String("qml"))
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
QStandardItem *item = new QStandardItem(fn);
|
|
|
|
|
m_fileListModel->appendRow(item);
|
2010-11-29 11:42:58 +01:00
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
if (mainScriptPath == fn)
|
|
|
|
|
currentIndex = item->index();
|
2010-11-29 11:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
if (currentIndex.isValid()) {
|
|
|
|
|
m_fileListCombo->setCurrentIndex(currentIndex.row());
|
|
|
|
|
} else {
|
2010-11-29 11:42:58 +01:00
|
|
|
m_fileListCombo->setCurrentIndex(0);
|
2010-12-03 17:04:29 +01:00
|
|
|
}
|
2010-11-29 11:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
void QmlProjectRunConfigurationWidget::setMainScript(int index)
|
2010-11-29 11:42:58 +01:00
|
|
|
{
|
2010-12-03 17:04:29 +01:00
|
|
|
if (index == 0) {
|
|
|
|
|
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInEditor);
|
|
|
|
|
} else {
|
|
|
|
|
const QString path = m_fileListModel->data(m_fileListModel->index(index, 0)).toString();
|
2012-01-02 11:53:37 +01:00
|
|
|
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInSettings, path);
|
2010-12-03 17:04:29 +01:00
|
|
|
}
|
2010-11-29 11:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProjectRunConfigurationWidget::onViewerArgsChanged()
|
|
|
|
|
{
|
|
|
|
|
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender()))
|
|
|
|
|
m_runConfiguration->m_qmlViewerArgs = lineEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:50:44 +01:00
|
|
|
void QmlProjectRunConfigurationWidget::userChangesChanged()
|
|
|
|
|
{
|
|
|
|
|
m_runConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProjectRunConfigurationWidget::userEnvironmentChangesChanged()
|
|
|
|
|
{
|
|
|
|
|
m_environmentWidget->setUserChanges(m_runConfiguration->userEnvironmentChanges());
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 11:42:58 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProjectManager
|