2009-04-22 15:21:04 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
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:39:41 +01:00
|
|
|
#include "qmljscodecompletion.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-06-03 15:49:29 +02:00
|
|
|
#include "qmljsquickfix.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"
|
2010-04-23 13:19:28 +02:00
|
|
|
|
2010-11-11 10:05:05 +01:00
|
|
|
#include <qmljs/qmljsicons.h>
|
|
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
|
|
|
|
|
2010-04-23 13:19:28 +02:00
|
|
|
#include <qmldesigner/qmldesignerconstants.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.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 <extensionsystem/pluginmanager.h>
|
|
|
|
|
#include <texteditor/fontsettings.h>
|
|
|
|
|
#include <texteditor/storagesettings.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
|
|
|
|
#include <texteditor/textfilewizard.h>
|
|
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
|
|
|
|
#include <texteditor/completionsupport.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QtPlugin>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QSettings>
|
2009-10-23 11:07:35 +02:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QCoreApplication>
|
2010-06-03 15:49:29 +02:00
|
|
|
#include <QtCore/QTimer>
|
2010-04-23 13:19:28 +02:00
|
|
|
#include <QtGui/QMenu>
|
2009-04-22 15:21:04 +02:00
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
using namespace QmlJSEditor;
|
|
|
|
|
using namespace QmlJSEditor::Internal;
|
|
|
|
|
using namespace QmlJSEditor::Constants;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-06-03 15:49:29 +02:00
|
|
|
enum {
|
|
|
|
|
QUICKFIX_INTERVAL = 20
|
|
|
|
|
};
|
|
|
|
|
|
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_wizard(0),
|
|
|
|
|
m_editor(0),
|
2010-05-10 18:30:09 +02:00
|
|
|
m_actionHandler(0)
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
|
|
|
|
m_instance = this;
|
2010-06-03 15:49:29 +02:00
|
|
|
|
|
|
|
|
m_quickFixCollector = 0;
|
|
|
|
|
m_quickFixTimer = new QTimer(this);
|
|
|
|
|
m_quickFixTimer->setInterval(20);
|
|
|
|
|
m_quickFixTimer->setSingleShot(true);
|
|
|
|
|
connect(m_quickFixTimer, SIGNAL(timeout()), this, SLOT(quickFixNow()));
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:57:07 +02:00
|
|
|
/*! Copied from cppplugin.cpp */
|
|
|
|
|
static inline
|
|
|
|
|
Core::Command *createSeparator(Core::ActionManager *am,
|
|
|
|
|
QObject *parent,
|
|
|
|
|
Core::Context &context,
|
|
|
|
|
const char *id)
|
|
|
|
|
{
|
|
|
|
|
QAction *separator = new QAction(parent);
|
|
|
|
|
separator->setSeparator(true);
|
|
|
|
|
return am->registerAction(separator, Core::Id(id), context);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *error_message)
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
|
|
|
|
Core::ICore *core = Core::ICore::instance();
|
2010-01-15 17:20:03 +01:00
|
|
|
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/qmljseditor/QmlJSEditor.mimetypes.xml"), error_message))
|
2009-04-22 15:21:04 +02:00
|
|
|
return false;
|
2009-09-04 16:51:11 +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);
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-08-23 16:00:24 +02:00
|
|
|
Core::Context context(QmlJSEditor::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);
|
|
|
|
|
|
2010-11-15 14:02:15 +01:00
|
|
|
Core::BaseFileWizardParameters qmlWizardParameters(Core::IWizard::FileWizard);
|
|
|
|
|
qmlWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_QML));
|
|
|
|
|
qmlWizardParameters.setDisplayCategory(QCoreApplication::translate("QmlJsEditor", Constants::WIZARD_TR_CATEGORY_QML));
|
|
|
|
|
qmlWizardParameters.setDescription(tr("Creates a QML file."));
|
|
|
|
|
qmlWizardParameters.setDisplayName(tr("QML File"));
|
|
|
|
|
qmlWizardParameters.setId(QLatin1String("Q.Qml"));
|
|
|
|
|
addAutoReleasedObject(new QmlFileWizard(qmlWizardParameters, core));
|
|
|
|
|
|
|
|
|
|
Core::BaseFileWizardParameters jsWizardParameters(Core::IWizard::FileWizard);
|
|
|
|
|
jsWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_QML));
|
|
|
|
|
jsWizardParameters.setDisplayCategory(QCoreApplication::translate("QmlJsEditor", Constants::WIZARD_TR_CATEGORY_QML));
|
|
|
|
|
jsWizardParameters.setDescription(tr("Creates a JavaScript file."));
|
|
|
|
|
jsWizardParameters.setDisplayName(tr("JS File"));
|
|
|
|
|
jsWizardParameters.setId(QLatin1String("Z.Js"));
|
|
|
|
|
addAutoReleasedObject(new JsFileWizard(jsWizardParameters, core));
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
m_actionHandler = new TextEditor::TextEditorActionHandler(QmlJSEditor::Constants::C_QMLJSEDITOR_ID,
|
2009-04-22 15:21:04 +02:00
|
|
|
TextEditor::TextEditorActionHandler::Format
|
|
|
|
|
| TextEditor::TextEditorActionHandler::UnCommentSelection
|
|
|
|
|
| TextEditor::TextEditorActionHandler::UnCollapseAll);
|
2009-09-11 14:42:50 +02:00
|
|
|
m_actionHandler->initializeActions();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-11-09 17:35:20 +01:00
|
|
|
Core::ActionManager *am = core->actionManager();
|
2010-02-08 12:50:10 +01:00
|
|
|
Core::ActionContainer *contextMenu = am->createMenu(QmlJSEditor::Constants::M_CONTEXT);
|
2010-09-16 12:57:07 +02:00
|
|
|
Core::ActionContainer *qmlToolsMenu = am->createMenu(Core::Id(Constants::M_TOOLS_QML));
|
2010-12-16 11:49:47 +01:00
|
|
|
qmlToolsMenu->setOnAllDisabledBehavior(Core::ActionContainer::Hide);
|
2010-09-16 12:57:07 +02:00
|
|
|
QMenu *menu = qmlToolsMenu->menu();
|
2010-09-23 15:18:07 +02:00
|
|
|
//: QML sub-menu in the Tools menu
|
|
|
|
|
menu->setTitle(tr("QML"));
|
2010-09-16 12:57:07 +02:00
|
|
|
am->actionContainer(Core::Constants::M_TOOLS)->addMenu(qmlToolsMenu);
|
2010-02-08 12:50:10 +01:00
|
|
|
|
2010-08-19 15:53:29 +02:00
|
|
|
Core::Command *cmd;
|
2010-02-08 12:50:10 +01:00
|
|
|
QAction *followSymbolUnderCursorAction = new QAction(tr("Follow Symbol Under Cursor"), this);
|
|
|
|
|
cmd = am->registerAction(followSymbolUnderCursorAction, Constants::FOLLOW_SYMBOL_UNDER_CURSOR, context);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
|
|
|
|
|
connect(followSymbolUnderCursorAction, SIGNAL(triggered()), this, SLOT(followSymbolUnderCursor()));
|
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);
|
|
|
|
|
cmd = am->registerAction(findUsagesAction, Constants::FIND_USAGES, context);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
|
|
|
|
|
connect(findUsagesAction, SIGNAL(triggered()), this, SLOT(findUsages()));
|
|
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
qmlToolsMenu->addAction(cmd);
|
|
|
|
|
|
2010-09-01 11:54:00 +02:00
|
|
|
QAction *showQuickToolbar = new QAction(tr("Show Qt Quick Toolbar"), this);
|
2010-08-04 13:50:15 +02:00
|
|
|
cmd = am->registerAction(showQuickToolbar, Constants::SHOW_QT_QUICK_HELPER, context);
|
2010-10-12 11:19:01 +02:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence(Qt::META + Qt::ALT + Qt::Key_Space));
|
|
|
|
|
#else
|
2010-08-04 13:50:15 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Space));
|
2010-10-12 11:19:01 +02:00
|
|
|
#endif
|
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:
|
|
|
|
|
Core::Context globalContext(Core::Constants::C_GLOBAL);
|
|
|
|
|
Core::Command *sep = createSeparator(am, this, globalContext,
|
|
|
|
|
Constants::SEPARATOR1);
|
|
|
|
|
sep->action()->setObjectName(Constants::M_REFACTORING_MENU_INSERTION_POINT);
|
|
|
|
|
contextMenu->addAction(sep);
|
|
|
|
|
contextMenu->addAction(createSeparator(am, this, globalContext,
|
|
|
|
|
Constants::SEPARATOR2));
|
2010-08-04 13:50:15 +02:00
|
|
|
|
2010-02-08 12:50:10 +01:00
|
|
|
cmd = am->command(TextEditor::Constants::AUTO_INDENT_SELECTION);
|
|
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
|
2009-11-09 17:35:20 +01:00
|
|
|
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
|
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
|
2010-05-10 18:30:09 +02:00
|
|
|
CodeCompletion *completion = new CodeCompletion(m_modelManager);
|
|
|
|
|
addAutoReleasedObject(completion);
|
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
|
|
|
|
2010-05-10 18:30:09 +02:00
|
|
|
// Set completion settings and keep them up to date
|
|
|
|
|
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
|
|
|
|
|
completion->setCompletionSettings(textEditorSettings->completionSettings());
|
|
|
|
|
connect(textEditorSettings, SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)),
|
|
|
|
|
completion, SLOT(setCompletionSettings(TextEditor::CompletionSettings)));
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
error_message->clear();
|
|
|
|
|
|
2010-04-01 17:21:18 +02:00
|
|
|
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
|
2010-07-30 22:16:59 +02:00
|
|
|
iconProvider->registerIconOverlayForSuffix(QIcon(QLatin1String(":/qmljseditor/images/qmlfile.png")), "qml");
|
2010-04-01 17:21:18 +02:00
|
|
|
|
2010-06-03 15:49:29 +02:00
|
|
|
m_quickFixCollector = new QmlJSQuickFixCollector;
|
|
|
|
|
addAutoReleasedObject(m_quickFixCollector);
|
2010-07-26 13:06:33 +02:00
|
|
|
QmlJSQuickFixCollector::registerQuickFixes(this);
|
2010-06-03 15:49:29 +02:00
|
|
|
|
2010-07-08 11:32:45 +02:00
|
|
|
addAutoReleasedObject(new QmlJSOutlineWidgetFactory);
|
|
|
|
|
|
2010-07-13 17:16:43 +02:00
|
|
|
m_qmlTaskManager = new QmlTaskManager;
|
|
|
|
|
addAutoReleasedObject(m_qmlTaskManager);
|
|
|
|
|
|
|
|
|
|
connect(m_modelManager, SIGNAL(documentChangedOnDisk(QmlJS::Document::Ptr)),
|
2011-04-21 11:09:29 +02:00
|
|
|
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()));
|
2010-07-13 17:16:43 +02:00
|
|
|
connect(m_modelManager, SIGNAL(aboutToRemoveFiles(QStringList)),
|
|
|
|
|
m_qmlTaskManager, SLOT(documentsRemoved(QStringList)));
|
|
|
|
|
|
2010-08-12 15:48:24 +02:00
|
|
|
addAutoReleasedObject(new QuickToolBar);
|
|
|
|
|
addAutoReleasedObject(new Internal::QuickToolBarSettingsPage);
|
|
|
|
|
|
2010-12-14 15:04:46 +01:00
|
|
|
connect(core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(currentEditorChanged(Core::IEditor*)));
|
|
|
|
|
|
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
|
|
|
{
|
2010-07-13 17:16:43 +02:00
|
|
|
ProjectExplorer::TaskHub *taskHub =
|
|
|
|
|
ExtensionSystem::PluginManager::instance()->getObject<ProjectExplorer::TaskHub>();
|
|
|
|
|
taskHub->addCategory(Constants::TASK_CATEGORY_QML, tr("QML"));
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
void QmlJSEditorPlugin::initializeEditor(QmlJSEditor::QmlJSTextEditorWidget *editor)
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_instance, /**/);
|
|
|
|
|
|
|
|
|
|
m_actionHandler->setupActions(editor);
|
|
|
|
|
|
|
|
|
|
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 12:50:10 +01:00
|
|
|
void QmlJSEditorPlugin::followSymbolUnderCursor()
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(em->currentEditor()->widget()))
|
2010-02-08 12:50:10 +01:00
|
|
|
editor->followSymbolUnderCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-24 14:05:34 +02:00
|
|
|
void QmlJSEditorPlugin::findUsages()
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
2011-02-21 16:02:26 +01:00
|
|
|
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(em->currentEditor()->widget()))
|
2010-09-24 14:05:34 +02:00
|
|
|
editor->findUsages();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-04 13:50:15 +02:00
|
|
|
void QmlJSEditorPlugin::showContextPane()
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(em->currentEditor()->widget()))
|
2010-08-04 13:50:15 +02:00
|
|
|
editor->showContextPane();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 13:19:28 +02:00
|
|
|
Core::Command *QmlJSEditorPlugin::addToolAction(QAction *a, Core::ActionManager *am,
|
2010-06-25 12:56:16 +02:00
|
|
|
Core::Context &context, const QString &name,
|
2010-04-23 13:19:28 +02:00
|
|
|
Core::ActionContainer *c1, const QString &keySequence)
|
|
|
|
|
{
|
|
|
|
|
Core::Command *command = am->registerAction(a, name, context);
|
|
|
|
|
if (!keySequence.isEmpty())
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(keySequence));
|
|
|
|
|
c1->addAction(command);
|
|
|
|
|
return command;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-03 15:49:29 +02:00
|
|
|
QmlJSQuickFixCollector *QmlJSEditorPlugin::quickFixCollector() const
|
|
|
|
|
{ return m_quickFixCollector; }
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
void QmlJSEditorPlugin::quickFix(TextEditor::ITextEditor *editable)
|
2010-06-03 15:49:29 +02:00
|
|
|
{
|
|
|
|
|
m_currentTextEditable = editable;
|
|
|
|
|
quickFixNow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSEditorPlugin::quickFixNow()
|
|
|
|
|
{
|
|
|
|
|
if (! m_currentTextEditable)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
2011-02-21 16:02:26 +01:00
|
|
|
QmlJSTextEditorWidget *currentEditor = qobject_cast<QmlJSTextEditorWidget*>(em->currentEditor()->widget());
|
2010-06-03 15:49:29 +02:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(m_currentTextEditable->widget())) {
|
2010-06-03 15:49:29 +02:00
|
|
|
if (currentEditor == editor) {
|
|
|
|
|
if (editor->isOutdated()) {
|
2010-07-13 10:45:20 +02:00
|
|
|
// qDebug() << "TODO: outdated document" << editor->editorRevision() << editor->semanticInfo().revision();
|
2010-06-03 15:49:29 +02:00
|
|
|
// ### FIXME: m_quickFixTimer->start(QUICKFIX_INTERVAL);
|
|
|
|
|
m_quickFixTimer->stop();
|
2010-06-07 12:12:07 +02:00
|
|
|
} else {
|
2011-02-21 14:02:00 +01:00
|
|
|
TextEditor::CompletionSupport::instance()
|
|
|
|
|
->complete(m_currentTextEditable, TextEditor::QuickFixCompletion, true);
|
2010-06-07 12:12:07 +02:00
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (! editor)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
else if (QmlJSTextEditorWidget *textEditor = qobject_cast<QmlJSTextEditorWidget *>(editor->widget())) {
|
2010-12-14 15:04:46 +01:00
|
|
|
textEditor->forceSemanticRehighlight();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
Q_EXPORT_PLUGIN(QmlJSEditorPlugin)
|