Commit bf5e43be authored by hjk's avatar hjk
Browse files

TextEditor: Merge ITextEditor and BaseTextEditor



Adjust all callers, de-export BaseTextEditorAnimator

Change-Id: I2329d976c1398e2449844bb480a4d4ed29859506
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 15421995
......@@ -42,15 +42,13 @@
QT_BEGIN_NAMESPACE
class QToolBar;
class QTimeLine;
class QPrinter;
QT_END_NAMESPACE
namespace Utils {
class LineColumnLabel;
}
namespace Utils { class LineColumnLabel; }
namespace TextEditor {
class TabSettings;
class RefactorOverlay;
struct RefactorMarker;
......@@ -67,7 +65,7 @@ namespace Internal {
typedef QString (QString::*TransformationMethod)() const;
}
class BaseTextEditor;
class BaseTextEditorWidget;
class FontSettings;
class BehaviorSettings;
class CompletionSettings;
......@@ -79,44 +77,109 @@ class Indenter;
class AutoCompleter;
class ExtraEncodingSettings;
class TEXTEDITOR_EXPORT BaseTextEditorAnimator : public QObject
class TEXTEDITOR_EXPORT BaseTextEditor : public Core::IEditor
{
Q_OBJECT
public:
BaseTextEditorAnimator(QObject *parent);
enum PositionOperation {
Current = 1,
EndOfLine = 2,
StartOfLine = 3,
Anchor = 4,
EndOfDoc = 5
};
inline void setPosition(int position) { m_position = position; }
inline int position() const { return m_position; }
BaseTextEditor(BaseTextEditorWidget *editorWidget);
~BaseTextEditor();
void setData(const QFont &f, const QPalette &pal, const QString &text);
virtual BaseTextEditorDocument *textDocument();
void draw(QPainter *p, const QPointF &pos);
QRectF rect() const;
enum MarkRequestKind {
BreakpointRequest,
BookmarkRequest,
TaskMarkRequest
};
inline qreal value() const { return m_value; }
inline QPointF lastDrawPos() const { return m_lastDrawPos; }
static BaseTextEditor *currentTextEditor();
void finish();
friend class BaseTextEditorWidget;
BaseTextEditorWidget *editorWidget() const { return m_editorWidget; }
BaseTextDocument *baseTextDocument();
bool isRunning() const;
// IEditor
Core::IDocument *document();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
signals:
void updateRequest(int position, QPointF lastPos, QRectF rect);
QByteArray saveState() const;
bool restoreState(const QByteArray &state);
QWidget *toolBar();
enum Side { Left, Right };
void insertExtraToolBarWidget(Side side, QWidget *widget);
QString contextHelpId() const; // from IContext
int currentLine() const;
int currentColumn() const;
void gotoLine(int line, int column = 0, bool centerLine = true);
/*! 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 */
virtual int position(PositionOperation posOp = Current, int at = -1) const;
/*! 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;
/*! Returns the cursor rectangle in pixels at \a pos, or current position if \a pos = -1 */
virtual QRect cursorRect(int pos = -1) 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);
virtual const Utils::CommentDefinition *commentDefinition() const;
virtual CompletionAssistProvider *completionAssistProvider();
signals:
void markRequested(TextEditor::BaseTextEditor *editor, int line, TextEditor::BaseTextEditor::MarkRequestKind kind);
void markContextMenuRequested(TextEditor::BaseTextEditor *editor, int line, QMenu *menu);
void tooltipOverrideRequested(TextEditor::BaseTextEditor *editor, const QPoint &globalPos, int position, bool *handled);
void tooltipRequested(TextEditor::BaseTextEditor *editor, const QPoint &globalPos, int position);
void markTooltipRequested(TextEditor::BaseTextEditor *editor, const QPoint &globalPos, int line);
void contextHelpIdRequested(TextEditor::BaseTextEditor *editor, int position);
private slots:
void step(qreal v);
void updateCursorPosition();
void openGotoLocator();
void setFileEncodingLabelVisible(bool visible);
void setFileEncodingLabelText(const QString &text);
private:
QTimeLine *m_timeline;
qreal m_value;
int m_position;
QPointF m_lastDrawPos;
QFont m_font;
QPalette m_palette;
QString m_text;
QSizeF m_size;
// Note: This is always a copy of IContext::m_widget.
BaseTextEditorWidget *m_editorWidget;
QToolBar *m_toolBar;
QWidget *m_stretchWidget;
QAction *m_cursorPositionLabelAction;
Utils::LineColumnLabel *m_cursorPositionLabel;
QAction *m_fileEncodingLabelAction;
Utils::LineColumnLabel *m_fileEncodingLabel;
};
......@@ -139,7 +202,7 @@ public:
QByteArray saveState() const;
bool restoreState(const QByteArray &state);
void gotoLine(int line, int column = 0, bool centerLine = true);
int position(ITextEditor::PositionOperation posOp = ITextEditor::Current,
int position(BaseTextEditor::PositionOperation posOp = BaseTextEditor::Current,
int at = -1) const;
void convertPosition(int pos, int *line, int *column) const;
......@@ -235,7 +298,7 @@ public:
static QString msgTextTooLarge(quint64 size);
void insertPlainText(const QString &text);
QString selectedText() const;
public slots:
virtual void copy();
......@@ -482,6 +545,8 @@ public:
int targetColumn;
};
QString selectedText() const;
protected:
/*!
Reimplement this function to enable code navigation.
......@@ -570,75 +635,6 @@ private slots:
void doFoo();
};
class TEXTEDITOR_EXPORT BaseTextEditor : public ITextEditor
{
Q_OBJECT
public:
BaseTextEditor(BaseTextEditorWidget *editorWidget);
~BaseTextEditor();
friend class BaseTextEditorWidget;
BaseTextEditorWidget *editorWidget() const { return m_editorWidget; }
BaseTextDocument *baseTextDocument() { return m_editorWidget->baseTextDocument(); }
// IEditor
Core::IDocument *document() { return m_editorWidget->baseTextDocument(); }
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
QByteArray saveState() const { return m_editorWidget->saveState(); }
bool restoreState(const QByteArray &state) { return m_editorWidget->restoreState(state); }
QWidget *toolBar();
enum Side { Left, Right };
void insertExtraToolBarWidget(Side side, QWidget *widget);
// ITextEditor
int currentLine() const;
int currentColumn() const;
void gotoLine(int line, int column = 0, bool centerLine = true) { m_editorWidget->gotoLine(line, column, centerLine); }
int columnCount() const;
int rowCount() const;
int position(PositionOperation posOp = Current, int at = -1) const
{ return m_editorWidget->position(posOp, at); }
void convertPosition(int pos, int *line, int *column) const
{ m_editorWidget->convertPosition(pos, line, column); }
QRect cursorRect(int pos = -1) const;
QString selectedText() const;
QString contextHelpId() const; // from IContext
// ITextEditor
void remove(int length);
void insert(const QString &string);
void replace(int length, const QString &string);
void setCursorPosition(int pos);
void select(int toPos);
const Utils::CommentDefinition *commentDefinition() const;
virtual CompletionAssistProvider *completionAssistProvider();
private slots:
void updateCursorPosition();
void openGotoLocator();
void setFileEncodingLabelVisible(bool visible);
void setFileEncodingLabelText(const QString &text);
private:
// Note: This is always a copy of IContext::m_widget.
BaseTextEditorWidget *m_editorWidget;
QToolBar *m_toolBar;
QWidget *m_stretchWidget;
QAction *m_cursorPositionLabelAction;
Utils::LineColumnLabel *m_cursorPositionLabel;
QAction *m_fileEncodingLabelAction;
Utils::LineColumnLabel *m_fileEncodingLabel;
};
} // namespace TextEditor
Q_DECLARE_METATYPE(TextEditor::BaseTextEditorWidget::Link)
......
......@@ -105,136 +105,6 @@ struct BaseTextEditorPrivateHighlightBlocks
};
class BaseTextEditorWidgetPrivate
{
BaseTextEditorWidgetPrivate(const BaseTextEditorWidgetPrivate &);
BaseTextEditorWidgetPrivate &operator=(const BaseTextEditorWidgetPrivate &);
public:
BaseTextEditorWidgetPrivate();
~BaseTextEditorWidgetPrivate();
void setupDocumentSignals();
void updateLineSelectionColor();
void print(QPrinter *printer);
BaseTextEditorWidget *q;
bool m_contentsChanged;
bool m_lastCursorChangeWasInteresting;
QSharedPointer<BaseTextDocument> m_document;
QByteArray m_tempState;
QByteArray m_tempNavigationState;
bool m_parenthesesMatchingEnabled;
// parentheses matcher
bool m_formatRange;
QTextCharFormat m_mismatchFormat;
QTimer m_parenthesesMatchingTimer;
// end parentheses matcher
QWidget *m_extraArea;
Core::Id m_tabSettingsId;
ICodeStylePreferences *m_codeStylePreferences;
DisplaySettings m_displaySettings;
MarginSettings m_marginSettings;
bool m_fontSettingsNeedsApply;
BehaviorSettings m_behaviorSettings;
int extraAreaSelectionAnchorBlockNumber;
int extraAreaToggleMarkBlockNumber;
int extraAreaHighlightFoldedBlockNumber;
TextEditorOverlay *m_overlay;
TextEditorOverlay *m_snippetOverlay;
TextEditorOverlay *m_searchResultOverlay;
bool snippetCheckCursor(const QTextCursor &cursor);
void snippetTabOrBacktab(bool forward);
RefactorOverlay *m_refactorOverlay;
QBasicTimer foldedBlockTimer;
int visibleFoldedBlockNumber;
int suggestedVisibleFoldedBlockNumber;
void clearVisibleFoldedBlock();
bool m_mouseOnFoldedMarker;
void foldLicenseHeader();
QBasicTimer autoScrollTimer;
uint m_marksVisible : 1;
uint m_codeFoldingVisible : 1;
uint m_codeFoldingSupported : 1;
uint m_revisionsVisible : 1;
uint m_lineNumbersVisible : 1;
uint m_highlightCurrentLine : 1;
uint m_requestMarkEnabled : 1;
uint m_lineSeparatorsAllowed : 1;
uint autoParenthesisOverwriteBackup : 1;
uint surroundWithEnabledOverwriteBackup : 1;
uint m_maybeFakeTooltipEvent : 1;
int m_visibleWrapColumn;
BaseTextEditorWidget::Link m_currentLink;
bool m_linkPressed;
QRegExp m_searchExpr;
Core::FindFlags m_findFlags;
void highlightSearchResults(const QTextBlock &block, TextEditorOverlay *overlay);
QTimer m_delayedUpdateTimer;
BaseTextEditor *m_editor;
QList<QTextEdit::ExtraSelection> m_extraSelections[BaseTextEditorWidget::NExtraSelectionKinds];
// block selection mode
bool m_inBlockSelectionMode;
QString copyBlockSelection();
void insertIntoBlockSelection(const QString &text = QString());
void setCursorToColumn(QTextCursor &cursor, int column,
QTextCursor::MoveMode moveMode = QTextCursor::MoveAnchor);
void removeBlockSelection();
void enableBlockSelection(const QTextCursor &cursor);
void enableBlockSelection(int positionBlock, int positionColumn,
int anchorBlock, int anchorColumn);
void disableBlockSelection(bool keepSelection = true);
void resetCursorFlashTimer();
QBasicTimer m_cursorFlashTimer;
bool m_cursorVisible;
bool m_moveLineUndoHack;
QTextCursor m_findScopeStart;
QTextCursor m_findScopeEnd;
int m_findScopeVerticalBlockSelectionFirstColumn;
int m_findScopeVerticalBlockSelectionLastColumn;
QTextCursor m_selectBlockAnchor;
Internal::BaseTextBlockSelection m_blockSelection;
void moveCursorVisible(bool ensureVisible = true);
int visualIndent(const QTextBlock &block) const;
BaseTextEditorPrivateHighlightBlocks m_highlightBlocksInfo;
QTimer m_highlightBlocksTimer;
QScopedPointer<CodeAssistant> m_codeAssistant;
bool m_assistRelevantContentAdded;
QPointer<BaseTextEditorAnimator> m_animator;
int m_cursorBlockNumber;
int m_blockCount;
QPoint m_markDragStart;
bool m_markDragging;
QScopedPointer<AutoCompleter> m_autoCompleter;
QScopedPointer<Internal::ClipboardAssistProvider> m_clipboardAssistProvider;
};
} // namespace Internal
} // namespace TextEditor
......
......@@ -28,7 +28,7 @@
****************************************************************************/
#include "findincurrentfile.h"
#include "itexteditor.h"
#include "basetexteditor.h"
#include <utils/filesearch.h>
#include <coreplugin/icore.h>
......@@ -64,7 +64,7 @@ Utils::FileIterator *FindInCurrentFile::files(const QStringList &nameFilters,
Q_UNUSED(nameFilters)
QString fileName = additionalParameters.toString();
QMap<QString, QTextCodec *> openEditorEncodings
= ITextEditorDocument::openedTextDocumentEncodings();
= BaseTextEditorDocument::openedTextDocumentEncodings();
QTextCodec *codec = openEditorEncodings.value(fileName);
if (!codec)
codec = Core::EditorManager::defaultTextCodec();
......
......@@ -64,7 +64,7 @@ Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters,
Q_UNUSED(nameFilters)
Q_UNUSED(additionalParameters)
QMap<QString, QTextCodec *> openEditorEncodings
= ITextEditorDocument::openedTextDocumentEncodings();
= BaseTextEditorDocument::openedTextDocumentEncodings();
QStringList fileNames;
QList<QTextCodec *> codecs;
foreach (Core::DocumentModel::Entry *entry,
......
......@@ -27,7 +27,7 @@
**
****************************************************************************/
#include "itexteditor.h"
#include "basetexteditor.h"
#include <coreplugin/editormanager/editormanager.h>
#include <QTextCodec>
......@@ -35,32 +35,32 @@
namespace TextEditor {
/*!
\class TextEditor::ITextEditorDocument
\brief The ITextEditorDocument class is an abstract base for documents of text editors.
\class TextEditor::BaseTextEditorDocument
\brief The BaseTextEditorDocument class is an abstract base for documents of text editors.
It is the base class for documents used by implementations of the ITextEditor class,
It is the base class for documents used by implementations of the BaseTextEditor class,
and contains basic functions for retrieving text content and markers (like bookmarks).
*/
/*!
\class TextEditor::ITextEditor
\brief The ITextEditor class is an abstract base class for text editors.
\class TextEditor::BaseTextEditor
\brief The BaseTextEditor class is an abstract base class for text editors.
It contains the basic functions for retrieving and setting cursor position and selections,
and operations on them, like removing or inserting. It uses implementations of
ITextEditorDocument as the underlying document.
BaseTextEditorDocument as the underlying document.
*/
ITextEditorDocument::ITextEditorDocument(QObject *parent)
BaseTextEditorDocument::BaseTextEditorDocument(QObject *parent)
: Core::TextDocument(parent)
{
}
QMap<QString, QString> ITextEditorDocument::openedTextDocumentContents()
QMap<QString, QString> BaseTextEditorDocument::openedTextDocumentContents()
{
QMap<QString, QString> workingCopy;
foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) {
ITextEditorDocument *textEditorDocument = qobject_cast<ITextEditorDocument *>(document);
BaseTextEditorDocument *textEditorDocument = qobject_cast<BaseTextEditorDocument *>(document);
if (!textEditorDocument)
continue;
QString fileName = textEditorDocument->filePath();
......@@ -69,11 +69,11 @@ QMap<QString, QString> ITextEditorDocument::openedTextDocumentContents()
return workingCopy;
}
QMap<QString, QTextCodec *> ITextEditorDocument::openedTextDocumentEncodings()
QMap<QString, QTextCodec *> BaseTextEditorDocument::openedTextDocumentEncodings()
{
QMap<QString, QTextCodec *> workingCopy;
foreach (Core::IDocument *document, Core::DocumentModel::openedDocuments()) {
ITextEditorDocument *textEditorDocument = qobject_cast<ITextEditorDocument *>(document);
BaseTextEditorDocument *textEditorDocument = qobject_cast<BaseTextEditorDocument *>(document);
if (!textEditorDocument)
continue;
QString fileName = textEditorDocument->filePath();
......@@ -82,15 +82,15 @@ QMap<QString, QTextCodec *> ITextEditorDocument::openedTextDocumentEncodings()
return workingCopy;
}
ITextEditorDocument *ITextEditor::textDocument()
BaseTextEditorDocument *BaseTextEditor::textDocument()
{
return qobject_cast<ITextEditorDocument *>(document());
return qobject_cast<BaseTextEditorDocument *>(document());
}
ITextEditor *ITextEditor::currentTextEditor()
BaseTextEditor *BaseTextEditor::currentTextEditor()
{
return qobject_cast<ITextEditor *>(Core::EditorManager::currentEditor());
return qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor());
}
} // namespace TextEditor
......@@ -69,11 +69,11 @@ private:
};
class TEXTEDITOR_EXPORT ITextEditorDocument : public Core::TextDocument
class TEXTEDITOR_EXPORT BaseTextEditorDocument : public Core::TextDocument
{
Q_OBJECT
public:
explicit ITextEditorDocument(QObject *parent = 0);
explicit BaseTextEditorDocument(QObject *parent = 0);
virtual QString plainText() const = 0;
virtual QString textAt(int pos, int length) const = 0;
......@@ -86,65 +86,6 @@ signals:
void contentsChanged();
};
class TEXTEDITOR_EXPORT ITextEditor : public Core::IEditor
{
Q_OBJECT
public:
enum PositionOperation {
Current = 1,
EndOfLine = 2,
StartOfLine = 3,
Anchor = 4,
EndOfDoc = 5
};
ITextEditor() {}
virtual ITextEditorDocument *textDocument();
/*! Returns the position at \a posOp in characters from the beginning of the document */
virtual int position(PositionOperation posOp = Current, int at = -1) const = 0;
/*! 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 = 0;
/*! Returns the cursor rectangle in pixels at \a pos, or current position if \a pos = -1 */
virtual QRect cursorRect(int pos = -1) const = 0;
/*! Returns the amount of visible columns (in characters) in the editor */
virtual int columnCount() const = 0;
/*! Returns the amount of visible lines (in characters) in the editor */
virtual int rowCount() const = 0;
virtual QString selectedText() const = 0;
/*! Removes \a length characters to the right of the cursor. */
virtual void remove(int length) = 0;
/*! Inserts the given string to the right of the cursor. */
virtual void insert(const QString &string) = 0;
/*! Replaces \a length characters to the right of the cursor with the given string. */
virtual void replace(int length, const QString &string) = 0;
/*! Sets current cursor position to \a pos. */
virtual void setCursorPosition(int pos) = 0;
/*! Selects text between current cursor position and \a toPos. */
virtual void select(int toPos) = 0;
virtual const Utils::CommentDefinition* commentDefinition() const = 0;
enum MarkRequestKind {
BreakpointRequest,
BookmarkRequest,
TaskMarkRequest
};
static ITextEditor *currentTextEditor();
signals:
void markRequested(TextEditor::ITextEditor *editor, int line, TextEditor::ITextEditor::MarkRequestKind kind);
void markContextMenuRequested(TextEditor::ITextEditor *editor, int line, QMenu *menu);
void tooltipOverrideRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int position, bool *handled);
void tooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int position);
void markTooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int line);
void contextHelpIdRequested(TextEditor::ITextEditor *editor, int position);
};
} // namespace TextEditor
#endif // ITEXTEDITOR_H
......@@ -214,7 +214,7 @@ void TextEditorPlugin::extensionsInitialized()
tr("Selected text within the current document."),
[]() -> QString {
QString value;
if (ITextEditor *editor = ITextEditor::currentTextEditor()) {
if (BaseTextEditor *editor = BaseTextEditor::currentTextEditor()) {
value = editor->selectedText();
value.replace(QChar::ParagraphSeparator, QLatin1String("\n"));
}
......@@ -224,35 +224,35 @@ void TextEditorPlugin::extensionsInitialized()
Core::VariableManager::registerIntVariable(kCurrentDocumentRow,
tr("Line number of the text cursor position in current document (starts with 1)."),
[]() -> int {