forked from qt-creator/qt-creator
QmlProject: Make sure 'mainFile: "xxx"' is always respected
Prevent user from overriding the file to launch through the run configuration dialog. The old logic was broken (main file was always the editor), and arbitrary files can now be previewed conveniently with Tools->External->Qt Quick->Preview. Task-number: QTCREATORBUG-6683 Change-Id: Icee1d11e5063ca634e835bb57ffc77bf973ee93f Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
@@ -179,16 +179,21 @@ void QmlProjectRunConfigurationWidget::updateFileComboBox()
|
||||
QmlProject *project = m_runConfiguration->qmlTarget()->qmlProject();
|
||||
QDir projectDir = project->projectDir();
|
||||
|
||||
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(CURRENT_FILE));
|
||||
QModelIndex currentIndex;
|
||||
QModelIndex fileInQmlProjectIndex;
|
||||
|
||||
const QString mainScriptInFilePath = projectDir.absoluteFilePath(project->mainFile());
|
||||
|
||||
QStringList sortedFiles = project->files();
|
||||
if (!sortedFiles.contains(mainScriptInFilePath))
|
||||
sortedFiles += mainScriptInFilePath;
|
||||
|
||||
// make paths relative to project directory
|
||||
QStringList relativeFiles;
|
||||
@@ -213,9 +218,6 @@ void QmlProjectRunConfigurationWidget::updateFileComboBox()
|
||||
|
||||
if (mainScriptPath == fn)
|
||||
currentIndex = item->index();
|
||||
|
||||
if (mainScriptInFilePath == fn)
|
||||
fileInQmlProjectIndex = item->index();
|
||||
}
|
||||
|
||||
if (currentIndex.isValid()) {
|
||||
@@ -223,27 +225,15 @@ void QmlProjectRunConfigurationWidget::updateFileComboBox()
|
||||
} else {
|
||||
m_fileListCombo->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
if (fileInQmlProjectIndex.isValid()) {
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
m_fileListModel->setData(fileInQmlProjectIndex, font, Qt::FontRole);
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProjectRunConfigurationWidget::setMainScript(int index)
|
||||
{
|
||||
QmlProject *project = m_runConfiguration->qmlTarget()->qmlProject();
|
||||
QDir projectDir = project->projectDir();
|
||||
if (index == 0) {
|
||||
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInEditor);
|
||||
} else {
|
||||
const QString path = m_fileListModel->data(m_fileListModel->index(index, 0)).toString();
|
||||
if (projectDir.relativeFilePath(project->mainFile()) == path) {
|
||||
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInProjectFile);
|
||||
} else {
|
||||
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInSettings, path);
|
||||
}
|
||||
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInSettings, path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user