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
|
|
|
|
|
|
|
#include "qmlprojectplugin.h"
|
2009-05-07 12:27:52 +02:00
|
|
|
#include "qmlproject.h"
|
2019-03-13 12:22:44 +01:00
|
|
|
#include "qmlprojectrunconfiguration.h"
|
2009-11-11 10:10:00 +01:00
|
|
|
|
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>
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2017-03-03 18:16:34 +01:00
|
|
|
#include <projectexplorer/projectmanager.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>
|
|
|
|
|
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.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>
|
|
|
|
|
|
|
|
#include <utils/infobar.h>
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QPointer>
|
|
|
|
|
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
|
|
|
|
2021-09-21 12:31:19 +02:00
|
|
|
const char openInQDSAppSetting[] = "OpenInQDSAppUiQml";
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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;
|
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();
|
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:03:50 +01:00
|
|
|
const QString &qdsPath = QmlProjectPlugin::qdsInstallationEntry().toString();
|
2021-09-21 12:31:19 +02:00
|
|
|
bool qdsStarted = false;
|
|
|
|
//-a and -client arguments help to append project to open design studio application
|
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
|
|
|
qdsStarted = QProcess::startDetached("/usr/bin/open", {"-a", qdsPath, fileName.toString()});
|
|
|
|
else
|
|
|
|
qdsStarted = QProcess::startDetached(qdsPath, {"-client", fileName.toString()});
|
|
|
|
|
|
|
|
if (!qdsStarted) {
|
|
|
|
QMessageBox::warning(Core::ICore::dialogParent(),
|
|
|
|
fileName.fileName(),
|
|
|
|
QObject::tr("Failed to start Qt Design Studio."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
Utils::FilePath findQmlProject(const Utils::FilePath &folder)
|
|
|
|
{
|
|
|
|
QDir dir = folder.toDir();
|
|
|
|
for (const QString &file : dir.entryList({"*.qmlproject"}))
|
|
|
|
return Utils::FilePath::fromString(folder.toString() + "/" + file);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils::FilePath findQmlProjectUpwards(const Utils::FilePath &folder)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-09-21 12:31:19 +02:00
|
|
|
if (!qmlDesignerEnabled()) {
|
|
|
|
connect(Core::EditorManager::instance(),
|
|
|
|
&Core::EditorManager::currentEditorChanged,
|
|
|
|
[this](Core::IEditor *editor) {
|
|
|
|
QmlJS::ModelManagerInterface *modelManager
|
|
|
|
= QmlJS::ModelManagerInterface::instance();
|
|
|
|
|
|
|
|
if (!editor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (d->lastMessageBox)
|
|
|
|
return;
|
|
|
|
auto filePath = editor->document()->filePath();
|
|
|
|
QmlJS::Document::Ptr document = modelManager->ensuredGetDocumentForPath(
|
|
|
|
filePath.toString());
|
|
|
|
if (!document.isNull()
|
|
|
|
&& document->language() == QmlJS::Dialect::QmlQtQuick2Ui) {
|
|
|
|
|
|
|
|
const QString description = tr("Files of the type ui.qml are intended for Qt Design Studio.");
|
|
|
|
|
|
|
|
if (!qdsInstallationExists()) {
|
|
|
|
if (Core::ICore::infoBar()->canInfoBeAdded(openInQDSAppSetting)) {
|
|
|
|
Utils::InfoBarEntry
|
|
|
|
info(openInQDSAppSetting,
|
|
|
|
description + tr(" Learn more about Qt Design Studio here: ")
|
|
|
|
+ "<a href='https://www.qt.io/product/ui-design-tools'>Qt Design Studio</a>",
|
2021-11-11 15:03:49 +01:00
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Disabled);
|
2021-09-21 12:31:19 +02:00
|
|
|
Core::ICore::infoBar()->addInfo(info);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Core::ICore::infoBar()->canInfoBeAdded(openInQDSAppSetting)) {
|
|
|
|
Utils::InfoBarEntry
|
|
|
|
info(openInQDSAppSetting,
|
|
|
|
description + "\n" + tr("Do you want to open this file in Qt Design Studio?"),
|
2021-11-11 15:03:49 +01:00
|
|
|
Utils::InfoBarEntry::GlobalSuppression::Disabled);
|
2021-09-21 12:31:19 +02:00
|
|
|
info.setCustomButtonInfo(tr("Open in Qt Design Studio"), [filePath] {
|
|
|
|
Core::ICore::infoBar()->removeInfo(openInQDSAppSetting);
|
|
|
|
|
|
|
|
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."));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Core::ICore::infoBar()->addInfo(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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");
|
2009-05-04 12:19:22 +02:00
|
|
|
return true;
|
2021-09-21 12:31:19 +02:00
|
|
|
} // namespace Internal
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2018-02-15 14:51:31 +01:00
|
|
|
} // namespace Internal
|
2010-02-16 13:39:13 +01:00
|
|
|
} // namespace QmlProjectManager
|