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:
@@ -39,27 +39,34 @@
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QMenu>
|
||||
|
||||
using namespace Core;
|
||||
using namespace QmlJSTools;
|
||||
using namespace QmlJSTools::Internal;
|
||||
|
||||
namespace QmlJSTools {
|
||||
namespace Internal {
|
||||
|
||||
enum { debug = 0 };
|
||||
|
||||
QmlJSToolsPlugin *QmlJSToolsPlugin::m_instance = 0;
|
||||
|
||||
QmlJSToolsPlugin::QmlJSToolsPlugin()
|
||||
: m_modelManager(0)
|
||||
class QmlJSToolsPluginPrivate : public QObject
|
||||
{
|
||||
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()
|
||||
{
|
||||
m_instance = 0;
|
||||
m_modelManager = 0; // deleted automatically
|
||||
delete d;
|
||||
}
|
||||
|
||||
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(error)
|
||||
|
||||
m_settings = new QmlJSToolsSettings(this); // force registration of qmljstools settings
|
||||
d = new QmlJSToolsPluginPrivate;
|
||||
|
||||
// Objects
|
||||
m_modelManager = new ModelManager(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
QmlJSToolsPluginPrivate::QmlJSToolsPluginPrivate()
|
||||
{
|
||||
// Core::VcsManager *vcsManager = Core::VcsManager::instance();
|
||||
// Core::DocumentManager *documentManager = Core::DocumentManager::instance();
|
||||
// connect(vcsManager, &Core::VcsManager::repositoryChanged,
|
||||
// m_modelManager, &ModelManager::updateModifiedSourceFiles);
|
||||
// &d->modelManager, &ModelManager::updateModifiedSourceFiles);
|
||||
// connect(documentManager, &DocumentManager::filesChangedInternally,
|
||||
// m_modelManager, &ModelManager::updateSourceFiles);
|
||||
|
||||
LocatorData *locatorData = new LocatorData;
|
||||
addAutoReleasedObject(locatorData);
|
||||
addAutoReleasedObject(new FunctionFilter(locatorData));
|
||||
addAutoReleasedObject(new QmlJSCodeStyleSettingsPage);
|
||||
addAutoReleasedObject(new BasicBundleProvider);
|
||||
// &d->modelManager, &ModelManager::updateSourceFiles);
|
||||
|
||||
// Menus
|
||||
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
||||
ActionContainer *mqmljstools = ActionManager::createMenu(Constants::M_TOOLS_QMLJS);
|
||||
QMenu *menu = mqmljstools->menu();
|
||||
menu->setTitle(tr("&QML/JS"));
|
||||
menu->setTitle(QmlJSToolsPlugin::tr("&QML/JS"));
|
||||
menu->setEnabled(true);
|
||||
mtools->addMenu(mqmljstools);
|
||||
|
||||
// Update context in global context
|
||||
m_resetCodeModelAction = new QAction(tr("Reset Code Model"), this);
|
||||
Command *cmd = ActionManager::registerAction(
|
||||
m_resetCodeModelAction, Constants::RESET_CODEMODEL);
|
||||
connect(m_resetCodeModelAction, &QAction::triggered,
|
||||
m_modelManager, &ModelManager::resetCodeModel);
|
||||
&resetCodeModelAction, Constants::RESET_CODEMODEL);
|
||||
connect(&resetCodeModelAction, &QAction::triggered,
|
||||
&modelManager, &ModelManager::resetCodeModel);
|
||||
mqmljstools->addAction(cmd);
|
||||
|
||||
// watch task progress
|
||||
connect(ProgressManager::instance(), &ProgressManager::taskStarted,
|
||||
this, &QmlJSToolsPlugin::onTaskStarted);
|
||||
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
|
||||
this, &QmlJSToolsPlugin::onAllTasksFinished);
|
||||
// Watch task progress
|
||||
connect(ProgressManager::instance(), &ProgressManager::taskStarted, this,
|
||||
[this](Core::Id type) {
|
||||
if (type == QmlJS::Constants::TASK_INDEX)
|
||||
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()
|
||||
{
|
||||
m_modelManager->delayedInitialization();
|
||||
d->modelManager.delayedInitialization();
|
||||
}
|
||||
|
||||
ExtensionSystem::IPlugin::ShutdownFlag QmlJSToolsPlugin::aboutToShutdown()
|
||||
{
|
||||
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);
|
||||
}
|
||||
} // Internal
|
||||
} // QmlJSTools
|
||||
|
||||
Reference in New Issue
Block a user