Commit 4f05d53e authored by Christian Kamm's avatar Christian Kamm Committed by Fawzi Mohamed
Browse files

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: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
parent 1d78e594
......@@ -137,6 +137,9 @@ public:
virtual CppQmlTypeHash cppQmlTypes() const = 0;
virtual BuiltinPackagesHash builtinPackages() const = 0;
public slots:
virtual void resetCodeModel() = 0;
signals:
void documentUpdated(QmlJS::Document::Ptr doc);
void documentChangedOnDisk(QmlJS::Document::Ptr doc);
......
......@@ -695,3 +695,22 @@ ModelManagerInterface::BuiltinPackagesHash ModelManager::builtinPackages() const
{
return Interpreter::CppQmlTypesLoader::builtinPackages;
}
void ModelManager::resetCodeModel()
{
QStringList documents;
{
QMutexLocker locker(&m_mutex);
// find all documents currently in the code model
foreach (Document::Ptr doc, _snapshot)
documents.append(doc->fileName());
// reset the snapshot
_snapshot = Snapshot();
}
// start a reparse thread
updateSourceFiles(documents, false);
}
......@@ -88,6 +88,9 @@ public:
virtual CppQmlTypeHash cppQmlTypes() const;
virtual BuiltinPackagesHash builtinPackages() const;
public slots:
virtual void resetCodeModel();
Q_SIGNALS:
void projectPathChanged(const QString &projectPath);
......
......@@ -49,6 +49,9 @@ const char * const QML_JS_CODE_STYLE_SETTINGS_NAME = QT_TRANSLATE_NOOP("QmlJSToo
const char * const QML_JS_SETTINGS_ID = "QmlJS";
const char * const QML_JS_SETTINGS_NAME = QT_TRANSLATE_NOOP("QmlJSTools", "Qt Quick");
const char * const M_TOOLS_QMLJS = "QmlJSTools.Tools.Menu";
const char * const RESET_CODEMODEL = "QmlJSTools.ResetCodeModel";
} // namespace Constants
} // namespace QmlJSEditor
......
......@@ -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)
......@@ -42,6 +42,7 @@
QT_BEGIN_NAMESPACE
class QFileInfo;
class QDir;
class QAction;
QT_END_NAMESPACE
namespace QmlJSTools {
......@@ -67,9 +68,14 @@ public:
ShutdownFlag aboutToShutdown();
ModelManager *modelManager() { return m_modelManager; }
private slots:
void onTaskStarted(const QString &type);
void onAllTasksFinished(const QString &type);
private:
ModelManager *m_modelManager;
QmlJSToolsSettings *m_settings;
QAction *m_resetCodeModelAction;
static QmlJSToolsPlugin *m_instance;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment