13#include <ktexteditor/linerange.h>
14#include <ktexteditor/mainwindow.h>
15#include <ktexteditor/view.h>
17#include <QJsonDocument>
23#include "katetextfolding.h"
24#include "katetextrange.h"
39class KateRendererConfig;
42class KateSpellCheckDialog;
44class KateViewInternal;
48class KateDictionaryBar;
49class KateSpellingMenu;
53class KateViewEncodingAction;
55class KateAbstractInputMode;
75class KTEXTEDITOR_EXPORT ViewPrivate final :
public KTextEditor::View
79 friend class KTextEditor::View;
80 friend class ::KateViewInternal;
81 friend class ::KateIconBorder;
82 friend class ::KateTextPreview;
83 friend MulticursorTest;
86 ViewPrivate(KTextEditor::DocumentPrivate *doc, QWidget *parent, KTextEditor::MainWindow *mainWindow =
nullptr);
87 ~ViewPrivate()
override;
93 KTextEditor::MainWindow *mainWindow()
const override
98 KTextEditor::Document *document()
const override;
100 ViewMode viewMode()
const override;
101 QString viewModeHuman()
const override;
102 InputMode viewInputMode()
const override;
103 QString viewInputModeHuman()
const override;
105 void setViewInputMode(InputMode mode)
override
110 void setInputMode(InputMode mode,
const bool rememberInConfig =
true);
113 KateViewInternal *getViewInternal()
115 return m_viewInternal;
122 void paste(
const QString *textToPaste =
nullptr);
137 void pasteFromFile();
142 void swapWithClipboard();
148 void applyWordWrap();
153 void copyFileLocation()
const;
159 void setContextMenu(QMenu *menu)
override;
160 QMenu *contextMenu()
const override;
161 QMenu *defaultContextMenu(QMenu *menu =
nullptr)
const override;
164 void aboutToShowContextMenu();
165 void aboutToHideContextMenu();
168 QPointer<QMenu> m_contextMenu;
174 bool setCursorPosition(KTextEditor::Cursor position)
override;
176 KTextEditor::Cursor cursorPosition()
const override;
178 KTextEditor::Cursor cursorPositionVirtual()
const override;
180 QPoint cursorToCoordinate(KTextEditor::Cursor cursor)
const override;
182 KTextEditor::Cursor coordinatesToCursor(
const QPoint &coord)
const override;
184 QPoint cursorPositionCoordinates()
const override;
186 bool setCursorPositionVisual(
const KTextEditor::Cursor position);
188 QScrollBar *verticalScrollBar()
const override;
189 QScrollBar *horizontalScrollBar()
const override;
196 int virtualCursorColumn()
const;
198 bool mouseTrackingEnabled()
const override;
199 bool setMouseTrackingEnabled(
bool enable)
override;
206 struct PlainSecondaryCursor {
207 KTextEditor::Cursor pos;
208 KTextEditor::Range range;
209 friend bool operator<(
const PlainSecondaryCursor &l,
const PlainSecondaryCursor &r)
211 return l.pos < r.pos;
214 struct SecondaryCursor {
215 std::unique_ptr<Kate::TextCursor> pos;
216 std::unique_ptr<Kate::TextRange> range;
219 KTextEditor::Cursor cursor()
const
221 return pos->toCursor();
224 friend bool operator<(
const SecondaryCursor &l,
const SecondaryCursor &r)
226 return l.cursor() < r.cursor();
229 friend bool operator<(
const SecondaryCursor &l, KTextEditor::Cursor r)
231 return l.cursor() < r;
234 friend bool operator==(
const SecondaryCursor &l,
const SecondaryCursor &r)
236 return l.cursor() == r.cursor() && l.selectionRange() == r.selectionRange();
239 KTextEditor::Range selectionRange()
const
244 void clearSelection()
252 bool isMulticursorNotAllowed()
const;
255 void addSecondaryCursor(KTextEditor::Cursor cursor);
256 void setSecondaryCursors(
const QList<KTextEditor::Cursor> &positions);
258 const std::vector<SecondaryCursor> &secondaryCursors()
const;
259 QList<PlainSecondaryCursor> plainSecondaryCursors()
const;
260 void addSecondaryCursorsWithSelection(
const QList<PlainSecondaryCursor> &cursorsWithSelection);
262 void clearSecondaryCursors();
263 void clearSecondarySelections();
267 void ensureUniqueCursors(
bool matchLine =
false);
270 QList<KTextEditor::Cursor> cursors()
const;
271 QList<KTextEditor::Range> selectionRanges()
const;
273 void setCursors(
const QList<KTextEditor::Cursor> &cursorPositions);
274 void setSelections(
const QList<KTextEditor::Range> &selectionRanges);
277 bool hasSelections()
const;
280 KTEXTEDITOR_NO_EXPORT
281 bool removeSecondaryCursors(
const std::vector<KTextEditor::Cursor> &cursorToRemove,
bool removeIfOverlapsSelection =
false);
282 KTEXTEDITOR_NO_EXPORT
283 Kate::TextRange *newSecondarySelectionRange(KTextEditor::Range);
284 KTEXTEDITOR_NO_EXPORT
286 KTEXTEDITOR_NO_EXPORT
289 std::vector<SecondaryCursor> m_secondaryCursors;
290 bool m_skipCurrentSelection =
false;
292 void addSecondaryCursorDown();
294 void addSecondaryCursorUp();
298 KTEXTEDITOR_NO_EXPORT
299 void notifyMousePositionChanged(
const KTextEditor::Cursor newPosition);
303 bool setCursorPositionInternal(
const KTextEditor::Cursor position, uint tabwidth = 1,
bool calledExternally =
false);
309 QStringList configKeys()
const override;
310 QVariant configValue(
const QString &key)
override;
311 void setConfigValue(
const QString &key,
const QVariant &value)
override;
318 KTextEditor::Range foldLine(
int line);
324 bool unfoldLine(
int line);
330 bool toggleFoldingOfLine(
int line);
340 bool toggleFoldingsInRange(
int line);
344 bool isCompletionActive()
const override;
345 void startCompletion(KTextEditor::Range word, KTextEditor::CodeCompletionModel *model)
override;
346 void startCompletion(
const Range &word,
347 const QList<KTextEditor::CodeCompletionModel *> &models = QList<KTextEditor::CodeCompletionModel *>(),
348 KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation)
override;
349 void abortCompletion()
override;
350 void forceCompletion()
override;
351 void registerCompletionModel(KTextEditor::CodeCompletionModel *model)
override;
352 void unregisterCompletionModel(KTextEditor::CodeCompletionModel *model)
override;
353 bool isCompletionModelRegistered(KTextEditor::CodeCompletionModel *model)
const;
354 QList<KTextEditor::CodeCompletionModel *> codeCompletionModels()
const override;
355 bool isAutomaticInvocationEnabled()
const override;
356 void setAutomaticInvocationEnabled(
bool enabled =
true)
override;
359 void completionExecuted(KTextEditor::View *view, KTextEditor::Cursor position, KTextEditor::CodeCompletionModel *model,
const QModelIndex &);
360 void completionAborted(KTextEditor::View *view);
363 void userInvokedCompletion();
366 KateCompletionWidget *completionWidget()
const;
367 mutable KateCompletionWidget *m_completionWidget;
368 void sendCompletionExecuted(
const KTextEditor::Cursor position, KTextEditor::CodeCompletionModel *model,
const QModelIndex &index);
369 void sendCompletionAborted();
375 void registerTextHintProvider(KTextEditor::TextHintProvider *provider)
override;
376 void unregisterTextHintProvider(KTextEditor::TextHintProvider *provider)
override;
377 void setTextHintDelay(
int delay)
override;
378 int textHintDelay()
const override;
381 bool dynWordWrap()
const
390 void registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider)
override;
391 void unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider)
override;
392 QRect inlineNoteRect(
const KateInlineNoteData ¬e)
const;
394 QVarLengthArray<KateInlineNoteData, 8> inlineNotes(
int line)
const;
397 std::vector<KTextEditor::InlineNoteProvider *> m_inlineNoteProviders;
400 void inlineNotesReset();
401 void inlineNotesLineChanged(
int line);
407 bool setSelection(KTextEditor::Range selection)
override;
409 bool removeSelection()
override
411 return clearSelection();
414 bool removeSelectionText()
override
416 return removeSelectedText();
419 bool setBlockSelection(
bool on)
override;
420 bool toggleBlockSelection();
422 bool clearSelection();
423 bool clearSelection(
bool redraw,
bool finishedChangingSelection =
true);
425 bool removeSelectedText();
430 bool selection()
const override;
431 QString selectionText()
const override;
432 bool blockSelection()
const override;
433 KTextEditor::Range selectionRange()
const override;
435 static void blockFix(KTextEditor::Range &range);
442 void deactivateEditActions();
443 void activateEditActions();
450 bool wrapCursor()
const;
453 bool cursorSelected(
const KTextEditor::Cursor cursor);
454 bool lineSelected(
int line);
455 bool lineEndSelected(
const KTextEditor::Cursor lineEndPos);
456 bool lineHasSelected(
int line);
457 bool lineIsSelection(
int line);
459 void ensureCursorColumnValid();
461 void tagSelection(KTextEditor::Range oldSelection);
463 void selectWord(
const KTextEditor::Cursor cursor);
464 void selectLine(
const KTextEditor::Cursor cursor);
469 void editEnd(
int editTagLineStart,
int editTagLineEnd,
bool tagFrom);
471 void editSetCursor(
const KTextEditor::Cursor cursor);
476 bool tagLine(
const KTextEditor::Cursor virtualCursor);
478 bool tagRange(KTextEditor::Range range,
bool realLines =
false);
479 bool tagLines(KTextEditor::LineRange lineRange,
bool realLines =
false);
480 bool tagLines(KTextEditor::Cursor
start, KTextEditor::Cursor end,
bool realCursors =
false);
481 bool tagLines(KTextEditor::Range range,
bool realRange =
false);
487 void repaintText(
bool paintOnlyDirty =
false);
489 void updateView(
bool changed =
false);
496 void setAnnotationModel(KTextEditor::AnnotationModel *model)
override;
497 KTextEditor::AnnotationModel *annotationModel()
const override;
498 void setAnnotationBorderVisible(
bool visible)
override;
499 bool isAnnotationBorderVisible()
const override;
500 void setAnnotationItemDelegate(KTextEditor::AbstractAnnotationItemDelegate *delegate)
override;
501 KTextEditor::AbstractAnnotationItemDelegate *annotationItemDelegate()
const override;
502 void setAnnotationUniformItemSizes(
bool enable)
override;
503 bool uniformAnnotationItemSizes()
const override;
507 void navigateRight();
510 void navigateAccept();
514 KTextEditor::AnnotationModel *m_annotationModel;
520 void emitNavigateLeft()
522 Q_EMIT navigateLeft();
524 void emitNavigateRight()
526 Q_EMIT navigateRight();
528 void emitNavigateUp()
532 void emitNavigateDown()
534 Q_EMIT navigateDown();
536 void emitNavigateAccept()
538 Q_EMIT navigateAccept();
540 void emitNavigateBack()
542 Q_EMIT navigateBack();
547 bool isOverwriteMode()
const;
549 bool isLineRTL(
int line)
const;
551 const QTextLayout *textLayout(
const KTextEditor::Cursor pos)
const;
562 void toggleComment();
568 void goToPreviousEditingPosition();
573 void goToNextEditingPosition();
618 void noIndentNewline();
634 void deleteWordLeft();
649 void deleteWordRight();
665 void transposeWord();
667 void shiftCursorLeft();
669 void shiftCursorRight();
671 void shiftWordLeft();
673 void shiftWordRight();
674 void markSelection();
686 void shiftTopOfView();
688 void shiftBottomOfView();
692 void shiftPageDown();
697 void toMatchingBracket();
698 void shiftToMatchingBracket();
699 void toPrevModifiedLine();
700 void toNextModifiedLine();
723 void readSessionConfig(
const KConfigGroup &config,
const QSet<QString> &flags = QSet<QString>())
override;
733 void writeSessionConfig(KConfigGroup &config,
const QSet<QString> &flags = QSet<QString>())
override;
736 void setEol(
int eol);
737 void setAddBom(
bool enabled);
739 void findSelectedForwards();
740 void findSelectedBackwards();
741 void findNextOccurunceAndSelect();
742 void findAllOccuruncesAndSelect();
743 void skipCurrentOccurunceSelection();
747 void showSearchWrappedHint(
bool isReverseSearch);
748 void createMultiCursorsFromSelection();
749 void removeCursorsFromEmptyLines();
751 void setFoldingMarkersOn(
bool enable);
752 void setIconBorder(
bool enable);
753 void setLineNumbersOn(
bool enable);
754 void setScrollBarMarks(
bool enable);
755 void setScrollBarMiniMap(
bool enable);
756 void setScrollBarMiniMapAll(
bool enable);
757 void setScrollBarMiniMapWidth(
int width);
758 void toggleFoldingMarkers();
759 void toggleIconBorder();
760 void toggleLineNumbersOn();
761 void toggleScrollBarMarks();
762 void toggleScrollBarMiniMap();
763 void toggleScrollBarMiniMapAll();
764 void toggleShowSpaces();
765 void toggleDynWordWrap();
766 void setDynWrapIndicators(
int mode);
773 KateRenderer *renderer();
774 KateRendererConfig *rendererConfig();
777 bool lineNumbersOn();
778 bool scrollBarMarks();
779 bool scrollBarMiniMap();
780 bool scrollBarMiniMapAll();
781 int dynWrapIndicators();
782 bool foldingMarkersOn();
783 bool forceRTLDirection()
const;
789 void slotSelectionChanged();
791 void toggleInputMode();
792 void cycleInputMode();
799 KTextEditor::DocumentPrivate *doc()
803 const KTextEditor::DocumentPrivate *doc()
const
809 void slotUpdateUndo();
812 void toggleWWMarker();
813 void toggleNPSpaces();
814 void toggleWordCount(
bool on);
815 void toggleWriteLock();
816 void switchToCmdLine();
817 void slotReadWriteChanged();
818 void toggleCamelCaseCursor();
821 void dropEventPass(QDropEvent *);
828 Kate::TextFolding &textFolding()
830 return m_textFolding;
834 void slotTextInserted(KTextEditor::View *view,
const KTextEditor::Cursor position,
const QString &text);
836 void exportHtmlToFile(
const QString &file);
839 void slotDocumentReloaded();
840 void slotDocumentAboutToReload();
842 void slotLostFocus();
843 void slotSaveCanceled(
const QString &error);
844 void slotConfigDialog();
845 void exportHtmlToClipboard();
846 void exportHtmlToFile();
849 void slotFoldToplevelNodes();
850 void slotExpandToplevelNodes();
851 void slotToggleFolding();
852 void slotToggleFoldingsInRange();
855 KTEXTEDITOR_NO_EXPORT
857 KTEXTEDITOR_NO_EXPORT
858 void setupConnections();
859 KTEXTEDITOR_NO_EXPORT
861 KTEXTEDITOR_NO_EXPORT
862 void setupEditActions();
863 KTEXTEDITOR_NO_EXPORT
864 void setupCodeFolding();
865 KTEXTEDITOR_NO_EXPORT
866 void setupSpeechActions();
868 std::vector<QAction *> m_editActions;
871 bool m_gotoBottomAfterReload;
872 bool m_markedSelection;
873 KToggleAction *m_toggleFoldingMarkers;
874 KToggleAction *m_toggleIconBar;
875 KToggleAction *m_toggleLineNumbers;
876 KToggleAction *m_toggleScrollBarMarks;
877 KToggleAction *m_toggleScrollBarMiniMap;
878 KToggleAction *m_toggleScrollBarMiniMapAll;
879 KToggleAction *m_toggleShowSpace;
880 KToggleAction *m_toggleDynWrap;
881 KSelectAction *m_setDynWrapIndicators;
882 KToggleAction *m_toggleWWMarker;
883 KToggleAction *m_toggleNPSpaces;
884 KToggleAction *m_toggleWordCount;
885 QAction *m_switchCmdLine;
886 KToggleAction *m_viInputModeAction;
888 KSelectAction *m_setEndOfLine;
889 KToggleAction *m_addBom;
893 QAction *m_copyHtmlAction;
895 QAction *m_clipboardHistory;
897 QAction *m_pasteSelection =
nullptr;
898 QAction *m_swapWithClipboard;
899 QAction *m_selectAll;
901 QAction *m_screenshotSelection =
nullptr;
903 QActionGroup *m_inputModeActions;
905 KToggleAction *m_toggleBlockSelection;
906 KToggleAction *m_toggleInsert;
907 KToggleAction *m_toggleWriteLock;
908 KToggleAction *m_forceRTLDirection;
911 bool m_forceRTL =
false;
912 bool m_accessibilityEnabled =
false;
914 KTextEditor::DocumentPrivate *
const m_doc;
915 Kate::TextFolding m_textFolding;
916 KateViewConfig *
const m_config;
917 KateRenderer *
const m_renderer;
918 KateViewInternal *
const m_viewInternal;
919 KateSpellCheckDialog *m_spell;
920 KateBookmarks *
const m_bookmarks;
923 QSpacerItem *m_topSpacer;
924 QSpacerItem *m_leftSpacer;
925 QSpacerItem *m_rightSpacer;
926 QSpacerItem *m_bottomSpacer;
929 void slotHlChanged();
935 inline KateViewConfig *config()
942 void updateDocumentConfig();
944 void updateRendererConfig();
947 void updateFoldingConfig();
951 bool m_updatingDocumentConfig;
954 Kate::TextRange m_selection;
961 bool insertTemplateInternal(
const KTextEditor::Cursor insertPosition,
const QString &templateString,
const QString &script = QString());
967 KateViewBar *bottomViewBar()
const;
968 KateDictionaryBar *dictionaryBar();
971 KTEXTEDITOR_NO_EXPORT
972 KateGotoBar *gotoBar();
980 KateViewBar *m_bottomViewBar;
983 KateGotoBar *m_gotoBar;
984 KateDictionaryBar *m_dictionaryBar;
988 KateAbstractInputMode *currentInputMode()
const;
991 KTextEditor::Range visibleRange();
994 bool event(QEvent *e)
override;
996 KToggleAction *m_toggleOnTheFlySpellCheck;
997 KateSpellingMenu *m_spellingMenu;
1000 void toggleOnTheFlySpellCheck(
bool b);
1003 void changeDictionary();
1004 void reflectOnTheFlySpellCheckStatus(
bool enabled);
1007 KateSpellingMenu *spellingMenu();
1010 bool m_userContextMenuSet;
1016 void saveFoldingState();
1021 void applyFoldingState();
1027 void clearFoldingState();
1030 KTEXTEDITOR_NO_EXPORT
1031 void clearHighlights();
1032 KTEXTEDITOR_NO_EXPORT
1033 void createHighlights();
1036 KTEXTEDITOR_NO_EXPORT
1037 void selectionChangedForHighlights();
1042 QJsonDocument m_savedFoldingState;
1044 QString m_currentTextForHighlights;
1046 std::vector<std::unique_ptr<KTextEditor::MovingRange>> m_rangesForHighlights;
1054 void notifyAboutRangeChange(KTextEditor::LineRange lineRange,
bool needsRepaint, Kate::TextRange *deleteRange);
1060 void slotDelayedUpdateOfView();
1066 void delayedUpdateOfView();
1072 void caretChangedRange(KTextEditor::View *);
1079 const QSet<Kate::TextRange *> *rangesMouseIn()
const
1081 return &m_rangesMouseIn;
1088 const QSet<Kate::TextRange *> *rangesCaretIn()
const
1090 return &m_rangesCaretIn;
1106 QTimer m_delayedUpdateTimer;
1111 KTextEditor::LineRange m_lineToUpdateRange;
1116 QSet<Kate::TextRange *> m_rangesMouseIn;
1121 QSet<Kate::TextRange *> m_rangesCaretIn;
1130 void postMessage(KTextEditor::Message *message, QList<std::shared_ptr<QAction>> actions);
1137 std::array<KateMessageWidget *, 5> m_messageWidgets{{
nullptr}};
1139 KateMessageLayout *m_notificationLayout =
nullptr;
1143 KateMessageWidget *messageWidget();
1149 QPointer<KTextEditor::MainWindow> m_mainWindow;
1155 bool print()
override;
1163 KateStatusBar *statusBar()
const
1171 void toggleStatusBar();
1177 KateViewEncodingAction *encodingAction()
const
1179 return m_encodingAction;
1186 KateModeMenu *modeAction()
const
1188 return m_modeAction;
1195 KateStatusBar *m_statusBar;
1200 KateViewEncodingAction *m_encodingAction;
1205 KateModeMenu *m_modeAction;
1210 bool m_temporaryAutomaticInvocationDisabled;
1223 QList<KTextEditor::AttributeBlock> lineAttributes(
int line)
override;
1228 bool m_autoFoldedFirstLine;
1231 void setScrollPositionInternal(KTextEditor::Cursor cursor);
1233 void setHorizontalScrollPositionInternal(
int x);
1235 KTextEditor::Cursor maxScrollPositionInternal()
const;
1237 int firstDisplayedLineInternal(LineType lineType)
const;
1239 int lastDisplayedLineInternal(LineType lineType)
const;
1241 QRect textAreaRectInternal()
const;
1249 std::unique_ptr<KateScriptActionMenu> m_scriptActionMenu;
1252 QPointer<KTextEditor::Message> m_wrappedMessage;
1253 bool m_isLastSearchReversed =
false;
An model for providing line annotation information.
ActivationType
Several automatic activation mechanisms exist for associated attributes.
static constexpr Cursor invalid() noexcept
Returns an invalid cursor.
Backend of KTextEditor::Document related public KTextEditor interfaces.
A source of inline notes for a document.
This class holds a Message to display in Views.
static constexpr Range invalid() noexcept
Returns an invalid range.
Internal data container for KTextEditor::InlineNote interface.
Class to layout KTextEditor::Messages in KateView.
Handles all of the work of rendering the text (used for the views and printing)
Class representing a 'clever' text cursor.
Q_SCRIPTABLE Q_NOREPLY void start()
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
KIOCORE_EXPORT bool operator==(const UDSEntry &entry, const UDSEntry &other)
QAction * up(const QObject *recvr, const char *slot, QObject *parent)
QAction * home(const QObject *recvr, const char *slot, QObject *parent)
QAction * paste(const QObject *recvr, const char *slot, QObject *parent)
QAction * replace(const QObject *recvr, const char *slot, QObject *parent)
QAction * cut(const QObject *recvr, const char *slot, QObject *parent)
QAction * copy(const QObject *recvr, const char *slot, QObject *parent)
QAction * selectAll(const QObject *recvr, const char *slot, QObject *parent)
QAction * printPreview(const QObject *recvr, const char *slot, QObject *parent)
QAction * findNext(const QObject *recvr, const char *slot, QObject *parent)
QAction * gotoLine(const QObject *recvr, const char *slot, QObject *parent)
const QList< QKeySequence > & end()
const QList< QKeySequence > & pasteSelection()
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
bool operator<(const PosRange< Trait > &l, const PosRange< Trait > &r)