2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 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.
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
|
|
#ifndef QMLJSEDITOR_H
|
|
|
|
|
#define QMLJSEDITOR_H
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
#include "qmljseditor_global.h"
|
|
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
#include <qmljs/qmljsscanner.h>
|
2012-04-12 15:51:56 +02:00
|
|
|
#include <qmljstools/qmljssemanticinfo.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
#include <texteditor/basetexteditor.h>
|
2010-09-16 12:57:07 +02:00
|
|
|
#include <texteditor/quickfix.h>
|
2012-04-26 14:17:42 +02:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
2009-05-14 14:09:00 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSharedPointer>
|
|
|
|
|
#include <QModelIndex>
|
2013-02-07 00:10:05 +01:00
|
|
|
#include <QTextLayout>
|
|
|
|
|
#include <QVector>
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QComboBox;
|
|
|
|
|
class QTimer;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
2009-09-22 17:25:18 +02:00
|
|
|
class ICore;
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
namespace QmlJS {
|
|
|
|
|
class ModelManagerInterface;
|
2010-07-07 13:09:30 +02:00
|
|
|
class IContextPane;
|
2010-08-26 10:50:00 +02:00
|
|
|
class LookupContext;
|
2012-05-10 17:06:29 +02:00
|
|
|
namespace AST {
|
|
|
|
|
class UiObjectMember;
|
|
|
|
|
}
|
2010-06-09 15:56:03 +02:00
|
|
|
}
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-07-28 17:33:21 +02:00
|
|
|
/*!
|
|
|
|
|
The top-level namespace of the QmlJSEditor plug-in.
|
|
|
|
|
*/
|
2010-06-09 15:56:03 +02:00
|
|
|
namespace QmlJSEditor {
|
2013-06-03 19:31:32 +02:00
|
|
|
class QmlJSEditor;
|
2010-09-24 14:05:34 +02:00
|
|
|
class FindReferences;
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
namespace Internal {
|
2010-07-12 14:45:22 +02:00
|
|
|
class QmlOutlineModel;
|
2011-08-11 13:52:02 +02:00
|
|
|
class SemanticInfoUpdater;
|
|
|
|
|
struct SemanticInfoUpdaterSource;
|
2011-08-16 09:47:54 +02:00
|
|
|
class SemanticHighlighter;
|
2014-01-17 17:09:15 +01:00
|
|
|
|
|
|
|
|
class QmlJSEditorDocument : public TextEditor::BaseTextDocument
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
QmlJSEditorDocument();
|
|
|
|
|
private slots:
|
|
|
|
|
void invalidateFormatterCache();
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-02 11:10:27 +01:00
|
|
|
} // namespace Internal
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-11-02 11:10:27 +01:00
|
|
|
struct QMLJSEDITOR_EXPORT Declaration
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2009-09-22 17:25:18 +02:00
|
|
|
QString text;
|
|
|
|
|
int startLine;
|
|
|
|
|
int startColumn;
|
|
|
|
|
int endLine;
|
|
|
|
|
int endColumn;
|
|
|
|
|
|
|
|
|
|
Declaration()
|
|
|
|
|
: startLine(0),
|
|
|
|
|
startColumn(0),
|
|
|
|
|
endLine(0),
|
|
|
|
|
endColumn(0)
|
|
|
|
|
{ }
|
2009-04-22 15:21:04 +02:00
|
|
|
};
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
class QMLJSEDITOR_EXPORT QmlJSTextEditorWidget : public TextEditor::BaseTextEditorWidget
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2009-09-22 17:25:18 +02:00
|
|
|
Q_OBJECT
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2012-04-13 11:57:34 +02:00
|
|
|
// used e.g. in qmljsprofiler
|
|
|
|
|
Q_PROPERTY(QmlJSTools::SemanticInfo semanticInfo READ semanticInfo)
|
|
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
public:
|
2011-02-21 16:02:26 +01:00
|
|
|
QmlJSTextEditorWidget(QWidget *parent = 0);
|
2014-01-09 18:04:45 +01:00
|
|
|
QmlJSTextEditorWidget(QmlJSTextEditorWidget *other);
|
2011-02-21 16:02:26 +01:00
|
|
|
~QmlJSTextEditorWidget();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
virtual void unCommentSelection();
|
2009-05-14 16:37:17 +02:00
|
|
|
|
2012-04-12 15:51:56 +02:00
|
|
|
QmlJSTools::SemanticInfo semanticInfo() const;
|
2011-11-18 13:25:09 +01:00
|
|
|
bool isSemanticInfoOutdated() const;
|
2010-07-13 10:45:20 +02:00
|
|
|
int editorRevision() const;
|
2013-02-07 00:10:05 +01:00
|
|
|
QVector<QTextLayout::FormatRange> diagnosticRanges() const;
|
2009-07-06 16:29:44 +02:00
|
|
|
|
2010-11-02 11:10:27 +01:00
|
|
|
Internal::QmlOutlineModel *outlineModel() const;
|
2010-07-12 16:40:15 +02:00
|
|
|
QModelIndex outlineModelIndex();
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2012-04-26 14:17:42 +02:00
|
|
|
static QVector<TextEditor::TextStyle> highlighterFormatCategories();
|
2010-10-27 17:38:22 +02:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
|
|
|
|
|
TextEditor::AssistReason reason) const;
|
2009-04-22 15:21:04 +02:00
|
|
|
public slots:
|
2011-11-18 13:25:09 +01:00
|
|
|
void reparseDocument();
|
|
|
|
|
void reparseDocumentNow();
|
|
|
|
|
void updateSemanticInfo();
|
|
|
|
|
void updateSemanticInfoNow();
|
2010-09-24 14:05:34 +02:00
|
|
|
void findUsages();
|
2011-07-11 12:53:05 +02:00
|
|
|
void renameUsages();
|
2010-08-04 13:50:15 +02:00
|
|
|
void showContextPane();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-01 11:09:47 +02:00
|
|
|
signals:
|
2010-07-12 14:45:22 +02:00
|
|
|
void outlineModelIndexChanged(const QModelIndex &index);
|
2012-05-10 17:06:29 +02:00
|
|
|
void selectedElementsChanged(QList<QmlJS::AST::UiObjectMember*> offsets,
|
|
|
|
|
const QString &wordAtCursor);
|
2011-11-07 15:14:43 +01:00
|
|
|
void semanticInfoUpdated();
|
2010-07-01 11:09:47 +02:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
private slots:
|
2010-01-18 16:15:23 +01:00
|
|
|
void onDocumentUpdated(QmlJS::Document::Ptr doc);
|
2010-04-16 12:42:12 +02:00
|
|
|
void modificationChanged(bool);
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-07-13 11:24:16 +02:00
|
|
|
void jumpToOutlineElement(int index);
|
2010-07-13 11:18:42 +02:00
|
|
|
void updateOutlineNow();
|
2010-07-13 11:24:16 +02:00
|
|
|
void updateOutlineIndexNow();
|
2010-08-05 10:44:50 +02:00
|
|
|
void updateCursorPositionNow();
|
2010-08-13 13:59:41 +02:00
|
|
|
void showTextMarker();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-14 16:30:48 +01:00
|
|
|
void updateUses();
|
|
|
|
|
void updateUsesNow();
|
|
|
|
|
|
2012-04-12 15:51:56 +02:00
|
|
|
void acceptNewSemanticInfo(const QmlJSTools::SemanticInfo &semanticInfo);
|
2010-07-07 13:09:30 +02:00
|
|
|
void onCursorPositionChanged();
|
2010-11-01 16:29:45 +01:00
|
|
|
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker);
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2010-09-16 12:57:07 +02:00
|
|
|
void performQuickFix(int index);
|
|
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
protected:
|
2009-09-22 17:25:18 +02:00
|
|
|
void contextMenuEvent(QContextMenuEvent *e);
|
2010-07-07 13:09:30 +02:00
|
|
|
bool event(QEvent *e);
|
|
|
|
|
void wheelEvent(QWheelEvent *event);
|
2010-07-20 15:01:06 +02:00
|
|
|
void resizeEvent(QResizeEvent *event);
|
|
|
|
|
void scrollContentsBy(int dx, int dy);
|
2014-01-21 11:26:39 +01:00
|
|
|
void applyFontSettings();
|
2011-02-21 16:02:26 +01:00
|
|
|
TextEditor::BaseTextEditor *createEditor();
|
2013-06-03 19:31:32 +02:00
|
|
|
void createToolBar(QmlJSEditor *editable);
|
2013-07-04 20:11:10 +02:00
|
|
|
TextEditor::BaseTextEditorWidget::Link findLinkAt(const QTextCursor &cursor,
|
|
|
|
|
bool resolveTarget = true,
|
|
|
|
|
bool inNextSplit = false);
|
2011-09-14 22:16:28 +02:00
|
|
|
QString foldReplacementText(const QTextBlock &block) const;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
|
|
|
|
private:
|
2014-01-09 18:04:45 +01:00
|
|
|
QmlJSTextEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
|
|
|
|
|
void ctor();
|
2010-01-19 12:54:17 +01:00
|
|
|
bool isClosingBrace(const QList<QmlJS::Token> &tokens) const;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-27 11:57:06 +02:00
|
|
|
void setSelectedElements();
|
2009-09-22 17:25:18 +02:00
|
|
|
QString wordUnderCursor() const;
|
2009-05-05 15:33:39 +02:00
|
|
|
|
2010-07-12 14:45:22 +02:00
|
|
|
QModelIndex indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex = QModelIndex()) const;
|
2010-07-20 15:01:06 +02:00
|
|
|
bool hideContextPane();
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2010-06-25 12:56:16 +02:00
|
|
|
const Core::Context m_context;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
QTimer *m_updateDocumentTimer;
|
2010-01-14 16:30:48 +01:00
|
|
|
QTimer *m_updateUsesTimer;
|
2011-11-18 13:25:09 +01:00
|
|
|
QTimer *m_updateSemanticInfoTimer;
|
2010-07-13 11:18:42 +02:00
|
|
|
QTimer *m_updateOutlineTimer;
|
2010-07-13 11:24:16 +02:00
|
|
|
QTimer *m_updateOutlineIndexTimer;
|
2010-09-29 19:35:25 +02:00
|
|
|
QTimer *m_cursorPositionTimer;
|
2010-07-13 11:24:16 +02:00
|
|
|
QComboBox *m_outlineCombo;
|
2010-11-02 11:10:27 +01:00
|
|
|
Internal::QmlOutlineModel *m_outlineModel;
|
2010-07-12 14:45:22 +02:00
|
|
|
QModelIndex m_outlineModelIndex;
|
2010-06-09 15:56:03 +02:00
|
|
|
QmlJS::ModelManagerInterface *m_modelManager;
|
2010-01-25 14:18:53 +01:00
|
|
|
|
2011-08-11 13:52:02 +02:00
|
|
|
Internal::SemanticInfoUpdater *m_semanticInfoUpdater;
|
2012-04-12 15:51:56 +02:00
|
|
|
QmlJSTools::SemanticInfo m_semanticInfo;
|
2011-12-02 14:46:23 +01:00
|
|
|
int m_futureSemanticInfoRevision;
|
2010-07-07 13:09:30 +02:00
|
|
|
|
2010-09-16 12:57:07 +02:00
|
|
|
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
|
2013-02-07 00:10:05 +01:00
|
|
|
QVector<QTextLayout::FormatRange> m_diagnosticRanges;
|
2010-09-16 12:57:07 +02:00
|
|
|
|
2010-07-07 13:09:30 +02:00
|
|
|
QmlJS::IContextPane *m_contextPane;
|
2010-07-13 11:25:45 +02:00
|
|
|
int m_oldCursorPosition;
|
2010-09-24 14:05:34 +02:00
|
|
|
|
|
|
|
|
FindReferences *m_findReferences;
|
2011-08-16 09:47:54 +02:00
|
|
|
Internal::SemanticHighlighter *m_semanticHighlighter;
|
|
|
|
|
|
|
|
|
|
friend class Internal::SemanticHighlighter;
|
2009-04-22 15:21:04 +02:00
|
|
|
};
|
|
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
} // namespace QmlJSEditor
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
#endif // QMLJSEDITOR_H
|