2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
#include "qmljseditorplugin.h"
|
2010-02-15 12:27:25 +01:00
|
|
|
#include "qmljshighlighter.h"
|
2010-01-15 17:20:03 +01:00
|
|
|
#include "qmljseditor.h"
|
|
|
|
|
#include "qmljseditorconstants.h"
|
|
|
|
|
#include "qmljseditorfactory.h"
|
2010-02-15 13:41:51 +01:00
|
|
|
#include "qmljshoverhandler.h"
|
2009-09-24 12:54:53 +02:00
|
|
|
#include "qmlfilewizard.h"
|
2010-11-15 14:02:15 +01:00
|
|
|
#include "jsfilewizard.h"
|
2010-07-08 11:32:45 +02:00
|
|
|
#include "qmljsoutline.h"
|
2010-04-23 13:19:28 +02:00
|
|
|
#include "qmljspreviewrunner.h"
|
2010-12-02 17:02:23 +01:00
|
|
|
#include "qmljssnippetprovider.h"
|
2010-07-13 17:16:43 +02:00
|
|
|
#include "qmltaskmanager.h"
|
2010-08-12 15:48:24 +02:00
|
|
|
#include "quicktoolbar.h"
|
|
|
|
|
#include "quicktoolbarsettingspage.h"
|
2011-04-15 16:19:23 +02:00
|
|
|
#include "qmljscompletionassist.h"
|
|
|
|
|
#include "qmljsquickfixassist.h"
|
2013-08-14 13:52:13 +02:00
|
|
|
#include "qmljshighlighterfactory.h"
|
2010-04-23 13:19:28 +02:00
|
|
|
|
2010-11-11 10:05:05 +01:00
|
|
|
#include <qmljs/qmljsicons.h>
|
|
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2011-11-07 15:14:43 +01:00
|
|
|
#include <qmljs/qmljsreformatter.h>
|
2011-02-03 15:48:14 +01:00
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
2010-11-11 10:05:05 +01:00
|
|
|
|
2010-04-23 13:19:28 +02:00
|
|
|
#include <qmldesigner/qmldesignerconstants.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2013-09-20 15:12:44 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-04-01 17:21:18 +02:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2010-02-08 12:50:10 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2010-07-13 17:16:43 +02:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
|
|
|
|
#include <texteditor/textfilewizard.h>
|
|
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2012-02-07 15:30:33 +01:00
|
|
|
#include <utils/json.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtPlugin>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QAction>
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
using namespace QmlJSEditor::Constants;
|
2012-03-07 16:40:03 +01:00
|
|
|
using namespace ProjectExplorer;
|
2013-09-20 15:12:44 +02:00
|
|
|
using namespace Core;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-06-03 15:49:29 +02:00
|
|
|
enum {
|
|
|
|
|
QUICKFIX_INTERVAL = 20
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
namespace QmlJSEditor {
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
void registerQuickFixes(ExtensionSystem::IPlugin *plugIn);
|
|
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
QmlJSEditorPlugin *QmlJSEditorPlugin::m_instance = 0;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
QmlJSEditorPlugin::QmlJSEditorPlugin() :
|
2009-09-04 16:51:11 +02:00
|
|
|
m_modelManager(0),
|
2009-04-22 15:21:04 +02:00
|
|
|
m_editor(0),
|
2011-04-15 16:19:23 +02:00
|
|
|
m_actionHandler(0),
|
2011-11-07 15:14:43 +01:00
|
|
|
m_quickFixAssistProvider(0),
|
|
|
|
|
m_reformatFileAction(0),
|
2012-02-07 15:30:33 +01:00
|
|
|
m_currentEditor(0),
|
|
|
|
|
m_jsonManager(new Utils::JsonSchemaManager(
|
2013-09-20 23:17:22 +02:00
|
|
|
QStringList() << Core::ICore::userResourcePath() + QLatin1String("/json/")
|
|
|
|
|
<< Core::ICore::resourcePath() + QLatin1String("/json/")))
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
QmlJSEditorPlugin::~QmlJSEditorPlugin()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
|
|
|
|
removeObject(m_editor);
|
|
|
|
|
delete m_actionHandler;
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2010-11-11 10:05:05 +01:00
|
|
|
m_modelManager = QmlJS::ModelManagerInterface::instance();
|
2010-12-02 17:02:23 +01:00
|
|
|
addAutoReleasedObject(new QmlJSSnippetProvider);
|
2013-08-14 13:52:13 +02:00
|
|
|
addAutoReleasedObject(new QmlJSHighlighterFactory);
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
// QML task updating manager
|
|
|
|
|
m_qmlTaskManager = new QmlTaskManager;
|
|
|
|
|
addAutoReleasedObject(m_qmlTaskManager);
|
|
|
|
|
connect(m_modelManager, SIGNAL(documentChangedOnDisk(QmlJS::Document::Ptr)),
|
|
|
|
|
m_qmlTaskManager, SLOT(updateMessages()));
|
|
|
|
|
// recompute messages when information about libraries changes
|
|
|
|
|
connect(m_modelManager, SIGNAL(libraryInfoUpdated(QString,QmlJS::LibraryInfo)),
|
|
|
|
|
m_qmlTaskManager, SLOT(updateMessages()));
|
|
|
|
|
// recompute messages when project data changes (files added or removed)
|
|
|
|
|
connect(m_modelManager, SIGNAL(projectInfoUpdated(ProjectInfo)),
|
|
|
|
|
m_qmlTaskManager, SLOT(updateMessages()));
|
|
|
|
|
connect(m_modelManager, SIGNAL(aboutToRemoveFiles(QStringList)),
|
|
|
|
|
m_qmlTaskManager, SLOT(documentsRemoved(QStringList)));
|
|
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
Core::Context context(Constants::C_QMLJSEDITOR_ID);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
m_editor = new QmlJSEditorFactory(this);
|
2009-04-22 15:21:04 +02:00
|
|
|
addObject(m_editor);
|
|
|
|
|
|
2013-09-20 15:12:44 +02:00
|
|
|
IWizard *wizard = new QmlFileWizard;
|
|
|
|
|
wizard->setWizardKind(Core::IWizard::FileWizard);
|
|
|
|
|
wizard->setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
|
|
|
|
|
wizard->setDisplayCategory(QCoreApplication::translate("QmlJsEditor", Core::Constants::WIZARD_TR_CATEGORY_QT));
|
|
|
|
|
wizard->setDescription(tr("Creates a QML file with boilerplate code, starting with \"import QtQuick 1.1\"."));
|
|
|
|
|
wizard->setDisplayName(tr("QML File (Qt Quick 1)"));
|
|
|
|
|
wizard->setId(QLatin1String(Constants::WIZARD_QML1FILE));
|
|
|
|
|
addAutoReleasedObject(wizard);
|
|
|
|
|
|
|
|
|
|
wizard = new QmlFileWizard;
|
|
|
|
|
wizard->setWizardKind(Core::IWizard::FileWizard);
|
|
|
|
|
wizard->setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
|
|
|
|
|
wizard->setDisplayCategory(QCoreApplication::translate("QmlJsEditor", Core::Constants::WIZARD_TR_CATEGORY_QT));
|
|
|
|
|
wizard->setDescription(tr("Creates a QML file with boilerplate code, starting with \"import QtQuick 2.0\"."));
|
|
|
|
|
wizard->setDisplayName(tr("QML File (Qt Quick 2)"));
|
|
|
|
|
wizard->setId(QLatin1String(Constants::WIZARD_QML2FILE));
|
|
|
|
|
addAutoReleasedObject(wizard);
|
|
|
|
|
|
|
|
|
|
wizard = new JsFileWizard;
|
|
|
|
|
wizard->setWizardKind(Core::IWizard::FileWizard);
|
|
|
|
|
wizard->setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
|
|
|
|
|
wizard->setDisplayCategory(QCoreApplication::translate("QmlJsEditor", Core::Constants::WIZARD_TR_CATEGORY_QT));
|
|
|
|
|
wizard->setDescription(tr("Creates a JavaScript file."));
|
|
|
|
|
wizard->setDisplayName(tr("JS File"));
|
|
|
|
|
wizard->setId(QLatin1String("Z.Js"));
|
|
|
|
|
addAutoReleasedObject(wizard);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
m_actionHandler = new TextEditor::TextEditorActionHandler(Constants::C_QMLJSEDITOR_ID,
|
2009-04-22 15:21:04 +02:00
|
|
|
TextEditor::TextEditorActionHandler::Format
|
|
|
|
|
| TextEditor::TextEditorActionHandler::UnCommentSelection
|
2012-03-27 23:18:46 +04:00
|
|
|
| TextEditor::TextEditorActionHandler::UnCollapseAll
|
|
|
|
|
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
|
2009-09-11 14:42:50 +02:00
|
|
|
m_actionHandler->initializeActions();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
Core::ActionContainer *contextMenu = Core::ActionManager::createMenu(Constants::M_CONTEXT);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionContainer *qmlToolsMenu = Core::ActionManager::actionContainer(Core::Id(QmlJSTools::Constants::M_TOOLS_QMLJS));
|
2011-06-29 12:03:53 +02:00
|
|
|
|
|
|
|
|
Core::Context globalContext(Core::Constants::C_GLOBAL);
|
2012-06-05 14:22:20 +02:00
|
|
|
qmlToolsMenu->addSeparator(globalContext);
|
2010-02-08 12:50:10 +01:00
|
|
|
|
2010-08-19 15:53:29 +02:00
|
|
|
Core::Command *cmd;
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR);
|
2009-11-09 17:35:20 +01:00
|
|
|
contextMenu->addAction(cmd);
|
2010-09-16 12:57:07 +02:00
|
|
|
qmlToolsMenu->addAction(cmd);
|
2010-02-08 12:50:10 +01:00
|
|
|
|
2010-09-24 14:05:34 +02:00
|
|
|
QAction *findUsagesAction = new QAction(tr("Find Usages"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(findUsagesAction, Constants::FIND_USAGES, context);
|
2010-09-24 14:05:34 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
|
|
|
|
|
connect(findUsagesAction, SIGNAL(triggered()), this, SLOT(findUsages()));
|
|
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
qmlToolsMenu->addAction(cmd);
|
|
|
|
|
|
2011-07-11 14:53:10 +02:00
|
|
|
QAction *renameUsagesAction = new QAction(tr("Rename Symbol Under Cursor"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(renameUsagesAction, Constants::RENAME_USAGES, context);
|
2011-07-11 12:53:05 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+R")));
|
|
|
|
|
connect(renameUsagesAction, SIGNAL(triggered()), this, SLOT(renameUsages()));
|
|
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
qmlToolsMenu->addAction(cmd);
|
|
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
QAction *semanticScan = new QAction(tr("Run Checks"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(semanticScan, Core::Id(Constants::RUN_SEMANTIC_SCAN), globalContext);
|
2011-08-09 14:40:04 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+C")));
|
|
|
|
|
connect(semanticScan, SIGNAL(triggered()), this, SLOT(runSemanticScan()));
|
|
|
|
|
qmlToolsMenu->addAction(cmd);
|
|
|
|
|
|
2011-11-07 15:14:43 +01:00
|
|
|
m_reformatFileAction = new QAction(tr("Reformat File"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(m_reformatFileAction, Core::Id(Constants::REFORMAT_FILE), context);
|
2011-11-07 15:14:43 +01:00
|
|
|
connect(m_reformatFileAction, SIGNAL(triggered()), this, SLOT(reformatFile()));
|
|
|
|
|
qmlToolsMenu->addAction(cmd);
|
|
|
|
|
|
2010-09-01 11:54:00 +02:00
|
|
|
QAction *showQuickToolbar = new QAction(tr("Show Qt Quick Toolbar"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::registerAction(showQuickToolbar, Constants::SHOW_QT_QUICK_HELPER, context);
|
2012-05-23 13:25:51 +02:00
|
|
|
cmd->setDefaultKeySequence(Core::UseMacShortcuts ? QKeySequence(Qt::META + Qt::ALT + Qt::Key_Space)
|
|
|
|
|
: QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Space));
|
2010-08-04 13:50:15 +02:00
|
|
|
connect(showQuickToolbar, SIGNAL(triggered()), this, SLOT(showContextPane()));
|
|
|
|
|
contextMenu->addAction(cmd);
|
2010-09-16 12:57:07 +02:00
|
|
|
qmlToolsMenu->addAction(cmd);
|
|
|
|
|
|
|
|
|
|
// Insert marker for "Refactoring" menu:
|
2012-06-05 14:22:20 +02:00
|
|
|
Core::Command *sep = contextMenu->addSeparator(globalContext);
|
2012-11-26 21:17:34 +02:00
|
|
|
sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT));
|
2012-06-05 14:22:20 +02:00
|
|
|
contextMenu->addSeparator(globalContext);
|
2010-08-04 13:50:15 +02:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::command(TextEditor::Constants::AUTO_INDENT_SELECTION);
|
2010-02-08 12:50:10 +01:00
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
cmd = Core::ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
2009-11-09 17:35:20 +01:00
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
m_quickFixAssistProvider = new QmlJSQuickFixAssistProvider;
|
|
|
|
|
addAutoReleasedObject(m_quickFixAssistProvider);
|
|
|
|
|
addAutoReleasedObject(new QmlJSCompletionAssistProvider);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-05-10 18:30:09 +02:00
|
|
|
addAutoReleasedObject(new HoverHandler);
|
2009-05-06 15:45:19 +02:00
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
errorMessage->clear();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2013-09-12 16:06:33 +02:00
|
|
|
Core::FileIconProvider::registerIconOverlayForSuffix(":/qmljseditor/images/qmlfile.png", "qml");
|
2010-04-01 17:21:18 +02:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
registerQuickFixes(this);
|
2010-06-03 15:49:29 +02:00
|
|
|
|
2010-07-08 11:32:45 +02:00
|
|
|
addAutoReleasedObject(new QmlJSOutlineWidgetFactory);
|
|
|
|
|
|
2010-08-12 15:48:24 +02:00
|
|
|
addAutoReleasedObject(new QuickToolBar);
|
|
|
|
|
addAutoReleasedObject(new Internal::QuickToolBarSettingsPage);
|
|
|
|
|
|
2013-08-29 17:17:24 +02:00
|
|
|
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(currentEditorChanged(Core::IEditor*)));
|
2010-12-14 15:04:46 +01:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
void QmlJSEditorPlugin::extensionsInitialized()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2013-08-15 12:14:46 +02:00
|
|
|
TaskHub::addCategory(Constants::TASK_CATEGORY_QML, tr("QML"));
|
|
|
|
|
TaskHub::addCategory(Constants::TASK_CATEGORY_QML_ANALYSIS, tr("QML Analysis"), false);
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-13 17:05:47 +02:00
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag QmlJSEditorPlugin::aboutToShutdown()
|
|
|
|
|
{
|
|
|
|
|
delete QmlJS::Icons::instance(); // delete object held by singleton
|
|
|
|
|
|
|
|
|
|
return IPlugin::aboutToShutdown();
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
void QmlJSEditorPlugin::initializeEditor(QmlJSTextEditorWidget *editor)
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2011-07-29 12:00:11 +02:00
|
|
|
QTC_CHECK(m_instance);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
|
|
|
|
m_actionHandler->setupActions(editor);
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
editor->setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
|
2013-09-19 17:59:27 +02:00
|
|
|
TextEditor::TextEditorSettings::initializeEditor(editor);
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-07 15:30:33 +01:00
|
|
|
Utils::JsonSchemaManager *QmlJSEditorPlugin::jsonManager() const
|
|
|
|
|
{
|
|
|
|
|
return m_jsonManager.data();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 14:05:34 +02:00
|
|
|
void QmlJSEditorPlugin::findUsages()
|
|
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(Core::EditorManager::currentEditor()->widget()))
|
2010-09-24 14:05:34 +02:00
|
|
|
editor->findUsages();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-11 12:53:05 +02:00
|
|
|
void QmlJSEditorPlugin::renameUsages()
|
|
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(Core::EditorManager::currentEditor()->widget()))
|
2011-07-11 12:53:05 +02:00
|
|
|
editor->renameUsages();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 15:14:43 +01:00
|
|
|
void QmlJSEditorPlugin::reformatFile()
|
|
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(Core::EditorManager::currentEditor()->widget())) {
|
2011-11-18 13:25:09 +01:00
|
|
|
QTC_ASSERT(!editor->isSemanticInfoOutdated(), return);
|
2011-11-07 15:14:43 +01:00
|
|
|
|
|
|
|
|
const QString &newText = QmlJS::reformat(editor->semanticInfo().document);
|
|
|
|
|
QTextCursor tc(editor->textCursor());
|
|
|
|
|
tc.movePosition(QTextCursor::Start);
|
|
|
|
|
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
|
|
|
|
tc.insertText(newText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-04 13:50:15 +02:00
|
|
|
void QmlJSEditorPlugin::showContextPane()
|
|
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(Core::EditorManager::currentEditor()->widget()))
|
2010-08-04 13:50:15 +02:00
|
|
|
editor->showContextPane();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *QmlJSEditorPlugin::addToolAction(QAction *a,
|
2011-11-10 11:36:51 +01:00
|
|
|
Core::Context &context, const Core::Id &id,
|
2010-04-23 13:19:28 +02:00
|
|
|
Core::ActionContainer *c1, const QString &keySequence)
|
|
|
|
|
{
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(a, id, context);
|
2010-04-23 13:19:28 +02:00
|
|
|
if (!keySequence.isEmpty())
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(keySequence));
|
|
|
|
|
c1->addAction(command);
|
|
|
|
|
return command;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
QmlJSQuickFixAssistProvider *QmlJSEditorPlugin::quickFixAssistProvider() const
|
2010-06-03 15:49:29 +02:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
return m_quickFixAssistProvider;
|
2010-06-03 15:49:29 +02:00
|
|
|
}
|
2010-04-23 13:19:28 +02:00
|
|
|
|
2010-12-14 15:04:46 +01:00
|
|
|
void QmlJSEditorPlugin::currentEditorChanged(Core::IEditor *editor)
|
|
|
|
|
{
|
2011-11-07 15:14:43 +01:00
|
|
|
QmlJSTextEditorWidget *newTextEditor = 0;
|
|
|
|
|
if (editor)
|
|
|
|
|
newTextEditor = qobject_cast<QmlJSTextEditorWidget *>(editor->widget());
|
|
|
|
|
|
|
|
|
|
if (m_currentEditor) {
|
|
|
|
|
disconnect(m_currentEditor.data(), SIGNAL(contentsChanged()),
|
|
|
|
|
this, SLOT(checkCurrentEditorSemanticInfoUpToDate()));
|
|
|
|
|
disconnect(m_currentEditor.data(), SIGNAL(semanticInfoUpdated()),
|
|
|
|
|
this, SLOT(checkCurrentEditorSemanticInfoUpToDate()));
|
|
|
|
|
}
|
|
|
|
|
m_currentEditor = newTextEditor;
|
|
|
|
|
if (newTextEditor) {
|
|
|
|
|
connect(newTextEditor, SIGNAL(contentsChanged()),
|
|
|
|
|
this, SLOT(checkCurrentEditorSemanticInfoUpToDate()));
|
|
|
|
|
connect(newTextEditor, SIGNAL(semanticInfoUpdated()),
|
|
|
|
|
this, SLOT(checkCurrentEditorSemanticInfoUpToDate()));
|
2011-11-18 13:25:09 +01:00
|
|
|
newTextEditor->reparseDocumentNow();
|
2010-12-14 15:04:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-09 14:40:04 +02:00
|
|
|
void QmlJSEditorPlugin::runSemanticScan()
|
|
|
|
|
{
|
|
|
|
|
m_qmlTaskManager->updateSemanticMessagesNow();
|
2013-08-15 12:14:46 +02:00
|
|
|
TaskHub::setCategoryVisibility(Constants::TASK_CATEGORY_QML_ANALYSIS, true);
|
|
|
|
|
TaskHub::requestPopup();
|
2011-08-09 14:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-07 15:14:43 +01:00
|
|
|
void QmlJSEditorPlugin::checkCurrentEditorSemanticInfoUpToDate()
|
|
|
|
|
{
|
2011-11-18 13:25:09 +01:00
|
|
|
const bool semanticInfoUpToDate = m_currentEditor && !m_currentEditor->isSemanticInfoOutdated();
|
2011-11-07 15:14:43 +01:00
|
|
|
m_reformatFileAction->setEnabled(semanticInfoUpToDate);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
} // namespace QmlJSEditor
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(QmlJSEditor::Internal::QmlJSEditorPlugin)
|