forked from qt-creator/qt-creator
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:
committed by
Fawzi Mohamed
parent
1d78e594d8
commit
4f05d53ef5
@@ -137,6 +137,9 @@ public:
|
|||||||
virtual CppQmlTypeHash cppQmlTypes() const = 0;
|
virtual CppQmlTypeHash cppQmlTypes() const = 0;
|
||||||
virtual BuiltinPackagesHash builtinPackages() const = 0;
|
virtual BuiltinPackagesHash builtinPackages() const = 0;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void resetCodeModel() = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void documentUpdated(QmlJS::Document::Ptr doc);
|
void documentUpdated(QmlJS::Document::Ptr doc);
|
||||||
void documentChangedOnDisk(QmlJS::Document::Ptr doc);
|
void documentChangedOnDisk(QmlJS::Document::Ptr doc);
|
||||||
|
|||||||
@@ -695,3 +695,22 @@ ModelManagerInterface::BuiltinPackagesHash ModelManager::builtinPackages() const
|
|||||||
{
|
{
|
||||||
return Interpreter::CppQmlTypesLoader::builtinPackages;
|
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 CppQmlTypeHash cppQmlTypes() const;
|
||||||
virtual BuiltinPackagesHash builtinPackages() const;
|
virtual BuiltinPackagesHash builtinPackages() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void resetCodeModel();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void projectPathChanged(const QString &projectPath);
|
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_ID = "QmlJS";
|
||||||
const char * const QML_JS_SETTINGS_NAME = QT_TRANSLATE_NOOP("QmlJSTools", "Qt Quick");
|
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 Constants
|
||||||
} // namespace QmlJSEditor
|
} // namespace QmlJSEditor
|
||||||
|
|
||||||
|
|||||||
@@ -46,12 +46,18 @@
|
|||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.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/QtPlugin>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
|
#include <QtGui/QMenu>
|
||||||
|
|
||||||
using namespace QmlJSTools::Internal;
|
using namespace QmlJSTools::Internal;
|
||||||
|
|
||||||
@@ -75,7 +81,9 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(arguments)
|
Q_UNUSED(arguments)
|
||||||
Q_UNUSED(error)
|
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
|
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(
|
TextEditor::CodeStylePreferencesManager::instance()->registerFactory(
|
||||||
new QmlJSTools::QmlJSCodeStylePreferencesFactory());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,4 +139,18 @@ ExtensionSystem::IPlugin::ShutdownFlag QmlJSToolsPlugin::aboutToShutdown()
|
|||||||
return SynchronousShutdown;
|
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)
|
Q_EXPORT_PLUGIN(QmlJSToolsPlugin)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QFileInfo;
|
class QFileInfo;
|
||||||
class QDir;
|
class QDir;
|
||||||
|
class QAction;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace QmlJSTools {
|
namespace QmlJSTools {
|
||||||
@@ -67,9 +68,14 @@ public:
|
|||||||
ShutdownFlag aboutToShutdown();
|
ShutdownFlag aboutToShutdown();
|
||||||
ModelManager *modelManager() { return m_modelManager; }
|
ModelManager *modelManager() { return m_modelManager; }
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onTaskStarted(const QString &type);
|
||||||
|
void onAllTasksFinished(const QString &type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModelManager *m_modelManager;
|
ModelManager *m_modelManager;
|
||||||
QmlJSToolsSettings *m_settings;
|
QmlJSToolsSettings *m_settings;
|
||||||
|
QAction *m_resetCodeModelAction;
|
||||||
|
|
||||||
static QmlJSToolsPlugin *m_instance;
|
static QmlJSToolsPlugin *m_instance;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user