2009-04-22 15:21:04 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
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
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2009-09-30 17:43:21 +02:00
|
|
|
#ifndef QMLEDITORW_H
|
|
|
|
|
#define QMLEDITORW_H
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-15 13:39:54 +01:00
|
|
|
#include <qmljs/qmldocument.h>
|
2009-12-02 17:59:27 +01:00
|
|
|
#include <qscripthighlighter/qscriptincrementalscanner.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
#include <texteditor/basetexteditor.h>
|
2009-05-14 14:09:00 +02: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
|
|
|
}
|
|
|
|
|
|
2009-12-07 16:57:31 +01:00
|
|
|
namespace Qml {
|
2009-12-08 11:52:28 +01:00
|
|
|
class QmlTypeSystem;
|
2009-12-07 16:57:31 +01:00
|
|
|
}
|
|
|
|
|
|
2009-09-30 17:43:21 +02:00
|
|
|
namespace QmlEditor {
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2009-09-30 17:43:21 +02:00
|
|
|
class QmlModelManagerInterface;
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2009-09-30 17:43:21 +02:00
|
|
|
class QmlHighlighter;
|
2009-12-08 13:58:51 +01:00
|
|
|
class QmlTextEditor;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-12-08 14:08:30 +01:00
|
|
|
class QmlEditorEditable : public TextEditor::BaseTextEditorEditable
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2009-09-22 17:25:18 +02:00
|
|
|
Q_OBJECT
|
2009-05-06 15:45:19 +02:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
public:
|
2009-12-08 14:08:30 +01:00
|
|
|
QmlEditorEditable(QmlTextEditor *);
|
2009-09-22 17:25:18 +02:00
|
|
|
QList<int> context() const;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
bool duplicateSupported() const { return true; }
|
|
|
|
|
Core::IEditor *duplicate(QWidget *parent);
|
2010-01-07 18:17:24 +01:00
|
|
|
QString id() const;
|
2009-09-22 17:25:18 +02:00
|
|
|
bool isTemporary() const { return false; }
|
2009-04-22 15:21:04 +02:00
|
|
|
|
|
|
|
|
private:
|
2009-09-22 17:25:18 +02:00
|
|
|
QList<int> m_context;
|
2009-04-22 15:21:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Declaration
|
|
|
|
|
{
|
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
|
|
|
};
|
|
|
|
|
|
2009-12-08 13:58:51 +01:00
|
|
|
class QmlTextEditor : public TextEditor::BaseTextEditor
|
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
|
|
|
|
|
|
|
|
public:
|
2009-09-22 17:25:18 +02:00
|
|
|
typedef QList<int> Context;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-12-08 13:58:51 +01:00
|
|
|
QmlTextEditor(QWidget *parent = 0);
|
|
|
|
|
~QmlTextEditor();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
QList<Declaration> declarations() const;
|
|
|
|
|
QStringList keywords() const;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
QList<QmlJS::DiagnosticMessage> diagnosticMessages() const
|
|
|
|
|
{ return m_diagnosticMessages; }
|
2009-05-06 15:45:19 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
virtual void unCommentSelection();
|
2009-05-14 16:37:17 +02:00
|
|
|
|
2010-01-14 16:22:43 +01:00
|
|
|
Qml::QmlDocument::Ptr qmlDocument() const { return m_document; }
|
2009-07-06 16:29:44 +02:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
public slots:
|
2009-09-22 17:25:18 +02:00
|
|
|
virtual void setFontSettings(const TextEditor::FontSettings &);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
|
|
|
|
private slots:
|
2010-01-14 16:22:43 +01:00
|
|
|
void onDocumentUpdated(Qml::QmlDocument::Ptr doc);
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
void updateDocument();
|
|
|
|
|
void updateDocumentNow();
|
|
|
|
|
void jumpToMethod(int index);
|
|
|
|
|
void updateMethodBoxIndex();
|
|
|
|
|
void updateMethodBoxToolTip();
|
|
|
|
|
void updateFileName();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-14 16:30:48 +01:00
|
|
|
void updateUses();
|
|
|
|
|
void updateUsesNow();
|
|
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
// refactoring ops
|
|
|
|
|
void renameIdUnderCursor();
|
2009-05-05 15:33:39 +02:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
protected:
|
2009-09-22 17:25:18 +02:00
|
|
|
void contextMenuEvent(QContextMenuEvent *e);
|
|
|
|
|
TextEditor::BaseTextEditorEditable *createEditableInterface();
|
2009-12-08 14:08:30 +01:00
|
|
|
void createToolBar(QmlEditorEditable *editable);
|
2009-09-11 14:42:50 +02:00
|
|
|
TextEditor::BaseTextEditor::Link findLinkAt(const QTextCursor &cursor, bool resolveTarget = true);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-12 14:13:43 +01:00
|
|
|
//// brace matching
|
|
|
|
|
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const;
|
|
|
|
|
virtual bool isInComment(const QTextCursor &cursor) const;
|
|
|
|
|
virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text, const QChar &la, int *skippedChars) const;
|
|
|
|
|
virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
|
|
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
private:
|
2009-09-22 17:25:18 +02:00
|
|
|
virtual bool isElectricCharacter(const QChar &ch) const;
|
|
|
|
|
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
|
2009-11-16 12:38:47 +01:00
|
|
|
bool isClosingBrace(const QList<SharedTools::QScriptIncrementalScanner::Token> &tokens) const;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
QString wordUnderCursor() const;
|
2009-05-05 15:33:39 +02:00
|
|
|
|
2009-09-22 17:25:18 +02:00
|
|
|
const 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;
|
2009-09-22 17:25:18 +02:00
|
|
|
QComboBox *m_methodCombo;
|
|
|
|
|
QList<Declaration> m_declarations;
|
|
|
|
|
QMap<QString, QList<QmlJS::AST::SourceLocation> > m_ids; // ### use QMultiMap
|
2010-01-14 16:30:48 +01:00
|
|
|
int m_idsRevision;
|
2009-09-22 17:25:18 +02:00
|
|
|
QList<QmlJS::DiagnosticMessage> m_diagnosticMessages;
|
2010-01-14 16:22:43 +01:00
|
|
|
Qml::QmlDocument::Ptr m_document;
|
2009-09-30 17:43:21 +02:00
|
|
|
QmlModelManagerInterface *m_modelManager;
|
2009-12-08 11:52:28 +01:00
|
|
|
Qml::QmlTypeSystem *m_typeSystem;
|
2010-01-14 16:30:48 +01:00
|
|
|
QTextCharFormat m_occurrencesFormat;
|
2009-04-22 15:21:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2009-09-30 17:43:21 +02:00
|
|
|
} // namespace QmlEditor
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-09-30 17:43:21 +02:00
|
|
|
#endif // QMLEDITORW_H
|