diff options
author | hjk <hjk121@nokiamail.com> | 2014-07-23 19:10:38 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2014-07-25 13:45:55 +0200 |
commit | bf5e43be94b24517d6e62acbfd18fdc5a25ede73 (patch) | |
tree | 6f977217f47634c08e30aadc20105654b3ae6918 /src/plugins/texteditor | |
parent | 15421995ab1d4eada18e721a3503c87f58e94db9 (diff) | |
download | qt-creator-bf5e43be94b24517d6e62acbfd18fdc5a25ede73.tar.gz |
TextEditor: Merge ITextEditor and BaseTextEditor
Adjust all callers, de-export BaseTextEditorAnimator
Change-Id: I2329d976c1398e2449844bb480a4d4ed29859506
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r-- | src/plugins/texteditor/basefilefind.cpp | 6 | ||||
-rw-r--r-- | src/plugins/texteditor/basehoverhandler.cpp | 19 | ||||
-rw-r--r-- | src/plugins/texteditor/basehoverhandler.h | 12 | ||||
-rw-r--r-- | src/plugins/texteditor/basetextdocument.h | 5 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor.cpp | 225 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor.h | 192 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor_p.h | 130 | ||||
-rw-r--r-- | src/plugins/texteditor/findincurrentfile.cpp | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/findinopenfiles.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/itexteditor.cpp | 32 | ||||
-rw-r--r-- | src/plugins/texteditor/itexteditor.h | 63 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditorplugin.cpp | 16 | ||||
-rw-r--r-- | src/plugins/texteditor/textmark.h | 2 |
13 files changed, 360 insertions, 348 deletions
diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp index 91983c9b10..3a9980b2f4 100644 --- a/src/plugins/texteditor/basefilefind.cpp +++ b/src/plugins/texteditor/basefilefind.cpp @@ -37,7 +37,7 @@ #include <coreplugin/dialogs/readonlyfilesdialog.h> #include <coreplugin/documentmanager.h> #include <coreplugin/find/ifindsupport.h> -#include <texteditor/itexteditor.h> +#include <texteditor/basetexteditor.h> #include <texteditor/refactoringchanges.h> #include <utils/stylehelper.h> #include <utils/qtcassert.h> @@ -174,12 +174,12 @@ void BaseFileFind::runSearch(Core::SearchResult *search) watcher->setFuture(Utils::findInFilesRegExp(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), - ITextEditorDocument::openedTextDocumentContents())); + BaseTextEditorDocument::openedTextDocumentContents())); } else { watcher->setFuture(Utils::findInFiles(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), - ITextEditorDocument::openedTextDocumentContents())); + BaseTextEditorDocument::openedTextDocumentContents())); } FutureProgress *progress = ProgressManager::addTask(watcher->future(), tr("Searching"), Constants::TASK_SEARCH); diff --git a/src/plugins/texteditor/basehoverhandler.cpp b/src/plugins/texteditor/basehoverhandler.cpp index ffee52f447..3b0e5845ab 100644 --- a/src/plugins/texteditor/basehoverhandler.cpp +++ b/src/plugins/texteditor/basehoverhandler.cpp @@ -28,7 +28,6 @@ ****************************************************************************/ #include "basehoverhandler.h" -#include "itexteditor.h" #include "basetexteditor.h" #include <coreplugin/icore.h> @@ -41,7 +40,7 @@ using namespace Core; namespace TextEditor { -static BaseTextEditorWidget *baseTextEditor(ITextEditor *editor) +static BaseTextEditorWidget *baseTextEditor(BaseTextEditor *editor) { if (!editor) return 0; @@ -63,16 +62,16 @@ void BaseHoverHandler::editorOpened(Core::IEditor *editor) if (acceptEditor(editor)) { BaseTextEditor *textEditor = qobject_cast<BaseTextEditor *>(editor); if (textEditor) { - connect(textEditor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*,QPoint,int)), - this, SLOT(showToolTip(TextEditor::ITextEditor*,QPoint,int))); + connect(textEditor, SIGNAL(tooltipRequested(TextEditor::BaseTextEditor*,QPoint,int)), + this, SLOT(showToolTip(TextEditor::BaseTextEditor*,QPoint,int))); - connect(textEditor, SIGNAL(contextHelpIdRequested(TextEditor::ITextEditor*,int)), - this, SLOT(updateContextHelpId(TextEditor::ITextEditor*,int))); + connect(textEditor, SIGNAL(contextHelpIdRequested(TextEditor::BaseTextEditor*,int)), + this, SLOT(updateContextHelpId(TextEditor::BaseTextEditor*,int))); } } } -void BaseHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos) +void BaseHoverHandler::showToolTip(TextEditor::BaseTextEditor *editor, const QPoint &point, int pos) { BaseTextEditorWidget *baseEditor = baseTextEditor(editor); if (!baseEditor) @@ -84,7 +83,7 @@ void BaseHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint operateTooltip(editor, point); } -void BaseHoverHandler::updateContextHelpId(TextEditor::ITextEditor *editor, int pos) +void BaseHoverHandler::updateContextHelpId(TextEditor::BaseTextEditor *editor, int pos) { BaseTextEditorWidget *baseEditor = baseTextEditor(editor); if (!baseEditor) @@ -150,7 +149,7 @@ void BaseHoverHandler::clear() m_lastHelpItemIdentified = HelpItem(); } -void BaseHoverHandler::process(ITextEditor *editor, int pos) +void BaseHoverHandler::process(BaseTextEditor *editor, int pos) { clear(); identifyMatch(editor, pos); @@ -172,7 +171,7 @@ void BaseHoverHandler::decorateToolTip() } } -void BaseHoverHandler::operateTooltip(ITextEditor *editor, const QPoint &point) +void BaseHoverHandler::operateTooltip(BaseTextEditor *editor, const QPoint &point) { if (m_toolTip.isEmpty()) Utils::ToolTip::hide(); diff --git a/src/plugins/texteditor/basehoverhandler.h b/src/plugins/texteditor/basehoverhandler.h index ea6c781568..7d487b21b1 100644 --- a/src/plugins/texteditor/basehoverhandler.h +++ b/src/plugins/texteditor/basehoverhandler.h @@ -44,7 +44,7 @@ namespace Core { class IEditor; } namespace TextEditor { -class ITextEditor; +class BaseTextEditor; class BaseTextEditorWidget; class TEXTEDITOR_EXPORT BaseHoverHandler : public QObject @@ -57,8 +57,8 @@ public: private slots: void editorOpened(Core::IEditor *editor); - void showToolTip(TextEditor::ITextEditor *editor, const QPoint &point, int pos); - void updateContextHelpId(TextEditor::ITextEditor *editor, int pos); + void showToolTip(TextEditor::BaseTextEditor *editor, const QPoint &point, int pos); + void updateContextHelpId(TextEditor::BaseTextEditor *editor, int pos); protected: void setToolTip(const QString &tooltip); @@ -75,12 +75,12 @@ protected: private: void clear(); - void process(ITextEditor *editor, int pos); + void process(BaseTextEditor *editor, int pos); virtual bool acceptEditor(Core::IEditor *editor) = 0; - virtual void identifyMatch(ITextEditor *editor, int pos) = 0; + virtual void identifyMatch(BaseTextEditor *editor, int pos) = 0; virtual void decorateToolTip(); - virtual void operateTooltip(ITextEditor *editor, const QPoint &point); + virtual void operateTooltip(BaseTextEditor *editor, const QPoint &point); bool m_diagnosticTooltip; QString m_toolTip; diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h index c371d145ad..370a24ba9a 100644 --- a/src/plugins/texteditor/basetextdocument.h +++ b/src/plugins/texteditor/basetextdocument.h @@ -33,7 +33,6 @@ #include "texteditor_global.h" #include "itexteditor.h" -#include "itexteditor.h" #include <QList> @@ -56,7 +55,7 @@ class TypingSettings; typedef QList<TextMark *> TextMarks; -class TEXTEDITOR_EXPORT BaseTextDocument : public ITextEditorDocument +class TEXTEDITOR_EXPORT BaseTextDocument : public BaseTextEditorDocument { Q_OBJECT @@ -64,7 +63,7 @@ public: BaseTextDocument(); virtual ~BaseTextDocument(); - // ITextEditorDocument + // BaseTextEditorDocument QString plainText() const; QString textAt(int pos, int length) const; QChar characterAt(int pos) const; diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 7238d2e795..01a917b4f1 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -119,6 +119,176 @@ using namespace Utils; namespace TextEditor { namespace Internal { +class BaseTextEditorAnimator : public QObject +{ + Q_OBJECT + +public: + BaseTextEditorAnimator(QObject *parent); + + inline void setPosition(int position) { m_position = position; } + inline int position() const { return m_position; } + + void setData(const QFont &f, const QPalette &pal, const QString &text); + + void draw(QPainter *p, const QPointF &pos); + QRectF rect() const; + + inline qreal value() const { return m_value; } + inline QPointF lastDrawPos() const { return m_lastDrawPos; } + + void finish(); + + bool isRunning() const; + +signals: + void updateRequest(int position, QPointF lastPos, QRectF rect); + + +private slots: + void step(qreal v); + +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; +}; + +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; +}; + class TextEditExtraArea : public QWidget { public: @@ -2059,28 +2229,28 @@ void BaseTextEditorWidget::gotoLine(int line, int column, bool centerLine) saveCurrentCursorPositionForNavigation(); } -int BaseTextEditorWidget::position(ITextEditor::PositionOperation posOp, int at) const +int BaseTextEditorWidget::position(BaseTextEditor::PositionOperation posOp, int at) const { QTextCursor tc = textCursor(); if (at != -1) tc.setPosition(at); - if (posOp == ITextEditor::Current) + if (posOp == BaseTextEditor::Current) return tc.position(); switch (posOp) { - case ITextEditor::EndOfLine: + case BaseTextEditor::EndOfLine: tc.movePosition(QTextCursor::EndOfLine); return tc.position(); - case ITextEditor::StartOfLine: + case BaseTextEditor::StartOfLine: tc.movePosition(QTextCursor::StartOfLine); return tc.position(); - case ITextEditor::Anchor: + case BaseTextEditor::Anchor: if (tc.hasSelection()) return tc.anchor(); break; - case ITextEditor::EndOfDoc: + case BaseTextEditor::EndOfDoc: tc.movePosition(QTextCursor::End); return tc.position(); default: @@ -4673,11 +4843,11 @@ void BaseTextEditorWidget::extraAreaMouseEvent(QMouseEvent *e) } } int line = n + 1; - ITextEditor::MarkRequestKind kind; + BaseTextEditor::MarkRequestKind kind; if (QApplication::keyboardModifiers() & Qt::ShiftModifier) - kind = ITextEditor::BookmarkRequest; + kind = BaseTextEditor::BookmarkRequest; else - kind = ITextEditor::BreakpointRequest; + kind = BaseTextEditor::BreakpointRequest; emit editor()->markRequested(editor(), line, kind); } @@ -6202,6 +6372,16 @@ BaseTextEditor::~BaseTextEditor() delete m_editorWidget; } +BaseTextDocument *BaseTextEditor::baseTextDocument() +{ + return m_editorWidget->baseTextDocument(); +} + +IDocument *BaseTextEditor::document() +{ + return m_editorWidget->baseTextDocument(); +} + QWidget *BaseTextEditor::toolBar() { return m_toolBar; @@ -6233,6 +6413,11 @@ int BaseTextEditor::currentColumn() const return cursor.position() - cursor.block().position() + 1; } +void BaseTextEditor::gotoLine(int line, int column, bool centerLine) +{ + m_editorWidget->gotoLine(line, column, centerLine); +} + int BaseTextEditor::columnCount() const { return m_editorWidget->columnCount(); @@ -6243,6 +6428,16 @@ int BaseTextEditor::rowCount() const return m_editorWidget->rowCount(); } +int BaseTextEditor::position(BaseTextEditor::PositionOperation posOp, int at) const +{ + return m_editorWidget->position(posOp, at); +} + +void BaseTextEditor::convertPosition(int pos, int *line, int *column) const +{ + m_editorWidget->convertPosition(pos, line, column); +} + QRect BaseTextEditor::cursorRect(int pos) const { QTextCursor tc = m_editorWidget->textCursor(); @@ -6644,4 +6839,16 @@ bool BaseTextEditor::open(QString *errorString, const QString &fileName, const Q return m_editorWidget->open(errorString, fileName, realFileName); } +QByteArray BaseTextEditor::saveState() const +{ + return m_editorWidget->saveState(); +} + +bool BaseTextEditor::restoreState(const QByteArray &state) +{ + return m_editorWidget->restoreState(state); +} + } // namespace TextEditor + +#include "basetexteditor.moc" diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 9d6c1fdd49..38595d56b8 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -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) diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 1e69b3525e..f5f4fe7f90 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -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 diff --git a/src/plugins/texteditor/findincurrentfile.cpp b/src/plugins/texteditor/findincurrentfile.cpp index 6a8a3a0716..ffa0068ef1 100644 --- a/src/plugins/texteditor/findincurrentfile.cpp +++ b/src/plugins/texteditor/findincurrentfile.cpp @@ -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(); diff --git a/src/plugins/texteditor/findinopenfiles.cpp b/src/plugins/texteditor/findinopenfiles.cpp index c444e8b0e3..9d15c02a7c 100644 --- a/src/plugins/texteditor/findinopenfiles.cpp +++ b/src/plugins/texteditor/findinopenfiles.cpp @@ -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, diff --git a/src/plugins/texteditor/itexteditor.cpp b/src/plugins/texteditor/itexteditor.cpp index 51ec0a6b84..2da0838c59 100644 --- a/src/plugins/texteditor/itexteditor.cpp +++ b/src/plugins/texteditor/itexteditor.cpp @@ -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 diff --git a/src/plugins/texteditor/itexteditor.h b/src/plugins/texteditor/itexteditor.h index 60a10a522b..52b23f79ff 100644 --- a/src/plugins/texteditor/itexteditor.h +++ b/src/plugins/texteditor/itexteditor.h @@ -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 diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index a390183e13..9b83e6b461 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -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 { - ITextEditor *editor = ITextEditor::currentTextEditor(); + BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); return editor ? editor->currentLine() : 0; }); Core::VariableManager::registerIntVariable(kCurrentDocumentColumn, tr("Column number of the text cursor position in current document (starts with 0)."), []() -> int { - ITextEditor *editor = ITextEditor::currentTextEditor(); + BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); return editor ? editor->currentColumn() : 0; }); Core::VariableManager::registerIntVariable(kCurrentDocumentRowCount, tr("Number of lines visible in current document."), []() -> int { - ITextEditor *editor = ITextEditor::currentTextEditor(); + BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); return editor ? editor->rowCount() : 0; }); Core::VariableManager::registerIntVariable(kCurrentDocumentColumnCount, tr("Number of columns visible in current document."), []() -> int { - ITextEditor *editor = ITextEditor::currentTextEditor(); + BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); return editor ? editor->columnCount() : 0; }); Core::VariableManager::registerIntVariable(kCurrentDocumentFontSize, tr("Current document's font size in points."), []() -> int { - ITextEditor *editor = ITextEditor::currentTextEditor(); + BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); return editor ? editor->widget()->font().pointSize() : 0; }); @@ -304,9 +304,9 @@ void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings) void TextEditorPlugin::updateCurrentSelection(const QString &text) { - if (ITextEditor *editor = qobject_cast<ITextEditor *>(Core::EditorManager::currentEditor())) { + if (BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor())) { const int pos = editor->position(); - int anchor = editor->position(ITextEditor::Anchor); + int anchor = editor->position(BaseTextEditor::Anchor); if (anchor < 0) // no selection anchor = pos; int selectionLength = pos - anchor; diff --git a/src/plugins/texteditor/textmark.h b/src/plugins/texteditor/textmark.h index 60d63fb96f..8532aea82b 100644 --- a/src/plugins/texteditor/textmark.h +++ b/src/plugins/texteditor/textmark.h @@ -43,7 +43,7 @@ QT_END_NAMESPACE namespace TextEditor { -class ITextEditor; +class BaseTextEditor; class BaseTextDocument; namespace Internal { class TextMarkRegistry; } |