Files
qt-creator/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp

157 lines
4.5 KiB
C++
Raw Normal View History

2009-12-11 14:56:04 +10:00
/**************************************************************************
**
** This file is part of Qt Creator
**
2010-03-05 11:25:49 +01:00
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2009-12-11 14:56:04 +10:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljsinspectorconstants.h"
#include "qmljsinspectorplugin.h"
2010-06-29 12:46:55 +02:00
#include "qmljsinspector.h"
2010-06-29 12:41:26 +02:00
#include "qmljsclientproxy.h"
#include "qmlinspectortoolbar.h"
2009-12-11 14:56:04 +10:00
#include <debugger/debuggeruiswitcher.h>
#include <debugger/debuggerconstants.h>
#include <debugger/qml/qmladapter.h>
#include <debugger/qml/qmlengine.h>
#include <qmlprojectmanager/qmlproject.h>
#include <qmljseditor/qmljseditorconstants.h>
#include <extensionsystem/pluginmanager.h>
2009-12-11 14:56:04 +10:00
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
2009-12-11 14:56:04 +10:00
#include <coreplugin/coreconstants.h>
#include <QtCore/QStringList>
#include <QtCore/QtPlugin>
#include <QtCore/QTimer>
#include <QtGui/QHBoxLayout>
#include <QtGui/QToolButton>
2009-12-11 14:56:04 +10:00
#include <QtCore/QDebug>
using namespace QmlJSInspector::Internal;
using namespace QmlJSInspector::Constants;
2009-12-11 14:56:04 +10:00
namespace {
2010-06-29 12:41:26 +02:00
InspectorPlugin *g_instance = 0; // the global QML/JS inspector instance
} // end of anonymous namespace
2009-12-11 14:56:04 +10:00
2010-06-29 12:41:26 +02:00
InspectorPlugin::InspectorPlugin()
: IPlugin()
, m_clientProxy(0)
2009-12-11 14:56:04 +10:00
{
Q_ASSERT(! g_instance);
g_instance = this;
2010-06-29 12:41:26 +02:00
m_inspectorUi = new InspectorUi(this);
2009-12-11 14:56:04 +10:00
}
2010-06-29 12:41:26 +02:00
InspectorPlugin::~InspectorPlugin()
2009-12-11 14:56:04 +10:00
{
}
QmlJS::ModelManagerInterface *InspectorPlugin::modelManager() const
{
return ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>();
}
2010-06-29 12:46:55 +02:00
InspectorPlugin *InspectorPlugin::instance()
{
return g_instance;
}
InspectorUi *InspectorPlugin::inspector() const
2010-06-29 12:46:55 +02:00
{
return m_inspectorUi;
2010-06-29 12:46:55 +02:00
}
ExtensionSystem::IPlugin::ShutdownFlag InspectorPlugin::aboutToShutdown()
2009-12-11 14:56:04 +10:00
{
m_inspectorUi->saveSettings();
return SynchronousShutdown;
2009-12-11 14:56:04 +10:00
}
2010-06-29 12:41:26 +02:00
bool InspectorPlugin::initialize(const QStringList &arguments, QString *errorString)
2009-12-11 14:56:04 +10:00
{
Q_UNUSED(arguments);
Q_UNUSED(errorString);
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
Debugger::DebuggerUISwitcher *uiSwitcher = pluginManager->getObject<Debugger::DebuggerUISwitcher>();
2009-12-11 14:56:04 +10:00
uiSwitcher->addLanguage(Debugger::QmlLanguage, tr("QML"), Core::Context(C_INSPECTOR));
2010-06-29 12:46:55 +02:00
2009-12-11 14:56:04 +10:00
return true;
}
2010-06-29 12:41:26 +02:00
void InspectorPlugin::extensionsInitialized()
2009-12-11 14:56:04 +10:00
{
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
connect(pluginManager, SIGNAL(objectAdded(QObject*)), SLOT(objectAdded(QObject*)));
connect(pluginManager, SIGNAL(aboutToRemoveObject(QObject*)), SLOT(aboutToRemoveObject(QObject*)));
m_inspectorUi->setupUi();
}
// The adapter object is only added to the pool with a succesful connection,
// so we can immediately init our stuff.
void InspectorPlugin::objectAdded(QObject *object)
{
Debugger::Internal::QmlAdapter *adapter = qobject_cast<Debugger::Internal::QmlAdapter *>(object);
if (adapter) {
m_clientProxy = new ClientProxy(adapter);
m_inspectorUi->connected(m_clientProxy);
return;
}
Debugger::Internal::QmlEngine *engine = qobject_cast<Debugger::Internal::QmlEngine*>(object);
if (engine) {
m_inspectorUi->setDebuggerEngine(engine);
}
}
2009-12-11 14:56:04 +10:00
void InspectorPlugin::aboutToRemoveObject(QObject *obj)
{
if (m_clientProxy && m_clientProxy->qmlAdapter() == obj) {
m_inspectorUi->disconnected();
delete m_clientProxy;
m_clientProxy = 0;
}
if (m_inspectorUi->debuggerEngine() == obj) {
m_inspectorUi->setDebuggerEngine(0);
}
}
2010-06-29 12:41:26 +02:00
Q_EXPORT_PLUGIN(InspectorPlugin)