forked from qt-creator/qt-creator
QmlJSPlugin: reorganize setup
Pimpl, remove use of global object pool, cosmetics, ... Change-Id: I9e1415b07d7ff8e95db0998c87ce7d75ca638a8e Reviewed-by: Marco Benelli <marco.benelli@qt.io>
This commit is contained in:
@@ -36,8 +36,7 @@ using namespace QmlJSTools::Internal;
|
|||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
using namespace QmlJS::AST;
|
using namespace QmlJS::AST;
|
||||||
|
|
||||||
LocatorData::LocatorData(QObject *parent)
|
LocatorData::LocatorData()
|
||||||
: QObject(parent)
|
|
||||||
{
|
{
|
||||||
ModelManagerInterface *manager = ModelManagerInterface::instance();
|
ModelManagerInterface *manager = ModelManagerInterface::instance();
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ class LocatorData : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit LocatorData(QObject *parent = 0);
|
LocatorData();
|
||||||
~LocatorData();
|
~LocatorData();
|
||||||
|
|
||||||
enum EntryType
|
enum EntryType
|
||||||
|
@@ -206,8 +206,7 @@ QHash<QString,Dialect> ModelManager::languageForSuffix() const
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelManager::ModelManager(QObject *parent):
|
ModelManager::ModelManager()
|
||||||
ModelManagerInterface(parent)
|
|
||||||
{
|
{
|
||||||
qRegisterMetaType<QmlJSTools::SemanticInfo>("QmlJSTools::SemanticInfo");
|
qRegisterMetaType<QmlJSTools::SemanticInfo>("QmlJSTools::SemanticInfo");
|
||||||
loadDefaultQmlTypeDescriptions();
|
loadDefaultQmlTypeDescriptions();
|
||||||
|
@@ -46,7 +46,7 @@ class QMLJSTOOLS_EXPORT ModelManager: public QmlJS::ModelManagerInterface
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModelManager(QObject *parent = 0);
|
ModelManager();
|
||||||
~ModelManager() override;
|
~ModelManager() override;
|
||||||
|
|
||||||
void delayedInitialization();
|
void delayedInitialization();
|
||||||
|
@@ -39,27 +39,34 @@
|
|||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
|
|
||||||
#include <QtPlugin>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace QmlJSTools;
|
|
||||||
using namespace QmlJSTools::Internal;
|
namespace QmlJSTools {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
enum { debug = 0 };
|
enum { debug = 0 };
|
||||||
|
|
||||||
QmlJSToolsPlugin *QmlJSToolsPlugin::m_instance = 0;
|
class QmlJSToolsPluginPrivate : public QObject
|
||||||
|
|
||||||
QmlJSToolsPlugin::QmlJSToolsPlugin()
|
|
||||||
: m_modelManager(0)
|
|
||||||
{
|
{
|
||||||
m_instance = this;
|
public:
|
||||||
}
|
QmlJSToolsPluginPrivate();
|
||||||
|
|
||||||
|
QmlJSToolsSettings settings;
|
||||||
|
ModelManager modelManager;
|
||||||
|
|
||||||
|
QAction resetCodeModelAction{QmlJSToolsPlugin::tr("Reset Code Model"), nullptr};
|
||||||
|
|
||||||
|
LocatorData locatorData;
|
||||||
|
FunctionFilter functionFilter{&locatorData};
|
||||||
|
QmlJSCodeStyleSettingsPage codeStyleSettingsPage;
|
||||||
|
BasicBundleProvider basicBundleProvider;
|
||||||
|
};
|
||||||
|
|
||||||
QmlJSToolsPlugin::~QmlJSToolsPlugin()
|
QmlJSToolsPlugin::~QmlJSToolsPlugin()
|
||||||
{
|
{
|
||||||
m_instance = 0;
|
delete d;
|
||||||
m_modelManager = 0; // deleted automatically
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
||||||
@@ -67,67 +74,53 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
Q_UNUSED(arguments)
|
Q_UNUSED(arguments)
|
||||||
Q_UNUSED(error)
|
Q_UNUSED(error)
|
||||||
|
|
||||||
m_settings = new QmlJSToolsSettings(this); // force registration of qmljstools settings
|
d = new QmlJSToolsPluginPrivate;
|
||||||
|
|
||||||
// Objects
|
return true;
|
||||||
m_modelManager = new ModelManager(this);
|
}
|
||||||
|
|
||||||
|
QmlJSToolsPluginPrivate::QmlJSToolsPluginPrivate()
|
||||||
|
{
|
||||||
// Core::VcsManager *vcsManager = Core::VcsManager::instance();
|
// Core::VcsManager *vcsManager = Core::VcsManager::instance();
|
||||||
// Core::DocumentManager *documentManager = Core::DocumentManager::instance();
|
// Core::DocumentManager *documentManager = Core::DocumentManager::instance();
|
||||||
// connect(vcsManager, &Core::VcsManager::repositoryChanged,
|
// connect(vcsManager, &Core::VcsManager::repositoryChanged,
|
||||||
// m_modelManager, &ModelManager::updateModifiedSourceFiles);
|
// &d->modelManager, &ModelManager::updateModifiedSourceFiles);
|
||||||
// connect(documentManager, &DocumentManager::filesChangedInternally,
|
// connect(documentManager, &DocumentManager::filesChangedInternally,
|
||||||
// m_modelManager, &ModelManager::updateSourceFiles);
|
// &d->modelManager, &ModelManager::updateSourceFiles);
|
||||||
|
|
||||||
LocatorData *locatorData = new LocatorData;
|
|
||||||
addAutoReleasedObject(locatorData);
|
|
||||||
addAutoReleasedObject(new FunctionFilter(locatorData));
|
|
||||||
addAutoReleasedObject(new QmlJSCodeStyleSettingsPage);
|
|
||||||
addAutoReleasedObject(new BasicBundleProvider);
|
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
||||||
ActionContainer *mqmljstools = ActionManager::createMenu(Constants::M_TOOLS_QMLJS);
|
ActionContainer *mqmljstools = ActionManager::createMenu(Constants::M_TOOLS_QMLJS);
|
||||||
QMenu *menu = mqmljstools->menu();
|
QMenu *menu = mqmljstools->menu();
|
||||||
menu->setTitle(tr("&QML/JS"));
|
menu->setTitle(QmlJSToolsPlugin::tr("&QML/JS"));
|
||||||
menu->setEnabled(true);
|
menu->setEnabled(true);
|
||||||
mtools->addMenu(mqmljstools);
|
mtools->addMenu(mqmljstools);
|
||||||
|
|
||||||
// Update context in global context
|
// Update context in global context
|
||||||
m_resetCodeModelAction = new QAction(tr("Reset Code Model"), this);
|
|
||||||
Command *cmd = ActionManager::registerAction(
|
Command *cmd = ActionManager::registerAction(
|
||||||
m_resetCodeModelAction, Constants::RESET_CODEMODEL);
|
&resetCodeModelAction, Constants::RESET_CODEMODEL);
|
||||||
connect(m_resetCodeModelAction, &QAction::triggered,
|
connect(&resetCodeModelAction, &QAction::triggered,
|
||||||
m_modelManager, &ModelManager::resetCodeModel);
|
&modelManager, &ModelManager::resetCodeModel);
|
||||||
mqmljstools->addAction(cmd);
|
mqmljstools->addAction(cmd);
|
||||||
|
|
||||||
// watch task progress
|
// Watch task progress
|
||||||
connect(ProgressManager::instance(), &ProgressManager::taskStarted,
|
connect(ProgressManager::instance(), &ProgressManager::taskStarted, this,
|
||||||
this, &QmlJSToolsPlugin::onTaskStarted);
|
[this](Core::Id type) {
|
||||||
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
|
if (type == QmlJS::Constants::TASK_INDEX)
|
||||||
this, &QmlJSToolsPlugin::onAllTasksFinished);
|
resetCodeModelAction.setEnabled(false);
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
|
||||||
|
[this](Core::Id type) {
|
||||||
|
if (type == QmlJS::Constants::TASK_INDEX)
|
||||||
|
resetCodeModelAction.setEnabled(true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSToolsPlugin::extensionsInitialized()
|
void QmlJSToolsPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
m_modelManager->delayedInitialization();
|
d->modelManager.delayedInitialization();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtensionSystem::IPlugin::ShutdownFlag QmlJSToolsPlugin::aboutToShutdown()
|
} // Internal
|
||||||
{
|
} // QmlJSTools
|
||||||
return SynchronousShutdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlJSToolsPlugin::onTaskStarted(Id type)
|
|
||||||
{
|
|
||||||
if (type == QmlJS::Constants::TASK_INDEX)
|
|
||||||
m_resetCodeModelAction->setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QmlJSToolsPlugin::onAllTasksFinished(Id type)
|
|
||||||
{
|
|
||||||
if (type == QmlJS::Constants::TASK_INDEX)
|
|
||||||
m_resetCodeModelAction->setEnabled(true);
|
|
||||||
}
|
|
||||||
|
@@ -25,48 +25,24 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/id.h>
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QFileInfo;
|
|
||||||
class QDir;
|
|
||||||
class QAction;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace QmlJSTools {
|
namespace QmlJSTools {
|
||||||
|
|
||||||
class QmlJSToolsSettings;
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class ModelManager;
|
|
||||||
|
|
||||||
class QmlJSToolsPlugin : public ExtensionSystem::IPlugin
|
class QmlJSToolsPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "QmlJSTools.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "QmlJSTools.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QmlJSToolsPlugin *instance() { return m_instance; }
|
~QmlJSToolsPlugin() final;
|
||||||
|
|
||||||
QmlJSToolsPlugin();
|
|
||||||
~QmlJSToolsPlugin();
|
|
||||||
|
|
||||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
|
||||||
void extensionsInitialized();
|
|
||||||
ShutdownFlag aboutToShutdown();
|
|
||||||
ModelManager *modelManager() { return m_modelManager; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onTaskStarted(Core::Id type);
|
bool initialize(const QStringList &arguments, QString *errorMessage) final;
|
||||||
void onAllTasksFinished(Core::Id type);
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
ModelManager *m_modelManager;
|
class QmlJSToolsPluginPrivate *d = nullptr;
|
||||||
QmlJSToolsSettings *m_settings;
|
|
||||||
QAction *m_resetCodeModelAction;
|
|
||||||
|
|
||||||
static QmlJSToolsPlugin *m_instance;
|
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
private slots:
|
private slots:
|
||||||
|
@@ -46,8 +46,7 @@ const char idKey[] = "QmlJSGlobal";
|
|||||||
|
|
||||||
static SimpleCodeStylePreferences *m_globalCodeStyle = 0;
|
static SimpleCodeStylePreferences *m_globalCodeStyle = 0;
|
||||||
|
|
||||||
QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
|
QmlJSToolsSettings::QmlJSToolsSettings()
|
||||||
: QObject(parent)
|
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!m_globalCodeStyle, return);
|
QTC_ASSERT(!m_globalCodeStyle, return);
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@ class QMLJSTOOLS_EXPORT QmlJSToolsSettings : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QmlJSToolsSettings(QObject *parent);
|
explicit QmlJSToolsSettings();
|
||||||
~QmlJSToolsSettings();
|
~QmlJSToolsSettings();
|
||||||
|
|
||||||
static TextEditor::SimpleCodeStylePreferences *globalCodeStyle();
|
static TextEditor::SimpleCodeStylePreferences *globalCodeStyle();
|
||||||
|
Reference in New Issue
Block a user