qmljseditor.h 5 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30

31 32
#ifndef QMLJSEDITOR_H
#define QMLJSEDITOR_H
33

34 35
#include "qmljseditor_global.h"

36
#include <qmljs/qmljsscanner.h>
37
#include <qmljstools/qmljssemanticinfo.h>
38
#include <texteditor/texteditor.h>
39
#include <texteditor/quickfix.h>
40
#include <texteditor/texteditorconstants.h>
41
#include <utils/uncommentselection.h>
42

43
#include <QModelIndex>
hjk's avatar
hjk committed
44
#include <QTimer>
Christian Kamm's avatar
Christian Kamm committed
45

46 47 48 49
QT_BEGIN_NAMESPACE
class QComboBox;
QT_END_NAMESPACE

50 51
namespace QmlJS {
    class ModelManagerInterface;
52
    class IContextPane;
53
namespace AST { class UiObjectMember; }
54
}
55

56
namespace QmlJSEditor {
57

58
class QmlJSEditorDocument;
59
class FindReferences;
60

61
namespace Internal {
62

63
class QmlJSEditorWidget : public TextEditor::TextEditorWidget
64
{
65
    Q_OBJECT
66 67

public:
68 69
    QmlJSEditorWidget();

70
    void finalizeInitialization() override;
71

72
    QmlJSEditorDocument *qmlJsEditorDocument() const;
73

74
    QModelIndex outlineModelIndex();
75

76
    TextEditor::AssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
77
                           TextEditor::AssistReason reason) const override;
78 79 80

    void inspectElementUnderCursor() const;

81
public slots:
82
    void findUsages();
83
    void renameUsages();
84
    void showContextPane();
85

86
signals:
87
    void outlineModelIndexChanged(const QModelIndex &index);
88 89
    void selectedElementsChanged(QList<QmlJS::AST::UiObjectMember*> offsets,
                                 const QString &wordAtCursor);
90
private slots:
91
    void modificationChanged(bool);
92

93 94
    void jumpToOutlineElement(int index);
    void updateOutlineIndexNow();
Eike Ziller's avatar
Eike Ziller committed
95
    void updateContextPane();
96
    void showTextMarker();
97

98 99
    void updateUses();

100
    void semanticInfoUpdated(const QmlJSTools::SemanticInfo &semanticInfo);
Christian Kamm's avatar
Christian Kamm committed
101

102
    void performQuickFix(int index);
103
    void updateCodeWarnings(QmlJS::Document::Ptr doc);
104

105
protected:
106 107 108 109 110 111
    void contextMenuEvent(QContextMenuEvent *e) override;
    bool event(QEvent *e) override;
    void wheelEvent(QWheelEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;
    void scrollContentsBy(int dx, int dy) override;
    void applyFontSettings() override;
112
    void createToolBar();
113
    TextEditor::TextEditorWidget::Link findLinkAt(const QTextCursor &cursor,
114
                                                      bool resolveTarget = true,
115 116 117
                                                      bool inNextSplit = false) override;
    QString foldReplacementText(const QTextBlock &block) const override;
    void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker) override;
118 119

private:
120
    bool isClosingBrace(const QList<QmlJS::Token> &tokens) const;
121

122
    void setSelectedElements();
123
    QString wordUnderCursor() const;
Roberto Raggi's avatar
Roberto Raggi committed
124

125
    QModelIndex indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex = QModelIndex()) const;
126
    bool hideContextPane();
Christian Kamm's avatar
Christian Kamm committed
127

128
    QmlJSEditorDocument *m_qmlJsEditorDocument;
hjk's avatar
hjk committed
129 130 131
    QTimer m_updateUsesTimer; // to wait for multiple text cursor position changes
    QTimer m_updateOutlineIndexTimer;
    QTimer m_contextPaneTimer;
132
    QComboBox *m_outlineCombo;
133
    QModelIndex m_outlineModelIndex;
134
    QmlJS::ModelManagerInterface *m_modelManager;
135

136
    TextEditor::QuickFixOperations m_quickFixes;
137

138
    QmlJS::IContextPane *m_contextPane;
Kai Koehne's avatar
Kai Koehne committed
139
    int m_oldCursorPosition;
140 141

    FindReferences *m_findReferences;
142 143
};

144 145 146 147 148 149 150 151

class QmlJSEditor : public TextEditor::BaseTextEditor
{
    Q_OBJECT

public:
    QmlJSEditor();

152
    bool isDesignModePreferred() const override;
153 154
};

155
class QmlJSEditorFactory : public TextEditor::TextEditorFactory
156 157 158 159 160 161 162
{
    Q_OBJECT

public:
    QmlJSEditorFactory();
};

163
} // namespace Internal
164
} // namespace QmlJSEditor
165

166
#endif // QMLJSEDITOR_H