1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "qmljstoolsplugin.h"
27 #include "qmljsmodelmanager.h"
28 #include "qmljsfunctionfilter.h"
29 #include "qmljslocatordata.h"
30 #include "qmljscodestylesettingspage.h"
31 #include "qmljstoolsconstants.h"
32 #include "qmljstoolssettings.h"
33 #include "qmljsbundleprovider.h"
34 
35 #include <coreplugin/icontext.h>
36 #include <coreplugin/icore.h>
37 #include <coreplugin/coreconstants.h>
38 #include <coreplugin/actionmanager/actionmanager.h>
39 #include <coreplugin/actionmanager/actioncontainer.h>
40 #include <coreplugin/progressmanager/progressmanager.h>
41 
42 #include <QMenu>
43 
44 using namespace Core;
45 
46 namespace QmlJSTools {
47 namespace Internal {
48 
49 enum { debug = 0 };
50 
51 class QmlJSToolsPluginPrivate : public QObject
52 {
53 public:
54     QmlJSToolsPluginPrivate();
55 
56     QmlJSToolsSettings settings;
57     ModelManager modelManager;
58 
59     QAction resetCodeModelAction{QmlJSToolsPlugin::tr("Reset Code Model"), nullptr};
60 
61     LocatorData locatorData;
62     FunctionFilter functionFilter{&locatorData};
63     QmlJSCodeStyleSettingsPage codeStyleSettingsPage;
64     BasicBundleProvider basicBundleProvider;
65 };
66 
~QmlJSToolsPlugin()67 QmlJSToolsPlugin::~QmlJSToolsPlugin()
68 {
69     delete d;
70 }
71 
initialize(const QStringList & arguments,QString * error)72 bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
73 {
74     Q_UNUSED(arguments)
75     Q_UNUSED(error)
76 
77     d = new QmlJSToolsPluginPrivate;
78 
79     return true;
80 }
81 
QmlJSToolsPluginPrivate()82 QmlJSToolsPluginPrivate::QmlJSToolsPluginPrivate()
83 {
84 //    Core::VcsManager *vcsManager = Core::VcsManager::instance();
85 //    Core::DocumentManager *documentManager = Core::DocumentManager::instance();
86 //    connect(vcsManager, &Core::VcsManager::repositoryChanged,
87 //            &d->modelManager, &ModelManager::updateModifiedSourceFiles);
88 //    connect(documentManager, &DocumentManager::filesChangedInternally,
89 //            &d->modelManager, &ModelManager::updateSourceFiles);
90 
91     // Menus
92     ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
93     ActionContainer *mqmljstools = ActionManager::createMenu(Constants::M_TOOLS_QMLJS);
94     QMenu *menu = mqmljstools->menu();
95     menu->setTitle(QmlJSToolsPlugin::tr("&QML/JS"));
96     menu->setEnabled(true);
97     mtools->addMenu(mqmljstools);
98 
99     // Update context in global context
100     Command *cmd = ActionManager::registerAction(
101                 &resetCodeModelAction, Constants::RESET_CODEMODEL);
102     connect(&resetCodeModelAction, &QAction::triggered,
103             &modelManager, &ModelManager::resetCodeModel);
104     mqmljstools->addAction(cmd);
105 
106     // Watch task progress
107     connect(ProgressManager::instance(), &ProgressManager::taskStarted, this,
108             [this](Utils::Id type) {
109                   if (type == QmlJS::Constants::TASK_INDEX)
110                       resetCodeModelAction.setEnabled(false);
111             });
112 
113     connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
114             [this](Utils::Id type) {
115                   if (type == QmlJS::Constants::TASK_INDEX)
116                       resetCodeModelAction.setEnabled(true);
117             });
118 }
119 
extensionsInitialized()120 void QmlJSToolsPlugin::extensionsInitialized()
121 {
122     d->modelManager.delayedInitialization();
123 }
124 
125 } // Internal
126 } // QmlJSTools
127