summaryrefslogtreecommitdiff
path: root/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp
blob: 5108c350c61a31fb0646737b89843a42cc692850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <QtCore/QStringList>
#include <QtCore/QtPlugin>
#include <QtCore/QDebug>

#include <coreplugin/icore.h>

#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/project.h>

#include <coreplugin/coreconstants.h>
#include <coreplugin/uniqueidmanager.h>

#include <extensionsystem/pluginmanager.h>

#include <QtDeclarative/qmldebug.h>
#include <QtDeclarative/qmldebugclient.h>

#include "runcontrol.h"
#include "qmlinspector.h"
#include "qmlinspectormode.h"
#include "inspectoroutputpane.h"
#include "qmlinspectorplugin.h"

QT_BEGIN_NAMESPACE


QmlInspectorPlugin::QmlInspectorPlugin()
    : m_inspectMode(0),
      m_runControl(0)
{
}

QmlInspectorPlugin::~QmlInspectorPlugin()
{
}

void QmlInspectorPlugin::shutdown()
{
    removeObject(m_inspectMode);
    delete m_inspectMode;
    m_inspectMode = 0;

    removeObject(m_outputPane);
    delete m_outputPane;
    m_outputPane = 0;
}

bool QmlInspectorPlugin::initialize(const QStringList &arguments, QString *errorString)
{
    Q_UNUSED(arguments);
    Q_UNUSED(errorString);

    Core::ICore *core = Core::ICore::instance();
    Core::UniqueIDManager *uidm = core->uniqueIDManager();

    QList<int> context;
    context.append(uidm->uniqueIdentifier(QmlInspector::Constants::C_INSPECTOR));
    context.append(uidm->uniqueIdentifier(Core::Constants::C_EDITORMANAGER));
    context.append(uidm->uniqueIdentifier(Core::Constants::C_NAVIGATION_PANE));

    m_inspectMode = new QmlInspectorMode(this);
    connect(m_inspectMode, SIGNAL(startViewer()), SLOT(startViewer()));
    connect(m_inspectMode, SIGNAL(stopViewer()), SLOT(stopViewer()));
    m_inspectMode->setContext(context);
    addObject(m_inspectMode);

    m_outputPane = new InspectorOutputPane;
    addObject(m_outputPane);

    connect(m_inspectMode, SIGNAL(statusMessage(QString)),
            m_outputPane, SLOT(addInspectorStatus(QString)));

    m_runControlFactory = new QmlInspectorRunControlFactory(this);
    addAutoReleasedObject(m_runControlFactory);
    
    return true;
}

void QmlInspectorPlugin::extensionsInitialized()
{
}

void QmlInspectorPlugin::startViewer()
{
    stopViewer();
    
    ProjectExplorer::Project *project = 0;
    ProjectExplorer::ProjectExplorerPlugin *plugin = ProjectExplorer::ProjectExplorerPlugin::instance();
    if (plugin)
        project = plugin->currentProject();
    if (!project) {
        qDebug() << "No project loaded"; // TODO should this just run the debugger without a viewer?
        return;
    }
        
    QSharedPointer<ProjectExplorer::RunConfiguration> rc = project->activeRunConfiguration();

    QmlInspector::StartParameters sp;
    sp.port = m_inspectMode->viewerPort();

    m_runControl = m_runControlFactory->create(rc, ProjectExplorer::Constants::RUNMODE, sp);

    if (m_runControl) {
        connect(m_runControl, SIGNAL(started()), m_inspectMode, SLOT(connectToViewer()));
        connect(m_runControl, SIGNAL(finished()), m_inspectMode, SLOT(disconnectFromViewer()));

        connect(m_runControl, SIGNAL(addToOutputWindow(RunControl*,QString)),
                m_outputPane, SLOT(addOutput(RunControl*,QString)));
        connect(m_runControl, SIGNAL(addToOutputWindowInline(RunControl*,QString)),
                m_outputPane, SLOT(addOutputInline(RunControl*,QString)));
        connect(m_runControl, SIGNAL(error(RunControl*,QString)),
                m_outputPane, SLOT(addErrorOutput(RunControl*,QString)));
 
        m_runControl->start();
        m_outputPane->popup(false);
    }
    
}

void QmlInspectorPlugin::stopViewer()
{
    if (m_runControl) {
        m_runControl->stop();
        m_runControl->deleteLater();
        m_runControl = 0;
    }
}


Q_EXPORT_PLUGIN(QmlInspectorPlugin)

QT_END_NAMESPACE