QmlJS: Add 'reset code model' action.

Having to restart Creator should be a thing of the past.

Task-number: QTCREATORBUG-4813
Change-Id: Ide242ee299b5d34aecba4823032e27741dde4a86
Reviewed-on: http://codereview.qt.nokia.com/668
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
Christian Kamm
2011-06-23 15:12:03 +02:00
committed by Fawzi Mohamed
parent 1d78e594d8
commit 4f05d53ef5
6 changed files with 78 additions and 1 deletions

View File

@@ -46,12 +46,18 @@
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <QtCore/QtPlugin>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QtGui/QMenu>
using namespace QmlJSTools::Internal;
@@ -75,7 +81,9 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
{
Q_UNUSED(arguments)
Q_UNUSED(error)
// Core::ICore *core = Core::ICore::instance();
Core::ICore *core = Core::ICore::instance();
Core::ActionManager *am = core->actionManager();
m_settings = new QmlJSToolsSettings(this); // force registration of qmljstools settings
@@ -97,6 +105,27 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
TextEditor::CodeStylePreferencesManager::instance()->registerFactory(
new QmlJSTools::QmlJSCodeStylePreferencesFactory());
// Menus
Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
Core::ActionContainer *mqmljstools = am->createMenu(Constants::M_TOOLS_QMLJS);
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);
Core::Context globalContext(Core::Constants::C_GLOBAL);
Core::Command *cmd = am->registerAction(m_resetCodeModelAction, Core::Id(Constants::RESET_CODEMODEL), globalContext);
connect(m_resetCodeModelAction, SIGNAL(triggered()), m_modelManager, SLOT(resetCodeModel()));
mqmljstools->addAction(cmd);
// watch task progress
connect(core->progressManager(), SIGNAL(taskStarted(QString)),
this, SLOT(onTaskStarted(QString)));
connect(core->progressManager(), SIGNAL(allTasksFinished(QString)),
this, SLOT(onAllTasksFinished(QString)));
return true;
}
@@ -110,4 +139,18 @@ ExtensionSystem::IPlugin::ShutdownFlag QmlJSToolsPlugin::aboutToShutdown()
return SynchronousShutdown;
}
void QmlJSToolsPlugin::onTaskStarted(const QString &type)
{
if (type == QmlJSTools::Constants::TASK_INDEX) {
m_resetCodeModelAction->setEnabled(false);
}
}
void QmlJSToolsPlugin::onAllTasksFinished(const QString &type)
{
if (type == QmlJSTools::Constants::TASK_INDEX) {
m_resetCodeModelAction->setEnabled(true);
}
}
Q_EXPORT_PLUGIN(QmlJSToolsPlugin)