forked from qt-creator/qt-creator
Sorting to QML project file selector, and update when files change
Task-number: BAUHAUS-548 Reviewed-by: kkoehne
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "qmlprojectmanagerconstants.h"
|
||||
#include "qmlprojectrunconfiguration.h"
|
||||
#include "qmlprojecttarget.h"
|
||||
#include "projectexplorer/projectexplorer.h"
|
||||
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
@@ -46,6 +47,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
#include <QStringListModel>
|
||||
#include <QDebug>
|
||||
|
||||
namespace QmlProjectManager {
|
||||
@@ -54,6 +56,7 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Internal::QmlProjectTarge
|
||||
ProjectExplorer::RunConfiguration(parent, QLatin1String(Constants::QML_RC_ID)),
|
||||
m_debugServerAddress("127.0.0.1"),
|
||||
m_debugServerPort(Constants::QML_DEFAULT_DEBUG_SERVER_PORT),
|
||||
m_fileListModel(new QStringListModel(this)),
|
||||
m_projectTarget(parent),
|
||||
m_usingCurrentFile(true),
|
||||
m_isEnabled(false)
|
||||
@@ -161,35 +164,12 @@ QWidget *QmlProjectRunConfiguration::configurationWidget()
|
||||
QWidget *config = new QWidget;
|
||||
QFormLayout *form = new QFormLayout(config);
|
||||
|
||||
QComboBox *combo = new QComboBox;
|
||||
m_fileListCombo = new QComboBox;
|
||||
m_fileListCombo.data()->setModel(m_fileListModel);
|
||||
updateFileComboBox();
|
||||
|
||||
QDir projectDir = qmlTarget()->qmlProject()->projectDir();
|
||||
QStringList files;
|
||||
|
||||
files.append(CURRENT_FILE);
|
||||
|
||||
int currentIndex = -1;
|
||||
|
||||
QStringList sortedFiles = qmlTarget()->qmlProject()->files();
|
||||
qStableSort(sortedFiles.begin(), sortedFiles.end(), caseInsensitiveLessThan);
|
||||
|
||||
foreach (const QString &fn, sortedFiles) {
|
||||
QFileInfo fileInfo(fn);
|
||||
if (fileInfo.suffix() != QLatin1String("qml"))
|
||||
continue;
|
||||
|
||||
QString fileName = projectDir.relativeFilePath(fn);
|
||||
if (fileName == m_scriptFile)
|
||||
currentIndex = files.size();
|
||||
|
||||
files.append(fileName);
|
||||
}
|
||||
|
||||
combo->addItems(files);
|
||||
if (currentIndex != -1)
|
||||
combo->setCurrentIndex(currentIndex);
|
||||
|
||||
connect(combo, SIGNAL(activated(QString)), this, SLOT(setMainScript(QString)));
|
||||
connect(m_fileListCombo.data(), SIGNAL(activated(QString)), this, SLOT(setMainScript(QString)));
|
||||
connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(fileListChanged()), SLOT(updateFileComboBox()));
|
||||
|
||||
Utils::PathChooser *qmlViewer = new Utils::PathChooser;
|
||||
qmlViewer->setExpectedKind(Utils::PathChooser::Command);
|
||||
@@ -212,13 +192,14 @@ QWidget *QmlProjectRunConfiguration::configurationWidget()
|
||||
|
||||
form->addRow(tr("QML Runtime"), qmlViewer);
|
||||
form->addRow(tr("QML Runtime arguments:"), qmlViewerArgs);
|
||||
form->addRow(tr("Main QML File:"), combo);
|
||||
form->addRow(tr("Main QML File:"), m_fileListCombo.data());
|
||||
form->addRow(tr("Debugging Address:"), debugServer);
|
||||
form->addRow(tr("Debugging Port:"), debugPort);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
QString QmlProjectRunConfiguration::mainScript() const
|
||||
{
|
||||
if (m_usingCurrentFile)
|
||||
@@ -227,6 +208,38 @@ QString QmlProjectRunConfiguration::mainScript() const
|
||||
return m_mainScriptFilename;
|
||||
}
|
||||
|
||||
void QmlProjectRunConfiguration::updateFileComboBox()
|
||||
{
|
||||
if (m_fileListCombo.isNull())
|
||||
return;
|
||||
|
||||
QDir projectDir = qmlTarget()->qmlProject()->projectDir();
|
||||
QStringList files;
|
||||
|
||||
files.append(CURRENT_FILE);
|
||||
int currentIndex = -1;
|
||||
QStringList sortedFiles = qmlTarget()->qmlProject()->files();
|
||||
qStableSort(sortedFiles.begin(), sortedFiles.end(), caseInsensitiveLessThan);
|
||||
|
||||
foreach (const QString &fn, sortedFiles) {
|
||||
QFileInfo fileInfo(fn);
|
||||
if (fileInfo.suffix() != QLatin1String("qml"))
|
||||
continue;
|
||||
|
||||
QString fileName = projectDir.relativeFilePath(fn);
|
||||
if (fileName == m_scriptFile)
|
||||
currentIndex = files.size();
|
||||
|
||||
files.append(fileName);
|
||||
}
|
||||
m_fileListModel->setStringList(files);
|
||||
|
||||
if (currentIndex != -1)
|
||||
m_fileListCombo.data()->setCurrentIndex(currentIndex);
|
||||
else
|
||||
m_fileListCombo.data()->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void QmlProjectRunConfiguration::onDebugServerAddressChanged()
|
||||
{
|
||||
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender()))
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
|
||||
#include "qmlprojectmanager_global.h"
|
||||
#include <projectexplorer/runconfiguration.h>
|
||||
#include <QWeakPointer>
|
||||
#include <QComboBox>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QStringListModel);
|
||||
|
||||
namespace Core {
|
||||
class IEditor;
|
||||
@@ -79,12 +83,14 @@ private slots:
|
||||
|
||||
QString mainScript() const;
|
||||
void setMainScript(const QString &scriptFile);
|
||||
void updateFileComboBox();
|
||||
|
||||
void onViewerChanged();
|
||||
void onViewerArgsChanged();
|
||||
void onDebugServerAddressChanged();
|
||||
void onDebugServerPortChanged();
|
||||
|
||||
|
||||
protected:
|
||||
QmlProjectRunConfiguration(Internal::QmlProjectTarget *parent, QmlProjectRunConfiguration *source);
|
||||
virtual bool fromMap(const QVariantMap &map);
|
||||
@@ -104,6 +110,10 @@ private:
|
||||
QString m_qmlViewerArgs;
|
||||
QString m_debugServerAddress;
|
||||
uint m_debugServerPort;
|
||||
QStringListModel *m_fileListModel;
|
||||
// weakpointer is used to make sure we don't try to manipulate
|
||||
// widget which was deleted already, as can be the case here.
|
||||
QWeakPointer<QComboBox> m_fileListCombo;
|
||||
|
||||
Internal::QmlProjectTarget *m_projectTarget;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user