forked from qt-creator/qt-creator
QmlProjectManager: Aspect-ify runconfiguration
Split the remaining manually managed data into a standard ArgumentsAspect and a new MainQmlFileAspect. Change-Id: I8a8fe3f4a08d602a7b6e9c9463d3d7de257b6e6c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -11,14 +11,12 @@ HEADERS += qmlproject.h \
|
|||||||
qmlprojectnodes.h \
|
qmlprojectnodes.h \
|
||||||
qmlprojectrunconfiguration.h \
|
qmlprojectrunconfiguration.h \
|
||||||
qmlprojectmanager_global.h \
|
qmlprojectmanager_global.h \
|
||||||
qmlprojectmanagerconstants.h \
|
qmlprojectmanagerconstants.h
|
||||||
qmlprojectrunconfigurationwidget.h
|
|
||||||
|
|
||||||
SOURCES += qmlproject.cpp \
|
SOURCES += qmlproject.cpp \
|
||||||
qmlprojectenvironmentaspect.cpp \
|
qmlprojectenvironmentaspect.cpp \
|
||||||
qmlprojectplugin.cpp \
|
qmlprojectplugin.cpp \
|
||||||
qmlprojectnodes.cpp \
|
qmlprojectnodes.cpp \
|
||||||
qmlprojectrunconfiguration.cpp \
|
qmlprojectrunconfiguration.cpp
|
||||||
qmlprojectrunconfigurationwidget.cpp
|
|
||||||
|
|
||||||
RESOURCES += qmlproject.qrc
|
RESOURCES += qmlproject.qrc
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ QtcPlugin {
|
|||||||
"qmlprojectmanagerconstants.h",
|
"qmlprojectmanagerconstants.h",
|
||||||
"qmlprojectnodes.cpp", "qmlprojectnodes.h",
|
"qmlprojectnodes.cpp", "qmlprojectnodes.h",
|
||||||
"qmlprojectplugin.cpp", "qmlprojectplugin.h",
|
"qmlprojectplugin.cpp", "qmlprojectplugin.h",
|
||||||
"qmlprojectrunconfiguration.cpp", "qmlprojectrunconfiguration.h",
|
"qmlprojectrunconfiguration.cpp", "qmlprojectrunconfiguration.h"
|
||||||
"qmlprojectrunconfigurationwidget.cpp", "qmlprojectrunconfigurationwidget.h"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,13 +26,16 @@
|
|||||||
#include "qmlprojectrunconfiguration.h"
|
#include "qmlprojectrunconfiguration.h"
|
||||||
#include "qmlproject.h"
|
#include "qmlproject.h"
|
||||||
#include "qmlprojectmanagerconstants.h"
|
#include "qmlprojectmanagerconstants.h"
|
||||||
#include "qmlprojectrunconfigurationwidget.h"
|
|
||||||
#include "qmlprojectenvironmentaspect.h"
|
#include "qmlprojectenvironmentaspect.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
|
|
||||||
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
|
|
||||||
#include <qtsupport/qtkitinformation.h>
|
#include <qtsupport/qtkitinformation.h>
|
||||||
#include <qtsupport/qtoutputformatter.h>
|
#include <qtsupport/qtoutputformatter.h>
|
||||||
#include <qtsupport/qtsupportconstants.h>
|
#include <qtsupport/qtsupportconstants.h>
|
||||||
@@ -44,6 +47,11 @@
|
|||||||
#include <utils/winutils.h>
|
#include <utils/winutils.h>
|
||||||
#include <qmljstools/qmljstoolsconstants.h>
|
#include <qmljstools/qmljstoolsconstants.h>
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QStandardItem>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace QtSupport;
|
using namespace QtSupport;
|
||||||
@@ -51,6 +59,225 @@ using namespace QtSupport;
|
|||||||
namespace QmlProjectManager {
|
namespace QmlProjectManager {
|
||||||
|
|
||||||
const char M_CURRENT_FILE[] = "CurrentFile";
|
const char M_CURRENT_FILE[] = "CurrentFile";
|
||||||
|
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
|
||||||
|
|
||||||
|
class MainQmlFileAspect : public IRunConfigurationAspect
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MainQmlFileAspect(RunConfiguration *rc);
|
||||||
|
~MainQmlFileAspect() { delete m_fileListCombo; }
|
||||||
|
|
||||||
|
enum MainScriptSource {
|
||||||
|
FileInEditor,
|
||||||
|
FileInProjectFile,
|
||||||
|
FileInSettings
|
||||||
|
};
|
||||||
|
|
||||||
|
void addToConfigurationLayout(QFormLayout *layout) final;
|
||||||
|
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:
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
MainQmlFileAspect::MainQmlFileAspect(RunConfiguration *rc)
|
||||||
|
: IRunConfigurationAspect(rc)
|
||||||
|
{
|
||||||
|
m_scriptFile = M_CURRENT_FILE;
|
||||||
|
|
||||||
|
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
||||||
|
this, &MainQmlFileAspect::changeCurrentFile);
|
||||||
|
connect(EditorManager::instance(), &EditorManager::currentDocumentStateChanged,
|
||||||
|
this, [this] { changeCurrentFile(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainQmlFileAspect::addToConfigurationLayout(QFormLayout *layout)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
connect(m_fileListCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
|
||||||
|
this, &MainQmlFileAspect::setMainScript);
|
||||||
|
|
||||||
|
layout->addRow(QmlProjectRunConfiguration::tr("Main QML file:"), m_fileListCombo);
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
Project *project = runConfiguration()->target()->project();
|
||||||
|
QDir projectDir(project->projectDirectory().toString());
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
QStringList sortedFiles = Utils::transform(project->files(Project::AllFiles),
|
||||||
|
&Utils::FileName::toString);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
QStandardItem *item = new QStandardItem(fn);
|
||||||
|
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
|
||||||
|
{
|
||||||
|
QmlProject *project = static_cast<QmlProject *>(runConfiguration()->target()->project());
|
||||||
|
if (!project->mainFile().isEmpty())
|
||||||
|
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;
|
||||||
|
Project *project = runConfiguration()->target()->project();
|
||||||
|
m_mainScriptFilename = project->projectDirectory().toString() + '/' + m_scriptFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
qobject_cast<QmlProjectRunConfiguration *>(runConfiguration())->updateEnabledState();
|
||||||
|
|
||||||
|
updateFileComboBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns absolute path to main script file.
|
||||||
|
*/
|
||||||
|
QString MainQmlFileAspect::mainScript() const
|
||||||
|
{
|
||||||
|
QmlProject *project = qobject_cast<QmlProject *>(runConfiguration()->target()->project());
|
||||||
|
if (!project)
|
||||||
|
return m_currentFileFilename;
|
||||||
|
if (!project->mainFile().isEmpty()) {
|
||||||
|
const QString pathInProject = project->mainFile();
|
||||||
|
if (QFileInfo(pathInProject).isAbsolute())
|
||||||
|
return pathInProject;
|
||||||
|
else
|
||||||
|
return QDir(project->canonicalProjectDir().toString()).absoluteFilePath(pathInProject);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
qobject_cast<QmlProjectRunConfiguration *>(runConfiguration())->updateEnabledState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// QmlProjectRunConfiguration
|
||||||
|
|
||||||
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
||||||
: RunConfiguration(target, id)
|
: RunConfiguration(target, id)
|
||||||
@@ -61,17 +288,15 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
|||||||
m_qmlViewerAspect->setPlaceHolderText(executable());
|
m_qmlViewerAspect->setPlaceHolderText(executable());
|
||||||
m_qmlViewerAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
|
m_qmlViewerAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
|
||||||
|
|
||||||
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
auto argumentAspect = addAspect<ArgumentsAspect>();
|
||||||
|
argumentAspect->setSettingsKey(Constants::QML_VIEWER_ARGUMENTS_KEY);
|
||||||
|
|
||||||
// reset default settings in constructor
|
m_mainQmlFileAspect = addAspect<MainQmlFileAspect>();
|
||||||
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
|
||||||
this, &QmlProjectRunConfiguration::changeCurrentFile);
|
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
||||||
connect(EditorManager::instance(), &EditorManager::currentDocumentStateChanged,
|
|
||||||
this, [this] { changeCurrentFile(); });
|
|
||||||
|
|
||||||
connect(target, &Target::kitChanged,
|
connect(target, &Target::kitChanged,
|
||||||
this, &QmlProjectRunConfiguration::updateEnabledState);
|
this, &QmlProjectRunConfiguration::updateEnabledState);
|
||||||
m_scriptFile = M_CURRENT_FILE;
|
|
||||||
|
|
||||||
setDisplayName(tr("QML Scene", "QMLRunConfiguration display name."));
|
setDisplayName(tr("QML Scene", "QMLRunConfiguration display name."));
|
||||||
updateEnabledState();
|
updateEnabledState();
|
||||||
@@ -131,7 +356,7 @@ QString QmlProjectRunConfiguration::executable() const
|
|||||||
QString QmlProjectRunConfiguration::commandLineArguments() const
|
QString QmlProjectRunConfiguration::commandLineArguments() const
|
||||||
{
|
{
|
||||||
// arguments in .user file
|
// arguments in .user file
|
||||||
QString args = m_qmlViewerArgs;
|
QString args = extraAspect<ArgumentsAspect>()->arguments();
|
||||||
const Target *currentTarget = target();
|
const Target *currentTarget = target();
|
||||||
const IDevice::ConstPtr device = DeviceKitInformation::device(currentTarget->kit());
|
const IDevice::ConstPtr device = DeviceKitInformation::device(currentTarget->kit());
|
||||||
const Utils::OsType osType = device ? device->osType() : Utils::HostOsInfo::hostOs();
|
const Utils::OsType osType = device ? device->osType() : Utils::HostOsInfo::hostOs();
|
||||||
@@ -151,62 +376,6 @@ QString QmlProjectRunConfiguration::commandLineArguments() const
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *QmlProjectRunConfiguration::createConfigurationWidget()
|
|
||||||
{
|
|
||||||
return wrapWidget(new Internal::QmlProjectRunConfigurationWidget(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
QmlProjectRunConfiguration::MainScriptSource QmlProjectRunConfiguration::mainScriptSource() const
|
|
||||||
{
|
|
||||||
QmlProject *project = static_cast<QmlProject *>(target()->project());
|
|
||||||
if (!project->mainFile().isEmpty())
|
|
||||||
return FileInProjectFile;
|
|
||||||
if (!m_mainScriptFilename.isEmpty())
|
|
||||||
return FileInSettings;
|
|
||||||
return FileInEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Returns absolute path to main script file.
|
|
||||||
*/
|
|
||||||
QString QmlProjectRunConfiguration::mainScript() const
|
|
||||||
{
|
|
||||||
QmlProject *project = qobject_cast<QmlProject *>(target()->project());
|
|
||||||
if (!project)
|
|
||||||
return m_currentFileFilename;
|
|
||||||
if (!project->mainFile().isEmpty()) {
|
|
||||||
const QString pathInProject = project->mainFile();
|
|
||||||
if (QFileInfo(pathInProject).isAbsolute())
|
|
||||||
return pathInProject;
|
|
||||||
else
|
|
||||||
return QDir(project->canonicalProjectDir().toString()).absoluteFilePath(pathInProject);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_mainScriptFilename.isEmpty())
|
|
||||||
return m_mainScriptFilename;
|
|
||||||
|
|
||||||
return m_currentFileFilename;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProjectRunConfiguration::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;
|
|
||||||
m_mainScriptFilename
|
|
||||||
= target()->project()->projectDirectory().toString() + QLatin1Char('/') + m_scriptFile;
|
|
||||||
}
|
|
||||||
updateEnabledState();
|
|
||||||
|
|
||||||
emit scriptSourceChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
Abi QmlProjectRunConfiguration::abi() const
|
Abi QmlProjectRunConfiguration::abi() const
|
||||||
{
|
{
|
||||||
Abi hostAbi = Abi::hostAbi();
|
Abi hostAbi = Abi::hostAbi();
|
||||||
@@ -214,41 +383,21 @@ Abi QmlProjectRunConfiguration::abi() const
|
|||||||
Abi::RuntimeQmlFormat, hostAbi.wordWidth());
|
Abi::RuntimeQmlFormat, hostAbi.wordWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap QmlProjectRunConfiguration::toMap() const
|
|
||||||
{
|
|
||||||
QVariantMap map(RunConfiguration::toMap());
|
|
||||||
|
|
||||||
map.insert(QLatin1String(Constants::QML_VIEWER_ARGUMENTS_KEY), m_qmlViewerArgs);
|
|
||||||
map.insert(QLatin1String(Constants::QML_MAINSCRIPT_KEY), m_scriptFile);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QmlProjectRunConfiguration::fromMap(const QVariantMap &map)
|
|
||||||
{
|
|
||||||
m_qmlViewerArgs = map.value(QLatin1String(Constants::QML_VIEWER_ARGUMENTS_KEY)).toString();
|
|
||||||
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);
|
|
||||||
|
|
||||||
return RunConfiguration::fromMap(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProjectRunConfiguration::changeCurrentFile(IEditor *editor)
|
|
||||||
{
|
|
||||||
if (!editor)
|
|
||||||
editor = EditorManager::currentEditor();
|
|
||||||
|
|
||||||
if (editor)
|
|
||||||
m_currentFileFilename = editor->document()->filePath().toString();
|
|
||||||
updateEnabledState();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProjectRunConfiguration::updateEnabledState()
|
void QmlProjectRunConfiguration::updateEnabledState()
|
||||||
|
{
|
||||||
|
bool qmlFileFound = m_mainQmlFileAspect->isQmlFilePresent();
|
||||||
|
if (!qmlFileFound) {
|
||||||
|
setEnabled(false);
|
||||||
|
} else {
|
||||||
|
const QString exe = executable();
|
||||||
|
if (exe.isEmpty())
|
||||||
|
setEnabled(false);
|
||||||
|
else
|
||||||
|
RunConfiguration::updateEnabledState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainQmlFileAspect::isQmlFilePresent()
|
||||||
{
|
{
|
||||||
bool qmlFileFound = false;
|
bool qmlFileFound = false;
|
||||||
if (mainScriptSource() == FileInEditor) {
|
if (mainScriptSource() == FileInEditor) {
|
||||||
@@ -267,7 +416,8 @@ void QmlProjectRunConfiguration::updateEnabledState()
|
|||||||
|| mainScriptMimeType.matchesName(QLatin1String(QmlJSTools::Constants::QMLPROJECT_MIMETYPE))) {
|
|| mainScriptMimeType.matchesName(QLatin1String(QmlJSTools::Constants::QMLPROJECT_MIMETYPE))) {
|
||||||
// find a qml file with lowercase filename. This is slow, but only done
|
// find a qml file with lowercase filename. This is slow, but only done
|
||||||
// in initialization/other border cases.
|
// in initialization/other border cases.
|
||||||
foreach (const Utils::FileName &filename, target()->project()->files(Project::AllFiles)) {
|
const auto files = runConfiguration()->target()->project()->files(Project::AllFiles);
|
||||||
|
for (const Utils::FileName &filename : files) {
|
||||||
const QFileInfo fi = filename.toFileInfo();
|
const QFileInfo fi = filename.toFileInfo();
|
||||||
|
|
||||||
if (!filename.isEmpty() && fi.baseName()[0].isLower()) {
|
if (!filename.isEmpty() && fi.baseName()[0].isLower()) {
|
||||||
@@ -280,23 +430,17 @@ void QmlProjectRunConfiguration::updateEnabledState()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // use default one
|
} else { // use default one
|
||||||
qmlFileFound = !mainScript().isEmpty();
|
qmlFileFound = !mainScript().isEmpty();
|
||||||
}
|
}
|
||||||
|
return qmlFileFound;
|
||||||
|
}
|
||||||
|
|
||||||
if (!qmlFileFound) {
|
QString QmlProjectRunConfiguration::mainScript() const
|
||||||
setEnabled(false);
|
{
|
||||||
} else {
|
return m_mainQmlFileAspect->mainScript();
|
||||||
const QString exe = executable();
|
|
||||||
if (exe.isEmpty()) {
|
|
||||||
setEnabled(false);
|
|
||||||
} else {
|
|
||||||
RunConfiguration::updateEnabledState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|||||||
@@ -30,61 +30,31 @@
|
|||||||
#include <projectexplorer/runconfiguration.h>
|
#include <projectexplorer/runconfiguration.h>
|
||||||
#include <projectexplorer/runconfigurationaspects.h>
|
#include <projectexplorer/runconfigurationaspects.h>
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
|
||||||
|
|
||||||
namespace QmlProjectManager {
|
namespace QmlProjectManager {
|
||||||
class QmlProject;
|
|
||||||
|
|
||||||
namespace Internal { class QmlProjectRunConfigurationWidget; }
|
class MainQmlFileAspect;
|
||||||
|
|
||||||
class QMLPROJECTMANAGER_EXPORT QmlProjectRunConfiguration : public ProjectExplorer::RunConfiguration
|
class QMLPROJECTMANAGER_EXPORT QmlProjectRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class Internal::QmlProjectRunConfigurationWidget;
|
|
||||||
friend class QmlProject; // to call updateEnabled()
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QmlProjectRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
|
QmlProjectRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
|
||||||
|
|
||||||
ProjectExplorer::Runnable runnable() const override;
|
|
||||||
|
|
||||||
enum MainScriptSource {
|
|
||||||
FileInEditor,
|
|
||||||
FileInProjectFile,
|
|
||||||
FileInSettings
|
|
||||||
};
|
|
||||||
MainScriptSource mainScriptSource() const;
|
|
||||||
void setScriptSource(MainScriptSource source, const QString &settingsPath = QString());
|
|
||||||
|
|
||||||
QString mainScript() const;
|
|
||||||
|
|
||||||
QString disabledReason() const override;
|
|
||||||
QWidget *createConfigurationWidget() override;
|
|
||||||
QVariantMap toMap() const override;
|
|
||||||
|
|
||||||
ProjectExplorer::Abi abi() const override;
|
|
||||||
ProjectExplorer::BaseStringAspect *qmlViewerAspect() const { return m_qmlViewerAspect; }
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void scriptSourceChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool fromMap(const QVariantMap &map) override;
|
friend class MainQmlFileAspect;
|
||||||
|
|
||||||
void changeCurrentFile(Core::IEditor* = 0);
|
ProjectExplorer::Runnable runnable() const final;
|
||||||
|
QString disabledReason() const final;
|
||||||
|
ProjectExplorer::Abi abi() const final;
|
||||||
void updateEnabledState() final;
|
void updateEnabledState() final;
|
||||||
|
|
||||||
|
QString mainScript() const;
|
||||||
QString executable() const;
|
QString executable() const;
|
||||||
QString commandLineArguments() const;
|
QString commandLineArguments() const;
|
||||||
|
|
||||||
// absolute path to current file (if being used)
|
|
||||||
QString m_currentFileFilename;
|
|
||||||
// absolute path to selected main script (if being used)
|
|
||||||
QString m_mainScriptFilename;
|
|
||||||
|
|
||||||
QString m_scriptFile;
|
|
||||||
QString m_qmlViewerArgs;
|
|
||||||
ProjectExplorer::BaseStringAspect *m_qmlViewerAspect;
|
ProjectExplorer::BaseStringAspect *m_qmlViewerAspect;
|
||||||
|
MainQmlFileAspect *m_mainQmlFileAspect;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|||||||
@@ -1,153 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** 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 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.
|
|
||||||
**
|
|
||||||
** 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.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "qmlprojectrunconfigurationwidget.h"
|
|
||||||
#include "qmlprojectrunconfiguration.h"
|
|
||||||
#include "qmlproject.h"
|
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <projectexplorer/projectexplorer.h>
|
|
||||||
#include <projectexplorer/target.h>
|
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
|
||||||
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QFormLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QStandardItemModel>
|
|
||||||
|
|
||||||
|
|
||||||
using Core::ICore;
|
|
||||||
using ProjectExplorer::ProjectExplorerPlugin;
|
|
||||||
|
|
||||||
namespace QmlProjectManager {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
QmlProjectRunConfigurationWidget::QmlProjectRunConfigurationWidget(QmlProjectRunConfiguration *rc) :
|
|
||||||
m_runConfiguration(rc),
|
|
||||||
m_fileListModel(new QStandardItemModel(this))
|
|
||||||
{
|
|
||||||
auto form = new QFormLayout(this);
|
|
||||||
rc->qmlViewerAspect()->addToConfigurationLayout(form);
|
|
||||||
|
|
||||||
m_fileListCombo = new QComboBox;
|
|
||||||
m_fileListCombo->setModel(m_fileListModel);
|
|
||||||
|
|
||||||
connect(m_fileListCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
|
|
||||||
this, &QmlProjectRunConfigurationWidget::setMainScript);
|
|
||||||
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::fileListChanged,
|
|
||||||
this, &QmlProjectRunConfigurationWidget::updateFileComboBox);
|
|
||||||
|
|
||||||
QLineEdit *qmlViewerArgs = new QLineEdit;
|
|
||||||
qmlViewerArgs->setText(rc->m_qmlViewerArgs);
|
|
||||||
connect(qmlViewerArgs, &QLineEdit::textChanged,
|
|
||||||
this, &QmlProjectRunConfigurationWidget::onViewerArgsChanged);
|
|
||||||
|
|
||||||
form->addRow(tr("Arguments:"), qmlViewerArgs);
|
|
||||||
form->addRow(tr("Main QML file:"), m_fileListCombo);
|
|
||||||
|
|
||||||
updateFileComboBox();
|
|
||||||
|
|
||||||
connect(rc, &QmlProjectRunConfiguration::scriptSourceChanged,
|
|
||||||
this, &QmlProjectRunConfigurationWidget::updateFileComboBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
|
|
||||||
{
|
|
||||||
return s1.toLower() < s2.toLower();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProjectRunConfigurationWidget::updateFileComboBox()
|
|
||||||
{
|
|
||||||
ProjectExplorer::Project *project = m_runConfiguration->target()->project();
|
|
||||||
QDir projectDir(project->projectDirectory().toString());
|
|
||||||
|
|
||||||
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);
|
|
||||||
m_fileListModel->clear();
|
|
||||||
m_fileListModel->appendRow(new QStandardItem(QLatin1String(CURRENT_FILE)));
|
|
||||||
QModelIndex currentIndex;
|
|
||||||
|
|
||||||
QStringList sortedFiles = Utils::transform(project->files(ProjectExplorer::Project::AllFiles),
|
|
||||||
&Utils::FileName::toString);
|
|
||||||
|
|
||||||
// make paths relative to project directory
|
|
||||||
QStringList relativeFiles;
|
|
||||||
foreach (const QString &fn, sortedFiles) {
|
|
||||||
relativeFiles += projectDir.relativeFilePath(fn);
|
|
||||||
}
|
|
||||||
sortedFiles = relativeFiles;
|
|
||||||
|
|
||||||
std::stable_sort(sortedFiles.begin(), sortedFiles.end(), caseInsensitiveLessThan);
|
|
||||||
|
|
||||||
QString mainScriptPath;
|
|
||||||
if (m_runConfiguration->mainScriptSource() != QmlProjectRunConfiguration::FileInEditor)
|
|
||||||
mainScriptPath = projectDir.relativeFilePath(m_runConfiguration->mainScript());
|
|
||||||
|
|
||||||
foreach (const QString &fn, sortedFiles) {
|
|
||||||
QFileInfo fileInfo(fn);
|
|
||||||
if (fileInfo.suffix() != QLatin1String("qml"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
QStandardItem *item = new QStandardItem(fn);
|
|
||||||
m_fileListModel->appendRow(item);
|
|
||||||
|
|
||||||
if (mainScriptPath == fn)
|
|
||||||
currentIndex = item->index();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentIndex.isValid())
|
|
||||||
m_fileListCombo->setCurrentIndex(currentIndex.row());
|
|
||||||
else
|
|
||||||
m_fileListCombo->setCurrentIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProjectRunConfigurationWidget::setMainScript(int index)
|
|
||||||
{
|
|
||||||
if (index == 0) {
|
|
||||||
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInEditor);
|
|
||||||
} else {
|
|
||||||
const QString path = m_fileListModel->data(m_fileListModel->index(index, 0)).toString();
|
|
||||||
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInSettings, path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlProjectRunConfigurationWidget::onViewerArgsChanged()
|
|
||||||
{
|
|
||||||
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender()))
|
|
||||||
m_runConfiguration->m_qmlViewerArgs = lineEdit->text();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmlProjectManager
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** 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 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.
|
|
||||||
**
|
|
||||||
** 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.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QComboBox)
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QStandardItemModel)
|
|
||||||
|
|
||||||
namespace QmlProjectManager {
|
|
||||||
|
|
||||||
class QmlProjectRunConfiguration;
|
|
||||||
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
const char CURRENT_FILE[] = QT_TRANSLATE_NOOP("QmlManager", "<Current File>");
|
|
||||||
|
|
||||||
class QmlProjectRunConfigurationWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QmlProjectRunConfigurationWidget(QmlProjectRunConfiguration *rc);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void updateFileComboBox();
|
|
||||||
void setMainScript(int index);
|
|
||||||
void onViewerArgsChanged();
|
|
||||||
|
|
||||||
QmlProjectRunConfiguration *m_runConfiguration;
|
|
||||||
|
|
||||||
QComboBox *m_fileListCombo;
|
|
||||||
QStandardItemModel *m_fileListModel;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmlProjectManager
|
|
||||||
Reference in New Issue
Block a user