| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-03-05 11:25:49 +01:00
										 |  |  | ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2009-06-17 00:01:27 +10:00
										 |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Commercial Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Licensees holding valid Qt Commercial licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the Qt Commercial License Agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** 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.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** If you are unsure which license is appropriate for your use, please | 
					
						
							| 
									
										
										
										
											2009-08-14 09:30:56 +02:00
										 |  |  | ** contact the sales department at http://qt.nokia.com/contact.
 | 
					
						
							| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2010-02-15 13:49:00 +01:00
										 |  |  | #include "qmljsmodelmanager.h"
 | 
					
						
							| 
									
										
										
										
											2009-09-24 12:54:53 +02:00
										 |  |  | #include "qmlfilewizard.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-07-13 17:05:47 +02:00
										 |  |  | #include "qmljs/qmljsicons.h"
 | 
					
						
							| 
									
										
										
										
											2010-07-13 17:16:43 +02:00
										 |  |  | #include "qmltaskmanager.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-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-02-15 13:49:00 +01:00
										 |  |  |     m_modelManager = new ModelManager(this); | 
					
						
							| 
									
										
										
										
											2009-09-04 16:51:11 +02:00
										 |  |  |     addAutoReleasedObject(m_modelManager); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:37:59 +02:00
										 |  |  |     Core::Context context(QmlJSEditor::Constants::C_QMLJSEDITOR_ID, | 
					
						
							|  |  |  |                           QmlDesigner::Constants::C_QT_QUICK_TOOLS_MENU); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard); | 
					
						
							| 
									
										
										
										
											2009-11-27 10:33:24 +01:00
										 |  |  |     wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT)); | 
					
						
							| 
									
										
										
										
											2010-01-07 18:17:24 +01:00
										 |  |  |     wizardParameters.setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT)); | 
					
						
							| 
									
										
										
										
											2009-09-24 12:54:53 +02:00
										 |  |  |     wizardParameters.setDescription(tr("Creates a Qt QML file.")); | 
					
						
							| 
									
										
										
										
											2010-01-07 18:17:24 +01:00
										 |  |  |     wizardParameters.setDisplayName(tr("Qt QML File")); | 
					
						
							| 
									
										
										
										
											2009-11-27 10:33:24 +01:00
										 |  |  |     wizardParameters.setId(QLatin1String("Q.Qml")); | 
					
						
							| 
									
										
										
										
											2009-09-24 12:54:53 +02:00
										 |  |  |     addAutoReleasedObject(new QmlFileWizard(wizardParameters, 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-04-23 13:19:28 +02:00
										 |  |  |     Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS); | 
					
						
							|  |  |  |     Core::ActionContainer *menuQtQuick = am->createMenu(Constants::M_QTQUICK); | 
					
						
							|  |  |  |     menuQtQuick->menu()->setTitle(tr("Qt Quick")); | 
					
						
							|  |  |  |     mtools->addMenu(menuQtQuick); | 
					
						
							|  |  |  |     m_actionPreview = new QAction("&Preview", this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 17:37:59 +02:00
										 |  |  |     Core::Context toolsMenuContext(QmlDesigner::Constants::C_QT_QUICK_TOOLS_MENU); | 
					
						
							| 
									
										
										
										
											2010-04-23 13:19:28 +02:00
										 |  |  |     Core::Command *cmd = addToolAction(m_actionPreview,  am, toolsMenuContext, | 
					
						
							|  |  |  |                    QLatin1String("QtQuick.Preview"), menuQtQuick, tr("Ctrl+Alt+R")); | 
					
						
							|  |  |  |     connect(cmd->action(), SIGNAL(triggered()), SLOT(openPreview())); | 
					
						
							|  |  |  |     m_previewRunner = new QmlJSPreviewRunner(this); | 
					
						
							| 
									
										
										
										
											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-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)), | 
					
						
							|  |  |  |             m_qmlTaskManager, SLOT(documentChangedOnDisk(QmlJS::Document::Ptr))); | 
					
						
							|  |  |  |     connect(m_modelManager, SIGNAL(aboutToRemoveFiles(QStringList)), | 
					
						
							|  |  |  |             m_qmlTaskManager, SLOT(documentsRemoved(QStringList))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-23 13:19:28 +02:00
										 |  |  | void QmlJSEditorPlugin::openPreview() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Core::EditorManager *em = Core::EditorManager::instance(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (em->currentEditor() && em->currentEditor()->id() == Constants::C_QMLJSEDITOR_ID) | 
					
						
							|  |  |  |         m_previewRunner->run(em->currentEditor()->file()->fileName()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-15 17:20:03 +01:00
										 |  |  | void QmlJSEditorPlugin::initializeEditor(QmlJSEditor::Internal::QmlJSTextEditor *editor) | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QTC_ASSERT(m_instance, /**/); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_actionHandler->setupActions(editor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TextEditor::TextEditorSettings::instance()->initializeEditor(editor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // auto completion
 | 
					
						
							| 
									
										
										
										
											2009-11-18 15:06:26 +01:00
										 |  |  |     connect(editor, SIGNAL(requestAutoCompletion(TextEditor::ITextEditable*, bool)), | 
					
						
							|  |  |  |             TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(TextEditor::ITextEditable*, bool))); | 
					
						
							| 
									
										
										
										
											2010-06-03 15:49:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // quick fix
 | 
					
						
							|  |  |  |     connect(editor, SIGNAL(requestQuickFix(TextEditor::ITextEditable*)), | 
					
						
							|  |  |  |             this, SLOT(quickFix(TextEditor::ITextEditable*))); | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-08 12:50:10 +01:00
										 |  |  | void QmlJSEditorPlugin::followSymbolUnderCursor() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Core::EditorManager *em = Core::EditorManager::instance(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (QmlJSTextEditor *editor = qobject_cast<QmlJSTextEditor*>(em->currentEditor()->widget())) | 
					
						
							|  |  |  |         editor->followSymbolUnderCursor(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void QmlJSEditorPlugin::quickFix(TextEditor::ITextEditable *editable) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_currentTextEditable = editable; | 
					
						
							|  |  |  |     quickFixNow(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void QmlJSEditorPlugin::quickFixNow() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (! m_currentTextEditable) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Core::EditorManager *em = Core::EditorManager::instance(); | 
					
						
							|  |  |  |     QmlJSTextEditor *currentEditor = qobject_cast<QmlJSTextEditor*>(em->currentEditor()->widget()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (QmlJSTextEditor *editor = qobject_cast<QmlJSTextEditor*>(m_currentTextEditable->widget())) { | 
					
						
							|  |  |  |         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 { | 
					
						
							| 
									
										
										
										
											2010-06-03 15:49:29 +02:00
										 |  |  |                 TextEditor::Internal::CompletionSupport::instance()->quickFix(m_currentTextEditable); | 
					
						
							| 
									
										
										
										
											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-01-15 17:20:03 +01:00
										 |  |  | Q_EXPORT_PLUGIN(QmlJSEditorPlugin) |