2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-07 12:14:35 +01: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.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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
|
|
|
****************************************************************************/
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
#include "qmldesignerplugin.h"
|
2013-03-12 11:49:56 +01:00
|
|
|
#include "exception.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
#include "qmldesignerconstants.h"
|
2010-02-26 11:08:17 +01:00
|
|
|
#include "designmodewidget.h"
|
2010-02-09 16:01:47 +01:00
|
|
|
#include "settingspage.h"
|
2010-02-26 11:08:17 +01:00
|
|
|
#include "designmodecontext.h"
|
2016-06-23 15:09:32 +02:00
|
|
|
#include "openuiqmlfiledialog.h"
|
2019-08-27 20:10:36 +02:00
|
|
|
#include "generateresource.h"
|
2019-12-11 21:29:10 +02:00
|
|
|
#include "nodeinstanceview.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2016-06-07 18:15:46 +02:00
|
|
|
#include <metainfo.h>
|
2015-09-18 16:41:34 +02:00
|
|
|
#include <connectionview.h>
|
|
|
|
|
#include <sourcetool/sourcetool.h>
|
|
|
|
|
#include <colortool/colortool.h>
|
2020-01-17 15:58:12 +01:00
|
|
|
#include <annotationeditor/annotationtool.h>
|
2015-09-18 16:41:34 +02:00
|
|
|
#include <texttool/texttool.h>
|
2019-01-30 14:59:39 +01:00
|
|
|
#include <timelineeditor/timelineview.h>
|
2015-09-18 16:41:34 +02:00
|
|
|
#include <pathtool/pathtool.h>
|
|
|
|
|
|
2019-07-18 16:19:33 +02:00
|
|
|
#include <qmljseditor/qmljseditor.h>
|
2010-02-25 16:54:42 +01:00
|
|
|
#include <qmljseditor/qmljseditorconstants.h>
|
2019-07-18 16:19:33 +02:00
|
|
|
#include <qmljseditor/qmljseditordocument.h>
|
2010-02-25 16:54:42 +01:00
|
|
|
|
2014-10-15 12:24:05 +02:00
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
|
|
|
|
|
2010-06-25 17:37:59 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2010-06-25 17:37:59 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/designmode.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2016-06-07 17:54:08 +02:00
|
|
|
#include <coreplugin/messagebox.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <coreplugin/modemanager.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2013-07-04 15:44:58 +02:00
|
|
|
#include <extensionsystem/pluginspec.h>
|
2014-03-11 16:18:03 +01:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2013-01-23 12:31:22 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2016-06-23 15:09:32 +02:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2014-03-26 14:34:30 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
2014-01-07 18:19:05 +01:00
|
|
|
#include <QTimer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <qplugin.h>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QProcessEnvironment>
|
2017-03-10 10:39:18 +01:00
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QWindow>
|
2020-02-04 09:13:10 +01:00
|
|
|
#include <QApplication>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2020-01-15 14:39:23 +01:00
|
|
|
static Q_LOGGING_CATEGORY(qmldesignerLog, "qtc.qmldesigner", QtWarningMsg)
|
2016-11-08 12:17:20 +01:00
|
|
|
|
2018-02-06 16:51:28 +01:00
|
|
|
using namespace QmlDesigner::Internal;
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2019-07-18 16:19:33 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class QtQuickDesignerFactory : public QmlJSEditor::QmlJSEditorFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QtQuickDesignerFactory();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QtQuickDesignerFactory::QtQuickDesignerFactory()
|
|
|
|
|
: QmlJSEditorFactory(QmlJSEditor::Constants::C_QTQUICKDESIGNEREDITOR_ID)
|
|
|
|
|
{
|
|
|
|
|
setDisplayName(QCoreApplication::translate("OpenWith::Editors", "Qt Quick Designer"));
|
|
|
|
|
|
|
|
|
|
addMimeType(QmlJSTools::Constants::QMLUI_MIMETYPE);
|
|
|
|
|
setDocumentCreator([this]() {
|
|
|
|
|
auto document = new QmlJSEditor::QmlJSEditorDocument(id());
|
2019-10-30 12:16:25 +01:00
|
|
|
document->setIsDesignModePreferred(
|
|
|
|
|
QmlDesigner::DesignerSettings::getValue(
|
|
|
|
|
QmlDesigner::DesignerSettingsKey::ALWAYS_DESIGN_MODE).toBool());
|
2019-07-18 16:19:33 +02:00
|
|
|
return document;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2018-02-06 16:51:28 +01:00
|
|
|
class QmlDesignerPluginPrivate
|
|
|
|
|
{
|
2014-03-26 14:34:30 +01:00
|
|
|
public:
|
|
|
|
|
ViewManager viewManager;
|
|
|
|
|
DocumentManager documentManager;
|
|
|
|
|
ShortCutManager shortCutManager;
|
2018-02-06 16:51:28 +01:00
|
|
|
SettingsPage settingsPage;
|
|
|
|
|
DesignModeWidget mainWidget;
|
2014-03-26 14:34:30 +01:00
|
|
|
DesignerSettings settings;
|
2018-02-06 16:51:28 +01:00
|
|
|
DesignModeContext *context = nullptr;
|
2019-07-18 16:19:33 +02:00
|
|
|
QtQuickDesignerFactory m_qtQuickDesignerFactory;
|
2017-02-28 18:05:59 +01:00
|
|
|
bool blockEditorChange = false;
|
2014-03-26 14:34:30 +01:00
|
|
|
};
|
|
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
QmlDesignerPlugin *QmlDesignerPlugin::m_instance = nullptr;
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
static bool isInDesignerMode()
|
|
|
|
|
{
|
2018-07-10 15:49:50 +02:00
|
|
|
return Core::ModeManager::currentModeId() == Core::Constants::MODE_DESIGN;
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
2010-02-09 11:09:11 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
static bool checkIfEditorIsQtQuick(Core::IEditor *editor)
|
|
|
|
|
{
|
2019-07-18 16:19:33 +02:00
|
|
|
if (editor
|
|
|
|
|
&& (editor->document()->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID
|
|
|
|
|
|| editor->document()->id() == QmlJSEditor::Constants::C_QTQUICKDESIGNEREDITOR_ID)) {
|
2016-04-26 16:00:08 +02:00
|
|
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
|
|
|
|
QmlJS::Document::Ptr document = modelManager->ensuredGetDocumentForPath(editor->document()->filePath().toString());
|
|
|
|
|
if (!document.isNull())
|
2018-02-19 12:26:51 +01:00
|
|
|
return document->language() == QmlJS::Dialect::QmlQtQuick2
|
2016-04-26 16:00:08 +02:00
|
|
|
|| document->language() == QmlJS::Dialect::QmlQtQuick2Ui
|
|
|
|
|
|| document->language() == QmlJS::Dialect::Qml;
|
|
|
|
|
|
2018-07-10 15:49:50 +02:00
|
|
|
if (Core::ModeManager::currentModeId() == Core::Constants::MODE_DESIGN) {
|
2016-06-22 12:24:03 +02:00
|
|
|
Core::AsynchronousMessageBox::warning(QmlDesignerPlugin::tr("Cannot Open Design Mode"),
|
2016-06-08 21:40:07 +03:00
|
|
|
QmlDesignerPlugin::tr("The QML file is not currently opened in a QML Editor."));
|
|
|
|
|
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
|
|
|
|
}
|
2016-06-07 17:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool isDesignerMode(Core::Id mode)
|
|
|
|
|
{
|
2018-01-23 09:09:46 +01:00
|
|
|
return mode == Core::Constants::MODE_DESIGN;
|
2016-04-26 16:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool documentIsAlreadyOpen(DesignDocument *designDocument, Core::IEditor *editor, Core::Id newMode)
|
|
|
|
|
{
|
|
|
|
|
return designDocument
|
|
|
|
|
&& editor == designDocument->editor()
|
|
|
|
|
&& isDesignerMode(newMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool shouldAssertInException()
|
2010-03-24 12:55:10 +01:00
|
|
|
{
|
|
|
|
|
QProcessEnvironment processEnvironment = QProcessEnvironment::systemEnvironment();
|
|
|
|
|
return !processEnvironment.value("QMLDESIGNER_ASSERT_ON_EXCEPTION").isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 11:43:04 +02:00
|
|
|
static bool warningsForQmlFilesInsteadOfUiQmlEnabled()
|
|
|
|
|
{
|
2017-01-19 13:46:37 +01:00
|
|
|
return DesignerSettings::getValue(DesignerSettingsKey::WARNING_FOR_QML_FILES_INSTEAD_OF_UIQML_FILES).toBool();
|
2016-10-24 11:43:04 +02:00
|
|
|
}
|
|
|
|
|
|
2014-03-26 14:34:30 +01:00
|
|
|
QmlDesignerPlugin::QmlDesignerPlugin()
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2014-03-26 14:34:30 +01:00
|
|
|
m_instance = this;
|
2010-01-07 15:13:01 +01:00
|
|
|
// Exceptions should never ever assert: they are handled in a number of
|
|
|
|
|
// places where it is actually VALID AND EXPECTED BEHAVIOUR to get an
|
|
|
|
|
// exception.
|
|
|
|
|
// If you still want to see exactly where the exception originally
|
|
|
|
|
// occurred, then you have various ways to do this:
|
|
|
|
|
// 1. set a breakpoint on the constructor of the exception
|
|
|
|
|
// 2. in gdb: "catch throw" or "catch throw Exception"
|
|
|
|
|
// 3. set a breakpoint on __raise_exception()
|
|
|
|
|
// And with gdb, you can even do this from your ~/.gdbinit file.
|
2010-03-24 12:55:10 +01:00
|
|
|
// DnD is not working with gdb so this is still needed to get a good stacktrace
|
|
|
|
|
|
|
|
|
|
Exception::setShouldAssert(shouldAssertInException());
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
QmlDesignerPlugin::~QmlDesignerPlugin()
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
if (d) {
|
2018-02-06 16:51:28 +01:00
|
|
|
Core::DesignMode::unregisterDesignWidget(&d->mainWidget);
|
2016-04-26 16:00:08 +02:00
|
|
|
Core::ICore::removeContextObject(d->context);
|
|
|
|
|
d->context = nullptr;
|
2014-03-26 14:34:30 +01:00
|
|
|
}
|
2016-04-26 16:00:08 +02:00
|
|
|
delete d;
|
|
|
|
|
d = nullptr;
|
|
|
|
|
m_instance = nullptr;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// INHERITED FROM ExtensionSystem::Plugin
|
|
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////
|
2019-08-27 20:10:36 +02:00
|
|
|
bool QmlDesignerPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage/* = 0*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2015-09-29 16:43:42 +02:00
|
|
|
if (!Utils::HostOsInfo::canCreateOpenGLContext(errorMessage))
|
2015-09-25 13:14:31 +02:00
|
|
|
return false;
|
2016-04-26 16:00:08 +02:00
|
|
|
d = new QmlDesignerPluginPrivate;
|
2019-08-27 20:10:36 +02:00
|
|
|
if (DesignerSettings::getValue(DesignerSettingsKey::STANDALONE_MODE).toBool())
|
|
|
|
|
GenerateResource::generateMenuEntry();
|
|
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-03-26 14:34:30 +01:00
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
bool QmlDesignerPlugin::delayedInitialize()
|
|
|
|
|
{
|
2016-06-07 18:15:46 +02:00
|
|
|
// adding default path to item library plugins
|
|
|
|
|
const QString pluginPath = Utils::HostOsInfo::isMacHost()
|
|
|
|
|
? QString(QCoreApplication::applicationDirPath() + "/../PlugIns/QmlDesigner")
|
|
|
|
|
: QString(QCoreApplication::applicationDirPath() + "/../"
|
|
|
|
|
+ QLatin1String(IDE_LIBRARY_BASENAME) + "/qtcreator/plugins/qmldesigner");
|
|
|
|
|
MetaInfo::setPluginPaths(QStringList(pluginPath));
|
|
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
d->settings.fromSettings(Core::ICore::settings());
|
|
|
|
|
|
2019-01-30 14:59:39 +01:00
|
|
|
d->viewManager.registerViewTakingOwnership(new QmlDesigner::Internal::ConnectionView);
|
2019-03-26 17:03:03 +01:00
|
|
|
if (DesignerSettings::getValue(DesignerSettingsKey::ENABLE_TIMELINEVIEW).toBool()) {
|
|
|
|
|
auto timelineView = new QmlDesigner::TimelineView;
|
|
|
|
|
d->viewManager.registerViewTakingOwnership(timelineView);
|
|
|
|
|
timelineView->registerActions();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
d->viewManager.registerFormEditorToolTakingOwnership(new QmlDesigner::SourceTool);
|
|
|
|
|
d->viewManager.registerFormEditorToolTakingOwnership(new QmlDesigner::ColorTool);
|
2020-01-17 15:58:12 +01:00
|
|
|
d->viewManager.registerFormEditorToolTakingOwnership(new QmlDesigner::AnnotationTool);
|
2017-01-23 17:42:26 +01:00
|
|
|
d->viewManager.registerFormEditorToolTakingOwnership(new QmlDesigner::TextTool);
|
|
|
|
|
d->viewManager.registerFormEditorToolTakingOwnership(new QmlDesigner::PathTool);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2014-03-26 14:34:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-03-17 14:14:00 +01:00
|
|
|
|
2014-03-26 14:34:30 +01:00
|
|
|
void QmlDesignerPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2018-07-12 10:46:43 +02:00
|
|
|
Core::DesignMode::setDesignModeIsRequired();
|
2018-07-06 09:11:05 +02:00
|
|
|
// delay after Core plugin's extensionsInitialized, so the DesignMode is availabe
|
|
|
|
|
connect(Core::ICore::instance(), &Core::ICore::coreAboutToOpen, this, [this] {
|
|
|
|
|
integrateIntoQtCreator(&d->mainWidget);
|
|
|
|
|
});
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
static QStringList allUiQmlFilesforCurrentProject(const Utils::FilePath &fileName)
|
2016-06-23 15:09:32 +02:00
|
|
|
{
|
|
|
|
|
QStringList list;
|
|
|
|
|
ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(fileName);
|
|
|
|
|
|
|
|
|
|
if (currentProject) {
|
2019-05-28 13:49:26 +02:00
|
|
|
foreach (const Utils::FilePath &fileName, currentProject->files(ProjectExplorer::Project::SourceFiles)) {
|
2016-06-23 15:09:32 +02:00
|
|
|
if (fileName.endsWith(".ui.qml"))
|
2017-12-06 10:27:27 +01:00
|
|
|
list.append(fileName.toString());
|
2016-06-23 15:09:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
static QString projectPath(const Utils::FilePath &fileName)
|
2016-06-23 15:09:32 +02:00
|
|
|
{
|
|
|
|
|
QString path;
|
|
|
|
|
ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(fileName);
|
|
|
|
|
|
|
|
|
|
if (currentProject)
|
|
|
|
|
path = currentProject->projectDirectory().toString();
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
void QmlDesignerPlugin::integrateIntoQtCreator(QWidget *modeWidget)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2017-01-23 17:42:26 +01:00
|
|
|
d->context = new Internal::DesignModeContext(modeWidget);
|
2016-04-26 16:00:08 +02:00
|
|
|
Core::ICore::addContextObject(d->context);
|
2010-11-17 12:59:08 +01:00
|
|
|
Core::Context qmlDesignerMainContext(Constants::C_QMLDESIGNER);
|
|
|
|
|
Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR);
|
2011-04-28 17:15:27 +02:00
|
|
|
Core::Context qmlDesignerNavigatorContext(Constants::C_QMLNAVIGATOR);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
d->context->context().add(qmlDesignerMainContext);
|
|
|
|
|
d->context->context().add(qmlDesignerFormEditorContext);
|
|
|
|
|
d->context->context().add(qmlDesignerNavigatorContext);
|
2017-01-30 14:59:10 +01:00
|
|
|
d->context->context().add(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
d->shortCutManager.registerActions(qmlDesignerMainContext, qmlDesignerFormEditorContext, qmlDesignerNavigatorContext);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
const QStringList mimeTypes = { QmlJSTools::Constants::QML_MIMETYPE,
|
|
|
|
|
QmlJSTools::Constants::QMLUI_MIMETYPE };
|
|
|
|
|
|
2018-01-23 09:09:46 +01:00
|
|
|
Core::DesignMode::registerDesignWidget(modeWidget, mimeTypes, d->context->context());
|
2017-01-23 17:42:26 +01:00
|
|
|
|
2018-07-06 09:11:05 +02:00
|
|
|
connect(Core::DesignMode::instance(), &Core::DesignMode::actionsUpdated,
|
|
|
|
|
&d->shortCutManager, &ShortCutManager::updateActions);
|
|
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, [this] (Core::IEditor *editor) {
|
2017-01-26 16:07:34 +01:00
|
|
|
if (d && checkIfEditorIsQtQuick(editor) && isInDesignerMode())
|
2016-04-26 16:00:08 +02:00
|
|
|
changeEditor();
|
|
|
|
|
});
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2017-01-23 17:42:26 +01:00
|
|
|
connect(Core::EditorManager::instance(), &Core::EditorManager::editorsClosed, [this] (QList<Core::IEditor*> editors) {
|
2016-04-26 16:00:08 +02:00
|
|
|
if (d) {
|
|
|
|
|
if (d->documentManager.hasCurrentDesignDocument()
|
2016-10-07 14:16:49 +02:00
|
|
|
&& editors.contains(currentDesignDocument()->textEditor()))
|
2016-04-26 16:00:08 +02:00
|
|
|
hideDesigner();
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
d->documentManager.removeEditors(editors);
|
|
|
|
|
}
|
|
|
|
|
});
|
2010-03-26 12:39:26 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged,
|
2017-01-23 17:42:26 +01:00
|
|
|
[this] (Core::Id newMode, Core::Id oldMode) {
|
2016-06-23 15:09:32 +02:00
|
|
|
|
2016-10-06 18:30:18 +02:00
|
|
|
Core::IEditor *currentEditor = Core::EditorManager::currentEditor();
|
|
|
|
|
if (d && currentEditor && checkIfEditorIsQtQuick(currentEditor) &&
|
|
|
|
|
!documentIsAlreadyOpen(currentDesignDocument(), currentEditor, newMode)) {
|
2016-04-26 16:00:08 +02:00
|
|
|
|
2017-03-13 15:09:11 +01:00
|
|
|
if (isDesignerMode(newMode)) {
|
2016-04-26 16:00:08 +02:00
|
|
|
showDesigner();
|
2017-03-13 15:09:11 +01:00
|
|
|
} else if (currentDesignDocument() ||
|
|
|
|
|
(!isDesignerMode(newMode) && isDesignerMode(oldMode))) {
|
|
|
|
|
hideDesigner();
|
|
|
|
|
}
|
2016-04-26 16:00:08 +02:00
|
|
|
}
|
|
|
|
|
});
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::showDesigner()
|
2010-02-26 14:28:26 +01:00
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
QTC_ASSERT(!d->documentManager.hasCurrentDesignDocument(), return);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2018-02-06 16:51:28 +01:00
|
|
|
d->mainWidget.initialize();
|
2016-06-23 15:09:32 +02:00
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
const Utils::FilePath fileName = Core::EditorManager::currentEditor()->document()->filePath();
|
2016-06-23 15:09:32 +02:00
|
|
|
const QStringList allUiQmlFiles = allUiQmlFilesforCurrentProject(fileName);
|
|
|
|
|
if (warningsForQmlFilesInsteadOfUiQmlEnabled() && !fileName.endsWith(".ui.qml") && !allUiQmlFiles.isEmpty()) {
|
2018-02-06 16:51:28 +01:00
|
|
|
OpenUiQmlFileDialog dialog(&d->mainWidget);
|
2016-06-23 15:09:32 +02:00
|
|
|
dialog.setUiQmlFiles(projectPath(fileName), allUiQmlFiles);
|
|
|
|
|
dialog.exec();
|
|
|
|
|
if (dialog.uiFileOpened()) {
|
|
|
|
|
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
|
|
|
|
Core::EditorManager::openEditorAt(dialog.uiQmlFile(), 0, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
d->shortCutManager.disconnectUndoActions(currentDesignDocument());
|
|
|
|
|
d->documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor());
|
|
|
|
|
d->shortCutManager.connectUndoActions(currentDesignDocument());
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
if (d->documentManager.hasCurrentDesignDocument()) {
|
2013-01-23 12:31:22 +01:00
|
|
|
activateAutoSynchronization();
|
2016-04-26 16:00:08 +02:00
|
|
|
d->shortCutManager.updateActions(currentDesignDocument()->textEditor());
|
2016-10-07 14:16:49 +02:00
|
|
|
d->viewManager.pushFileOnCrumbleBar(currentDesignDocument()->fileName());
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
d->shortCutManager.updateUndoActions(currentDesignDocument());
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::hideDesigner()
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
if (d->documentManager.hasCurrentDesignDocument()) {
|
2013-01-23 12:31:22 +01:00
|
|
|
deactivateAutoSynchronization();
|
2018-02-06 16:51:28 +01:00
|
|
|
d->mainWidget.saveSettings();
|
2010-02-26 14:28:26 +01:00
|
|
|
}
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
d->shortCutManager.disconnectUndoActions(currentDesignDocument());
|
|
|
|
|
d->documentManager.setCurrentDesignDocument(nullptr);
|
|
|
|
|
d->shortCutManager.updateUndoActions(nullptr);
|
2010-02-26 14:28:26 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::changeEditor()
|
2010-03-16 17:17:09 +01:00
|
|
|
{
|
2017-02-28 18:05:59 +01:00
|
|
|
if (d->blockEditorChange)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
if (d->documentManager.hasCurrentDesignDocument()) {
|
2013-01-23 12:31:22 +01:00
|
|
|
deactivateAutoSynchronization();
|
2018-02-06 16:51:28 +01:00
|
|
|
d->mainWidget.saveSettings();
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
d->shortCutManager.disconnectUndoActions(currentDesignDocument());
|
|
|
|
|
d->documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor());
|
2018-02-06 16:51:28 +01:00
|
|
|
d->mainWidget.initialize();
|
2016-04-26 16:00:08 +02:00
|
|
|
d->shortCutManager.connectUndoActions(currentDesignDocument());
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
if (d->documentManager.hasCurrentDesignDocument()) {
|
2013-01-23 12:31:22 +01:00
|
|
|
activateAutoSynchronization();
|
2016-10-07 14:16:49 +02:00
|
|
|
d->viewManager.pushFileOnCrumbleBar(currentDesignDocument()->fileName());
|
2016-04-26 16:00:08 +02:00
|
|
|
d->viewManager.setComponentViewToMaster();
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
d->shortCutManager.updateUndoActions(currentDesignDocument());
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::jumpTextCursorToSelectedModelNode()
|
|
|
|
|
{
|
|
|
|
|
// visual editor -> text editor
|
|
|
|
|
ModelNode selectedNode;
|
2014-06-26 11:25:04 +02:00
|
|
|
if (!rewriterView()->selectedModelNodes().isEmpty())
|
2018-01-13 18:49:39 +01:00
|
|
|
selectedNode = rewriterView()->selectedModelNodes().constFirst();
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
if (selectedNode.isValid()) {
|
2014-06-26 11:25:04 +02:00
|
|
|
const int nodeOffset = rewriterView()->nodeOffset(selectedNode);
|
2013-01-23 12:31:22 +01:00
|
|
|
if (nodeOffset > 0) {
|
2016-04-26 16:00:08 +02:00
|
|
|
const ModelNode currentSelectedNode = rewriterView()->
|
|
|
|
|
nodeAtTextCursorPosition(currentDesignDocument()->plainTextEdit()->textCursor().position());
|
2013-01-23 12:31:22 +01:00
|
|
|
if (currentSelectedNode != selectedNode) {
|
|
|
|
|
int line, column;
|
|
|
|
|
currentDesignDocument()->textEditor()->convertPosition(nodeOffset, &line, &column);
|
2018-11-02 14:17:12 +01:00
|
|
|
// line has to be 1 based, column 0 based!
|
|
|
|
|
currentDesignDocument()->textEditor()->gotoLine(line, column - 1);
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
2010-03-16 17:17:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
2010-03-26 12:39:26 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::selectModelNodeUnderTextCursor()
|
|
|
|
|
{
|
2014-05-06 12:41:51 +02:00
|
|
|
const int cursorPosition = currentDesignDocument()->plainTextEdit()->textCursor().position();
|
2014-06-26 11:25:04 +02:00
|
|
|
ModelNode modelNode = rewriterView()->nodeAtTextCursorPosition(cursorPosition);
|
2014-05-06 12:41:51 +02:00
|
|
|
if (modelNode.isValid())
|
2014-06-26 11:25:04 +02:00
|
|
|
rewriterView()->setSelectedModelNode(modelNode);
|
2010-03-16 17:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::activateAutoSynchronization()
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
// text editor -> visual editor
|
2013-11-11 22:20:47 +02:00
|
|
|
if (!currentDesignDocument()->isDocumentLoaded())
|
2013-01-23 12:31:22 +01:00
|
|
|
currentDesignDocument()->loadDocument(currentDesignDocument()->plainTextEdit());
|
|
|
|
|
|
2019-10-30 08:25:31 +01:00
|
|
|
currentDesignDocument()->updateActiveTarget();
|
|
|
|
|
currentDesignDocument()->updateActiveTarget();
|
2018-02-06 16:51:28 +01:00
|
|
|
d->mainWidget.enableWidgets();
|
2013-08-01 11:48:36 +02:00
|
|
|
currentDesignDocument()->attachRewriterToModel();
|
2013-02-04 15:03:46 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
resetModelSelection();
|
|
|
|
|
|
2013-02-06 13:47:29 +01:00
|
|
|
viewManager().attachComponentView();
|
|
|
|
|
viewManager().attachViewsExceptRewriterAndComponetView();
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-10 16:36:55 +01:00
|
|
|
selectModelNodeUnderTextCursor();
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2018-02-06 16:51:28 +01:00
|
|
|
d->mainWidget.setupNavigatorHistory(currentDesignDocument()->textEditor());
|
2013-01-23 12:31:22 +01:00
|
|
|
|
2017-01-10 16:36:55 +01:00
|
|
|
currentDesignDocument()->updateSubcomponentManager();
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::deactivateAutoSynchronization()
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
viewManager().detachViewsExceptRewriterAndComponetView();
|
|
|
|
|
viewManager().detachComponentView();
|
2013-02-04 15:03:46 +01:00
|
|
|
viewManager().detachRewriterView();
|
|
|
|
|
documentManager().currentDesignDocument()->resetToDocumentModel();
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::resetModelSelection()
|
|
|
|
|
{
|
2016-11-08 12:17:20 +01:00
|
|
|
if (!rewriterView()) {
|
|
|
|
|
qCWarning(qmldesignerLog) << "No rewriter existing while calling resetModelSelection";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!currentModel()) {
|
|
|
|
|
qCWarning(qmldesignerLog) << "No current QmlDesigner document model while calling resetModelSelection";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
rewriterView()->setSelectedModelNodes(QList<ModelNode>());
|
2014-06-26 11:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RewriterView *QmlDesignerPlugin::rewriterView() const
|
|
|
|
|
{
|
|
|
|
|
return currentDesignDocument()->rewriterView();
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-30 14:58:11 +02:00
|
|
|
Model *QmlDesignerPlugin::currentModel() const
|
|
|
|
|
{
|
|
|
|
|
return currentDesignDocument()->currentModel();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
DesignDocument *QmlDesignerPlugin::currentDesignDocument() const
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
if (d)
|
|
|
|
|
return d->documentManager.currentDesignDocument();
|
2014-03-26 14:34:30 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
return nullptr;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
Internal::DesignModeWidget *QmlDesignerPlugin::mainWidget() const
|
2010-02-09 11:09:11 +01:00
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
if (d)
|
2018-02-06 16:51:28 +01:00
|
|
|
return &d->mainWidget;
|
2014-03-26 14:34:30 +01:00
|
|
|
|
2016-04-26 16:00:08 +02:00
|
|
|
return nullptr;
|
2010-02-09 11:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-01 10:25:07 +01:00
|
|
|
QWidget *QmlDesignerPlugin::createProjectExplorerWidget(QWidget *parent) const
|
|
|
|
|
{
|
|
|
|
|
return Internal::DesignModeWidget::createProjectExplorerWidget(parent);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-07 18:19:05 +01:00
|
|
|
void QmlDesignerPlugin::switchToTextModeDeferred()
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
QTimer::singleShot(0, this, [] () {
|
|
|
|
|
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
|
|
|
|
});
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-28 18:05:59 +01:00
|
|
|
void QmlDesignerPlugin::emitCurrentTextEditorChanged(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
d->blockEditorChange = true;
|
2019-01-16 18:06:21 +01:00
|
|
|
emit Core::EditorManager::instance()->currentEditorChanged(editor);
|
2017-02-28 18:05:59 +01:00
|
|
|
d->blockEditorChange = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-10 10:39:18 +01:00
|
|
|
double QmlDesignerPlugin::formEditorDevicePixelRatio()
|
|
|
|
|
{
|
|
|
|
|
if (DesignerSettings::getValue(DesignerSettingsKey::IGNORE_DEVICE_PIXEL_RATIO).toBool())
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
const QList<QWindow *> topLevelWindows = QApplication::topLevelWindows();
|
|
|
|
|
if (topLevelWindows.isEmpty())
|
|
|
|
|
return 1;
|
2018-01-13 18:49:39 +01:00
|
|
|
return topLevelWindows.constFirst()->screen()->devicePixelRatio();
|
2017-03-10 10:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
QmlDesignerPlugin *QmlDesignerPlugin::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentManager &QmlDesignerPlugin::documentManager()
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
return d->documentManager;
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DocumentManager &QmlDesignerPlugin::documentManager() const
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
return d->documentManager;
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewManager &QmlDesignerPlugin::viewManager()
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
return d->viewManager;
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ViewManager &QmlDesignerPlugin::viewManager() const
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
return d->viewManager;
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-18 13:28:44 +02:00
|
|
|
DesignerActionManager &QmlDesignerPlugin::designerActionManager()
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
return d->viewManager.designerActionManager();
|
2013-09-18 13:28:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DesignerActionManager &QmlDesignerPlugin::designerActionManager() const
|
|
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
return d->viewManager.designerActionManager();
|
2014-01-07 18:19:05 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
DesignerSettings QmlDesignerPlugin::settings()
|
2010-02-09 11:09:11 +01:00
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
d->settings.fromSettings(Core::ICore::settings());
|
|
|
|
|
return d->settings;
|
2010-02-09 11:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::setSettings(const DesignerSettings &s)
|
2010-02-09 11:09:11 +01:00
|
|
|
{
|
2016-04-26 16:00:08 +02:00
|
|
|
if (s != d->settings) {
|
|
|
|
|
d->settings = s;
|
|
|
|
|
d->settings.toSettings(Core::ICore::settings());
|
2010-02-09 11:09:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 16:19:33 +02:00
|
|
|
} // namespace QmlDesigner
|