qmljstoolsplugin.cpp 5.08 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12
** 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
Eike Ziller's avatar
Eike Ziller committed
13 14
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24 25 26
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30 31 32

#include "qmljstoolsplugin.h"
#include "qmljsmodelmanager.h"
33 34
#include "qmljsfunctionfilter.h"
#include "qmljslocatordata.h"
35 36
#include "qmljscodestylesettingspage.h"
#include "qmljstoolsconstants.h"
Jarek Kobus's avatar
Jarek Kobus committed
37
#include "qmljstoolssettings.h"
38
#include "qmlconsolemanager.h"
39
#include "qmljsbundleprovider.h"
40 41

#include <coreplugin/icore.h>
42 43 44
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
45
#include <coreplugin/mimedatabase.h>
46
#include <coreplugin/progressmanager/progressmanager.h>
47

48 49
#include <QtPlugin>
#include <QMenu>
50

51
using namespace Core;
52
using namespace QmlJSTools;
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
using namespace QmlJSTools::Internal;

enum { debug = 0 };

QmlJSToolsPlugin *QmlJSToolsPlugin::m_instance = 0;

QmlJSToolsPlugin::QmlJSToolsPlugin()
    : m_modelManager(0)
{
    m_instance = this;
}

QmlJSToolsPlugin::~QmlJSToolsPlugin()
{
    m_instance = 0;
    m_modelManager = 0; // deleted automatically
69
    m_consoleManager = 0; // deleted automatically
70 71 72 73 74
}

bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
{
    Q_UNUSED(arguments)
75

hjk's avatar
hjk committed
76
    if (!MimeDatabase::addMimeTypes(QLatin1String(":/qmljstools/QmlJSTools.mimetypes.xml"), error))
77 78
        return false;

Jarek Kobus's avatar
Jarek Kobus committed
79 80
    m_settings = new QmlJSToolsSettings(this); // force registration of qmljstools settings

81 82
    // Objects
    m_modelManager = new ModelManager(this);
83 84
    m_consoleManager = new QmlConsoleManager(this);

85 86
//    VCSManager *vcsManager = core->vcsManager();
//    DocumentManager *fileManager = core->fileManager();
87 88 89 90 91
//    connect(vcsManager, SIGNAL(repositoryChanged(QString)),
//            m_modelManager, SLOT(updateModifiedSourceFiles()));
//    connect(fileManager, SIGNAL(filesChangedInternally(QStringList)),
//            m_modelManager, SLOT(updateSourceFiles(QStringList)));

92 93 94
    LocatorData *locatorData = new LocatorData;
    addAutoReleasedObject(locatorData);
    addAutoReleasedObject(new FunctionFilter(locatorData));
Jarek Kobus's avatar
Jarek Kobus committed
95
    addAutoReleasedObject(new QmlJSCodeStyleSettingsPage);
96
    addAutoReleasedObject(new BasicBundleProvider);
Jarek Kobus's avatar
Jarek Kobus committed
97

98
    // Menus
99 100
    ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
    ActionContainer *mqmljstools = ActionManager::createMenu(Constants::M_TOOLS_QMLJS);
101 102 103 104 105 106 107
    QMenu *menu = mqmljstools->menu();
    menu->setTitle(tr("&QML/JS"));
    menu->setEnabled(true);
    mtools->addMenu(mqmljstools);

    // Update context in global context
    m_resetCodeModelAction = new QAction(tr("Reset Code Model"), this);
108 109 110
    Context globalContext(Core::Constants::C_GLOBAL);
    Command *cmd = ActionManager::registerAction(
                m_resetCodeModelAction, Constants::RESET_CODEMODEL, globalContext);
Montel Laurent's avatar
Montel Laurent committed
111 112
    connect(m_resetCodeModelAction, &QAction::triggered,
            m_modelManager, &ModelManager::resetCodeModel);
113 114 115
    mqmljstools->addAction(cmd);

    // watch task progress
116 117 118 119
    connect(ProgressManager::instance(), SIGNAL(taskStarted(Core::Id)),
            this, SLOT(onTaskStarted(Core::Id)));
    connect(ProgressManager::instance(), SIGNAL(allTasksFinished(Core::Id)),
            this, SLOT(onAllTasksFinished(Core::Id)));
120

121 122 123 124 125
    return true;
}

void QmlJSToolsPlugin::extensionsInitialized()
{
126
    m_modelManager->delayedInitialization();
127 128 129 130 131 132 133
}

ExtensionSystem::IPlugin::ShutdownFlag QmlJSToolsPlugin::aboutToShutdown()
{
    return SynchronousShutdown;
}

134
void QmlJSToolsPlugin::onTaskStarted(Core::Id type)
135
{
136
    if (type == QmlJS::Constants::TASK_INDEX)
137 138 139
        m_resetCodeModelAction->setEnabled(false);
}

140
void QmlJSToolsPlugin::onAllTasksFinished(Core::Id type)
141
{
142
    if (type == QmlJS::Constants::TASK_INDEX)
143 144
        m_resetCodeModelAction->setEnabled(true);
}