2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-01-07 15:13:01 +01:00
|
|
|
#include "exception.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
#include "qmldesignerplugin.h"
|
|
|
|
|
#include "qmldesignerconstants.h"
|
|
|
|
|
#include "pluginmanager.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"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-25 16:54:42 +01:00
|
|
|
#include <qmljseditor/qmljseditorconstants.h>
|
|
|
|
|
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2010-06-25 17:37:59 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-02-25 16:54:42 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-06-25 17:37:59 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/designmode.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <coreplugin/dialogs/iwizard.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2010-06-25 17:37:59 +02:00
|
|
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <coreplugin/editormanager/openeditorsmodel.h>
|
2010-06-25 17:37:59 +02:00
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <coreplugin/modemanager.h>
|
2010-06-25 17:37:59 +02:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <qplugin.h>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QProcessEnvironment>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
QmlDesignerPlugin *QmlDesignerPlugin::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
static bool isQmlFile(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
return editor && editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool isInDesignerMode()
|
|
|
|
|
{
|
|
|
|
|
return Core::ModeManager::currentMode() == Core::DesignMode::instance();
|
|
|
|
|
}
|
2010-02-09 11:09:11 +01:00
|
|
|
|
2010-03-24 12:55:10 +01:00
|
|
|
bool shouldAssertInException()
|
|
|
|
|
{
|
|
|
|
|
QProcessEnvironment processEnvironment = QProcessEnvironment::systemEnvironment();
|
|
|
|
|
return !processEnvironment.value("QMLDESIGNER_ASSERT_ON_EXCEPTION").isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
QmlDesignerPlugin::QmlDesignerPlugin() :
|
|
|
|
|
m_isActive(false)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-03-12 16:02:23 +01:00
|
|
|
|
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
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::ICore::removeContextObject(m_context);
|
2013-01-23 12:31:22 +01:00
|
|
|
m_context = 0;
|
|
|
|
|
m_instance = 0;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// INHERITED FROM ExtensionSystem::Plugin
|
|
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////
|
2013-01-23 12:31:22 +01:00
|
|
|
bool QmlDesignerPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage/* = 0*/) // =0;
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-11-17 12:59:08 +01:00
|
|
|
const Core::Context switchContext(QmlDesigner::Constants::C_QMLDESIGNER,
|
2010-06-28 10:07:05 +02:00
|
|
|
QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
|
2010-02-25 16:54:42 +01:00
|
|
|
|
|
|
|
|
QAction *switchAction = new QAction(tr("Switch Text/Design"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(
|
|
|
|
|
switchAction, QmlDesigner::Constants::SWITCH_TEXT_DESIGN, switchContext);
|
2010-02-25 16:54:42 +01:00
|
|
|
command->setDefaultKeySequence(QKeySequence(Qt::Key_F4));
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
m_instance = this;
|
2010-02-09 11:09:11 +01:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
const QString pluginPath = Utils::HostOsInfo::isMacHost()
|
|
|
|
|
? QString(QCoreApplication::applicationDirPath() + "/../PlugIns/QmlDesigner")
|
|
|
|
|
: QString(QCoreApplication::applicationDirPath() + "/../"
|
|
|
|
|
+ QLatin1String(IDE_LIBRARY_BASENAME) + "/qtcreator/qmldesigner");
|
2012-08-29 12:40:38 +02:00
|
|
|
m_pluginManager.setPluginPaths(QStringList() << pluginPath);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-26 11:08:17 +01:00
|
|
|
createDesignModeWidget();
|
2010-03-08 14:54:24 +01:00
|
|
|
connect(switchAction, SIGNAL(triggered()), this, SLOT(switchTextDesign()));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
addAutoReleasedObject(new Internal::SettingsPage);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-03-17 14:14:00 +01:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
m_settings.fromSettings(Core::ICore::settings());
|
2010-07-06 11:11:27 +02:00
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
errorMessage->clear();
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::createDesignModeWidget()
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
m_mainWidget = new Internal::DesignModeWidget;
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
m_context = new Internal::DesignModeContext(m_mainWidget);
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::ICore::addContextObject(m_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
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
m_context->context().add(qmlDesignerMainContext);
|
|
|
|
|
m_context->context().add(qmlDesignerFormEditorContext);
|
|
|
|
|
m_context->context().add(qmlDesignerNavigatorContext);
|
|
|
|
|
m_context->context().add(ProjectExplorer::Constants::LANG_QMLJS);
|
|
|
|
|
|
2013-02-11 13:28:59 +01:00
|
|
|
m_shortCutManager.registerActions(qmlDesignerMainContext, qmlDesignerFormEditorContext, qmlDesignerNavigatorContext);
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
connect(Core::ICore::editorManager(),
|
|
|
|
|
SIGNAL(currentEditorChanged(Core::IEditor*)),
|
|
|
|
|
this,
|
|
|
|
|
SLOT(onCurrentEditorChanged(Core::IEditor*)));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
connect(Core::ICore::editorManager(),
|
|
|
|
|
SIGNAL(editorsClosed(QList<Core::IEditor*>)),
|
|
|
|
|
this,
|
|
|
|
|
SLOT(onTextEditorsClosed(QList<Core::IEditor*>)));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
// connect(Core::ICore::editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
|
|
|
|
// &m_documentManager, SLOT(currentTextEditorChanged(Core::IEditor*)));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
// connect(Core::ICore::instance(), SIGNAL(contextChanged(Core::IContext*,Core::Context)),
|
|
|
|
|
// this, SLOT(contextChanged(Core::IContext*,Core::Context)));
|
|
|
|
|
|
|
|
|
|
connect(Core::ModeManager::instance(),
|
|
|
|
|
SIGNAL(currentModeChanged(Core::IMode*,Core::IMode*)),
|
|
|
|
|
SLOT(onCurrentModeChanged(Core::IMode*,Core::IMode*)));
|
2010-03-26 12:39:26 +01: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
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
Q_ASSERT(!m_documentManager.hasCurrentDesignDocument());
|
|
|
|
|
|
|
|
|
|
m_shortCutManager.disconnectUndoActions(currentDesignDocument());
|
|
|
|
|
|
|
|
|
|
m_documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor());
|
|
|
|
|
|
|
|
|
|
m_shortCutManager.connectUndoActions(currentDesignDocument());
|
|
|
|
|
|
|
|
|
|
m_mainWidget->initialize();
|
|
|
|
|
|
|
|
|
|
if (m_documentManager.hasCurrentDesignDocument()) {
|
|
|
|
|
activateAutoSynchronization();
|
2013-02-04 18:49:56 +01:00
|
|
|
m_shortCutManager.updateActions(currentDesignDocument()->textEditor());
|
2013-01-23 12:31:22 +01:00
|
|
|
m_viewManager.pushFileOnCrambleBar(m_documentManager.currentDesignDocument()->fileName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_shortCutManager.updateUndoActions(currentDesignDocument());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::hideDesigner()
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument()->currentModel()
|
|
|
|
|
&& !currentDesignDocument()->hasQmlSyntaxErrors())
|
|
|
|
|
jumpTextCursorToSelectedModelNode();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_documentManager.hasCurrentDesignDocument()) {
|
|
|
|
|
deactivateAutoSynchronization();
|
|
|
|
|
m_mainWidget->saveSettings();
|
2010-02-26 14:28:26 +01:00
|
|
|
}
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
m_shortCutManager.disconnectUndoActions(currentDesignDocument());
|
|
|
|
|
|
|
|
|
|
m_documentManager.setCurrentDesignDocument(0);
|
|
|
|
|
|
|
|
|
|
m_shortCutManager.updateUndoActions(0);
|
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
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
if (m_documentManager.hasCurrentDesignDocument()) {
|
|
|
|
|
deactivateAutoSynchronization();
|
|
|
|
|
m_mainWidget->saveSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_shortCutManager.disconnectUndoActions(currentDesignDocument());
|
|
|
|
|
|
|
|
|
|
m_documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor());
|
|
|
|
|
|
|
|
|
|
m_mainWidget->initialize();
|
|
|
|
|
|
|
|
|
|
m_shortCutManager.connectUndoActions(currentDesignDocument());
|
2010-03-26 12:39:26 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
if (m_documentManager.hasCurrentDesignDocument()) {
|
|
|
|
|
activateAutoSynchronization();
|
2013-02-06 13:12:55 +01:00
|
|
|
m_viewManager.pushFileOnCrambleBar(m_documentManager.currentDesignDocument()->fileName());
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_shortCutManager.updateUndoActions(currentDesignDocument());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::jumpTextCursorToSelectedModelNode()
|
|
|
|
|
{
|
|
|
|
|
// visual editor -> text editor
|
|
|
|
|
ModelNode selectedNode;
|
|
|
|
|
if (!currentDesignDocument()->rewriterView()->selectedModelNodes().isEmpty())
|
|
|
|
|
selectedNode = currentDesignDocument()->rewriterView()->selectedModelNodes().first();
|
|
|
|
|
|
|
|
|
|
if (selectedNode.isValid()) {
|
|
|
|
|
const int nodeOffset = currentDesignDocument()->rewriterView()->nodeOffset(selectedNode);
|
|
|
|
|
if (nodeOffset > 0) {
|
|
|
|
|
const ModelNode currentSelectedNode
|
|
|
|
|
= currentDesignDocument()->rewriterView()->nodeAtTextCursorPosition(currentDesignDocument()->plainTextEdit()->textCursor().position());
|
|
|
|
|
if (currentSelectedNode != selectedNode) {
|
|
|
|
|
int line, column;
|
|
|
|
|
currentDesignDocument()->textEditor()->convertPosition(nodeOffset, &line, &column);
|
|
|
|
|
currentDesignDocument()->textEditor()->gotoLine(line, column);
|
|
|
|
|
}
|
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()
|
|
|
|
|
{
|
|
|
|
|
const int cursorPos = currentDesignDocument()->plainTextEdit()->textCursor().position();
|
|
|
|
|
ModelNode node = currentDesignDocument()->rewriterView()->nodeAtTextCursorPosition(cursorPos);
|
|
|
|
|
if (currentDesignDocument()->rewriterView() && node.isValid()) {
|
|
|
|
|
currentDesignDocument()->rewriterView()->setSelectedModelNodes(QList<ModelNode>() << node);
|
2010-03-26 12:39:26 +01:00
|
|
|
}
|
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
|
|
|
|
|
if (!currentDesignDocument()->isDocumentLoaded()) {
|
|
|
|
|
currentDesignDocument()->loadDocument(currentDesignDocument()->plainTextEdit());
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-04 15:03:46 +01:00
|
|
|
currentDesignDocument()->activateDocumentModel();
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
QList<RewriterView::Error> errors = currentDesignDocument()->qmlSyntaxErrors();
|
|
|
|
|
if (errors.isEmpty()) {
|
|
|
|
|
selectModelNodeUnderTextCursor();
|
|
|
|
|
m_mainWidget->enableWidgets();
|
2013-02-11 13:31:03 +01:00
|
|
|
m_mainWidget->setupNavigatorHistory(currentDesignDocument()->textEditor());
|
2013-01-23 12:31:22 +01:00
|
|
|
} else {
|
|
|
|
|
m_mainWidget->disableWidgets();
|
|
|
|
|
m_mainWidget->showErrorMessage(errors);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 09:50:31 +01:00
|
|
|
currentDesignDocument()->updateSubcomponentManager();
|
2013-01-23 12:31:22 +01:00
|
|
|
|
|
|
|
|
connect(currentDesignDocument()->rewriterView(),
|
|
|
|
|
SIGNAL(errorsChanged(QList<RewriterView::Error>)),
|
|
|
|
|
m_mainWidget,
|
|
|
|
|
SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
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
|
|
|
|
|
|
|
|
disconnect(currentDesignDocument()->rewriterView(),
|
|
|
|
|
SIGNAL(errorsChanged(QList<RewriterView::Error>)),
|
|
|
|
|
m_mainWidget,
|
|
|
|
|
SLOT(updateErrorStatus(QList<RewriterView::Error>)));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::resetModelSelection()
|
|
|
|
|
{
|
|
|
|
|
if (currentDesignDocument()->rewriterView() && currentDesignDocument()->currentModel())
|
|
|
|
|
currentDesignDocument()->rewriterView()->setSelectedModelNodes(QList<ModelNode>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::onCurrentEditorChanged(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (editor
|
|
|
|
|
&& editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID
|
|
|
|
|
&& isInDesignerMode())
|
|
|
|
|
{
|
|
|
|
|
m_shortCutManager.updateActions(editor);
|
|
|
|
|
changeEditor();
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
static bool isDesignerMode(Core::IMode *mode)
|
|
|
|
|
{
|
|
|
|
|
return mode == Core::DesignMode::instance();
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::onCurrentModeChanged(Core::IMode *newMode, Core::IMode *oldMode)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2013-01-28 16:15:46 +01:00
|
|
|
if (!Core::EditorManager::currentEditor())
|
|
|
|
|
return;
|
|
|
|
|
|
2013-01-24 16:54:37 +01:00
|
|
|
if (Core::EditorManager::currentEditor()
|
|
|
|
|
&& Core::EditorManager::currentEditor()->id() != QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
if ((currentDesignDocument()
|
|
|
|
|
&& Core::EditorManager::currentEditor() == currentDesignDocument()->editor())
|
|
|
|
|
&& isDesignerMode(newMode))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!isDesignerMode(newMode) && isDesignerMode(oldMode))
|
|
|
|
|
hideDesigner();
|
|
|
|
|
else if (Core::EditorManager::currentEditor()
|
|
|
|
|
&& isDesignerMode(newMode)
|
|
|
|
|
&& isQmlFile(Core::EditorManager::currentEditor()))
|
|
|
|
|
showDesigner();
|
|
|
|
|
else if (currentDesignDocument())
|
|
|
|
|
hideDesigner();
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
DesignDocument *QmlDesignerPlugin::currentDesignDocument() const
|
|
|
|
|
{
|
|
|
|
|
return m_documentManager.currentDesignDocument();
|
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
|
|
|
{
|
2013-01-23 12:31:22 +01:00
|
|
|
return m_mainWidget;
|
2010-02-09 11:09:11 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::onTextEditorsClosed(QList<Core::IEditor*> editors)
|
|
|
|
|
{
|
|
|
|
|
if (m_documentManager.hasCurrentDesignDocument()
|
|
|
|
|
&& editors.contains(m_documentManager.currentDesignDocument()->textEditor()))
|
|
|
|
|
hideDesigner();
|
|
|
|
|
|
|
|
|
|
m_documentManager.removeEditors(editors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
QStringList mimeTypes;
|
|
|
|
|
mimeTypes.append("application/x-qml");
|
|
|
|
|
|
|
|
|
|
Core::DesignMode::instance()->registerDesignWidget(m_mainWidget, mimeTypes, m_context->context());
|
|
|
|
|
connect(Core::DesignMode::instance(),
|
|
|
|
|
SIGNAL(actionsUpdated(Core::IEditor*)),
|
|
|
|
|
&m_shortCutManager,
|
|
|
|
|
SLOT(updateActions(Core::IEditor*)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlDesignerPlugin *QmlDesignerPlugin::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DocumentManager &QmlDesignerPlugin::documentManager()
|
|
|
|
|
{
|
|
|
|
|
return m_documentManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DocumentManager &QmlDesignerPlugin::documentManager() const
|
|
|
|
|
{
|
|
|
|
|
return m_documentManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewManager &QmlDesignerPlugin::viewManager()
|
|
|
|
|
{
|
|
|
|
|
return m_viewManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ViewManager &QmlDesignerPlugin::viewManager() const
|
|
|
|
|
{
|
|
|
|
|
return m_viewManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDesignerPlugin::switchTextDesign()
|
2010-02-25 16:54:42 +01:00
|
|
|
{
|
2012-01-26 01:18:02 +01:00
|
|
|
if (Core::ModeManager::currentMode()->id() == Core::Constants::MODE_EDIT) {
|
2012-05-08 09:43:14 +02:00
|
|
|
Core::IEditor *editor = Core::EditorManager::currentEditor();
|
2013-01-23 12:31:22 +01:00
|
|
|
if (editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
|
2012-01-26 01:18:02 +01:00
|
|
|
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
|
|
|
|
|
} else if (Core::ModeManager::currentMode()->id() == Core::Constants::MODE_DESIGN) {
|
|
|
|
|
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
2010-02-25 16:54:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
DesignerSettings QmlDesignerPlugin::settings()
|
2010-02-09 11:09:11 +01:00
|
|
|
{
|
2012-10-26 13:57:58 +02:00
|
|
|
m_settings.fromSettings(Core::ICore::settings());
|
2010-02-09 11:09:11 +01:00
|
|
|
return m_settings;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
void QmlDesignerPlugin::setSettings(const DesignerSettings &s)
|
2010-02-09 11:09:11 +01:00
|
|
|
{
|
|
|
|
|
if (s != m_settings) {
|
|
|
|
|
m_settings = s;
|
2012-08-09 12:58:51 +03:00
|
|
|
m_settings.toSettings(Core::ICore::settings());
|
2010-02-09 11:09:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-23 12:31:22 +01:00
|
|
|
Q_EXPORT_PLUGIN(QmlDesigner::QmlDesignerPlugin)
|