2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-05-04 12:19:22 +02: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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
#include "qdslandingpage.h"
|
2009-05-04 12:19:22 +02:00
|
|
|
#include "qmlprojectplugin.h"
|
2009-05-07 12:27:52 +02:00
|
|
|
#include "qmlproject.h"
|
2022-02-22 16:33:53 +01:00
|
|
|
#include "qmlprojectconstants.h"
|
2019-03-13 12:22:44 +01:00
|
|
|
#include "qmlprojectrunconfiguration.h"
|
2022-05-12 12:33:12 +03:00
|
|
|
#include "projectfilecontenttools.h"
|
2022-05-11 15:45:41 +03:00
|
|
|
#include "cmakegen/cmakeprojectconverter.h"
|
|
|
|
#include "cmakegen/generatecmakelists.h"
|
2022-05-25 14:15:17 +03:00
|
|
|
#include "qmlprojectgen/qmlprojectgenerator.h"
|
2009-11-11 10:10:00 +01:00
|
|
|
|
2022-05-10 14:23:51 +02:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2022-05-18 13:07:59 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2022-05-06 14:27:58 +03:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
#include <coreplugin/designmode.h>
|
2021-09-21 12:31:19 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2010-04-01 17:21:18 +02:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
2009-05-04 12:19:22 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2021-09-21 12:31:19 +02:00
|
|
|
#include <coreplugin/messagebox.h>
|
2022-05-06 14:27:58 +03:00
|
|
|
#include <coreplugin/modemanager.h>
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2022-05-10 14:23:51 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2017-03-03 18:16:34 +01:00
|
|
|
#include <projectexplorer/projectmanager.h>
|
2022-05-10 14:23:51 +02:00
|
|
|
#include <projectexplorer/projectnodes.h>
|
|
|
|
#include <projectexplorer/projecttree.h>
|
2019-03-13 12:22:44 +01:00
|
|
|
#include <projectexplorer/runcontrol.h>
|
2021-09-21 12:31:19 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2022-05-10 14:23:51 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2021-09-21 12:31:19 +02:00
|
|
|
|
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2017-03-03 18:16:34 +01:00
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
#include <qmljseditor/qmljseditor.h>
|
|
|
|
#include <qmljseditor/qmljseditorconstants.h>
|
|
|
|
|
2017-03-03 18:16:34 +01:00
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
2011-07-21 10:40:56 +02:00
|
|
|
|
2021-09-21 12:31:19 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
#include <extensionsystem/pluginspec.h>
|
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
#include <utils/fileutils.h>
|
2021-11-17 10:38:52 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2021-09-21 12:31:19 +02:00
|
|
|
|
2022-05-10 14:23:51 +02:00
|
|
|
#include <QAction>
|
2022-05-06 14:27:58 +03:00
|
|
|
#include <QDesktopServices>
|
2021-09-21 12:31:19 +02:00
|
|
|
#include <QMessageBox>
|
2022-05-18 13:07:59 +02:00
|
|
|
#include <QPointer>
|
2021-09-21 12:31:19 +02:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2017-03-03 18:16:34 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
namespace QmlProjectManager {
|
2018-02-15 14:51:31 +01:00
|
|
|
namespace Internal {
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
const char alwaysOpenUiQmlMode[] = "J.QtQuick/QmlJSEditor.openUiQmlMode";
|
|
|
|
const char installQdsUrl[] = "https://www.qt.io/product/ui-design-tools";
|
2021-09-21 12:31:19 +02:00
|
|
|
|
|
|
|
static bool isQmlDesigner(const ExtensionSystem::PluginSpec *spec)
|
|
|
|
{
|
|
|
|
if (!spec)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return spec->name().contains("QmlDesigner");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool qmlDesignerEnabled()
|
|
|
|
{
|
|
|
|
const auto plugins = ExtensionSystem::PluginManager::plugins();
|
|
|
|
const auto it = std::find_if(plugins.begin(), plugins.end(), &isQmlDesigner);
|
|
|
|
return it != plugins.end() && (*it)->plugin();
|
|
|
|
}
|
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
static QString alwaysOpenWithMode()
|
|
|
|
{
|
|
|
|
return Core::ICore::settings()->value(alwaysOpenUiQmlMode, "").toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setAlwaysOpenWithMode(const QString &mode)
|
2022-01-21 20:08:28 +01:00
|
|
|
{
|
2022-05-06 14:27:58 +03:00
|
|
|
Core::ICore::settings()->setValue(alwaysOpenUiQmlMode, mode);
|
2022-01-21 20:08:28 +01:00
|
|
|
}
|
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
static void clearAlwaysOpenWithMode()
|
2022-01-21 20:08:28 +01:00
|
|
|
{
|
2022-05-06 14:27:58 +03:00
|
|
|
Core::ICore::settings()->remove(alwaysOpenUiQmlMode);
|
2022-01-21 20:08:28 +01:00
|
|
|
}
|
|
|
|
|
2019-03-13 12:22:44 +01:00
|
|
|
class QmlProjectPluginPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QmlProjectRunConfigurationFactory runConfigFactory;
|
2021-09-21 12:31:19 +02:00
|
|
|
RunWorkerFactory runWorkerFactory{RunWorkerFactory::make<SimpleTargetRunner>(),
|
|
|
|
{ProjectExplorer::Constants::NORMAL_RUN_MODE},
|
|
|
|
{runConfigFactory.runConfigurationId()}};
|
|
|
|
QPointer<QMessageBox> lastMessageBox;
|
2022-05-06 14:27:58 +03:00
|
|
|
QdsLandingPage *landingPage = nullptr;
|
2022-06-01 17:33:39 +03:00
|
|
|
QdsLandingPageWidget *landingPageWidget = nullptr;
|
2019-03-13 12:22:44 +01:00
|
|
|
};
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
QmlProjectPlugin::~QmlProjectPlugin()
|
|
|
|
{
|
2021-09-21 12:31:19 +02:00
|
|
|
if (d->lastMessageBox)
|
|
|
|
d->lastMessageBox->deleteLater();
|
2022-05-06 14:27:58 +03:00
|
|
|
if (d->landingPage)
|
|
|
|
d->landingPage->deleteLater();
|
2022-06-01 17:33:39 +03:00
|
|
|
if (d->landingPageWidget)
|
|
|
|
d->landingPageWidget->deleteLater();
|
2019-03-13 12:22:44 +01:00
|
|
|
delete d;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2021-09-21 12:31:19 +02:00
|
|
|
void QmlProjectPlugin::openQDS(const Utils::FilePath &fileName)
|
|
|
|
{
|
2021-11-17 10:38:52 +01:00
|
|
|
const Utils::FilePath &qdsPath = QmlProjectPlugin::qdsInstallationEntry();
|
2021-09-21 12:31:19 +02:00
|
|
|
bool qdsStarted = false;
|
2022-02-22 16:33:53 +01:00
|
|
|
qputenv(Constants::enviromentLaunchedQDS, "true");
|
2021-09-21 12:31:19 +02:00
|
|
|
//-a and -client arguments help to append project to open design studio application
|
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
2021-11-17 10:38:52 +01:00
|
|
|
qdsStarted = Utils::QtcProcess::startDetached(
|
|
|
|
{"/usr/bin/open", {"-a", qdsPath.path(), fileName.toString()}});
|
2021-09-21 12:31:19 +02:00
|
|
|
else
|
2021-11-17 10:38:52 +01:00
|
|
|
qdsStarted = Utils::QtcProcess::startDetached({qdsPath, {"-client", fileName.toString()}});
|
2021-09-21 12:31:19 +02:00
|
|
|
|
|
|
|
if (!qdsStarted) {
|
|
|
|
QMessageBox::warning(Core::ICore::dialogParent(),
|
|
|
|
fileName.fileName(),
|
|
|
|
QObject::tr("Failed to start Qt Design Studio."));
|
2022-05-06 14:27:58 +03:00
|
|
|
if (alwaysOpenWithMode() == Core::Constants::MODE_DESIGN)
|
|
|
|
clearAlwaysOpenWithMode();
|
2021-09-21 12:31:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-17 10:03:50 +01:00
|
|
|
Utils::FilePath QmlProjectPlugin::qdsInstallationEntry()
|
2021-09-21 12:31:19 +02:00
|
|
|
{
|
|
|
|
QSettings *settings = Core::ICore::settings();
|
|
|
|
const QString qdsInstallationEntry = "QML/Designer/DesignStudioInstallation"; //set in installer
|
|
|
|
|
2021-11-17 10:03:50 +01:00
|
|
|
return Utils::FilePath::fromUserInput(settings->value(qdsInstallationEntry).toString());
|
2021-09-21 12:31:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProjectPlugin::qdsInstallationExists()
|
|
|
|
{
|
2021-11-17 10:03:50 +01:00
|
|
|
return qdsInstallationEntry().exists();
|
2021-09-21 12:31:19 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
bool QmlProjectPlugin::checkIfEditorIsuiQml(Core::IEditor *editor)
|
2021-09-21 12:31:19 +02:00
|
|
|
{
|
2022-05-06 14:27:58 +03:00
|
|
|
if (editor
|
|
|
|
&& (editor->document()->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID
|
|
|
|
|| editor->document()->id() == QmlJSEditor::Constants::C_QTQUICKDESIGNEREDITOR_ID)) {
|
|
|
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
|
|
|
QmlJS::Document::Ptr document =
|
|
|
|
modelManager->ensuredGetDocumentForPath(editor->document()->filePath().toString());
|
|
|
|
if (!document.isNull())
|
|
|
|
return document->language() == QmlJS::Dialect::QmlQtQuick2Ui;
|
|
|
|
}
|
|
|
|
return false;
|
2021-09-21 12:31:19 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
const Utils::FilePath findQmlProject(const Utils::FilePath &folder)
|
|
|
|
{
|
|
|
|
const Utils::FilePaths files = folder.dirEntries({QStringList("*.qmlproject"), QDir::Files});
|
|
|
|
if (files.isEmpty())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return files.constFirst();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Utils::FilePath findQmlProjectUpwards(const Utils::FilePath &folder)
|
2021-09-21 12:31:19 +02:00
|
|
|
{
|
|
|
|
auto ret = findQmlProject(folder);
|
|
|
|
if (ret.exists())
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
QDir dir = folder.toDir();
|
|
|
|
if (dir.cdUp())
|
|
|
|
return findQmlProjectUpwards(Utils::FilePath::fromString(dir.absolutePath()));
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool findAndOpenProject(const Utils::FilePath &filePath)
|
|
|
|
{
|
|
|
|
|
|
|
|
ProjectExplorer::Project *project
|
|
|
|
= ProjectExplorer::SessionManager::projectForFile(filePath);
|
|
|
|
|
|
|
|
if (project) {
|
|
|
|
if (project->projectFilePath().suffix() == "qmlproject") {
|
|
|
|
QmlProjectPlugin::openQDS(project->projectFilePath());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
auto projectFolder = project->rootProjectDirectory();
|
|
|
|
auto qmlProjectFile = findQmlProject(projectFolder);
|
|
|
|
if (qmlProjectFile.exists()) {
|
|
|
|
QmlProjectPlugin::openQDS(qmlProjectFile);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto qmlProjectFile = findQmlProjectUpwards(filePath);
|
|
|
|
if (qmlProjectFile.exists()) {
|
|
|
|
QmlProjectPlugin::openQDS(qmlProjectFile);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-21 20:08:28 +01:00
|
|
|
void QmlProjectPlugin::openInQDSWithProject(const Utils::FilePath &filePath)
|
|
|
|
{
|
|
|
|
if (findAndOpenProject(filePath)) {
|
|
|
|
openQDS(filePath);
|
|
|
|
//The first one might be ignored when QDS is starting up
|
|
|
|
QTimer::singleShot(4000, [filePath] { openQDS(filePath); });
|
|
|
|
} else {
|
|
|
|
Core::AsynchronousMessageBox::warning(
|
|
|
|
tr("Qt Design Studio"),
|
|
|
|
tr("No project file (*.qmlproject) found for Qt Design "
|
|
|
|
"Studio.\n Qt Design Studio requires a .qmlproject "
|
|
|
|
"based project to open the .ui.qml file."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 14:23:51 +02:00
|
|
|
static QmlBuildSystem *qmlBuildSystemforFileNode(const FileNode *fileNode)
|
|
|
|
{
|
|
|
|
if (!fileNode)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (QmlProject *qmlProject = qobject_cast<QmlProject*>(fileNode->getProject())) {
|
|
|
|
auto target = qmlProject->activeTarget();
|
|
|
|
if (!target)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return qobject_cast<QmlProjectManager::QmlBuildSystem *>(target->buildSystem());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
|
|
|
|
{
|
2015-02-04 09:32:46 +01:00
|
|
|
Q_UNUSED(errorMessage)
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2019-03-13 12:22:44 +01:00
|
|
|
d = new QmlProjectPluginPrivate;
|
2010-02-26 14:46:04 +01:00
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
if (!qmlDesignerEnabled()) {
|
|
|
|
d->landingPageWidget = new QdsLandingPageWidget();
|
|
|
|
|
|
|
|
const QStringList mimeTypes = {QmlJSTools::Constants::QMLUI_MIMETYPE};
|
|
|
|
auto context = new Internal::DesignModeContext(d->landingPageWidget);
|
|
|
|
Core::ICore::addContextObject(context);
|
|
|
|
|
|
|
|
Core::DesignMode::registerDesignWidget(d->landingPageWidget, mimeTypes, context->context());
|
|
|
|
|
|
|
|
connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged,
|
|
|
|
this, &QmlProjectPlugin::editorModeChanged);
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:31:19 +02:00
|
|
|
|
2017-03-03 18:16:34 +01:00
|
|
|
ProjectManager::registerProjectType<QmlProject>(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
|
2021-09-21 12:31:19 +02:00
|
|
|
Core::FileIconProvider::registerIconOverlayForSuffix(":/qmlproject/images/qmlproject.png",
|
|
|
|
"qmlproject");
|
2022-05-10 14:23:51 +02:00
|
|
|
|
|
|
|
if (QmlProject::isQtDesignStudio()) {
|
|
|
|
Core::ActionContainer *menu = Core::ActionManager::actionContainer(
|
|
|
|
ProjectExplorer::Constants::M_FILECONTEXT);
|
|
|
|
QAction *mainfileAction = new QAction(tr("Set as main .qml file"), this);
|
|
|
|
mainfileAction->setEnabled(false);
|
|
|
|
|
|
|
|
connect(mainfileAction, &QAction::triggered, this, []() {
|
|
|
|
const Node *currentNode = ProjectTree::currentNode();
|
|
|
|
if (!currentNode || !currentNode->asFileNode()
|
|
|
|
|| currentNode->asFileNode()->fileType() != FileType::QML)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const Utils::FilePath file = currentNode->filePath();
|
|
|
|
|
|
|
|
QmlBuildSystem *buildSystem = qmlBuildSystemforFileNode(currentNode->asFileNode());
|
|
|
|
if (buildSystem)
|
|
|
|
buildSystem->setMainFileInProjectFile(file);
|
|
|
|
});
|
|
|
|
|
|
|
|
menu->addAction(Core::ActionManager::registerAction(
|
|
|
|
mainfileAction,
|
|
|
|
"QmlProject.setMainFile",
|
|
|
|
Core::Context(ProjectExplorer::Constants::C_PROJECT_TREE)),
|
|
|
|
ProjectExplorer::Constants::G_FILE_OTHER);
|
|
|
|
mainfileAction->setVisible(false);
|
|
|
|
connect(ProjectTree::instance(),
|
|
|
|
&ProjectTree::currentNodeChanged,
|
|
|
|
mainfileAction,
|
|
|
|
[mainfileAction](Node *node) {
|
|
|
|
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
|
|
|
|
|
|
|
const bool isVisible = fileNode && fileNode->fileType() == FileType::QML
|
|
|
|
&& fileNode->filePath().completeSuffix() == "qml";
|
|
|
|
|
|
|
|
mainfileAction->setVisible(isVisible);
|
|
|
|
|
|
|
|
if (!isVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QmlBuildSystem *buildSystem = qmlBuildSystemforFileNode(fileNode);
|
|
|
|
|
|
|
|
if (buildSystem)
|
|
|
|
mainfileAction->setEnabled(buildSystem->mainFilePath()
|
|
|
|
!= fileNode->filePath());
|
|
|
|
});
|
|
|
|
|
|
|
|
QAction *mainUifileAction = new QAction(tr("Set as main .ui.qml file"), this);
|
|
|
|
mainUifileAction->setEnabled(false);
|
|
|
|
|
|
|
|
connect(mainUifileAction, &QAction::triggered, this, []() {
|
|
|
|
const Node *currentNode = ProjectTree::currentNode();
|
|
|
|
if (!currentNode || !currentNode->asFileNode()
|
|
|
|
|| currentNode->asFileNode()->fileType() != FileType::QML)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const Utils::FilePath file = currentNode->filePath();
|
|
|
|
|
|
|
|
QmlBuildSystem *buildSystem = qmlBuildSystemforFileNode(currentNode->asFileNode());
|
|
|
|
if (buildSystem)
|
|
|
|
buildSystem->setMainUiFileInProjectFile(file);
|
|
|
|
});
|
|
|
|
|
|
|
|
menu->addAction(Core::ActionManager::registerAction(
|
|
|
|
mainUifileAction,
|
|
|
|
"QmlProject.setMainUIFile",
|
|
|
|
Core::Context(ProjectExplorer::Constants::C_PROJECT_TREE)),
|
|
|
|
ProjectExplorer::Constants::G_FILE_OTHER);
|
|
|
|
mainUifileAction->setVisible(false);
|
|
|
|
connect(ProjectTree::instance(),
|
|
|
|
&ProjectTree::currentNodeChanged,
|
|
|
|
mainUifileAction,
|
|
|
|
[mainUifileAction](Node *node) {
|
|
|
|
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
|
|
|
const bool isVisible = fileNode && fileNode->fileType() == FileType::QML
|
|
|
|
&& fileNode->filePath().completeSuffix() == "ui.qml";
|
|
|
|
|
|
|
|
mainUifileAction->setVisible(isVisible);
|
|
|
|
|
|
|
|
if (!isVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QmlBuildSystem *buildSystem = qmlBuildSystemforFileNode(fileNode);
|
|
|
|
if (buildSystem)
|
|
|
|
mainUifileAction->setEnabled(buildSystem->mainUiFilePath()
|
|
|
|
!= fileNode->filePath());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-11 15:45:41 +03:00
|
|
|
GenerateCmake::generateMenuEntry();
|
|
|
|
GenerateCmake::CmakeProjectConverter::generateMenuEntry();
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
return true;
|
2022-05-12 12:33:12 +03:00
|
|
|
}
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
void QmlProjectPlugin::initializeQmlLandingPage()
|
|
|
|
{
|
2022-06-01 17:33:39 +03:00
|
|
|
d->landingPage = new QdsLandingPage(d->landingPageWidget);
|
2022-05-06 14:27:58 +03:00
|
|
|
connect(d->landingPage, &QdsLandingPage::openCreator, this, &QmlProjectPlugin::openQtc);
|
|
|
|
connect(d->landingPage, &QdsLandingPage::openDesigner, this, &QmlProjectPlugin::openQds);
|
|
|
|
connect(d->landingPage, &QdsLandingPage::installDesigner, this, &QmlProjectPlugin::installQds);
|
|
|
|
connect(d->landingPage, &QdsLandingPage::generateCmake, this, &QmlProjectPlugin::generateCmake);
|
|
|
|
connect(d->landingPage, &QdsLandingPage::generateProjectFile, this, &QmlProjectPlugin::generateProjectFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::displayQmlLandingPage()
|
|
|
|
{
|
2022-06-01 17:33:39 +03:00
|
|
|
if (!d->landingPage)
|
|
|
|
initializeQmlLandingPage();
|
|
|
|
|
2022-05-25 14:15:17 +03:00
|
|
|
updateQmlLandingPageProjectInfo(projectFilePath());
|
2022-05-06 14:27:58 +03:00
|
|
|
d->landingPage->setQdsInstalled(qdsInstallationExists());
|
|
|
|
d->landingPage->setCmakeResources(ProjectFileContentTools::rootCmakeFiles());
|
|
|
|
d->landingPage->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::hideQmlLandingPage()
|
|
|
|
{
|
2022-06-01 17:33:39 +03:00
|
|
|
if (d->landingPage)
|
|
|
|
d->landingPage->hide();
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isDesignerMode(Utils::Id mode)
|
|
|
|
{
|
|
|
|
return mode == Core::Constants::MODE_DESIGN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::editorModeChanged(Utils::Id newMode, Utils::Id oldMode)
|
|
|
|
{
|
|
|
|
Core::IEditor *currentEditor = Core::EditorManager::currentEditor();
|
|
|
|
if (checkIfEditorIsuiQml(currentEditor)) {
|
|
|
|
if (isDesignerMode(newMode)) {
|
|
|
|
if (alwaysOpenWithMode() == Core::Constants::MODE_DESIGN)
|
|
|
|
openQds();
|
|
|
|
else if (alwaysOpenWithMode() == Core::Constants::MODE_EDIT)
|
|
|
|
openQtc();
|
|
|
|
else
|
|
|
|
displayQmlLandingPage();
|
|
|
|
} else if (isDesignerMode(oldMode)) {
|
|
|
|
hideQmlLandingPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::openQtc(bool permanent)
|
|
|
|
{
|
|
|
|
if (permanent)
|
|
|
|
setAlwaysOpenWithMode(Core::Constants::MODE_EDIT);
|
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
if (d->landingPage)
|
|
|
|
hideQmlLandingPage();
|
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::openQds(bool permanent)
|
|
|
|
{
|
|
|
|
if (permanent)
|
|
|
|
setAlwaysOpenWithMode(Core::Constants::MODE_DESIGN);
|
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
if (d->landingPage)
|
|
|
|
hideQmlLandingPage();
|
|
|
|
|
2022-05-06 14:27:58 +03:00
|
|
|
auto editor = Core::EditorManager::currentEditor();
|
|
|
|
if (editor)
|
|
|
|
openInQDSWithProject(editor->document()->filePath());
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::installQds()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(installQdsUrl));
|
|
|
|
hideQmlLandingPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::generateCmake()
|
|
|
|
{
|
|
|
|
qWarning() << "TODO generate cmake";
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::generateProjectFile()
|
|
|
|
{
|
2022-05-25 14:15:17 +03:00
|
|
|
GenerateQmlProject::QmlProjectFileGenerator generator;
|
|
|
|
|
|
|
|
Core::IEditor *editor = Core::EditorManager::currentEditor();
|
|
|
|
if (editor)
|
|
|
|
if (generator.prepareForUiQmlFile(editor->document()->filePath()))
|
|
|
|
if (generator.execute())
|
|
|
|
updateQmlLandingPageProjectInfo(generator.targetFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProjectPlugin::updateQmlLandingPageProjectInfo(const Utils::FilePath &projectFile)
|
|
|
|
{
|
|
|
|
if (d->landingPage) {
|
|
|
|
const QString qtVersionString = ProjectFileContentTools::qtVersion(projectFile);
|
|
|
|
const QString qdsVersionString = ProjectFileContentTools::qdsVersion(projectFile);
|
|
|
|
d->landingPage->setProjectFileExists(projectFile.exists());
|
|
|
|
d->landingPage->setQtVersion(qtVersionString);
|
|
|
|
d->landingPage->setQdsVersion(qdsVersionString);
|
|
|
|
}
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Utils::FilePath QmlProjectPlugin::projectFilePath()
|
|
|
|
{
|
|
|
|
auto project = ProjectExplorer::SessionManager::startupProject();
|
|
|
|
const QmlProjectManager::QmlProject *qmlProject = qobject_cast<const QmlProjectManager::QmlProject*>(project);
|
|
|
|
if (qmlProject)
|
|
|
|
return qmlProject->projectFilePath();
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:51:31 +01:00
|
|
|
} // namespace Internal
|
2010-02-16 13:39:13 +01:00
|
|
|
} // namespace QmlProjectManager
|