2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
#include "qmljseditor_global.h"
|
|
|
|
|
|
2020-07-16 08:17:01 +02:00
|
|
|
#include <qmljs/parser/qmljsast_p.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>
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/texteditor.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>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <utils/uncommentselection.h>
|
2009-05-14 14:09:00 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QModelIndex>
|
2014-08-26 17:15:37 +02:00
|
|
|
#include <QTimer>
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QComboBox;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2020-07-16 08:17:01 +02:00
|
|
|
namespace QmlJS { class ModelManagerInterface; }
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-06-09 15:56:03 +02:00
|
|
|
namespace QmlJSEditor {
|
2014-08-20 01:47:42 +02:00
|
|
|
|
2014-02-07 13:45:51 +01:00
|
|
|
class QmlJSEditorDocument;
|
2018-02-21 11:47:01 +01:00
|
|
|
class QuickToolBar;
|
2010-09-24 14:05:34 +02:00
|
|
|
class FindReferences;
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2019-08-07 17:04:47 +02:00
|
|
|
class QMLJSEDITOR_EXPORT QmlJSEditorWidget : public TextEditor::TextEditorWidget
|
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:
|
2014-08-23 00:19:48 +02:00
|
|
|
QmlJSEditorWidget();
|
|
|
|
|
|
2015-06-01 17:55:31 +02:00
|
|
|
void finalizeInitialization() override;
|
2020-09-23 16:38:01 +02:00
|
|
|
void restoreState(const QByteArray &state) override;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2014-02-07 13:45:51 +01:00
|
|
|
QmlJSEditorDocument *qmlJsEditorDocument() const;
|
2014-01-30 17:18:35 +01:00
|
|
|
|
2010-07-12 16:40:15 +02:00
|
|
|
QModelIndex outlineModelIndex();
|
2017-04-06 17:22:52 +02:00
|
|
|
void updateOutlineIndexNow();
|
2017-04-06 17:27:52 +02:00
|
|
|
bool isOutlineCursorChangesBlocked();
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2022-11-15 14:19:06 +01:00
|
|
|
std::unique_ptr<TextEditor::AssistInterface> createAssistInterface(
|
|
|
|
|
TextEditor::AssistKind assistKind, TextEditor::AssistReason reason) const override;
|
2015-01-08 22:43:39 +03:00
|
|
|
|
|
|
|
|
void inspectElementUnderCursor() const;
|
|
|
|
|
|
2018-11-28 07:26:14 +01:00
|
|
|
void findUsages() override;
|
2020-05-06 07:30:33 +02:00
|
|
|
void renameSymbolUnderCursor() override;
|
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);
|
2016-06-27 22:25:11 +03:00
|
|
|
private:
|
2020-11-17 15:50:11 +01:00
|
|
|
void updateModificationChange(bool);
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2010-07-13 11:24:16 +02:00
|
|
|
void jumpToOutlineElement(int index);
|
2014-01-30 15:48:24 +01:00
|
|
|
void updateContextPane();
|
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();
|
|
|
|
|
|
2014-01-24 16:53:16 +01:00
|
|
|
void semanticInfoUpdated(const QmlJSTools::SemanticInfo &semanticInfo);
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2014-01-24 16:53:16 +01:00
|
|
|
void updateCodeWarnings(QmlJS::Document::Ptr doc);
|
2020-02-20 15:19:12 +01:00
|
|
|
void foldAuxiliaryData();
|
2010-09-16 12:57:07 +02:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
protected:
|
2015-06-01 17:55:31 +02:00
|
|
|
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;
|
2014-08-19 00:54:45 +02:00
|
|
|
void createToolBar();
|
2018-02-21 11:58:16 +01:00
|
|
|
void findLinkAt(const QTextCursor &cursor,
|
2022-06-03 15:17:33 +02:00
|
|
|
const Utils::LinkHandler &processLinkCallback,
|
2018-02-21 11:58:16 +01:00
|
|
|
bool resolveTarget = true,
|
|
|
|
|
bool inNextSplit = false) override;
|
2015-06-01 17:55:31 +02:00
|
|
|
QString foldReplacementText(const QTextBlock &block) const override;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
|
|
|
|
private:
|
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
|
|
|
|
2017-03-31 12:19:48 +02:00
|
|
|
QmlJSEditorDocument *m_qmlJsEditorDocument = nullptr;
|
2014-08-26 17:15:37 +02:00
|
|
|
QTimer m_updateUsesTimer; // to wait for multiple text cursor position changes
|
|
|
|
|
QTimer m_updateOutlineIndexTimer;
|
|
|
|
|
QTimer m_contextPaneTimer;
|
2010-07-13 11:24:16 +02:00
|
|
|
QComboBox *m_outlineCombo;
|
2010-07-12 14:45:22 +02:00
|
|
|
QModelIndex m_outlineModelIndex;
|
2017-03-31 12:19:48 +02:00
|
|
|
QmlJS::ModelManagerInterface *m_modelManager = nullptr;
|
2010-01-25 14:18:53 +01:00
|
|
|
|
2018-02-21 11:47:01 +01:00
|
|
|
QuickToolBar *m_contextPane = nullptr;
|
2017-03-31 12:19:48 +02:00
|
|
|
int m_oldCursorPosition = -1;
|
2010-09-24 14:05:34 +02:00
|
|
|
|
|
|
|
|
FindReferences *m_findReferences;
|
2009-04-22 15:21:04 +02:00
|
|
|
};
|
|
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
|
2019-08-07 17:04:47 +02:00
|
|
|
class QMLJSEDITOR_EXPORT QmlJSEditor : public TextEditor::BaseTextEditor
|
2014-08-20 01:47:42 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QmlJSEditor();
|
|
|
|
|
|
2019-07-18 16:19:33 +02:00
|
|
|
QmlJSEditorDocument *qmlJSDocument() const;
|
2015-06-01 17:55:31 +02:00
|
|
|
bool isDesignModePreferred() const override;
|
2014-08-20 01:47:42 +02:00
|
|
|
};
|
|
|
|
|
|
2019-08-07 17:04:47 +02:00
|
|
|
class QMLJSEDITOR_EXPORT QmlJSEditorFactory : public TextEditor::TextEditorFactory
|
2014-08-20 01:47:42 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QmlJSEditorFactory();
|
2020-06-26 13:59:38 +02:00
|
|
|
QmlJSEditorFactory(Utils::Id id);
|
2017-04-24 15:52:04 +02:00
|
|
|
|
|
|
|
|
static void decorateEditor(TextEditor::TextEditorWidget *editor);
|
2014-08-20 01:47:42 +02:00
|
|
|
};
|
|
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
} // namespace QmlJSEditor
|