2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
|
#include "qmlprojectplugin.h"
|
2024-01-16 12:56:24 +01:00
|
|
|
|
|
|
|
|
#include "qdslandingpage.h"
|
2009-05-07 12:27:52 +02:00
|
|
|
#include "qmlproject.h"
|
2022-02-22 16:33:53 +01:00
|
|
|
#include "qmlprojectconstants.h"
|
2024-01-18 10:14:05 +01:00
|
|
|
#include "qmlprojectmanagerconstants.h"
|
2023-01-19 15:36:40 +01:00
|
|
|
#include "qmlprojectmanagertr.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"
|
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>
|
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
|
|
|
|
2024-01-12 14:04:37 +01:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
|
|
|
|
|
2024-01-16 12:56:24 +01:00
|
|
|
#include <extensionsystem/iplugin.h>
|
|
|
|
|
|
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>
|
2023-02-14 15:47:22 +01:00
|
|
|
#include <projectexplorer/projectmanager.h>
|
2022-05-10 14:23:51 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2021-09-21 12:31:19 +02:00
|
|
|
|
2024-01-17 10:25:21 +01:00
|
|
|
#include <qmlprofiler/qmlprofilerruncontrol.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>
|
2022-05-31 11:16:44 +02:00
|
|
|
#include <utils/fsengine/fileiconprovider.h>
|
2023-10-19 17:17:37 +02:00
|
|
|
#include <utils/mimeconstants.h>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2023-09-22 16:15:27 +02:00
|
|
|
#include <utils/qtcsettings.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>
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
using namespace Core;
|
2024-01-17 10:25:21 +01:00
|
|
|
using namespace QmlProfiler;
|
2024-01-12 14:04:37 +01:00
|
|
|
using namespace Debugger;
|
2017-03-03 18:16:34 +01:00
|
|
|
using namespace ProjectExplorer;
|
2023-09-22 16:15:27 +02:00
|
|
|
using namespace Utils;
|
2017-03-03 18:16:34 +01:00
|
|
|
|
2023-01-06 13:56:00 +01:00
|
|
|
namespace QmlProjectManager::Internal {
|
2009-05-04 12:19:22 +02:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
return ICore::settings()
|
2022-06-20 23:51:16 +02:00
|
|
|
->value(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE, "")
|
|
|
|
|
.toString();
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void setAlwaysOpenWithMode(const QString &mode)
|
2022-01-21 20:08:28 +01:00
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
ICore::settings()->setValue(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE, 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
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
ICore::settings()->remove(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE);
|
2022-01-21 20:08:28 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 12:22:44 +01:00
|
|
|
class QmlProjectPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-09-21 12:31:19 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
void openQDS(const FilePath &fileName)
|
2021-09-21 12:31:19 +02:00
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
const FilePath qdsPath = 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
|
2024-01-16 11:53:49 +01:00
|
|
|
if (HostOsInfo::isMacHost())
|
|
|
|
|
qdsStarted = Process::startDetached(
|
2021-11-17 10:38:52 +01:00
|
|
|
{"/usr/bin/open", {"-a", qdsPath.path(), fileName.toString()}});
|
2021-09-21 12:31:19 +02:00
|
|
|
else
|
2024-01-16 11:53:49 +01:00
|
|
|
qdsStarted = Process::startDetached({qdsPath, {"-client", fileName.toString()}});
|
2021-09-21 12:31:19 +02:00
|
|
|
|
|
|
|
|
if (!qdsStarted) {
|
2024-01-16 11:53:49 +01:00
|
|
|
QMessageBox::warning(ICore::dialogParent(),
|
2021-09-21 12:31:19 +02:00
|
|
|
fileName.fileName(),
|
2023-01-19 15:36:40 +01:00
|
|
|
Tr::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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
FilePath qdsInstallationEntry()
|
2021-09-21 12:31:19 +02:00
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
QtcSettings *settings = ICore::settings();
|
2023-09-22 16:15:27 +02:00
|
|
|
const Key qdsInstallationEntry = "QML/Designer/DesignStudioInstallation"; //set in installer
|
2021-09-21 12:31:19 +02:00
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
return FilePath::fromUserInput(settings->value(qdsInstallationEntry).toString());
|
2021-09-21 12:31:19 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
bool qdsInstallationExists()
|
2021-09-21 12:31:19 +02:00
|
|
|
{
|
2021-11-17 10:03:50 +01:00
|
|
|
return qdsInstallationEntry().exists();
|
2021-09-21 12:31:19 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
bool checkIfEditorIsuiQml(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();
|
2022-06-20 12:35:13 +02:00
|
|
|
QmlJS::Document::Ptr document = modelManager->ensuredGetDocumentForPath(
|
|
|
|
|
editor->document()->filePath());
|
2022-05-06 14:27:58 +03:00
|
|
|
if (!document.isNull())
|
|
|
|
|
return document->language() == QmlJS::Dialect::QmlQtQuick2Ui;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2021-09-21 12:31:19 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
const FilePath findQmlProject(const FilePath &folder)
|
2022-05-06 14:27:58 +03:00
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
const FilePaths files = folder.dirEntries({QStringList("*.qmlproject"), QDir::Files});
|
2022-05-06 14:27:58 +03:00
|
|
|
if (files.isEmpty())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
return files.constFirst();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
const FilePath findQmlProjectUpwards(const FilePath &folder)
|
2021-09-21 12:31:19 +02:00
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
FilePath ret = findQmlProject(folder);
|
2021-09-21 12:31:19 +02:00
|
|
|
if (ret.exists())
|
|
|
|
|
return ret;
|
|
|
|
|
|
2022-07-28 15:59:52 +02:00
|
|
|
if (folder.parentDir().isDir())
|
|
|
|
|
return findQmlProjectUpwards(folder.parentDir());
|
|
|
|
|
|
2021-09-21 12:31:19 +02:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
static bool findAndOpenProject(const FilePath &filePath)
|
2021-09-21 12:31:19 +02:00
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
if (Project *project = ProjectManager::projectForFile(filePath)) {
|
2021-09-21 12:31:19 +02:00
|
|
|
if (project->projectFilePath().suffix() == "qmlproject") {
|
2024-01-16 11:53:49 +01:00
|
|
|
openQDS(project->projectFilePath());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
FilePath projectFolder = project->rootProjectDirectory();
|
|
|
|
|
FilePath qmlProjectFile = findQmlProject(projectFolder);
|
|
|
|
|
if (qmlProjectFile.exists()) {
|
|
|
|
|
openQDS(qmlProjectFile);
|
2021-09-21 12:31:19 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
FilePath qmlProjectFile = findQmlProjectUpwards(filePath);
|
2021-09-21 12:31:19 +02:00
|
|
|
if (qmlProjectFile.exists()) {
|
2024-01-16 11:53:49 +01:00
|
|
|
openQDS(qmlProjectFile);
|
2021-09-21 12:31:19 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
void openInQDSWithProject(const FilePath &filePath)
|
2022-01-21 20:08:28 +01:00
|
|
|
{
|
|
|
|
|
if (findAndOpenProject(filePath)) {
|
|
|
|
|
openQDS(filePath);
|
|
|
|
|
//The first one might be ignored when QDS is starting up
|
|
|
|
|
QTimer::singleShot(4000, [filePath] { openQDS(filePath); });
|
|
|
|
|
} else {
|
2024-01-16 11:53:49 +01:00
|
|
|
AsynchronousMessageBox::warning(
|
2023-01-19 15:36:40 +01:00
|
|
|
Tr::tr("Qt Design Studio"),
|
|
|
|
|
Tr::tr("No project file (*.qmlproject) found for Qt Design "
|
2022-10-19 18:39:25 +02:00
|
|
|
"Studio.\nQt Design Studio requires a .qmlproject "
|
2022-01-21 20:08:28 +01:00
|
|
|
"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())) {
|
2024-01-16 11:53:49 +01:00
|
|
|
Target *target = qmlProject->activeTarget();
|
2022-05-10 14:23:51 +02:00
|
|
|
if (!target)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
return qobject_cast<QmlProjectManager::QmlBuildSystem *>(target->buildSystem());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 12:56:24 +01:00
|
|
|
class QmlProjectPlugin final : public ExtensionSystem::IPlugin
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "QmlProjectManager.json")
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
~QmlProjectPlugin()
|
|
|
|
|
{
|
|
|
|
|
if (d->lastMessageBox)
|
|
|
|
|
d->lastMessageBox->deleteLater();
|
|
|
|
|
if (d->landingPage)
|
|
|
|
|
d->landingPage->deleteLater();
|
|
|
|
|
if (d->landingPageWidget)
|
|
|
|
|
d->landingPageWidget->deleteLater();
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void editorModeChanged(Utils::Id newMode, Utils::Id oldMode);
|
|
|
|
|
void openQtc(bool permanent = false);
|
|
|
|
|
void openQds(bool permanent = false);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void initialize() final;
|
2024-01-18 10:14:05 +01:00
|
|
|
|
|
|
|
|
void extensionsInitialized() final
|
|
|
|
|
{
|
|
|
|
|
// These rely on the base tool factories being present:
|
|
|
|
|
static SimpleTargetRunnerFactory runWorkerFactory{{Constants::QML_RUNCONFIG_ID}};
|
|
|
|
|
static SimpleQmlProfilerRunnerFactory qmlProfilerRunWorkerFactory{{Constants::QML_RUNCONFIG_ID}};
|
|
|
|
|
static SimpleDebugRunnerFactory debugRunWorkerFactory{{Constants::QML_RUNCONFIG_ID}};
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 12:56:24 +01:00
|
|
|
void displayQmlLandingPage();
|
|
|
|
|
void hideQmlLandingPage();
|
|
|
|
|
void updateQmlLandingPageProjectInfo(const Utils::FilePath &projectFile);
|
|
|
|
|
|
|
|
|
|
class QmlProjectPluginPrivate *d = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-20 12:28:36 +01:00
|
|
|
void QmlProjectPlugin::initialize()
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2024-01-18 10:23:11 +01:00
|
|
|
setupQmlProjectRunConfiguration();
|
|
|
|
|
|
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()) {
|
2022-06-20 23:51:16 +02:00
|
|
|
d->landingPage = new QdsLandingPage();
|
|
|
|
|
qmlRegisterSingletonInstance<QdsLandingPage>("LandingPageApi",
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
"LandingPageApi",
|
|
|
|
|
d->landingPage);
|
|
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
d->landingPageWidget = new QdsLandingPageWidget();
|
|
|
|
|
|
2023-10-19 17:17:37 +02:00
|
|
|
const QStringList mimeTypes = {Utils::Constants::QMLUI_MIMETYPE};
|
2022-06-01 17:33:39 +03:00
|
|
|
auto context = new Internal::DesignModeContext(d->landingPageWidget);
|
2024-01-16 11:53:49 +01:00
|
|
|
ICore::addContextObject(context);
|
2022-06-01 17:33:39 +03:00
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
DesignMode::registerDesignWidget(d->landingPageWidget, mimeTypes, context->context());
|
2022-06-01 17:33:39 +03:00
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
|
2022-06-01 17:33:39 +03:00
|
|
|
this, &QmlProjectPlugin::editorModeChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 17:17:37 +02:00
|
|
|
ProjectManager::registerProjectType<QmlProject>(Utils::Constants::QMLPROJECT_MIMETYPE);
|
2024-01-16 11:53:49 +01:00
|
|
|
FileIconProvider::registerIconOverlayForSuffix(":/qmlproject/images/qmlproject.png",
|
|
|
|
|
"qmlproject");
|
2022-05-10 14:23:51 +02:00
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
if (ICore::isQtDesignStudio()) {
|
|
|
|
|
ActionContainer *menu = ActionManager::actionContainer(
|
2022-05-10 14:23:51 +02:00
|
|
|
ProjectExplorer::Constants::M_FILECONTEXT);
|
2023-01-19 15:36:40 +01:00
|
|
|
QAction *mainfileAction = new QAction(Tr::tr("Set as Main .qml File"), this);
|
2022-05-10 14:23:51 +02:00
|
|
|
mainfileAction->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
connect(mainfileAction, &QAction::triggered, this, []() {
|
|
|
|
|
const Node *currentNode = ProjectTree::currentNode();
|
|
|
|
|
if (!currentNode || !currentNode->asFileNode()
|
|
|
|
|
|| currentNode->asFileNode()->fileType() != FileType::QML)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
const FilePath file = currentNode->filePath();
|
2022-05-10 14:23:51 +02:00
|
|
|
|
|
|
|
|
QmlBuildSystem *buildSystem = qmlBuildSystemforFileNode(currentNode->asFileNode());
|
|
|
|
|
if (buildSystem)
|
|
|
|
|
buildSystem->setMainFileInProjectFile(file);
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
menu->addAction(ActionManager::registerAction(
|
2022-05-10 14:23:51 +02:00
|
|
|
mainfileAction,
|
|
|
|
|
"QmlProject.setMainFile",
|
2024-01-16 11:53:49 +01:00
|
|
|
Context(ProjectExplorer::Constants::C_PROJECT_TREE)),
|
2022-05-10 14:23:51 +02:00
|
|
|
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());
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-19 15:36:40 +01:00
|
|
|
QAction *mainUifileAction = new QAction(Tr::tr("Set as Main .ui.qml File"), this);
|
2022-05-10 14:23:51 +02:00
|
|
|
mainUifileAction->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
connect(mainUifileAction, &QAction::triggered, this, []() {
|
|
|
|
|
const Node *currentNode = ProjectTree::currentNode();
|
|
|
|
|
if (!currentNode || !currentNode->asFileNode()
|
|
|
|
|
|| currentNode->asFileNode()->fileType() != FileType::QML)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
const FilePath file = currentNode->filePath();
|
2022-05-10 14:23:51 +02:00
|
|
|
|
|
|
|
|
QmlBuildSystem *buildSystem = qmlBuildSystemforFileNode(currentNode->asFileNode());
|
|
|
|
|
if (buildSystem)
|
|
|
|
|
buildSystem->setMainUiFileInProjectFile(file);
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
menu->addAction(ActionManager::registerAction(
|
2022-05-10 14:23:51 +02:00
|
|
|
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-06-27 14:24:35 +02:00
|
|
|
GenerateCmake::generateMenuEntry(this);
|
2024-01-16 11:53:49 +01:00
|
|
|
if (ICore::isQtDesignStudio())
|
2022-07-20 10:36:44 +02:00
|
|
|
GenerateCmake::CmakeProjectConverter::generateMenuEntry(this);
|
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::displayQmlLandingPage()
|
|
|
|
|
{
|
2022-06-01 17:33:39 +03:00
|
|
|
if (!d->landingPage)
|
2022-06-20 23:51:16 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
d->landingPage->setWidget(d->landingPageWidget->widget());
|
2022-06-01 17:33:39 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
static bool isDesignerMode(Id mode)
|
2022-05-06 14:27:58 +03:00
|
|
|
{
|
|
|
|
|
return mode == Core::Constants::MODE_DESIGN;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
void QmlProjectPlugin::editorModeChanged(Id newMode, Id oldMode)
|
2022-05-06 14:27:58 +03:00
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
IEditor *currentEditor = EditorManager::currentEditor();
|
2022-05-06 14:27:58 +03:00
|
|
|
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();
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProjectPlugin::openQds(bool permanent)
|
|
|
|
|
{
|
|
|
|
|
if (permanent)
|
|
|
|
|
setAlwaysOpenWithMode(Core::Constants::MODE_DESIGN);
|
|
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
if (d->landingPage)
|
|
|
|
|
hideQmlLandingPage();
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
if (IEditor *editor = EditorManager::currentEditor())
|
2022-05-06 14:27:58 +03:00
|
|
|
openInQDSWithProject(editor->document()->filePath());
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
void QmlProjectPlugin::updateQmlLandingPageProjectInfo(const FilePath &projectFile)
|
2022-05-25 14:15:17 +03:00
|
|
|
{
|
2022-06-20 23:51:16 +02:00
|
|
|
if (!d->landingPage)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-01-16 11:53:49 +01:00
|
|
|
FilePath projectFilePath()
|
2022-05-06 14:27:58 +03:00
|
|
|
{
|
2024-01-16 11:53:49 +01:00
|
|
|
Project *project = ProjectManager::startupProject();
|
|
|
|
|
|
|
|
|
|
if (const QmlProject *qmlProject = qobject_cast<const QmlProject*>(project))
|
2022-05-06 14:27:58 +03:00
|
|
|
return qmlProject->projectFilePath();
|
2024-01-16 11:53:49 +01:00
|
|
|
|
|
|
|
|
if (project) {
|
|
|
|
|
FilePath projectFolder = project->rootProjectDirectory();
|
|
|
|
|
FilePath qmlProjectFile = findQmlProject(projectFolder);
|
2022-11-18 14:46:04 +01:00
|
|
|
if (qmlProjectFile.exists())
|
|
|
|
|
return qmlProjectFile;
|
|
|
|
|
}
|
2022-05-06 14:27:58 +03:00
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 13:56:00 +01:00
|
|
|
} // QmlProjectManager::Internal
|
2024-01-16 12:56:24 +01:00
|
|
|
|
|
|
|
|
#include "qmlprojectplugin.moc"
|