forked from qt-creator/qt-creator
QmlJSEditorPlugin: Refactor
This follows the recently introduced pattern for plugin setup - Pimpl QmlJSEditorPlugin - remove unneeded uses of global object pool - apply "static pattern" - simplify some constructors of data members in some cases - use in-class initialization in some case Change-Id: I95b42d0885f4a8d6c9bfe1e4c004d3ace0a3eba5 Reviewed-by: Marco Benelli <marco.benelli@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -829,7 +829,7 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|||||||
AssistInterface *interface = createAssistInterface(QuickFix, ExplicitlyInvoked);
|
AssistInterface *interface = createAssistInterface(QuickFix, ExplicitlyInvoked);
|
||||||
if (interface) {
|
if (interface) {
|
||||||
QScopedPointer<IAssistProcessor> processor(
|
QScopedPointer<IAssistProcessor> processor(
|
||||||
QmlJSEditorPlugin::instance()->quickFixAssistProvider()->createProcessor());
|
QmlJSEditorPlugin::quickFixAssistProvider()->createProcessor());
|
||||||
QScopedPointer<IAssistProposal> proposal(processor->perform(interface));
|
QScopedPointer<IAssistProposal> proposal(processor->perform(interface));
|
||||||
if (!proposal.isNull()) {
|
if (!proposal.isNull()) {
|
||||||
GenericProposalModel *model = static_cast<GenericProposalModel *>(proposal->model());
|
GenericProposalModel *model = static_cast<GenericProposalModel *>(proposal->model());
|
||||||
|
@@ -685,7 +685,7 @@ Internal::QmlOutlineModel *QmlJSEditorDocument::outlineModel() const
|
|||||||
|
|
||||||
TextEditor::IAssistProvider *QmlJSEditorDocument::quickFixAssistProvider() const
|
TextEditor::IAssistProvider *QmlJSEditorDocument::quickFixAssistProvider() const
|
||||||
{
|
{
|
||||||
return Internal::QmlJSEditorPlugin::instance()->quickFixAssistProvider();
|
return Internal::QmlJSEditorPlugin::quickFixAssistProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorDocument::setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges)
|
void QmlJSEditorDocument::setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges)
|
||||||
|
@@ -58,12 +58,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/json.h>
|
#include <utils/json.h>
|
||||||
|
|
||||||
#include <QtPlugin>
|
|
||||||
#include <QSettings>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QTimer>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
@@ -71,57 +66,88 @@ using namespace QmlJSEditor::Constants;
|
|||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
enum {
|
namespace QmlJSEditor {
|
||||||
QUICKFIX_INTERVAL = 20
|
namespace Internal {
|
||||||
|
|
||||||
|
class QmlJSEditorPluginPrivate : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QmlJSEditorPluginPrivate();
|
||||||
|
|
||||||
|
void currentEditorChanged(IEditor *editor);
|
||||||
|
void runSemanticScan();
|
||||||
|
void checkCurrentEditorSemanticInfoUpToDate();
|
||||||
|
void autoFormatOnSave(IDocument *document);
|
||||||
|
|
||||||
|
Command *addToolAction(QAction *a, Context &context, Id id,
|
||||||
|
ActionContainer *c1, const QString &keySequence);
|
||||||
|
|
||||||
|
void findUsages();
|
||||||
|
void renameUsages();
|
||||||
|
void reformatFile();
|
||||||
|
void showContextPane();
|
||||||
|
|
||||||
|
QmlJSQuickFixAssistProvider m_quickFixAssistProvider;
|
||||||
|
QmlTaskManager m_qmlTaskManager;
|
||||||
|
|
||||||
|
QAction *m_reformatFileAction = nullptr;
|
||||||
|
|
||||||
|
QPointer<QmlJSEditorDocument> m_currentDocument;
|
||||||
|
|
||||||
|
Utils::JsonSchemaManager m_jsonManager{{ICore::userResourcePath() + "/json/",
|
||||||
|
ICore::resourcePath() + "/json/"}};
|
||||||
|
QmlJSEditorFactory m_qmlJSEditorFactory;
|
||||||
|
QmlJSOutlineWidgetFactory m_qmlJSOutlineWidgetFactory;
|
||||||
|
QuickToolBar m_quickToolBar;
|
||||||
|
QmlJsEditingSettingsPage m_qmJSEditingSettingsPage;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
static QmlJSEditorPlugin *m_instance = nullptr;
|
||||||
using namespace Internal;
|
|
||||||
|
|
||||||
QmlJSEditorPlugin *QmlJSEditorPlugin::m_instance = 0;
|
QmlJSEditorPlugin::QmlJSEditorPlugin()
|
||||||
|
|
||||||
QmlJSEditorPlugin::QmlJSEditorPlugin() :
|
|
||||||
m_modelManager(0),
|
|
||||||
m_quickFixAssistProvider(0),
|
|
||||||
m_reformatFileAction(0),
|
|
||||||
m_currentDocument(0),
|
|
||||||
m_jsonManager(new Utils::JsonSchemaManager(
|
|
||||||
QStringList() << ICore::userResourcePath() + QLatin1String("/json/")
|
|
||||||
<< ICore::resourcePath() + QLatin1String("/json/")))
|
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlJSEditorPlugin::~QmlJSEditorPlugin()
|
QmlJSEditorPlugin::~QmlJSEditorPlugin()
|
||||||
{
|
{
|
||||||
m_instance = 0;
|
delete d;
|
||||||
|
d = nullptr;
|
||||||
|
m_instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
bool QmlJSEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||||
|
{
|
||||||
|
Q_UNUSED(arguments);
|
||||||
|
Q_UNUSED(errorMessage);
|
||||||
|
|
||||||
|
d = new QmlJSEditorPluginPrivate;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QmlJSEditorPluginPrivate::QmlJSEditorPluginPrivate()
|
||||||
{
|
{
|
||||||
m_modelManager = QmlJS::ModelManagerInterface::instance();
|
|
||||||
TextEditor::SnippetProvider::registerGroup(Constants::QML_SNIPPETS_GROUP_ID,
|
TextEditor::SnippetProvider::registerGroup(Constants::QML_SNIPPETS_GROUP_ID,
|
||||||
tr("QML", "SnippetProvider"),
|
QmlJSEditorPlugin::tr("QML", "SnippetProvider"),
|
||||||
&QmlJSEditorFactory::decorateEditor);
|
&QmlJSEditorFactory::decorateEditor);
|
||||||
|
|
||||||
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
||||||
|
|
||||||
// QML task updating manager
|
// QML task updating manager
|
||||||
m_qmlTaskManager = new QmlTaskManager;
|
connect(modelManager, &QmlJS::ModelManagerInterface::documentChangedOnDisk,
|
||||||
addAutoReleasedObject(m_qmlTaskManager);
|
&m_qmlTaskManager, &QmlTaskManager::updateMessages);
|
||||||
connect(m_modelManager, &QmlJS::ModelManagerInterface::documentChangedOnDisk,
|
|
||||||
m_qmlTaskManager, &QmlTaskManager::updateMessages);
|
|
||||||
// recompute messages when information about libraries changes
|
// recompute messages when information about libraries changes
|
||||||
connect(m_modelManager, &QmlJS::ModelManagerInterface::libraryInfoUpdated,
|
connect(modelManager, &QmlJS::ModelManagerInterface::libraryInfoUpdated,
|
||||||
m_qmlTaskManager, &QmlTaskManager::updateMessages);
|
&m_qmlTaskManager, &QmlTaskManager::updateMessages);
|
||||||
// recompute messages when project data changes (files added or removed)
|
// recompute messages when project data changes (files added or removed)
|
||||||
connect(m_modelManager, &QmlJS::ModelManagerInterface::projectInfoUpdated,
|
connect(modelManager, &QmlJS::ModelManagerInterface::projectInfoUpdated,
|
||||||
m_qmlTaskManager, &QmlTaskManager::updateMessages);
|
&m_qmlTaskManager, &QmlTaskManager::updateMessages);
|
||||||
connect(m_modelManager, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
|
connect(modelManager, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
|
||||||
m_qmlTaskManager, &QmlTaskManager::documentsRemoved);
|
&m_qmlTaskManager, &QmlTaskManager::documentsRemoved);
|
||||||
|
|
||||||
Context context(Constants::C_QMLJSEDITOR_ID);
|
Context context(Constants::C_QMLJSEDITOR_ID);
|
||||||
|
|
||||||
addAutoReleasedObject(new QmlJSEditorFactory);
|
|
||||||
|
|
||||||
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
|
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
|
||||||
ActionContainer *qmlToolsMenu = ActionManager::actionContainer(Id(QmlJSTools::Constants::M_TOOLS_QMLJS));
|
ActionContainer *qmlToolsMenu = ActionManager::actionContainer(Id(QmlJSTools::Constants::M_TOOLS_QMLJS));
|
||||||
|
|
||||||
@@ -132,32 +158,32 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
qmlToolsMenu->addAction(cmd);
|
qmlToolsMenu->addAction(cmd);
|
||||||
|
|
||||||
QAction *findUsagesAction = new QAction(tr("Find Usages"), this);
|
QAction *findUsagesAction = new QAction(QmlJSEditorPlugin::tr("Find Usages"), this);
|
||||||
cmd = ActionManager::registerAction(findUsagesAction, Constants::FIND_USAGES, context);
|
cmd = ActionManager::registerAction(findUsagesAction, Constants::FIND_USAGES, context);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
|
cmd->setDefaultKeySequence(QKeySequence(QmlJSEditorPlugin::tr("Ctrl+Shift+U")));
|
||||||
connect(findUsagesAction, &QAction::triggered, this, &QmlJSEditorPlugin::findUsages);
|
connect(findUsagesAction, &QAction::triggered, this, &QmlJSEditorPluginPrivate::findUsages);
|
||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
qmlToolsMenu->addAction(cmd);
|
qmlToolsMenu->addAction(cmd);
|
||||||
|
|
||||||
QAction *renameUsagesAction = new QAction(tr("Rename Symbol Under Cursor"), this);
|
QAction *renameUsagesAction = new QAction(QmlJSEditorPlugin::tr("Rename Symbol Under Cursor"), this);
|
||||||
cmd = ActionManager::registerAction(renameUsagesAction, Constants::RENAME_USAGES, context);
|
cmd = ActionManager::registerAction(renameUsagesAction, Constants::RENAME_USAGES, context);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+R")));
|
cmd->setDefaultKeySequence(QKeySequence(QmlJSEditorPlugin::tr("Ctrl+Shift+R")));
|
||||||
connect(renameUsagesAction, &QAction::triggered, this, &QmlJSEditorPlugin::renameUsages);
|
connect(renameUsagesAction, &QAction::triggered, this, &QmlJSEditorPluginPrivate::renameUsages);
|
||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
qmlToolsMenu->addAction(cmd);
|
qmlToolsMenu->addAction(cmd);
|
||||||
|
|
||||||
QAction *semanticScan = new QAction(tr("Run Checks"), this);
|
QAction *semanticScan = new QAction(QmlJSEditorPlugin::tr("Run Checks"), this);
|
||||||
cmd = ActionManager::registerAction(semanticScan, Id(Constants::RUN_SEMANTIC_SCAN));
|
cmd = ActionManager::registerAction(semanticScan, Id(Constants::RUN_SEMANTIC_SCAN));
|
||||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+C")));
|
cmd->setDefaultKeySequence(QKeySequence(QmlJSEditorPlugin::tr("Ctrl+Shift+C")));
|
||||||
connect(semanticScan, &QAction::triggered, this, &QmlJSEditorPlugin::runSemanticScan);
|
connect(semanticScan, &QAction::triggered, this, &QmlJSEditorPluginPrivate::runSemanticScan);
|
||||||
qmlToolsMenu->addAction(cmd);
|
qmlToolsMenu->addAction(cmd);
|
||||||
|
|
||||||
m_reformatFileAction = new QAction(tr("Reformat File"), this);
|
m_reformatFileAction = new QAction(QmlJSEditorPlugin::tr("Reformat File"), this);
|
||||||
cmd = ActionManager::registerAction(m_reformatFileAction, Id(Constants::REFORMAT_FILE), context);
|
cmd = ActionManager::registerAction(m_reformatFileAction, Id(Constants::REFORMAT_FILE), context);
|
||||||
connect(m_reformatFileAction, &QAction::triggered, this, &QmlJSEditorPlugin::reformatFile);
|
connect(m_reformatFileAction, &QAction::triggered, this, &QmlJSEditorPluginPrivate::reformatFile);
|
||||||
qmlToolsMenu->addAction(cmd);
|
qmlToolsMenu->addAction(cmd);
|
||||||
|
|
||||||
QAction *inspectElementAction = new QAction(tr("Inspect API for Element Under Cursor"), this);
|
QAction *inspectElementAction = new QAction(QmlJSEditorPlugin::tr("Inspect API for Element Under Cursor"), this);
|
||||||
cmd = ActionManager::registerAction(inspectElementAction,
|
cmd = ActionManager::registerAction(inspectElementAction,
|
||||||
Id(Constants::INSPECT_ELEMENT_UNDER_CURSOR), context);
|
Id(Constants::INSPECT_ELEMENT_UNDER_CURSOR), context);
|
||||||
connect(inspectElementAction, &QAction::triggered, [] {
|
connect(inspectElementAction, &QAction::triggered, [] {
|
||||||
@@ -166,11 +192,11 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
});
|
});
|
||||||
qmlToolsMenu->addAction(cmd);
|
qmlToolsMenu->addAction(cmd);
|
||||||
|
|
||||||
QAction *showQuickToolbar = new QAction(tr("Show Qt Quick Toolbar"), this);
|
QAction *showQuickToolbar = new QAction(QmlJSEditorPlugin::tr("Show Qt Quick Toolbar"), this);
|
||||||
cmd = ActionManager::registerAction(showQuickToolbar, Constants::SHOW_QT_QUICK_HELPER, context);
|
cmd = ActionManager::registerAction(showQuickToolbar, Constants::SHOW_QT_QUICK_HELPER, context);
|
||||||
cmd->setDefaultKeySequence(useMacShortcuts ? QKeySequence(Qt::META + Qt::ALT + Qt::Key_Space)
|
cmd->setDefaultKeySequence(useMacShortcuts ? QKeySequence(Qt::META + Qt::ALT + Qt::Key_Space)
|
||||||
: QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Space));
|
: QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Space));
|
||||||
connect(showQuickToolbar, &QAction::triggered, this, &QmlJSEditorPlugin::showContextPane);
|
connect(showQuickToolbar, &QAction::triggered, this, &QmlJSEditorPluginPrivate::showContextPane);
|
||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
qmlToolsMenu->addAction(cmd);
|
qmlToolsMenu->addAction(cmd);
|
||||||
|
|
||||||
@@ -185,24 +211,13 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
|
|
||||||
m_quickFixAssistProvider = new QmlJSQuickFixAssistProvider(this);
|
|
||||||
|
|
||||||
errorMessage->clear();
|
|
||||||
|
|
||||||
FileIconProvider::registerIconOverlayForSuffix(ProjectExplorer::Constants::FILEOVERLAY_QML, "qml");
|
FileIconProvider::registerIconOverlayForSuffix(ProjectExplorer::Constants::FILEOVERLAY_QML, "qml");
|
||||||
|
|
||||||
addAutoReleasedObject(new QmlJSOutlineWidgetFactory);
|
|
||||||
|
|
||||||
addAutoReleasedObject(new QuickToolBar);
|
|
||||||
addAutoReleasedObject(new QmlJsEditingSettingsPage);
|
|
||||||
|
|
||||||
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
||||||
this, &QmlJSEditorPlugin::currentEditorChanged);
|
this, &QmlJSEditorPluginPrivate::currentEditorChanged);
|
||||||
|
|
||||||
connect(EditorManager::instance(), &Core::EditorManager::aboutToSave,
|
connect(EditorManager::instance(), &EditorManager::aboutToSave,
|
||||||
this, &QmlJSEditorPlugin::autoFormatOnSave);
|
this, &QmlJSEditorPluginPrivate::autoFormatOnSave);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::extensionsInitialized()
|
void QmlJSEditorPlugin::extensionsInitialized()
|
||||||
@@ -218,24 +233,24 @@ ExtensionSystem::IPlugin::ShutdownFlag QmlJSEditorPlugin::aboutToShutdown()
|
|||||||
return IPlugin::aboutToShutdown();
|
return IPlugin::aboutToShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::JsonSchemaManager *QmlJSEditorPlugin::jsonManager() const
|
Utils::JsonSchemaManager *QmlJSEditorPlugin::jsonManager()
|
||||||
{
|
{
|
||||||
return m_jsonManager.data();
|
return &m_instance->d->m_jsonManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::findUsages()
|
void QmlJSEditorPluginPrivate::findUsages()
|
||||||
{
|
{
|
||||||
if (QmlJSEditorWidget *editor = qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget()))
|
if (QmlJSEditorWidget *editor = qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget()))
|
||||||
editor->findUsages();
|
editor->findUsages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::renameUsages()
|
void QmlJSEditorPluginPrivate::renameUsages()
|
||||||
{
|
{
|
||||||
if (QmlJSEditorWidget *editor = qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget()))
|
if (QmlJSEditorWidget *editor = qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget()))
|
||||||
editor->renameUsages();
|
editor->renameUsages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::reformatFile()
|
void QmlJSEditorPluginPrivate::reformatFile()
|
||||||
{
|
{
|
||||||
if (m_currentDocument) {
|
if (m_currentDocument) {
|
||||||
QmlJS::Document::Ptr document = m_currentDocument->semanticInfo().document;
|
QmlJS::Document::Ptr document = m_currentDocument->semanticInfo().document;
|
||||||
@@ -281,13 +296,13 @@ void QmlJSEditorPlugin::reformatFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::showContextPane()
|
void QmlJSEditorPluginPrivate::showContextPane()
|
||||||
{
|
{
|
||||||
if (QmlJSEditorWidget *editor = qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget()))
|
if (QmlJSEditorWidget *editor = qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget()))
|
||||||
editor->showContextPane();
|
editor->showContextPane();
|
||||||
}
|
}
|
||||||
|
|
||||||
Command *QmlJSEditorPlugin::addToolAction(QAction *a,
|
Command *QmlJSEditorPluginPrivate::addToolAction(QAction *a,
|
||||||
Context &context, Id id,
|
Context &context, Id id,
|
||||||
ActionContainer *c1, const QString &keySequence)
|
ActionContainer *c1, const QString &keySequence)
|
||||||
{
|
{
|
||||||
@@ -298,14 +313,14 @@ Command *QmlJSEditorPlugin::addToolAction(QAction *a,
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlJSQuickFixAssistProvider *QmlJSEditorPlugin::quickFixAssistProvider() const
|
QmlJSQuickFixAssistProvider *QmlJSEditorPlugin::quickFixAssistProvider()
|
||||||
{
|
{
|
||||||
return m_quickFixAssistProvider;
|
return &m_instance->d->m_quickFixAssistProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::currentEditorChanged(IEditor *editor)
|
void QmlJSEditorPluginPrivate::currentEditorChanged(IEditor *editor)
|
||||||
{
|
{
|
||||||
QmlJSEditorDocument *document = 0;
|
QmlJSEditorDocument *document = nullptr;
|
||||||
if (editor)
|
if (editor)
|
||||||
document = qobject_cast<QmlJSEditorDocument *>(editor->document());
|
document = qobject_cast<QmlJSEditorDocument *>(editor->document());
|
||||||
|
|
||||||
@@ -314,26 +329,26 @@ void QmlJSEditorPlugin::currentEditorChanged(IEditor *editor)
|
|||||||
m_currentDocument = document;
|
m_currentDocument = document;
|
||||||
if (document) {
|
if (document) {
|
||||||
connect(document->document(), &QTextDocument::contentsChanged,
|
connect(document->document(), &QTextDocument::contentsChanged,
|
||||||
this, &QmlJSEditorPlugin::checkCurrentEditorSemanticInfoUpToDate);
|
this, &QmlJSEditorPluginPrivate::checkCurrentEditorSemanticInfoUpToDate);
|
||||||
connect(document, &QmlJSEditorDocument::semanticInfoUpdated,
|
connect(document, &QmlJSEditorDocument::semanticInfoUpdated,
|
||||||
this, &QmlJSEditorPlugin::checkCurrentEditorSemanticInfoUpToDate);
|
this, &QmlJSEditorPluginPrivate::checkCurrentEditorSemanticInfoUpToDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::runSemanticScan()
|
void QmlJSEditorPluginPrivate::runSemanticScan()
|
||||||
{
|
{
|
||||||
m_qmlTaskManager->updateSemanticMessagesNow();
|
m_qmlTaskManager.updateSemanticMessagesNow();
|
||||||
TaskHub::setCategoryVisibility(Constants::TASK_CATEGORY_QML_ANALYSIS, true);
|
TaskHub::setCategoryVisibility(Constants::TASK_CATEGORY_QML_ANALYSIS, true);
|
||||||
TaskHub::requestPopup();
|
TaskHub::requestPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::checkCurrentEditorSemanticInfoUpToDate()
|
void QmlJSEditorPluginPrivate::checkCurrentEditorSemanticInfoUpToDate()
|
||||||
{
|
{
|
||||||
const bool semanticInfoUpToDate = m_currentDocument && !m_currentDocument->isSemanticInfoOutdated();
|
const bool semanticInfoUpToDate = m_currentDocument && !m_currentDocument->isSemanticInfoOutdated();
|
||||||
m_reformatFileAction->setEnabled(semanticInfoUpToDate);
|
m_reformatFileAction->setEnabled(semanticInfoUpToDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorPlugin::autoFormatOnSave(Core::IDocument *document)
|
void QmlJSEditorPluginPrivate::autoFormatOnSave(IDocument *document)
|
||||||
{
|
{
|
||||||
if (!QmlJsEditingSettings::get().autoFormatOnSave())
|
if (!QmlJsEditingSettings::get().autoFormatOnSave())
|
||||||
return;
|
return;
|
||||||
@@ -344,12 +359,13 @@ void QmlJSEditorPlugin::autoFormatOnSave(Core::IDocument *document)
|
|||||||
|
|
||||||
// Check if file is contained in the current project (if wished)
|
// Check if file is contained in the current project (if wished)
|
||||||
if (QmlJsEditingSettings::get().autoFormatOnlyCurrentProject()) {
|
if (QmlJsEditingSettings::get().autoFormatOnlyCurrentProject()) {
|
||||||
const ProjectExplorer::Project *pro = ProjectExplorer::ProjectTree::currentProject();
|
const Project *pro = ProjectTree::currentProject();
|
||||||
if (!pro || !pro->files(ProjectExplorer::Project::SourceFiles).contains(document->filePath()))
|
if (!pro || !pro->files(Project::SourceFiles).contains(document->filePath()))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reformatFile();
|
reformatFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
} // namespace QmlJSEditor
|
} // namespace QmlJSEditor
|
||||||
|
@@ -26,32 +26,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
#include <coreplugin/icontext.h>
|
|
||||||
#include <coreplugin/id.h>
|
|
||||||
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
|
||||||
|
|
||||||
namespace Utils { class JsonSchemaManager; }
|
namespace Utils { class JsonSchemaManager; }
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
class Command;
|
|
||||||
class ActionContainer;
|
|
||||||
class IDocument;
|
|
||||||
class IEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace QmlJS { class ModelManagerInterface; }
|
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
|
|
||||||
class QmlJSEditorDocument;
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class QmlJSQuickFixAssistProvider;
|
class QmlJSQuickFixAssistProvider;
|
||||||
class QmlTaskManager;
|
|
||||||
|
|
||||||
class QmlJSEditorPlugin : public ExtensionSystem::IPlugin
|
class QmlJSEditorPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
@@ -60,44 +41,17 @@ class QmlJSEditorPlugin : public ExtensionSystem::IPlugin
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
QmlJSEditorPlugin();
|
QmlJSEditorPlugin();
|
||||||
virtual ~QmlJSEditorPlugin();
|
~QmlJSEditorPlugin() final;
|
||||||
|
|
||||||
// IPlugin
|
static QmlJSQuickFixAssistProvider *quickFixAssistProvider();
|
||||||
bool initialize(const QStringList &arguments, QString *errorMessage = 0);
|
static Utils::JsonSchemaManager *jsonManager();
|
||||||
void extensionsInitialized();
|
|
||||||
ShutdownFlag aboutToShutdown();
|
|
||||||
|
|
||||||
static QmlJSEditorPlugin *instance()
|
|
||||||
{ return m_instance; }
|
|
||||||
|
|
||||||
QmlJSQuickFixAssistProvider *quickFixAssistProvider() const;
|
|
||||||
|
|
||||||
Utils::JsonSchemaManager *jsonManager() const;
|
|
||||||
|
|
||||||
void findUsages();
|
|
||||||
void renameUsages();
|
|
||||||
void reformatFile();
|
|
||||||
void showContextPane();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void currentEditorChanged(Core::IEditor *editor);
|
bool initialize(const QStringList &arguments, QString *errorMessage) final;
|
||||||
void runSemanticScan();
|
void extensionsInitialized() final;
|
||||||
void checkCurrentEditorSemanticInfoUpToDate();
|
ShutdownFlag aboutToShutdown() final;
|
||||||
void autoFormatOnSave(Core::IDocument *document);
|
|
||||||
|
|
||||||
Core::Command *addToolAction(QAction *a, Core::Context &context, Core::Id id,
|
class QmlJSEditorPluginPrivate *d = nullptr;
|
||||||
Core::ActionContainer *c1, const QString &keySequence);
|
|
||||||
|
|
||||||
static QmlJSEditorPlugin *m_instance;
|
|
||||||
|
|
||||||
QmlJS::ModelManagerInterface *m_modelManager;
|
|
||||||
QmlJSQuickFixAssistProvider *m_quickFixAssistProvider;
|
|
||||||
QmlTaskManager *m_qmlTaskManager;
|
|
||||||
|
|
||||||
QAction *m_reformatFileAction;
|
|
||||||
|
|
||||||
QPointer<QmlJSEditorDocument> m_currentDocument;
|
|
||||||
QScopedPointer<Utils::JsonSchemaManager> m_jsonManager;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -80,12 +80,6 @@ class QmlJSQuickFixAssistProcessor : public IAssistProcessor
|
|||||||
// ---------------------------
|
// ---------------------------
|
||||||
// QmlJSQuickFixAssistProvider
|
// QmlJSQuickFixAssistProvider
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
QmlJSQuickFixAssistProvider::QmlJSQuickFixAssistProvider(QObject *parent)
|
|
||||||
: IAssistProvider(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QmlJSQuickFixAssistProvider::~QmlJSQuickFixAssistProvider()
|
|
||||||
{}
|
|
||||||
|
|
||||||
IAssistProvider::RunType QmlJSQuickFixAssistProvider::runType() const
|
IAssistProvider::RunType QmlJSQuickFixAssistProvider::runType() const
|
||||||
{
|
{
|
||||||
|
@@ -53,8 +53,8 @@ private:
|
|||||||
class QmlJSQuickFixAssistProvider : public TextEditor::IAssistProvider
|
class QmlJSQuickFixAssistProvider : public TextEditor::IAssistProvider
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QmlJSQuickFixAssistProvider(QObject *parent = nullptr);
|
QmlJSQuickFixAssistProvider() = default;
|
||||||
~QmlJSQuickFixAssistProvider();
|
~QmlJSQuickFixAssistProvider() = default;
|
||||||
|
|
||||||
IAssistProvider::RunType runType() const override;
|
IAssistProvider::RunType runType() const override;
|
||||||
TextEditor::IAssistProcessor *createProcessor() const override;
|
TextEditor::IAssistProcessor *createProcessor() const override;
|
||||||
|
@@ -125,8 +125,7 @@ QmlJSTools::SemanticInfo SemanticInfoUpdater::makeNewSemanticInfo(const QmlJS::D
|
|||||||
semanticInfo.setRootScopeChain(QSharedPointer<const ScopeChain>(scopeChain));
|
semanticInfo.setRootScopeChain(QSharedPointer<const ScopeChain>(scopeChain));
|
||||||
|
|
||||||
if (doc->language() == Dialect::Json) {
|
if (doc->language() == Dialect::Json) {
|
||||||
Utils::JsonSchema *schema =
|
Utils::JsonSchema *schema = QmlJSEditorPlugin::jsonManager()->schemaForFile(doc->fileName());
|
||||||
QmlJSEditorPlugin::instance()->jsonManager()->schemaForFile(doc->fileName());
|
|
||||||
if (schema) {
|
if (schema) {
|
||||||
JsonCheck jsonChecker(doc);
|
JsonCheck jsonChecker(doc);
|
||||||
semanticInfo.staticAnalysisMessages = jsonChecker(schema);
|
semanticInfo.staticAnalysisMessages = jsonChecker(schema);
|
||||||
|
@@ -47,9 +47,7 @@ using namespace Utils;
|
|||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
QmlTaskManager::QmlTaskManager(QObject *parent) :
|
QmlTaskManager::QmlTaskManager()
|
||||||
QObject(parent),
|
|
||||||
m_updatingSemantic(false)
|
|
||||||
{
|
{
|
||||||
// displaying results incrementally leads to flickering
|
// displaying results incrementally leads to flickering
|
||||||
// connect(&m_messageCollector, &QFutureWatcherBase::resultsReadyAt,
|
// connect(&m_messageCollector, &QFutureWatcherBase::resultsReadyAt,
|
||||||
|
@@ -43,7 +43,7 @@ class QmlTaskManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QmlTaskManager(QObject *parent = 0);
|
QmlTaskManager();
|
||||||
|
|
||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ private:
|
|||||||
QHash<QString, QList<ProjectExplorer::Task> > m_docsWithTasks;
|
QHash<QString, QList<ProjectExplorer::Task> > m_docsWithTasks;
|
||||||
QFutureWatcher<FileErrorMessages> m_messageCollector;
|
QFutureWatcher<FileErrorMessages> m_messageCollector;
|
||||||
QTimer m_updateDelay;
|
QTimer m_updateDelay;
|
||||||
bool m_updatingSemantic;
|
bool m_updatingSemantic = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
@@ -74,12 +74,8 @@ static inline const ObjectValue * getPropertyChangesTarget(Node *node, const Sco
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuickToolBar::QuickToolBar(QObject *parent)
|
QuickToolBar::QuickToolBar()
|
||||||
: ::IContextPane(parent)
|
|
||||||
, m_editorWidget(0)
|
|
||||||
, m_blockWriting(false)
|
|
||||||
{
|
{
|
||||||
m_node = 0;
|
|
||||||
contextWidget();
|
contextWidget();
|
||||||
|
|
||||||
m_propertyOrder
|
m_propertyOrder
|
||||||
|
@@ -38,7 +38,7 @@ class QuickToolBar : public QmlJS::IContextPane
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QuickToolBar(QObject *parent = 0);
|
QuickToolBar();
|
||||||
~QuickToolBar();
|
~QuickToolBar();
|
||||||
void apply(TextEditor::TextEditorWidget *widget, QmlJS::Document::Ptr document, const QmlJS::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false);
|
void apply(TextEditor::TextEditorWidget *widget, QmlJS::Document::Ptr document, const QmlJS::ScopeChain *scopeChain, QmlJS::AST::Node *node, bool update, bool force = false);
|
||||||
bool isAvailable(TextEditor::TextEditorWidget *widget, QmlJS::Document::Ptr document, QmlJS::AST::Node *node);
|
bool isAvailable(TextEditor::TextEditorWidget *widget, QmlJS::Document::Ptr document, QmlJS::AST::Node *node);
|
||||||
@@ -59,9 +59,9 @@ private:
|
|||||||
QmlEditorWidgets::ContextPaneWidget* contextWidget();
|
QmlEditorWidgets::ContextPaneWidget* contextWidget();
|
||||||
QPointer<QmlEditorWidgets::ContextPaneWidget> m_widget;
|
QPointer<QmlEditorWidgets::ContextPaneWidget> m_widget;
|
||||||
QmlJS::Document::Ptr m_doc;
|
QmlJS::Document::Ptr m_doc;
|
||||||
QmlJS::AST::Node *m_node;
|
QmlJS::AST::Node *m_node = nullptr;
|
||||||
TextEditor::TextEditorWidget *m_editorWidget;
|
TextEditor::TextEditorWidget *m_editorWidget = nullptr;
|
||||||
bool m_blockWriting;
|
bool m_blockWriting = false;
|
||||||
QStringList m_propertyOrder;
|
QStringList m_propertyOrder;
|
||||||
QStringList m_prototypes;
|
QStringList m_prototypes;
|
||||||
QString m_oldType;
|
QString m_oldType;
|
||||||
|
Reference in New Issue
Block a user