2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01: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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-07-25 14:10:41 +02:00
|
|
|
#include "texteditor_global.h"
|
2016-01-11 20:41:31 +01:00
|
|
|
#include "blockrange.h"
|
2015-02-26 13:22:35 +01:00
|
|
|
#include "codeassist/assistenums.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-12-01 13:29:12 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2014-07-25 14:10:41 +02:00
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2014-08-22 12:14:06 +02:00
|
|
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
2010-09-07 09:51:20 +02:00
|
|
|
|
2017-10-05 09:45:33 +02:00
|
|
|
#include <utils/link.h>
|
2014-07-30 16:01:34 +02:00
|
|
|
#include <utils/uncommentselection.h>
|
|
|
|
|
|
2014-10-15 13:27:22 +02:00
|
|
|
#include <QLabel>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPlainTextEdit>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <QSharedPointer>
|
2014-07-30 17:02:39 +02:00
|
|
|
#include <functional>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QToolBar;
|
2011-11-23 16:05:55 +01:00
|
|
|
class QPrinter;
|
2014-07-25 14:10:41 +02:00
|
|
|
class QMenu;
|
|
|
|
|
class QPainter;
|
|
|
|
|
class QPoint;
|
|
|
|
|
class QRect;
|
|
|
|
|
class QTextBlock;
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2017-11-02 13:06:38 +01:00
|
|
|
namespace Core {
|
|
|
|
|
class HighlightScrollBarController;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace TextEditor {
|
2015-02-26 13:22:35 +01:00
|
|
|
class TextDocument;
|
2014-09-30 13:08:05 +02:00
|
|
|
class BaseHoverHandler;
|
2010-11-01 16:29:45 +01:00
|
|
|
class RefactorOverlay;
|
|
|
|
|
struct RefactorMarker;
|
2015-02-26 13:22:35 +01:00
|
|
|
class SyntaxHighlighter;
|
2014-09-04 00:04:18 +02:00
|
|
|
class AssistInterface;
|
2011-04-15 16:19:23 +02:00
|
|
|
class IAssistProvider;
|
2011-08-16 10:45:23 +02:00
|
|
|
class ICodeStylePreferences;
|
2013-08-30 12:55:06 +02:00
|
|
|
class CompletionAssistProvider;
|
2018-02-02 10:50:53 +01:00
|
|
|
using RefactorMarkers = QList<RefactorMarker>;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace Internal {
|
2014-10-15 00:36:39 +02:00
|
|
|
class BaseTextEditorPrivate;
|
|
|
|
|
class TextEditorFactoryPrivate;
|
|
|
|
|
class TextEditorWidgetPrivate;
|
|
|
|
|
class TextEditorOverlay;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-27 11:19:04 +02:00
|
|
|
class AutoCompleter;
|
|
|
|
|
class BaseTextEditor;
|
2014-09-26 11:37:54 +02:00
|
|
|
class TextEditorFactory;
|
|
|
|
|
class TextEditorWidget;
|
2014-08-27 11:19:04 +02:00
|
|
|
class PlainTextEditorFactory;
|
|
|
|
|
|
2010-08-13 12:53:36 +02:00
|
|
|
class BehaviorSettings;
|
|
|
|
|
class CompletionSettings;
|
|
|
|
|
class DisplaySettings;
|
2014-08-27 11:19:04 +02:00
|
|
|
class ExtraEncodingSettings;
|
|
|
|
|
class FontSettings;
|
|
|
|
|
class Indenter;
|
2014-01-09 14:44:25 +01:00
|
|
|
class MarginSettings;
|
2010-08-13 12:53:36 +02:00
|
|
|
class StorageSettings;
|
2014-08-27 11:19:04 +02:00
|
|
|
class TypingSettings;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-09-30 17:45:48 +02:00
|
|
|
enum TextMarkRequestKind
|
|
|
|
|
{
|
|
|
|
|
BreakpointRequest,
|
|
|
|
|
BookmarkRequest,
|
|
|
|
|
TaskMarkRequest
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-23 19:10:38 +02:00
|
|
|
class TEXTEDITOR_EXPORT BaseTextEditor : public Core::IEditor
|
2009-04-28 18:34:58 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2014-08-19 00:54:45 +02:00
|
|
|
BaseTextEditor();
|
2018-02-02 10:50:53 +01:00
|
|
|
~BaseTextEditor() override;
|
2009-04-28 18:34:58 +02:00
|
|
|
|
2014-08-22 16:38:38 +02:00
|
|
|
virtual void finalizeInitialization() {}
|
|
|
|
|
|
2014-07-23 19:10:38 +02:00
|
|
|
static BaseTextEditor *currentTextEditor();
|
2009-04-28 18:34:58 +02:00
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *editorWidget() const;
|
2014-09-22 18:43:31 +02:00
|
|
|
TextDocument *textDocument() const;
|
2014-08-27 11:57:32 +02:00
|
|
|
|
|
|
|
|
// Some convenience text access
|
|
|
|
|
void setTextCursor(const QTextCursor &cursor);
|
|
|
|
|
QTextCursor textCursor() const;
|
|
|
|
|
QChar characterAt(int pos) const;
|
|
|
|
|
QString textAt(int from, int to) const;
|
2009-04-28 18:34:58 +02:00
|
|
|
|
2014-08-20 13:56:57 +02:00
|
|
|
void addContext(Core::Id id);
|
|
|
|
|
|
2014-07-23 19:10:38 +02:00
|
|
|
// IEditor
|
2015-06-01 17:55:31 +02:00
|
|
|
Core::IDocument *document() override;
|
2009-04-28 19:02:58 +02:00
|
|
|
|
2015-06-01 17:55:31 +02:00
|
|
|
IEditor *duplicate() override;
|
2014-07-30 13:13:24 +02:00
|
|
|
|
2015-06-01 17:55:31 +02:00
|
|
|
QByteArray saveState() const override;
|
|
|
|
|
bool restoreState(const QByteArray &state) override;
|
|
|
|
|
QWidget *toolBar() override;
|
2014-07-23 19:10:38 +02:00
|
|
|
|
2018-01-17 16:06:13 +01:00
|
|
|
void contextHelpId(const HelpIdCallback &callback) const override; // from IContext
|
2015-06-01 17:55:31 +02:00
|
|
|
void setContextHelpId(const QString &id) override;
|
2014-07-23 19:10:38 +02:00
|
|
|
|
2015-06-01 17:55:31 +02:00
|
|
|
int currentLine() const override;
|
|
|
|
|
int currentColumn() const override;
|
|
|
|
|
void gotoLine(int line, int column = 0, bool centerLine = true) override;
|
2014-07-23 19:10:38 +02:00
|
|
|
|
|
|
|
|
/*! Returns the amount of visible columns (in characters) in the editor */
|
|
|
|
|
int columnCount() const;
|
|
|
|
|
|
|
|
|
|
/*! Returns the amount of visible lines (in characters) in the editor */
|
|
|
|
|
int rowCount() const;
|
|
|
|
|
|
|
|
|
|
/*! Returns the position at \a posOp in characters from the beginning of the document */
|
2014-09-30 17:45:48 +02:00
|
|
|
virtual int position(TextPositionOperation posOp = CurrentPosition, int at = -1) const;
|
2014-07-23 19:10:38 +02:00
|
|
|
|
|
|
|
|
/*! Converts the \a pos in characters from beginning of document to \a line and \a column */
|
|
|
|
|
virtual void convertPosition(int pos, int *line, int *column) const;
|
|
|
|
|
|
|
|
|
|
virtual QString selectedText() const;
|
|
|
|
|
|
|
|
|
|
/*! Removes \a length characters to the right of the cursor. */
|
|
|
|
|
virtual void remove(int length);
|
|
|
|
|
/*! Inserts the given string to the right of the cursor. */
|
|
|
|
|
virtual void insert(const QString &string);
|
|
|
|
|
/*! Replaces \a length characters to the right of the cursor with the given string. */
|
|
|
|
|
virtual void replace(int length, const QString &string);
|
|
|
|
|
/*! Sets current cursor position to \a pos. */
|
|
|
|
|
virtual void setCursorPosition(int pos);
|
|
|
|
|
/*! Selects text between current cursor position and \a toPos. */
|
|
|
|
|
virtual void select(int toPos);
|
|
|
|
|
|
2009-04-28 18:34:58 +02:00
|
|
|
private:
|
2014-09-26 11:37:54 +02:00
|
|
|
friend class TextEditorFactory;
|
2014-10-15 00:36:39 +02:00
|
|
|
friend class Internal::TextEditorFactoryPrivate;
|
2014-07-26 12:45:48 +02:00
|
|
|
Internal::BaseTextEditorPrivate *d;
|
2009-04-28 18:34:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
class TEXTEDITOR_EXPORT TextEditorWidget : public QPlainTextEdit
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2010-08-05 15:01:20 +02:00
|
|
|
Q_PROPERTY(int verticalBlockSelectionFirstColumn READ verticalBlockSelectionFirstColumn)
|
|
|
|
|
Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
|
2013-05-24 14:23:07 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2018-02-02 10:50:53 +01:00
|
|
|
TextEditorWidget(QWidget *parent = nullptr);
|
2015-06-01 17:55:31 +02:00
|
|
|
~TextEditorWidget() override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-02-26 13:22:35 +01:00
|
|
|
void setTextDocument(const QSharedPointer<TextDocument> &doc);
|
2014-09-22 18:43:31 +02:00
|
|
|
TextDocument *textDocument() const;
|
2015-02-26 13:22:35 +01:00
|
|
|
QSharedPointer<TextDocument> textDocumentPtr() const;
|
2013-12-12 15:07:54 +01:00
|
|
|
|
2015-06-02 17:14:48 +02:00
|
|
|
virtual void aboutToOpen(const QString &fileName, const QString &realFileName);
|
|
|
|
|
virtual void openFinishedSuccessfully();
|
2013-12-12 15:07:54 +01:00
|
|
|
// IEditor
|
2008-12-02 12:01:29 +01:00
|
|
|
QByteArray saveState() const;
|
|
|
|
|
bool restoreState(const QByteArray &state);
|
2017-05-23 14:34:22 +02:00
|
|
|
void gotoLine(int line, int column = 0, bool centerLine = true, bool animate = false);
|
2014-09-30 17:45:48 +02:00
|
|
|
int position(TextPositionOperation posOp = CurrentPosition,
|
2013-05-24 14:23:07 +02:00
|
|
|
int at = -1) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
void convertPosition(int pos, int *line, int *column) const;
|
2014-09-03 08:35:58 +02:00
|
|
|
using QPlainTextEdit::cursorRect;
|
|
|
|
|
QRect cursorRect(int pos) const;
|
|
|
|
|
void setCursorPosition(int pos);
|
2015-08-24 13:39:40 +02:00
|
|
|
QToolBar *toolBar();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void print(QPrinter *);
|
|
|
|
|
|
2009-11-02 14:02:18 +01:00
|
|
|
void appendStandardContextMenuActions(QMenu *menu);
|
|
|
|
|
|
2014-08-19 12:12:45 +02:00
|
|
|
void setAutoCompleter(AutoCompleter *autoCompleter);
|
|
|
|
|
AutoCompleter *autoCompleter() const;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Works only in conjunction with a syntax highlighter that puts
|
|
|
|
|
// parentheses into text block user data
|
|
|
|
|
void setParenthesesMatchingEnabled(bool b);
|
|
|
|
|
bool isParenthesesMatchingEnabled() const;
|
|
|
|
|
|
|
|
|
|
void setHighlightCurrentLine(bool b);
|
|
|
|
|
bool highlightCurrentLine() const;
|
|
|
|
|
|
|
|
|
|
void setLineNumbersVisible(bool b);
|
|
|
|
|
bool lineNumbersVisible() const;
|
|
|
|
|
|
2013-02-05 14:14:33 +01:00
|
|
|
void setAlwaysOpenLinksInNextSplit(bool b);
|
|
|
|
|
bool alwaysOpenLinksInNextSplit() const;
|
2012-11-01 03:43:28 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void setMarksVisible(bool b);
|
|
|
|
|
bool marksVisible() const;
|
|
|
|
|
|
|
|
|
|
void setRequestMarkEnabled(bool b);
|
|
|
|
|
bool requestMarkEnabled() const;
|
|
|
|
|
|
|
|
|
|
void setLineSeparatorsAllowed(bool b);
|
|
|
|
|
bool lineSeparatorsAllowed() const;
|
|
|
|
|
|
|
|
|
|
bool codeFoldingVisible() const;
|
|
|
|
|
|
2009-03-16 17:23:50 +01:00
|
|
|
void setCodeFoldingSupported(bool b);
|
|
|
|
|
bool codeFoldingSupported() const;
|
|
|
|
|
|
2009-09-08 13:03:24 +02:00
|
|
|
void setMouseNavigationEnabled(bool b);
|
|
|
|
|
bool mouseNavigationEnabled() const;
|
|
|
|
|
|
2014-02-10 13:23:59 +01:00
|
|
|
void setMouseHidingEnabled(bool b);
|
|
|
|
|
bool mouseHidingEnabled() const;
|
|
|
|
|
|
2009-12-09 16:27:34 +01:00
|
|
|
void setScrollWheelZoomingEnabled(bool b);
|
|
|
|
|
bool scrollWheelZoomingEnabled() const;
|
|
|
|
|
|
2011-07-20 13:40:24 +02:00
|
|
|
void setConstrainTooltips(bool b);
|
|
|
|
|
bool constrainTooltips() const;
|
|
|
|
|
|
2011-09-19 19:00:53 +02:00
|
|
|
void setCamelCaseNavigationEnabled(bool b);
|
|
|
|
|
bool camelCaseNavigationEnabled() const;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void setRevisionsVisible(bool b);
|
|
|
|
|
bool revisionsVisible() const;
|
|
|
|
|
|
|
|
|
|
void setVisibleWrapColumn(int column);
|
|
|
|
|
int visibleWrapColumn() const;
|
|
|
|
|
|
2010-12-13 15:17:33 +01:00
|
|
|
int columnCount() const;
|
|
|
|
|
int rowCount() const;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void setReadOnly(bool b);
|
|
|
|
|
|
2010-03-29 16:44:27 +02:00
|
|
|
void insertCodeSnippet(const QTextCursor &cursor, const QString &snippet);
|
2010-01-19 16:36:48 +01:00
|
|
|
|
2010-09-13 13:52:50 +02:00
|
|
|
void setBlockSelection(bool on);
|
2014-06-16 14:20:36 +02:00
|
|
|
void setBlockSelection(int positionBlock, int positionColumn, int anchhorBlock,
|
|
|
|
|
int anchorColumn);
|
|
|
|
|
void setBlockSelection(const QTextCursor &cursor);
|
|
|
|
|
QTextCursor blockSelection() const;
|
2010-09-13 13:52:50 +02:00
|
|
|
bool hasBlockSelection() const;
|
2010-04-12 20:49:40 +02:00
|
|
|
|
2010-08-05 15:01:20 +02:00
|
|
|
int verticalBlockSelectionFirstColumn() const;
|
|
|
|
|
int verticalBlockSelectionLastColumn() const;
|
2010-04-12 20:49:40 +02:00
|
|
|
|
2010-07-09 16:09:08 +02:00
|
|
|
QRegion translatedLineRegion(int lineStart, int lineEnd) const;
|
|
|
|
|
|
2011-02-21 16:45:07 +01:00
|
|
|
QPoint toolTipPosition(const QTextCursor &c) const;
|
|
|
|
|
|
2018-02-02 10:50:53 +01:00
|
|
|
void invokeAssist(AssistKind assistKind, IAssistProvider *provider = nullptr);
|
2011-04-15 16:19:23 +02:00
|
|
|
|
2014-09-04 00:04:18 +02:00
|
|
|
virtual TextEditor::AssistInterface *createAssistInterface(AssistKind assistKind,
|
2011-04-15 16:19:23 +02:00
|
|
|
AssistReason assistReason) const;
|
2014-01-14 09:50:12 +01:00
|
|
|
static QMimeData *duplicateMimeData(const QMimeData *source);
|
2011-04-15 16:19:23 +02:00
|
|
|
|
2013-07-15 15:14:10 +02:00
|
|
|
static QString msgTextTooLarge(quint64 size);
|
|
|
|
|
|
2014-06-16 14:20:36 +02:00
|
|
|
void insertPlainText(const QString &text);
|
2014-07-23 19:10:38 +02:00
|
|
|
|
2014-07-25 16:23:50 +02:00
|
|
|
QWidget *extraArea() const;
|
2018-02-02 10:50:53 +01:00
|
|
|
virtual int extraAreaWidth(int *markWidthPtr = nullptr) const;
|
2014-07-25 16:23:50 +02:00
|
|
|
virtual void extraAreaPaintEvent(QPaintEvent *);
|
|
|
|
|
virtual void extraAreaLeaveEvent(QEvent *);
|
|
|
|
|
virtual void extraAreaContextMenuEvent(QContextMenuEvent *);
|
|
|
|
|
virtual void extraAreaMouseEvent(QMouseEvent *);
|
|
|
|
|
void updateFoldingHighlight(const QPoint &pos);
|
|
|
|
|
|
|
|
|
|
void setLanguageSettingsId(Core::Id settingsId);
|
|
|
|
|
Core::Id languageSettingsId() const;
|
|
|
|
|
|
|
|
|
|
void setCodeStyle(ICodeStylePreferences *settings);
|
|
|
|
|
|
|
|
|
|
const DisplaySettings &displaySettings() const;
|
|
|
|
|
const MarginSettings &marginSettings() const;
|
2015-12-20 19:59:00 +01:00
|
|
|
const BehaviorSettings &behaviorSettings() const;
|
2014-07-25 16:23:50 +02:00
|
|
|
|
|
|
|
|
void ensureCursorVisible();
|
2017-05-23 14:34:22 +02:00
|
|
|
void ensureBlockIsUnfolded(QTextBlock block);
|
2014-07-25 16:23:50 +02:00
|
|
|
|
2015-06-23 15:56:45 +02:00
|
|
|
static Core::Id FakeVimSelection;
|
|
|
|
|
static Core::Id SnippetPlaceholderSelection;
|
|
|
|
|
static Core::Id CurrentLineSelection;
|
|
|
|
|
static Core::Id ParenthesesMatchingSelection;
|
2016-06-01 10:19:59 +02:00
|
|
|
static Core::Id AutoCompleteSelection;
|
2015-06-23 15:56:45 +02:00
|
|
|
static Core::Id CodeWarningsSelection;
|
|
|
|
|
static Core::Id CodeSemanticsSelection;
|
|
|
|
|
static Core::Id UndefinedSymbolSelection;
|
|
|
|
|
static Core::Id UnusedSymbolSelection;
|
|
|
|
|
static Core::Id OtherSelection;
|
|
|
|
|
static Core::Id ObjCSelection;
|
|
|
|
|
static Core::Id DebuggerExceptionSelection;
|
|
|
|
|
|
2014-10-21 17:50:10 +02:00
|
|
|
void setExtraSelections(Core::Id kind, const QList<QTextEdit::ExtraSelection> &selections);
|
|
|
|
|
QList<QTextEdit::ExtraSelection> extraSelections(Core::Id kind) const;
|
2014-07-25 16:23:50 +02:00
|
|
|
QString extraSelectionTooltip(int pos) const;
|
|
|
|
|
|
|
|
|
|
RefactorMarkers refactorMarkers() const;
|
|
|
|
|
void setRefactorMarkers(const RefactorMarkers &markers);
|
|
|
|
|
|
|
|
|
|
// the blocks list must be sorted
|
|
|
|
|
void setIfdefedOutBlocks(const QList<BlockRange> &blocks);
|
2014-07-30 10:04:01 +02:00
|
|
|
bool isMissingSyntaxDefinition() const;
|
2014-06-16 14:20:36 +02:00
|
|
|
|
2014-08-01 16:41:18 +02:00
|
|
|
enum Side { Left, Right };
|
2016-10-13 13:11:07 +02:00
|
|
|
QAction *insertExtraToolBarWidget(Side side, QWidget *widget);
|
2014-08-01 16:41:18 +02:00
|
|
|
|
2016-06-01 10:19:59 +02:00
|
|
|
// keep the auto completion even if the focus is lost
|
|
|
|
|
void keepAutoCompletionHighlight(bool keepHighlight);
|
2016-06-10 15:13:38 +02:00
|
|
|
void setAutoCompleteSkipPosition(const QTextCursor &cursor);
|
2016-06-01 10:19:59 +02:00
|
|
|
|
2011-12-13 12:15:30 +01:00
|
|
|
virtual void copy();
|
2009-12-03 18:35:36 +01:00
|
|
|
virtual void paste();
|
|
|
|
|
virtual void cut();
|
2012-01-18 12:09:41 +01:00
|
|
|
virtual void selectAll();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-07-25 16:23:50 +02:00
|
|
|
virtual void format();
|
|
|
|
|
virtual void rewrapParagraph();
|
|
|
|
|
virtual void unCommentSelection();
|
2014-08-28 17:00:12 +02:00
|
|
|
|
2015-07-01 13:18:49 +09:00
|
|
|
virtual void encourageApply();
|
|
|
|
|
|
2014-07-25 16:23:50 +02:00
|
|
|
virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
|
2014-09-24 12:40:28 +02:00
|
|
|
virtual void setMarginSettings(const TextEditor::MarginSettings &);
|
2014-08-28 17:00:12 +02:00
|
|
|
void setBehaviorSettings(const TextEditor::BehaviorSettings &);
|
|
|
|
|
void setTypingSettings(const TextEditor::TypingSettings &);
|
|
|
|
|
void setStorageSettings(const TextEditor::StorageSettings &);
|
|
|
|
|
void setCompletionSettings(const TextEditor::CompletionSettings &);
|
|
|
|
|
void setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &);
|
2014-07-25 16:23:50 +02:00
|
|
|
|
2011-12-13 12:15:30 +01:00
|
|
|
void circularPaste();
|
2012-03-02 08:16:23 +08:00
|
|
|
void switchUtf8bom();
|
2011-12-13 12:15:30 +01:00
|
|
|
|
2015-11-30 14:37:24 +01:00
|
|
|
void zoomF(float delta);
|
2009-11-30 19:00:36 +01:00
|
|
|
void zoomReset();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-14 17:24:35 +02:00
|
|
|
void cutLine();
|
2010-11-27 14:02:20 +09:00
|
|
|
void copyLine();
|
2016-09-26 15:55:04 +02:00
|
|
|
void duplicateSelection();
|
|
|
|
|
void duplicateSelectionAndComment();
|
2008-12-02 12:01:29 +01:00
|
|
|
void deleteLine();
|
2017-04-26 10:48:48 +02:00
|
|
|
void deleteEndOfLine();
|
2011-09-26 14:21:19 +02:00
|
|
|
void deleteEndOfWord();
|
|
|
|
|
void deleteEndOfWordCamelCase();
|
2017-04-26 10:48:48 +02:00
|
|
|
void deleteStartOfLine();
|
2011-09-26 14:21:19 +02:00
|
|
|
void deleteStartOfWord();
|
|
|
|
|
void deleteStartOfWordCamelCase();
|
2010-05-20 15:10:26 +02:00
|
|
|
void unfoldAll();
|
|
|
|
|
void fold();
|
|
|
|
|
void unfold();
|
2008-12-02 12:01:29 +01:00
|
|
|
void selectEncoding();
|
2013-04-18 10:06:13 +02:00
|
|
|
void updateTextCodecLabel();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-04 18:37:02 +01:00
|
|
|
void gotoBlockStart();
|
|
|
|
|
void gotoBlockEnd();
|
|
|
|
|
void gotoBlockStartWithSelection();
|
|
|
|
|
void gotoBlockEndWithSelection();
|
|
|
|
|
|
2010-05-07 15:24:30 +02:00
|
|
|
void gotoLineStart();
|
|
|
|
|
void gotoLineStartWithSelection();
|
|
|
|
|
void gotoLineEnd();
|
|
|
|
|
void gotoLineEndWithSelection();
|
|
|
|
|
void gotoNextLine();
|
|
|
|
|
void gotoNextLineWithSelection();
|
|
|
|
|
void gotoPreviousLine();
|
|
|
|
|
void gotoPreviousLineWithSelection();
|
|
|
|
|
void gotoPreviousCharacter();
|
|
|
|
|
void gotoPreviousCharacterWithSelection();
|
|
|
|
|
void gotoNextCharacter();
|
|
|
|
|
void gotoNextCharacterWithSelection();
|
|
|
|
|
void gotoPreviousWord();
|
|
|
|
|
void gotoPreviousWordWithSelection();
|
|
|
|
|
void gotoNextWord();
|
|
|
|
|
void gotoNextWordWithSelection();
|
2010-11-10 12:53:45 +01:00
|
|
|
void gotoPreviousWordCamelCase();
|
|
|
|
|
void gotoPreviousWordCamelCaseWithSelection();
|
|
|
|
|
void gotoNextWordCamelCase();
|
|
|
|
|
void gotoNextWordCamelCaseWithSelection();
|
2008-12-04 18:37:02 +01:00
|
|
|
|
2015-12-20 19:59:00 +01:00
|
|
|
virtual bool selectBlockUp();
|
|
|
|
|
virtual bool selectBlockDown();
|
2016-08-02 08:17:35 +02:00
|
|
|
void selectWordUnderCursor();
|
2008-12-04 19:25:20 +01:00
|
|
|
|
2017-06-01 17:15:35 +02:00
|
|
|
void showContextMenu();
|
|
|
|
|
|
2008-12-10 18:01:33 +01:00
|
|
|
void moveLineUp();
|
|
|
|
|
void moveLineDown();
|
|
|
|
|
|
2014-06-02 14:21:46 +02:00
|
|
|
void viewPageUp();
|
|
|
|
|
void viewPageDown();
|
|
|
|
|
void viewLineUp();
|
|
|
|
|
void viewLineDown();
|
|
|
|
|
|
2009-05-15 23:17:11 +02:00
|
|
|
void copyLineUp();
|
|
|
|
|
void copyLineDown();
|
|
|
|
|
|
2010-01-20 17:51:05 +01:00
|
|
|
void joinLines();
|
2010-01-20 16:54:06 +01:00
|
|
|
|
2010-05-03 17:03:11 +02:00
|
|
|
void insertLineAbove();
|
|
|
|
|
void insertLineBelow();
|
|
|
|
|
|
2011-02-25 11:10:42 +01:00
|
|
|
void uppercaseSelection();
|
|
|
|
|
void lowercaseSelection();
|
|
|
|
|
|
2017-08-13 20:38:08 +03:00
|
|
|
void sortSelectedLines();
|
|
|
|
|
|
2008-12-09 17:43:31 +01:00
|
|
|
void cleanWhitespace();
|
|
|
|
|
|
2012-01-22 17:05:02 -05:00
|
|
|
void indent();
|
|
|
|
|
void unindent();
|
|
|
|
|
|
2014-06-16 14:20:36 +02:00
|
|
|
void undo();
|
|
|
|
|
void redo();
|
|
|
|
|
|
2012-03-27 23:18:46 +04:00
|
|
|
void openLinkUnderCursor();
|
2013-02-05 14:14:33 +01:00
|
|
|
void openLinkUnderCursorInNextSplit();
|
2012-03-27 23:18:46 +04:00
|
|
|
|
2013-03-19 11:41:40 +01:00
|
|
|
/// Abort code assistant if it is running.
|
|
|
|
|
void abortAssist();
|
2014-07-30 10:53:51 +02:00
|
|
|
|
2015-02-03 09:18:57 +01:00
|
|
|
void configureGenericHighlighter();
|
2014-08-27 16:59:03 +02:00
|
|
|
|
|
|
|
|
Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim.
|
2013-03-19 11:41:40 +01:00
|
|
|
|
2015-04-16 15:05:53 +02:00
|
|
|
/*! Returns the document line number for the visible \a row.
|
|
|
|
|
*
|
|
|
|
|
* The first visible row is 0, the last visible row is rowCount() - 1.
|
|
|
|
|
*
|
|
|
|
|
* Any invalid row will return -1 as line number.
|
|
|
|
|
*/
|
|
|
|
|
int lineForVisibleRow(int row) const;
|
|
|
|
|
|
|
|
|
|
/*! Returns the first visible line of the document. */
|
|
|
|
|
int firstVisibleLine() const;
|
|
|
|
|
/*! Returns the last visible line of the document. */
|
|
|
|
|
int lastVisibleLine() const;
|
|
|
|
|
/*! Returns the line visible closest to the vertical center of the editor. */
|
|
|
|
|
int centerVisibleLine() const;
|
|
|
|
|
|
2017-11-02 13:06:38 +01:00
|
|
|
Core::HighlightScrollBarController *highlightScrollBarController() const;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
2014-10-01 22:39:47 +02:00
|
|
|
void assistFinished(); // Used in tests.
|
2013-10-30 09:27:32 +01:00
|
|
|
void readOnlyChanged();
|
2014-07-25 16:23:50 +02:00
|
|
|
|
|
|
|
|
void requestBlockUpdate(const QTextBlock &);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
protected:
|
2015-04-16 15:05:53 +02:00
|
|
|
QTextBlock blockForVisibleRow(int row) const;
|
2015-06-01 17:55:31 +02:00
|
|
|
bool event(QEvent *e) override;
|
|
|
|
|
void inputMethodEvent(QInputMethodEvent *e) override;
|
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
|
void wheelEvent(QWheelEvent *e) override;
|
|
|
|
|
void changeEvent(QEvent *e) override;
|
|
|
|
|
void focusInEvent(QFocusEvent *e) override;
|
|
|
|
|
void focusOutEvent(QFocusEvent *e) override;
|
|
|
|
|
void showEvent(QShowEvent *) override;
|
|
|
|
|
bool viewportEvent(QEvent *event) override;
|
|
|
|
|
void resizeEvent(QResizeEvent *) override;
|
|
|
|
|
void paintEvent(QPaintEvent *) override;
|
2014-09-25 15:48:21 +02:00
|
|
|
virtual void paintBlock(QPainter *painter,
|
|
|
|
|
const QTextBlock &block,
|
|
|
|
|
const QPointF &offset,
|
|
|
|
|
const QVector<QTextLayout::FormatRange> &selections,
|
|
|
|
|
const QRect &clipRect) const;
|
2015-06-01 17:55:31 +02:00
|
|
|
void timerEvent(QTimerEvent *) override;
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *) override;
|
|
|
|
|
void mousePressEvent(QMouseEvent *) override;
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent *) override;
|
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *) override;
|
|
|
|
|
void leaveEvent(QEvent *) override;
|
|
|
|
|
void keyReleaseEvent(QKeyEvent *) override;
|
|
|
|
|
void dragEnterEvent(QDragEnterEvent *e) override;
|
|
|
|
|
|
|
|
|
|
QMimeData *createMimeDataFromSelection() const override;
|
|
|
|
|
bool canInsertFromMimeData(const QMimeData *source) const override;
|
|
|
|
|
void insertFromMimeData(const QMimeData *source) override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-04-23 09:09:20 +02:00
|
|
|
virtual QString plainTextFromSelection(const QTextCursor &cursor) const;
|
2013-01-20 23:09:09 +01:00
|
|
|
static QString convertToPlainText(const QString &txt);
|
|
|
|
|
|
|
|
|
|
virtual QString lineNumber(int blockNumber) const;
|
|
|
|
|
virtual int lineNumberDigits() const;
|
2013-04-09 10:26:31 +02:00
|
|
|
virtual bool selectionVisible(int blockNumber) const;
|
2013-04-10 13:51:04 +02:00
|
|
|
virtual bool replacementVisible(int blockNumber) const;
|
2013-06-05 15:25:42 +02:00
|
|
|
virtual QColor replacementPenColor(int blockNumber) const;
|
2010-07-12 14:15:38 +02:00
|
|
|
|
2014-02-06 12:41:29 +01:00
|
|
|
virtual void triggerPendingUpdates();
|
2014-01-21 11:26:39 +01:00
|
|
|
virtual void applyFontSettings();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-08-20 21:40:21 +02:00
|
|
|
virtual void onRefactorMarkerClicked(const RefactorMarker &) {}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
void showDefaultContextMenu(QContextMenuEvent *e, Core::Id menuContextId);
|
2014-08-22 16:38:38 +02:00
|
|
|
virtual void finalizeInitialization() {}
|
2014-09-26 11:37:54 +02:00
|
|
|
virtual void finalizeInitializationAfterDuplication(TextEditorWidget *) {}
|
2015-12-20 19:59:00 +01:00
|
|
|
static QTextCursor flippedCursor(const QTextCursor &cursor);
|
2012-07-24 23:30:32 +04:00
|
|
|
|
2017-07-19 10:43:47 +02:00
|
|
|
void addHoverHandler(BaseHoverHandler *handler);
|
|
|
|
|
|
2010-01-06 14:57:45 +01:00
|
|
|
public:
|
2014-07-23 19:10:38 +02:00
|
|
|
QString selectedText() const;
|
|
|
|
|
|
2015-02-03 09:18:57 +01:00
|
|
|
void setupGenericHighlighter();
|
2014-08-28 18:46:39 +02:00
|
|
|
void setupFallBackEditor(Core::Id id);
|
2014-07-30 11:41:06 +02:00
|
|
|
|
2014-09-03 08:35:58 +02:00
|
|
|
void remove(int length);
|
|
|
|
|
void replace(int length, const QString &string);
|
|
|
|
|
QChar characterAt(int pos) const;
|
|
|
|
|
QString textAt(int from, int to) const;
|
|
|
|
|
|
2018-01-17 16:06:13 +01:00
|
|
|
void contextHelpId(const Core::IContext::HelpIdCallback &callback);
|
2014-09-30 13:08:05 +02:00
|
|
|
void setContextHelpId(const QString &id);
|
|
|
|
|
|
2014-09-30 17:35:35 +02:00
|
|
|
static TextEditorWidget *currentTextEditorWidget();
|
|
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
protected:
|
2009-09-08 13:03:24 +02:00
|
|
|
/*!
|
|
|
|
|
Reimplement this function to enable code navigation.
|
|
|
|
|
|
|
|
|
|
\a resolveTarget is set to true when the target of the link is relevant
|
|
|
|
|
(it isn't until the link is used).
|
|
|
|
|
*/
|
2017-10-05 09:45:33 +02:00
|
|
|
virtual Utils::Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
|
|
|
|
|
bool inNextSplit = false);
|
2009-09-08 13:03:24 +02:00
|
|
|
|
|
|
|
|
/*!
|
2014-09-26 12:03:20 +02:00
|
|
|
Returns whether the link was opened successfully.
|
2009-09-08 13:03:24 +02:00
|
|
|
*/
|
2017-10-05 09:45:33 +02:00
|
|
|
bool openLink(const Utils::Link &link, bool inNextSplit = false);
|
2009-09-08 13:03:24 +02:00
|
|
|
|
2011-09-14 22:16:28 +02:00
|
|
|
/*!
|
|
|
|
|
Reimplement this function to change the default replacement text.
|
|
|
|
|
*/
|
|
|
|
|
virtual QString foldReplacementText(const QTextBlock &block) const;
|
2013-04-25 17:37:20 +02:00
|
|
|
virtual void drawCollapsedBlockPopup(QPainter &painter,
|
|
|
|
|
const QTextBlock &block,
|
|
|
|
|
QPointF offset,
|
|
|
|
|
const QRect &clip);
|
|
|
|
|
int visibleFoldedBlockNumber() const;
|
2015-04-21 12:36:11 +02:00
|
|
|
void doSetTextCursor(const QTextCursor &cursor) override;
|
|
|
|
|
void doSetTextCursor(const QTextCursor &cursor, bool keepBlockSelection);
|
2011-09-14 22:16:28 +02:00
|
|
|
|
2014-09-01 14:11:39 +02:00
|
|
|
signals:
|
2014-09-30 16:54:26 +02:00
|
|
|
void markRequested(TextEditor::TextEditorWidget *widget,
|
2014-09-30 17:45:48 +02:00
|
|
|
int line, TextEditor::TextMarkRequestKind kind);
|
2014-09-30 16:54:26 +02:00
|
|
|
void markContextMenuRequested(TextEditor::TextEditorWidget *widget,
|
|
|
|
|
int line, QMenu *menu);
|
|
|
|
|
void tooltipOverrideRequested(TextEditor::TextEditorWidget *widget,
|
2014-09-19 16:17:05 +02:00
|
|
|
const QPoint &globalPos, int position, bool *handled);
|
2014-09-01 14:11:39 +02:00
|
|
|
void tooltipRequested(const QPoint &globalPos, int position);
|
2018-02-02 10:50:53 +01:00
|
|
|
void activateEditor(Core::EditorManager::OpenEditorFlags flags = nullptr);
|
2014-09-01 14:11:39 +02:00
|
|
|
|
2017-03-19 19:57:04 +02:00
|
|
|
protected:
|
2014-08-01 12:52:22 +02:00
|
|
|
virtual void slotCursorPositionChanged(); // Used in VcsBase
|
|
|
|
|
virtual void slotCodeStyleSettingsChanged(const QVariant &); // Used in CppEditor
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-04-21 12:39:01 +02:00
|
|
|
bool inFindScope(const QTextCursor &cursor);
|
|
|
|
|
bool inFindScope(int selectionStart, int selectionEnd);
|
|
|
|
|
|
2014-07-25 16:23:50 +02:00
|
|
|
private:
|
2014-09-26 11:37:54 +02:00
|
|
|
Internal::TextEditorWidgetPrivate *d;
|
2014-08-01 15:06:28 +02:00
|
|
|
friend class BaseTextEditor;
|
2014-09-26 11:37:54 +02:00
|
|
|
friend class TextEditorFactory;
|
2014-10-15 00:36:39 +02:00
|
|
|
friend class Internal::TextEditorFactoryPrivate;
|
2014-09-26 11:37:54 +02:00
|
|
|
friend class Internal::TextEditorWidgetPrivate;
|
2014-07-25 16:23:50 +02:00
|
|
|
friend class Internal::TextEditorOverlay;
|
|
|
|
|
friend class RefactorOverlay;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2014-10-15 13:27:22 +02:00
|
|
|
class TEXTEDITOR_EXPORT TextEditorLinkLabel : public QLabel
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-02-02 10:50:53 +01:00
|
|
|
TextEditorLinkLabel(QWidget *parent = nullptr);
|
2014-10-15 13:27:22 +02:00
|
|
|
|
2017-10-05 09:45:33 +02:00
|
|
|
void setLink(Utils::Link link);
|
|
|
|
|
Utils::Link link() const;
|
2014-10-15 13:27:22 +02:00
|
|
|
|
|
|
|
|
protected:
|
2018-02-02 10:50:53 +01:00
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
2014-10-15 13:27:22 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QPoint m_dragStartPosition;
|
2017-10-05 09:45:33 +02:00
|
|
|
Utils::Link m_link;
|
2014-10-15 13:27:22 +02:00
|
|
|
};
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
class TEXTEDITOR_EXPORT TextEditorFactory : public Core::IEditorFactory
|
2014-08-22 12:14:06 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2018-02-02 10:50:53 +01:00
|
|
|
TextEditorFactory(QObject *parent = nullptr);
|
|
|
|
|
~TextEditorFactory() override;
|
|
|
|
|
|
|
|
|
|
using EditorCreator = std::function<BaseTextEditor *()>;
|
|
|
|
|
using DocumentCreator = std::function<TextDocument *()>;
|
|
|
|
|
using EditorWidgetCreator = std::function<TextEditorWidget *()>;
|
|
|
|
|
using SyntaxHighLighterCreator = std::function<SyntaxHighlighter *()>;
|
|
|
|
|
using IndenterCreator = std::function<Indenter *()>;
|
|
|
|
|
using AutoCompleterCreator = std::function<AutoCompleter *()>;
|
2014-08-22 16:38:38 +02:00
|
|
|
|
2016-05-31 10:59:45 +02:00
|
|
|
void setDocumentCreator(const DocumentCreator &creator);
|
|
|
|
|
void setEditorWidgetCreator(const EditorWidgetCreator &creator);
|
|
|
|
|
void setEditorCreator(const EditorCreator &creator);
|
|
|
|
|
void setIndenterCreator(const IndenterCreator &creator);
|
|
|
|
|
void setSyntaxHighlighterCreator(const SyntaxHighLighterCreator &creator);
|
2015-02-03 09:18:57 +01:00
|
|
|
void setUseGenericHighlighter(bool enabled);
|
2016-05-31 10:59:45 +02:00
|
|
|
void setAutoCompleterCreator(const AutoCompleterCreator &creator);
|
2014-08-22 12:14:06 +02:00
|
|
|
|
|
|
|
|
void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
|
|
|
|
|
void setEditorActionHandlers(uint optionalActions);
|
|
|
|
|
|
2014-09-30 13:08:05 +02:00
|
|
|
void addHoverHandler(BaseHoverHandler *handler);
|
2014-10-01 22:39:47 +02:00
|
|
|
void setCompletionAssistProvider(CompletionAssistProvider *provider);
|
2014-09-30 13:08:05 +02:00
|
|
|
|
2017-04-24 16:01:14 +02:00
|
|
|
void setCommentDefinition(Utils::CommentDefinition definition);
|
2014-09-03 11:24:38 +02:00
|
|
|
void setDuplicatedSupported(bool on);
|
2014-10-15 00:36:39 +02:00
|
|
|
void setMarksVisible(bool on);
|
|
|
|
|
void setParenthesesMatchingEnabled(bool on);
|
|
|
|
|
void setCodeFoldingSupported(bool on);
|
2014-09-01 16:16:44 +02:00
|
|
|
|
2017-02-12 00:21:32 +01:00
|
|
|
Core::IEditor *createEditor() override;
|
2014-08-28 13:45:42 +02:00
|
|
|
|
2014-08-22 12:14:06 +02:00
|
|
|
private:
|
2014-08-22 16:38:38 +02:00
|
|
|
friend class BaseTextEditor;
|
2014-08-27 11:19:04 +02:00
|
|
|
friend class PlainTextEditorFactory;
|
2014-10-15 00:36:39 +02:00
|
|
|
Internal::TextEditorFactoryPrivate *d;
|
2014-08-22 12:14:06 +02:00
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace TextEditor
|
|
|
|
|
|
2017-07-04 18:10:07 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
2017-06-20 08:28:10 +02:00
|
|
|
uint qHash(const QColor &color);
|
|
|
|
|
|
2017-07-04 18:10:07 +02:00
|
|
|
QT_END_NAMESPACE
|