diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 0348812557f89794b846723e025cc6db648e7ef8..1e06172687e5e8903a23f69e7798e5728e63e21d 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -685,6 +685,14 @@ int QmlJSTextEditor::documentRevision() const return document()->revision(); } +bool QmlJSTextEditor::isOutdated() const +{ + if (m_semanticInfo.revision() != documentRevision()) + return true; + + return false; +} + Core::IEditor *QmlJSEditorEditable::duplicate(QWidget *parent) { QmlJSTextEditor *newEditor = new QmlJSTextEditor(parent); diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 1fb222e51b5a03bc648e9e5a801eb60ba07955f8..fd5fe9c3cd955a53c5cf03c9c69b8ad43cb9191c 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -211,6 +211,7 @@ public: SemanticInfo semanticInfo() const; int documentRevision() const; + bool isOutdated() const; public slots: void followSymbolUnderCursor(); diff --git a/src/plugins/qmljseditor/qmljseditor.pro b/src/plugins/qmljseditor/qmljseditor.pro index 0f0c3e238ce7e32a3413bb33a9a7239f8bfdfe7c..dc7c0a65d30026b52bee29d1ba65f4e48794ce35 100644 --- a/src/plugins/qmljseditor/qmljseditor.pro +++ b/src/plugins/qmljseditor/qmljseditor.pro @@ -22,7 +22,8 @@ HEADERS += \ qmljshoverhandler.h \ qmljsmodelmanager.h \ qmljsmodelmanagerinterface.h \ - qmljspreviewrunner.h + qmljspreviewrunner.h \ + qmljsquickfix.h SOURCES += \ qmljscodecompletion.cpp \ @@ -36,7 +37,8 @@ SOURCES += \ qmljshoverhandler.cpp \ qmljsmodelmanager.cpp \ qmljsmodelmanagerinterface.cpp \ - qmljspreviewrunner.cpp + qmljspreviewrunner.cpp \ + qmljsquickfix.cpp RESOURCES += qmljseditor.qrc OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index f998309ac172fb3dd971b8039cbaeb6c89599ac7..3a85c988d6686bb6d36b98fbadf6637adcd711df 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -37,6 +37,7 @@ #include "qmljsmodelmanager.h" #include "qmlfilewizard.h" #include "qmljspreviewrunner.h" +#include "qmljsquickfix.h" #include <qmldesigner/qmldesignerconstants.h> @@ -64,6 +65,7 @@ #include <QtCore/QSettings> #include <QtCore/QDir> #include <QtCore/QCoreApplication> +#include <QtCore/QTimer> #include <QtGui/QMenu> #include <QtGui/QAction> @@ -71,6 +73,10 @@ using namespace QmlJSEditor; using namespace QmlJSEditor::Internal; using namespace QmlJSEditor::Constants; +enum { + QUICKFIX_INTERVAL = 20 +}; + QmlJSEditorPlugin *QmlJSEditorPlugin::m_instance = 0; QmlJSEditorPlugin::QmlJSEditorPlugin() : @@ -80,6 +86,12 @@ QmlJSEditorPlugin::QmlJSEditorPlugin() : m_actionHandler(0) { m_instance = this; + + m_quickFixCollector = 0; + m_quickFixTimer = new QTimer(this); + m_quickFixTimer->setInterval(20); + m_quickFixTimer->setSingleShot(true); + connect(m_quickFixTimer, SIGNAL(timeout()), this, SLOT(quickFixNow())); } QmlJSEditorPlugin::~QmlJSEditorPlugin() @@ -163,6 +175,9 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance(); iconProvider->registerIconOverlayForSuffix(QIcon(":/qmljseditor/images/qmlfile.png"), "qml"); + m_quickFixCollector = new QmlJSQuickFixCollector; + addAutoReleasedObject(m_quickFixCollector); + return true; } @@ -190,6 +205,10 @@ void QmlJSEditorPlugin::initializeEditor(QmlJSEditor::Internal::QmlJSTextEditor // auto completion connect(editor, SIGNAL(requestAutoCompletion(TextEditor::ITextEditable*, bool)), TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(TextEditor::ITextEditable*, bool))); + + // quick fix + connect(editor, SIGNAL(requestQuickFix(TextEditor::ITextEditable*)), + this, SLOT(quickFix(TextEditor::ITextEditable*))); } void QmlJSEditorPlugin::followSymbolUnderCursor() @@ -211,5 +230,33 @@ Core::Command *QmlJSEditorPlugin::addToolAction(QAction *a, Core::ActionManager return command; } +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()) { + // qDebug() << "TODO: outdated document" << editor->documentRevision() << editor->semanticInfo().revision(); + // ### FIXME: m_quickFixTimer->start(QUICKFIX_INTERVAL); + m_quickFixTimer->stop(); + }else + TextEditor::Internal::CompletionSupport::instance()->quickFix(m_currentTextEditable); + } + } +} Q_EXPORT_PLUGIN(QmlJSEditorPlugin) diff --git a/src/plugins/qmljseditor/qmljseditorplugin.h b/src/plugins/qmljseditor/qmljseditorplugin.h index db534f0f290faad17c0da689cb871a369c26eed4..d5d87a053aca67d2c0a205771a5ca02bdf26ff5d 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.h +++ b/src/plugins/qmljseditor/qmljseditorplugin.h @@ -31,8 +31,10 @@ #define QMLJSEDITORPLUGIN_H #include <extensionsystem/iplugin.h> +#include <QtCore/QPointer> QT_FORWARD_DECLARE_CLASS(QAction) +QT_FORWARD_DECLARE_CLASS(QTimer) namespace TextEditor { class TextEditorActionHandler; @@ -44,6 +46,10 @@ class ActionContainer; class ActionManager; } +namespace TextEditor { +class ITextEditable; +} + namespace QmlJSEditor { class ModelManagerInterface; @@ -54,6 +60,7 @@ namespace Internal { class QmlJSEditorFactory; class QmlJSTextEditor; class QmlJSPreviewRunner; +class QmlJSQuickFixCollector; class QmlJSEditorPlugin : public ExtensionSystem::IPlugin { @@ -70,6 +77,8 @@ public: static QmlJSEditorPlugin *instance() { return m_instance; } + QmlJSQuickFixCollector *quickFixCollector() const; + void initializeEditor(QmlJSTextEditor *editor); public Q_SLOTS: @@ -77,6 +86,8 @@ public Q_SLOTS: private Q_SLOTS: void openPreview(); + void quickFix(TextEditor::ITextEditable *editable); + void quickFixNow(); private: Core::Command *addToolAction(QAction *a, Core::ActionManager *am, const QList<int> &context, const QString &name, @@ -91,6 +102,11 @@ private: QmlFileWizard *m_wizard; QmlJSEditorFactory *m_editor; TextEditor::TextEditorActionHandler *m_actionHandler; + + QmlJSQuickFixCollector *m_quickFixCollector; + + QTimer *m_quickFixTimer; + QPointer<TextEditor::ITextEditable> m_currentTextEditable; }; } // namespace Internal diff --git a/src/plugins/qmljseditor/qmljsquickfix.cpp b/src/plugins/qmljseditor/qmljsquickfix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a90a76c4ed1de83842eff477e4613928e5443290 --- /dev/null +++ b/src/plugins/qmljseditor/qmljsquickfix.cpp @@ -0,0 +1,67 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "qmljsquickfix.h" +#include "qmljseditor.h" +#include <QtCore/QDebug> + +using namespace QmlJSEditor::Internal; + +QmlJSQuickFixCollector::QmlJSQuickFixCollector() +{ +} + +QmlJSQuickFixCollector::~QmlJSQuickFixCollector() +{ +} + +TextEditor::QuickFixState *QmlJSQuickFixCollector::initializeCompletion(TextEditor::ITextEditable *editable) +{ + if (QmlJSTextEditor *editor = qobject_cast<QmlJSTextEditor *>(editable->widget())) { + const SemanticInfo info = editor->semanticInfo(); + + if (editor->isOutdated()) { + // outdated + qWarning() << "TODO: outdated semantic info, force a reparse."; + return 0; + } + + // ### TODO create the quickfix state + return 0; + } + + return 0; +} + +QList<TextEditor::QuickFixOperation::Ptr> QmlJSQuickFixCollector::quickFixOperations(TextEditor::BaseTextEditor *) const +{ + QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations; + + return quickFixOperations; +} diff --git a/src/plugins/qmljseditor/qmljsquickfix.h b/src/plugins/qmljseditor/qmljsquickfix.h new file mode 100644 index 0000000000000000000000000000000000000000..b5a5d535b181b5a5a967c24a0680ab823d1395af --- /dev/null +++ b/src/plugins/qmljseditor/qmljsquickfix.h @@ -0,0 +1,56 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef QMLJSQUICKFIX_H +#define QMLJSQUICKFIX_H + +#include <texteditor/quickfix.h> + +namespace QmlJSEditor { + +class ModelManagerInterface; + +namespace Internal { + +class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector +{ + Q_OBJECT + +public: + QmlJSQuickFixCollector(); + virtual ~QmlJSQuickFixCollector(); + + virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable); + virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const; +}; + +} // end of namespace Internal +} // end of namespace QmlJSEditor + +#endif // QMLJSQUICKFIX_H