aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/qmlpreview/CMakeLists.txt2
-rw-r--r--src/plugins/qmlpreview/qmlpreview.qbs1
-rw-r--r--src/plugins/qmlpreview/qmlpreview_dependencies.pri3
-rw-r--r--src/plugins/qmlprojectmanager/CMakeLists.txt1
-rw-r--r--src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp268
-rw-r--r--src/plugins/qmlprojectmanager/qmlmainfileaspect.h83
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectmanager.pro2
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectmanager.qbs1
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp272
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h10
10 files changed, 373 insertions, 270 deletions
diff --git a/src/plugins/qmlpreview/CMakeLists.txt b/src/plugins/qmlpreview/CMakeLists.txt
index 1788cb38475..cf65ef4ded3 100644
--- a/src/plugins/qmlpreview/CMakeLists.txt
+++ b/src/plugins/qmlpreview/CMakeLists.txt
@@ -1,6 +1,6 @@
add_qtc_plugin(QmlPreview
DEPENDS QmlDebug qmljs
- PLUGIN_DEPENDS Core ProjectExplorer QmlJSTools QtSupport ResourceEditor
+ PLUGIN_DEPENDS Core ProjectExplorer QmlJSTools QtSupport ResourceEditor QmlProjectManager
SOURCES
qmlpreviewclient.cpp qmlpreviewclient.h
qmlpreviewconnectionmanager.cpp qmlpreviewconnectionmanager.h
diff --git a/src/plugins/qmlpreview/qmlpreview.qbs b/src/plugins/qmlpreview/qmlpreview.qbs
index d59d5a99253..342d400469c 100644
--- a/src/plugins/qmlpreview/qmlpreview.qbs
+++ b/src/plugins/qmlpreview/qmlpreview.qbs
@@ -9,6 +9,7 @@ QtcPlugin {
Depends { name: "QmlDebug" }
Depends { name: "QmlJS" }
Depends { name: "QmlJSTools" }
+ Depends { name: "QmlProjectManager" }
Depends { name: "QtSupport" }
Depends { name: "ResourceEditor" }
Depends { name: "Utils" }
diff --git a/src/plugins/qmlpreview/qmlpreview_dependencies.pri b/src/plugins/qmlpreview/qmlpreview_dependencies.pri
index 3bd81f7cd7d..c96b8c68d0f 100644
--- a/src/plugins/qmlpreview/qmlpreview_dependencies.pri
+++ b/src/plugins/qmlpreview/qmlpreview_dependencies.pri
@@ -10,4 +10,5 @@ QTC_PLUGIN_DEPENDS += \
projectexplorer \
qmljstools \
qtsupport \
- resourceeditor
+ resourceeditor \
+ qmlprojectmanager
diff --git a/src/plugins/qmlprojectmanager/CMakeLists.txt b/src/plugins/qmlprojectmanager/CMakeLists.txt
index ddef6f61f2a..c512e2b0b70 100644
--- a/src/plugins/qmlprojectmanager/CMakeLists.txt
+++ b/src/plugins/qmlprojectmanager/CMakeLists.txt
@@ -5,6 +5,7 @@ add_qtc_plugin(QmlProjectManager
fileformat/filefilteritems.cpp fileformat/filefilteritems.h
fileformat/qmlprojectfileformat.cpp fileformat/qmlprojectfileformat.h
fileformat/qmlprojectitem.cpp fileformat/qmlprojectitem.h
+ qmlmainfileaspect.cpp qmlmainfileaspect.h
qmlproject.cpp qmlproject.h
qmlproject.qrc
qmlprojectconstants.h
diff --git a/src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp b/src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp
new file mode 100644
index 00000000000..818f6e9da46
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlmainfileaspect.cpp
@@ -0,0 +1,268 @@
+/****************************************************************************
+**
+** 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 "qmlmainfileaspect.h"
+
+#include "qmlproject.h"
+#include "qmlprojectmanagerconstants.h"
+#include "qmlprojectrunconfiguration.h"
+
+#include <qmljstools/qmljstoolsconstants.h>
+
+#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/editormanager/ieditor.h>
+
+#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/target.h>
+
+#include <utils/mimetypes/mimedatabase.h>
+
+#include <QComboBox>
+
+using namespace Core;
+using namespace ProjectExplorer;
+
+namespace QmlProjectManager {
+
+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();
+}
+
+QmlMainFileAspect::QmlMainFileAspect(Target *target)
+ : m_target(target)
+ , m_scriptFile(M_CURRENT_FILE)
+{
+ connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
+ this, &QmlMainFileAspect::changeCurrentFile);
+ connect(EditorManager::instance(), &EditorManager::currentDocumentStateChanged,
+ this, [this] { changeCurrentFile(); });
+}
+
+QmlMainFileAspect::~QmlMainFileAspect()
+{
+ delete m_fileListCombo;
+}
+
+void QmlMainFileAspect::addToLayout(LayoutBuilder &builder)
+{
+ QTC_ASSERT(!m_fileListCombo, delete m_fileListCombo);
+ m_fileListCombo = new QComboBox;
+ m_fileListCombo->setModel(&m_fileListModel);
+
+ updateFileComboBox();
+
+ connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::fileListChanged,
+ this, &QmlMainFileAspect::updateFileComboBox);
+ connect(m_fileListCombo, QOverload<int>::of(&QComboBox::activated),
+ this, &QmlMainFileAspect::setMainScript);
+
+ builder.addItems(QmlProjectRunConfiguration::tr("Main QML file:"), m_fileListCombo.data());
+}
+
+void QmlMainFileAspect::toMap(QVariantMap &map) const
+{
+ map.insert(Constants::QML_MAINSCRIPT_KEY, m_scriptFile);
+}
+
+void QmlMainFileAspect::fromMap(const QVariantMap &map)
+{
+ m_scriptFile = map.value(Constants::QML_MAINSCRIPT_KEY,
+ M_CURRENT_FILE).toString();
+
+ if (m_scriptFile == M_CURRENT_FILE)
+ setScriptSource(FileInEditor);
+ else if (m_scriptFile.isEmpty())
+ setScriptSource(FileInProjectFile);
+ else
+ setScriptSource(FileInSettings, m_scriptFile);
+}
+
+void QmlMainFileAspect::updateFileComboBox()
+{
+ QDir projectDir(m_target->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(CURRENT_FILE));
+ QModelIndex currentIndex;
+
+ QStringList sortedFiles = Utils::transform(m_target->project()->files(Project::SourceFiles),
+ &Utils::FilePath::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() != "qml")
+ continue;
+
+ auto 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);
+ }
+}
+
+QmlMainFileAspect::MainScriptSource QmlMainFileAspect::mainScriptSource() const
+{
+ if (!qmlBuildSystem()->mainFile().isEmpty())
+ return FileInProjectFile;
+ if (!m_mainScriptFilename.isEmpty())
+ return FileInSettings;
+ return FileInEditor;
+}
+
+void QmlMainFileAspect::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 QmlMainFileAspect::setScriptSource(MainScriptSource source, const QString &settingsPath)
+{
+ if (source == FileInEditor) {
+ m_scriptFile = M_CURRENT_FILE;
+ m_mainScriptFilename.clear();
+ } else if (source == FileInProjectFile) {
+ m_scriptFile.clear();
+ m_mainScriptFilename.clear();
+ } else { // FileInSettings
+ m_scriptFile = settingsPath;
+ m_mainScriptFilename = m_target->project()->projectDirectory().toString() + '/' + m_scriptFile;
+ }
+
+ emit changed();
+ updateFileComboBox();
+}
+
+/**
+ Returns absolute path to main script file.
+ */
+QString QmlMainFileAspect::mainScript() const
+{
+ if (!qmlBuildSystem()->mainFile().isEmpty()) {
+ const QString pathInProject = qmlBuildSystem()->mainFile();
+ if (QFileInfo(pathInProject).isAbsolute())
+ return pathInProject;
+ else
+ return QDir(qmlBuildSystem()->canonicalProjectDir().toString()).absoluteFilePath(pathInProject);
+ }
+
+ if (!m_mainScriptFilename.isEmpty())
+ return m_mainScriptFilename;
+
+ return m_currentFileFilename;
+}
+
+void QmlMainFileAspect::changeCurrentFile(Core::IEditor *editor)
+{
+ if (!editor)
+ editor = EditorManager::currentEditor();
+
+ if (editor)
+ m_currentFileFilename = editor->document()->filePath().toString();
+
+ emit changed();
+}
+
+bool QmlMainFileAspect::isQmlFilePresent()
+{
+ bool qmlFileFound = false;
+ if (mainScriptSource() == FileInEditor) {
+ IDocument *document = EditorManager::currentDocument();
+ Utils::MimeType mainScriptMimeType = Utils::mimeTypeForFile(mainScript());
+ if (document) {
+ m_currentFileFilename = document->filePath().toString();
+ if (mainScriptMimeType.matchesName(ProjectExplorer::Constants::QML_MIMETYPE)
+ || mainScriptMimeType.matchesName(ProjectExplorer::Constants::QMLUI_MIMETYPE)) {
+ qmlFileFound = true;
+ }
+ }
+ if (!document
+ || mainScriptMimeType.matchesName(QmlJSTools::Constants::QMLPROJECT_MIMETYPE)) {
+ // find a qml file with lowercase filename. This is slow, but only done
+ // in initialization/other border cases.
+ const auto files = m_target->project()->files(Project::SourceFiles);
+ for (const Utils::FilePath &filename : files) {
+ const QFileInfo fi = filename.toFileInfo();
+
+ if (!filename.isEmpty() && fi.baseName().at(0).isLower()) {
+ Utils::MimeType type = Utils::mimeTypeForFile(fi);
+ if (type.matchesName(ProjectExplorer::Constants::QML_MIMETYPE)
+ || type.matchesName(ProjectExplorer::Constants::QMLUI_MIMETYPE)) {
+ m_currentFileFilename = filename.toString();
+ qmlFileFound = true;
+ break;
+ }
+ }
+ }
+ }
+ } else { // use default one
+ qmlFileFound = !mainScript().isEmpty();
+ }
+ return qmlFileFound;
+}
+
+QmlBuildSystem *QmlMainFileAspect::qmlBuildSystem() const
+{
+ return static_cast<QmlBuildSystem *>(m_target->buildSystem());
+}
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlmainfileaspect.h b/src/plugins/qmlprojectmanager/qmlmainfileaspect.h
new file mode 100644
index 00000000000..2c1b047ea37
--- /dev/null
+++ b/src/plugins/qmlprojectmanager/qmlmainfileaspect.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** 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 "qmlprojectmanager_global.h"
+
+#include <projectexplorer/runconfigurationaspects.h>
+
+#include <QStandardItemModel>
+
+namespace Core {
+class IEditor;
+}
+class QComboBox;
+
+namespace QmlProjectManager {
+
+class QmlProject;
+class QmlBuildSystem;
+
+class QMLPROJECTMANAGER_EXPORT QmlMainFileAspect : public ProjectExplorer::ProjectConfigurationAspect
+{
+public:
+ explicit QmlMainFileAspect(ProjectExplorer::Target *target);
+ ~QmlMainFileAspect() override;
+
+ enum MainScriptSource {
+ FileInEditor,
+ FileInProjectFile,
+ FileInSettings
+ };
+
+ void addToLayout(ProjectExplorer::LayoutBuilder &builder) 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(Core::IEditor *editor = nullptr);
+ bool isQmlFilePresent();
+ QmlBuildSystem *qmlBuildSystem() const;
+
+public:
+
+ ProjectExplorer::Target *m_target = nullptr;
+ 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;
+};
+
+} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
index ffd837e8276..049c5a801b7 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
+++ b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
@@ -6,6 +6,7 @@ include(fileformat/fileformat.pri)
DEFINES += QMLPROJECTMANAGER_LIBRARY
HEADERS += \
+ qmlmainfileaspect.h \
qmlproject.h \
qmlprojectplugin.h \
qmlprojectconstants.h \
@@ -15,6 +16,7 @@ HEADERS += \
qmlprojectmanagerconstants.h
SOURCES += \
+ qmlmainfileaspect.cpp \
qmlproject.cpp \
qmlprojectplugin.cpp \
qmlprojectnodes.cpp \
diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager.qbs b/src/plugins/qmlprojectmanager/qmlprojectmanager.qbs
index 258ef8d754d..b82c390df8f 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectmanager.qbs
+++ b/src/plugins/qmlprojectmanager/qmlprojectmanager.qbs
@@ -15,6 +15,7 @@ QtcPlugin {
Group {
name: "General"
files: [
+ "qmlmainfileaspect.cpp", "qmlmainfileaspect.h"
"qmlproject.cpp", "qmlproject.h",
"qmlproject.qrc",
"qmlprojectconstants.h",
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
index 1be8e33a2f2..2edfc2d7164 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp
@@ -26,6 +26,7 @@
#include "qmlprojectrunconfiguration.h"
#include "qmlproject.h"
#include "qmlprojectmanagerconstants.h"
+#include "qmlmainfileaspect.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
@@ -35,7 +36,10 @@
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/runcontrol.h>
+#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
+#include <projectexplorer/environmentaspect.h>
+#include <projectexplorer/projectconfigurationaspects.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtsupportconstants.h>
@@ -48,11 +52,6 @@
#include <qmljstools/qmljstoolsconstants.h>
-#include <QComboBox>
-#include <QCoreApplication>
-#include <QFormLayout>
-#include <QStandardItem>
-
using namespace Core;
using namespace ProjectExplorer;
using namespace QtSupport;
@@ -60,223 +59,6 @@ using namespace Utils;
namespace QmlProjectManager {
-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 ProjectConfigurationAspect
-{
-public:
- explicit MainQmlFileAspect(Target *target);
- ~MainQmlFileAspect() override { delete m_fileListCombo; }
-
- enum MainScriptSource {
- FileInEditor,
- FileInProjectFile,
- FileInSettings
- };
-
- void addToLayout(LayoutBuilder &builder) 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:
- QmlBuildSystem *qmlBuildSystem() const
- {
- return static_cast<QmlBuildSystem *>(m_target->buildSystem());
- }
-
- Target *m_target = nullptr;
- 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(Target *target)
- : m_target(target)
- , m_scriptFile(M_CURRENT_FILE)
-{
- connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
- this, &MainQmlFileAspect::changeCurrentFile);
- connect(EditorManager::instance(), &EditorManager::currentDocumentStateChanged,
- this, [this] { changeCurrentFile(); });
-}
-
-void MainQmlFileAspect::addToLayout(LayoutBuilder &builder)
-{
- 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, QOverload<int>::of(&QComboBox::activated),
- this, &MainQmlFileAspect::setMainScript);
-
- builder.addItems(QmlProjectRunConfiguration::tr("Main QML file:"), m_fileListCombo.data());
-}
-
-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()
-{
- QDir projectDir(m_target->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(m_target->project()->files(Project::SourceFiles),
- &FilePath::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;
-
- auto 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
-{
- if (!qmlBuildSystem()->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;
- m_mainScriptFilename = m_target->project()->projectDirectory().toString() + '/' + m_scriptFile;
- }
-
- emit changed();
- updateFileComboBox();
-}
-
-/**
- Returns absolute path to main script file.
- */
-QString MainQmlFileAspect::mainScript() const
-{
- if (!qmlBuildSystem()->mainFile().isEmpty()) {
- const QString pathInProject = qmlBuildSystem()->mainFile();
- if (QFileInfo(pathInProject).isAbsolute())
- return pathInProject;
- else
- return QDir(qmlBuildSystem()->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();
-
- emit changed();
-}
-
-
// QmlProjectRunConfiguration
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
@@ -314,8 +96,8 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
return CommandLine(qmlScenePath(), commandLineArguments(), CommandLine::Raw);
});
- m_mainQmlFileAspect = addAspect<MainQmlFileAspect>(target);
- connect(m_mainQmlFileAspect, &MainQmlFileAspect::changed, this, &RunConfiguration::update);
+ m_qmlMainFileAspect = addAspect<QmlMainFileAspect>(target);
+ connect(m_qmlMainFileAspect, &QmlMainFileAspect::changed, this, &RunConfiguration::update);
connect(target, &Target::kitChanged, this, &RunConfiguration::update);
@@ -409,54 +191,16 @@ QString QmlProjectRunConfiguration::commandLineArguments() const
bool QmlProjectRunConfiguration::isEnabled() const
{
- if (m_mainQmlFileAspect->isQmlFilePresent() && !commandLine().executable().isEmpty()) {
+ if (m_qmlMainFileAspect->isQmlFilePresent() && !commandLine().executable().isEmpty()) {
BuildSystem *bs = activeBuildSystem();
return !bs->isParsing() && bs->hasParsingData();
}
return false;
}
-bool MainQmlFileAspect::isQmlFilePresent()
-{
- bool qmlFileFound = false;
- if (mainScriptSource() == FileInEditor) {
- IDocument *document = EditorManager::currentDocument();
- MimeType mainScriptMimeType = Utils::mimeTypeForFile(mainScript());
- if (document) {
- m_currentFileFilename = document->filePath().toString();
- if (mainScriptMimeType.matchesName(ProjectExplorer::Constants::QML_MIMETYPE)
- || mainScriptMimeType.matchesName(ProjectExplorer::Constants::QMLUI_MIMETYPE)) {
- qmlFileFound = true;
- }
- }
- if (!document
- || mainScriptMimeType.matchesName(QmlJSTools::Constants::QMLPROJECT_MIMETYPE)) {
- // find a qml file with lowercase filename. This is slow, but only done
- // in initialization/other border cases.
- const auto files = m_target->project()->files(Project::SourceFiles);
- for (const FilePath &filename : files) {
- const QFileInfo fi = filename.toFileInfo();
-
- if (!filename.isEmpty() && fi.baseName().at(0).isLower()) {
- Utils::MimeType type = Utils::mimeTypeForFile(fi);
- if (type.matchesName(ProjectExplorer::Constants::QML_MIMETYPE)
- || type.matchesName(ProjectExplorer::Constants::QMLUI_MIMETYPE)) {
- m_currentFileFilename = filename.toString();
- qmlFileFound = true;
- break;
- }
- }
- }
- }
- } else { // use default one
- qmlFileFound = !mainScript().isEmpty();
- }
- return qmlFileFound;
-}
-
QString QmlProjectRunConfiguration::mainScript() const
{
- return m_mainQmlFileAspect->mainScript();
+ return m_qmlMainFileAspect->mainScript();
}
namespace Internal {
diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
index d905f2758b1..afb16ddbb7a 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
+++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.h
@@ -28,11 +28,13 @@
#include "qmlprojectmanager_global.h"
#include <projectexplorer/runconfiguration.h>
-#include <projectexplorer/runconfigurationaspects.h>
+namespace ProjectExplorer {
+class BaseStringAspect;
+}
namespace QmlProjectManager {
-class MainQmlFileAspect;
+class QmlMainFileAspect;
class QMLPROJECTMANAGER_EXPORT QmlProjectRunConfiguration : public ProjectExplorer::RunConfiguration
{
@@ -50,8 +52,8 @@ private:
Utils::FilePath qmlScenePath() const;
QString commandLineArguments() const;
- ProjectExplorer::BaseStringAspect *m_qmlViewerAspect;
- MainQmlFileAspect *m_mainQmlFileAspect;
+ ProjectExplorer::BaseStringAspect *m_qmlViewerAspect = nullptr;
+ QmlMainFileAspect *m_qmlMainFileAspect = nullptr;
};
namespace Internal {