| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <coreplugin/icore.h>
 | 
					
						
							|  |  |  | #include <coreplugin/coreconstants.h>
 | 
					
						
							|  |  |  | #include <coreplugin/mimedatabase.h>
 | 
					
						
							|  |  |  | #include <coreplugin/uniqueidmanager.h>
 | 
					
						
							|  |  |  | #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>
 | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							| 
									
										
										
										
											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-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), | 
					
						
							|  |  |  |     m_actionHandler(0), | 
					
						
							|  |  |  |     m_completion(0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-01 13:34:02 +02:00
										 |  |  |     QList<int> context; | 
					
						
							| 
									
										
										
										
											2010-01-15 17:20:03 +01:00
										 |  |  |     context<< core->uniqueIDManager()->uniqueIdentifier(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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Core::Command *cmd = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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-02-15 13:39:41 +01:00
										 |  |  |     m_completion = new CodeCompletion(m_modelManager); | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  |     addAutoReleasedObject(m_completion); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 13:41:51 +01:00
										 |  |  |     addAutoReleasedObject(new HoverHandler()); | 
					
						
							| 
									
										
										
										
											2009-05-06 15:45:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  |     // Restore settings
 | 
					
						
							|  |  |  |     QSettings *settings = Core::ICore::instance()->settings(); | 
					
						
							|  |  |  |     settings->beginGroup(QLatin1String("CppTools")); // ### FIXME:
 | 
					
						
							|  |  |  |     settings->beginGroup(QLatin1String("Completion")); | 
					
						
							|  |  |  |     const bool caseSensitive = settings->value(QLatin1String("CaseSensitive"), true).toBool(); | 
					
						
							|  |  |  |     m_completion->setCaseSensitivity(caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); | 
					
						
							|  |  |  |     settings->endGroup(); | 
					
						
							|  |  |  |     settings->endGroup(); | 
					
						
							| 
									
										
										
										
											2010-01-29 21:33:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  |     error_message->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-15 17:20:03 +01:00
										 |  |  | void QmlJSEditorPlugin::extensionsInitialized() | 
					
						
							| 
									
										
										
										
											2009-04-22 15:21:04 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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))); | 
					
						
							| 
									
										
										
										
											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-01-15 17:20:03 +01:00
										 |  |  | Q_EXPORT_PLUGIN(QmlJSEditorPlugin) |