KTextEditor

kateview.h
1/*
2 SPDX-FileCopyrightText: 2002 John Firebaugh <jfirebaugh@kde.org>
3 SPDX-FileCopyrightText: 2001 Christoph Cullmann <cullmann@kde.org>
4 SPDX-FileCopyrightText: 2001-2010 Joseph Wenninger <jowenn@kde.org>
5 SPDX-FileCopyrightText: 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#ifndef kate_view_h
11#define kate_view_h
12
13#include <ktexteditor/linerange.h>
14#include <ktexteditor/mainwindow.h>
15#include <ktexteditor/view.h>
16
17#include <QJsonDocument>
18#include <QPointer>
19#include <QTimer>
20
21#include <array>
22
23#include "katetextfolding.h"
24#include "katetextrange.h"
25
26namespace KTextEditor
27{
28class AnnotationModel;
29class Message;
30class InlineNoteProvider;
31class DocumentPrivate;
32}
33
34namespace Kate
35{
36class TextCursor;
37}
38class KateBookmarks;
39class KateRendererConfig;
40class KateViewConfig;
41class KateRenderer;
42class KateSpellCheckDialog;
44class KateViewInternal;
45class KateViewBar;
46class KateTextPreview;
47class KateGotoBar;
48class KateDictionaryBar;
49class KateSpellingMenu;
51class KateIconBorder;
52class KateStatusBar;
53class KateViewEncodingAction;
54class KateModeMenu;
55class KateAbstractInputMode;
59class MulticursorTest;
60
61class KToggleAction;
62class KSelectAction;
63
64class QAction;
65class QTextLayout;
66class QSpacerItem;
67class QMenu;
68class QActionGroup;
69
70namespace KTextEditor
71{
72//
73// Kate KTextEditor::View class ;)
74//
75class KTEXTEDITOR_EXPORT ViewPrivate final : public KTextEditor::View
76{
77 Q_OBJECT
78
79 friend class KTextEditor::View;
80 friend class ::KateViewInternal;
81 friend class ::KateIconBorder;
82 friend class ::KateTextPreview;
83 friend MulticursorTest;
84
85public:
86 ViewPrivate(KTextEditor::DocumentPrivate *doc, QWidget *parent, KTextEditor::MainWindow *mainWindow = nullptr);
87 ~ViewPrivate() override;
88
89 /**
90 * Get the view's main window, if any
91 * \return the view's main window
92 */
93 KTextEditor::MainWindow *mainWindow() const override
94 {
95 return m_mainWindow;
96 }
97
98 KTextEditor::Document *document() const override;
99
100 ViewMode viewMode() const override;
101 QString viewModeHuman() const override;
102 InputMode viewInputMode() const override;
103 QString viewInputModeHuman() const override;
104
105 void setViewInputMode(InputMode mode) override
106 {
107 setInputMode(mode);
108 }
109
110 void setInputMode(InputMode mode, const bool rememberInConfig = true);
111
112public:
113 KateViewInternal *getViewInternal()
114 {
115 return m_viewInternal;
116 }
117
118 //
119 // KTextEditor::ClipboardInterface
120 //
121public Q_SLOTS:
122 void paste(const QString *textToPaste = nullptr);
123 void cut();
124 void copy();
125 void screenshot();
126
127private Q_SLOTS:
128 /**
129 * Paste the global mouse selection. Support for Selection is provided only
130 * on systems with a global mouse selection (e.g. X11).
131 */
132 void pasteSelection();
133
134 /**
135 * Insert contents of selected file into the currently open file
136 */
137 void pasteFromFile();
138
139 /**
140 * Copy current selected stuff and paste previous content of clipboard as one operation.
141 */
142 void swapWithClipboard();
143
144 /**
145 * Wrap lines touched by the selection with respect of existing paragraphs.
146 * Work is done by KTextEditor::DocumentPrivate::wrapParagraph
147 */
148 void applyWordWrap();
149
150 /**
151 * Copy the current file name and line number
152 */
153 void copyFileLocation() const;
154
155 //
156 // KTextEditor::PopupMenuInterface
157 //
158public:
159 void setContextMenu(QMenu *menu) override;
160 QMenu *contextMenu() const override;
161 QMenu *defaultContextMenu(QMenu *menu = nullptr) const override;
162
163private Q_SLOTS:
164 void aboutToShowContextMenu();
165 void aboutToHideContextMenu();
166
167private:
168 QPointer<QMenu> m_contextMenu;
169
170 //
171 // KTextEditor::ViewCursorInterface
172 //
173public:
174 bool setCursorPosition(KTextEditor::Cursor position) override;
175
176 KTextEditor::Cursor cursorPosition() const override;
177
178 KTextEditor::Cursor cursorPositionVirtual() const override;
179
180 QPoint cursorToCoordinate(KTextEditor::Cursor cursor) const override;
181
182 KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) const override;
183
184 QPoint cursorPositionCoordinates() const override;
185
186 bool setCursorPositionVisual(const KTextEditor::Cursor position);
187
188 QScrollBar *verticalScrollBar() const override;
189 QScrollBar *horizontalScrollBar() const override;
190
191 /**
192 * Return the virtual cursor column, each tab is expanded into the
193 * document's tabWidth characters. If word wrap is off, the cursor may be
194 * behind the line's length.
195 */
196 int virtualCursorColumn() const;
197
198 bool mouseTrackingEnabled() const override;
199 bool setMouseTrackingEnabled(bool enable) override;
200
201 /*
202 * multicursor stuff
203 */
204
205 // Helper structs to work with multicursors
206 struct PlainSecondaryCursor {
208 KTextEditor::Range range;
209 friend bool operator<(const PlainSecondaryCursor &l, const PlainSecondaryCursor &r)
210 {
211 return l.pos < r.pos;
212 }
213 };
214 struct SecondaryCursor {
215 std::unique_ptr<Kate::TextCursor> pos;
216 std::unique_ptr<Kate::TextRange> range;
218
219 KTextEditor::Cursor cursor() const
220 {
221 return pos->toCursor();
222 }
223
224 friend bool operator<(const SecondaryCursor &l, const SecondaryCursor &r)
225 {
226 return l.cursor() < r.cursor();
227 }
228
229 friend bool operator<(const SecondaryCursor &l, KTextEditor::Cursor r)
230 {
231 return l.cursor() < r;
232 }
233
234 friend bool operator==(const SecondaryCursor &l, const SecondaryCursor &r)
235 {
236 return l.cursor() == r.cursor() && l.selectionRange() == r.selectionRange();
237 }
238
239 KTextEditor::Range selectionRange() const
240 {
241 return range ? range->toRange() : KTextEditor::Range::invalid();
242 }
243
244 void clearSelection()
245 {
246 range.reset();
248 }
249 };
250
251 // Just a helper to control the states in which we disallow multicursor
252 bool isMulticursorNotAllowed() const;
253
254 // Adds a secondary cursor
255 void addSecondaryCursor(KTextEditor::Cursor cursor);
256 void setSecondaryCursors(const QList<KTextEditor::Cursor> &positions);
257
258 const std::vector<SecondaryCursor> &secondaryCursors() const;
259 QList<PlainSecondaryCursor> plainSecondaryCursors() const;
260 void addSecondaryCursorsWithSelection(const QList<PlainSecondaryCursor> &cursorsWithSelection);
261
262 void clearSecondaryCursors();
263 void clearSecondarySelections();
264
265 // Check all the cursors, and remove cursors which have the same positions
266 // if @p matchLine is true, cursors whose line are same will be considered equal
267 void ensureUniqueCursors(bool matchLine = false);
268
269 // For multicursor external api
270 QList<KTextEditor::Cursor> cursors() const;
271 QList<KTextEditor::Range> selectionRanges() const;
272
273 void setCursors(const QList<KTextEditor::Cursor> &cursorPositions);
274 void setSelections(const QList<KTextEditor::Range> &selectionRanges);
275
276 // Returns true if primary or secondary cursors have selection
277 bool hasSelections() const;
278
279private:
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
285 void sortCursors();
286 KTEXTEDITOR_NO_EXPORT
287 void paintCursors();
288
289 std::vector<SecondaryCursor> m_secondaryCursors;
290 bool m_skipCurrentSelection = false;
291
292 void addSecondaryCursorDown();
293 // exported for multicursortest
294 void addSecondaryCursorUp();
295 // exported for multicursortest
296
297private:
298 KTEXTEDITOR_NO_EXPORT
299 void notifyMousePositionChanged(const KTextEditor::Cursor newPosition);
300
301 // Internal
302public:
303 bool setCursorPositionInternal(const KTextEditor::Cursor position, uint tabwidth = 1, bool calledExternally = false);
304
305 //
306 // KTextEditor::ConfigInterface
307 //
308public:
309 QStringList configKeys() const override;
310 QVariant configValue(const QString &key) override;
311 void setConfigValue(const QString &key, const QVariant &value) override;
312
313public:
314 /**
315 * Try to fold an unfolded range starting at @p line
316 * @return the new folded range on success, otherwise an unvalid range
317 */
318 KTextEditor::Range foldLine(int line);
319
320 /**
321 * Try to unfold a folded range starting at @p line
322 * @return true when a range was unfolded, otherwise false
323 */
324 bool unfoldLine(int line);
325
326 /**
327 * Try to toggle the folding state of a range starting at line @p line
328 * @return true when the line was toggled, false when not
329 */
330 bool toggleFoldingOfLine(int line);
331
332 /**
333 * Try to change all the foldings inside a folding range starting at @p line
334 * but not the range itself starting there.
335 * However, should the range itself be folded, will only the range unfolded
336 * and the containing ranges kept untouched.
337 * Should the range not contain other ranges will the range itself folded,
338 * @return true when any range was folded or unfolded, otherwise false
339 */
340 bool toggleFoldingsInRange(int line);
341
342 // Code Completion Interface
343public:
344 bool isCompletionActive() const override;
345 void startCompletion(KTextEditor::Range word, KTextEditor::CodeCompletionModel *model) override;
346 void startCompletion(const Range &word,
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;
357
358Q_SIGNALS:
359 void completionExecuted(KTextEditor::View *view, KTextEditor::Cursor position, KTextEditor::CodeCompletionModel *model, const QModelIndex &);
360 void completionAborted(KTextEditor::View *view);
361
362public Q_SLOTS:
363 void userInvokedCompletion();
364
365public:
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();
370
371 //
372 // KTextEditor::TextHintInterface
373 //
374public:
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;
379
380public:
381 bool dynWordWrap() const
382 {
383 return m_hasWrap;
384 }
385
386 //
387 // Inline Notes Interface
388 //
389public:
390 void registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) override;
391 void unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) override;
392 QRect inlineNoteRect(const KateInlineNoteData &note) const;
393
394 QVarLengthArray<KateInlineNoteData, 8> inlineNotes(int line) const;
395
396private:
397 std::vector<KTextEditor::InlineNoteProvider *> m_inlineNoteProviders;
398
399private Q_SLOTS:
400 void inlineNotesReset();
401 void inlineNotesLineChanged(int line);
402
403 //
404 // KTextEditor::SelectionInterface stuff
405 //
406public Q_SLOTS:
407 bool setSelection(KTextEditor::Range selection) override;
408
409 bool removeSelection() override
410 {
411 return clearSelection();
412 }
413
414 bool removeSelectionText() override
415 {
416 return removeSelectedText();
417 }
418
419 bool setBlockSelection(bool on) override;
420 bool toggleBlockSelection();
421
422 bool clearSelection();
423 bool clearSelection(bool redraw, bool finishedChangingSelection = true);
424
425 bool removeSelectedText();
426
427 bool selectAll();
428
429public:
430 bool selection() const override;
431 QString selectionText() const override;
432 bool blockSelection() const override;
433 KTextEditor::Range selectionRange() const override;
434
435 static void blockFix(KTextEditor::Range &range);
436
437 //
438 // Arbitrary Syntax HL + Action extensions
439 //
440public:
441 // Action association extension
442 void deactivateEditActions();
443 void activateEditActions();
444
445 //
446 // internal helper stuff, for katerenderer and so on
447 //
448public:
449 // should cursor be wrapped ? take config + blockselection state in account
450 bool wrapCursor() const;
451
452 // some internal functions to get selection state of a line/col
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);
458
459 void ensureCursorColumnValid();
460
461 void tagSelection(KTextEditor::Range oldSelection);
462
463 void selectWord(const KTextEditor::Cursor cursor);
464 void selectLine(const KTextEditor::Cursor cursor);
465
466 // BEGIN EDIT STUFF
467public:
468 void editStart();
469 void editEnd(int editTagLineStart, int editTagLineEnd, bool tagFrom);
470
471 void editSetCursor(const KTextEditor::Cursor cursor);
472 // END
473
474 // BEGIN TAG & CLEAR
475public:
476 bool tagLine(const KTextEditor::Cursor virtualCursor);
477
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);
482
483 void tagAll();
484
485 void clear();
486
487 void repaintText(bool paintOnlyDirty = false);
488
489 void updateView(bool changed = false);
490 // END
491
492 //
493 // KTextEditor::AnnotationView
494 //
495public:
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;
504
505Q_SIGNALS:
506 void navigateLeft();
507 void navigateRight();
508 void navigateUp();
509 void navigateDown();
510 void navigateAccept();
511 void navigateBack();
512
513private:
514 KTextEditor::AnnotationModel *m_annotationModel;
515
516 //
517 // KTextEditor::View
518 //
519public:
520 void emitNavigateLeft()
521 {
522 Q_EMIT navigateLeft();
523 }
524 void emitNavigateRight()
525 {
526 Q_EMIT navigateRight();
527 }
528 void emitNavigateUp()
529 {
530 Q_EMIT navigateUp();
531 }
532 void emitNavigateDown()
533 {
534 Q_EMIT navigateDown();
535 }
536 void emitNavigateAccept()
537 {
538 Q_EMIT navigateAccept();
539 }
540 void emitNavigateBack()
541 {
542 Q_EMIT navigateBack();
543 }
544 /**
545 Return values for "save" related commands.
546 */
547 bool isOverwriteMode() const;
548
549 bool isLineRTL(int line) const;
550
551 const QTextLayout *textLayout(const KTextEditor::Cursor pos) const;
552
553public Q_SLOTS:
554 void indent();
555 void unIndent();
556 void cleanIndent();
557 void formatIndent();
558 void align(); // alias of formatIndent, for backward compatibility
559 void alignOn();
560 void comment();
561 void uncomment();
562 void toggleComment();
563 void killLine();
564
565 /**
566 * Sets the cursor to the previous editing position in this document
567 */
568 void goToPreviousEditingPosition();
569
570 /**
571 * Sets the cursor to the next editing position in this document.
572 */
573 void goToNextEditingPosition();
574
575 /**
576 * Uppercases selected text, or an alphabetic character next to the cursor.
577 */
578 void uppercase();
579
580 /**
581 * Lowercases selected text, or an alphabetic character next to the cursor.
582 */
583 void lowercase();
584
585 /**
586 * Capitalizes the selection (makes each word start with an uppercase) or
587 * the word under the cursor.
588 */
589 void capitalize();
590
591 /**
592 * Joins lines touched by the selection.
593 */
594 void joinLines();
595
596 /**
597 * Performs a line break (insert a new line char) at current cursor position
598 * and indent the new line.
599 *
600 * Most work is done by @c KTextEditor::DocumentPrivate::newLine and
601 * @c KateAutoIndent::userTypedChar
602 * @see KTextEditor::DocumentPrivate::newLine, KateAutoIndent
603 */
604 void keyReturn();
605
606 /**
607 * Performs a line break (insert a new line char) at current cursor position
608 * but keep all leading non word char as indent for the new line.
609 */
610 void smartNewline();
611
612 /**
613 * Inserts a new line character at the current cursor position, with
614 * the newly inserted line having no indentation regardless of indentation
615 * settings. Useful e.g. for inserting a new, empty, line to separate
616 * blocks of code inside a function.
617 */
618 void noIndentNewline();
619
620 void newLineAbove();
621
622 void newLineBelow();
623
624 /**
625 * Insert a tabulator char at current cursor position.
626 */
627 void backspace();
628
629 /**
630 * Remove the word left from the current cursor position including all leading
631 * space.
632 * @see KateViewInternal::wordPrev
633 */
634 void deleteWordLeft();
635
636 /**
637 * Remove the current selection. When nothing is selected the char right
638 * from the current cursor position is removed.
639 * @see KTextEditor::DocumentPrivate::del
640 */
641 void keyDelete();
642
643 /**
644 * When the char right from the current cursor position is a space is all
645 * space to the right removed. Otherwise is the word to the right including
646 * all trialling space removed.
647 * @see KateViewInternal::wordNext
648 */
649 void deleteWordRight();
650
651 /**
652 * Transpose the characters left and right from the current cursor position
653 * and move the cursor one position to the right. If the char right to the
654 * current cursor position is a new line char, nothing is done.
655 * @see KTextEditor::DocumentPrivate::transpose
656 */
657 void transpose();
658
659 /**
660 * Transpose the word at the current cursor position with the word to the right (or to the left for RTL layouts).
661 * If the word is the last in the line, try swapping with the previous word instead.
662 * If the word is the only one in the line, no swapping is done.
663 * @see KTextEditor::DocumentPrivate::swapTextRanges
664 */
665 void transposeWord();
666 void cursorLeft();
667 void shiftCursorLeft();
668 void cursorRight();
669 void shiftCursorRight();
670 void wordLeft();
671 void shiftWordLeft();
672 void wordRight();
673 void shiftWordRight();
674 void markSelection();
675 void home();
676 void shiftHome();
677 void end();
678 void shiftEnd();
679 void up();
680 void shiftUp();
681 void down();
682 void shiftDown();
683 void scrollUp();
684 void scrollDown();
685 void topOfView();
686 void shiftTopOfView();
687 void bottomOfView();
688 void shiftBottomOfView();
689 void pageUp();
690 void shiftPageUp();
691 void pageDown();
692 void shiftPageDown();
693 void top();
694 void shiftTop();
695 void bottom();
696 void shiftBottom();
697 void toMatchingBracket();
698 void shiftToMatchingBracket();
699 void toPrevModifiedLine();
700 void toNextModifiedLine();
701 /**
702 * Insert a tabulator char at current cursor position.
703 */
704 void insertTab();
705
706 void gotoLine();
707
708 // config file / session management functions
709public:
710 /**
711 * Read session settings from the given \p config.
712 *
713 * Known flags:
714 * "SkipUrl" => don't save/restore the file
715 * "SkipMode" => don't save/restore the mode
716 * "SkipHighlighting" => don't save/restore the highlighting
717 * "SkipEncoding" => don't save/restore the encoding
718 *
719 * \param config read the session settings from this KConfigGroup
720 * \param flags additional flags
721 * \see writeSessionConfig()
722 */
723 void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
724
725 /**
726 * Write session settings to the \p config.
727 * See readSessionConfig() for more details.
728 *
729 * \param config write the session settings to this KConfigGroup
730 * \param flags additional flags
731 * \see readSessionConfig()
732 */
733 void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
734
735public Q_SLOTS:
736 void setEol(int eol);
737 void setAddBom(bool enabled);
738 void find();
739 void findSelectedForwards();
740 void findSelectedBackwards();
741 void findNextOccurunceAndSelect();
742 void findAllOccuruncesAndSelect();
743 void skipCurrentOccurunceSelection();
744 void replace();
745 void findNext();
746 void findPrevious();
747 void showSearchWrappedHint(bool isReverseSearch);
748 void createMultiCursorsFromSelection();
749 void removeCursorsFromEmptyLines();
750
751 void setFoldingMarkersOn(bool enable); // Not in KTextEditor::View, but should be
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);
767
768public:
769 int getEol() const;
770 QMenu *getEolMenu();
771
772public:
773 KateRenderer *renderer();
774 KateRendererConfig *rendererConfig();
775
776 bool iconBorder();
777 bool lineNumbersOn();
778 bool scrollBarMarks();
779 bool scrollBarMiniMap();
780 bool scrollBarMiniMapAll();
781 int dynWrapIndicators();
782 bool foldingMarkersOn();
783 bool forceRTLDirection() const;
784
785private Q_SLOTS:
786 /**
787 * used to update actions after selection changed
788 */
789 void slotSelectionChanged();
790
791 void toggleInputMode();
792 void cycleInputMode();
793
794public:
795 /**
796 * accessor to katedocument pointer
797 * @return pointer to document
798 */
800 {
801 return m_doc;
802 }
803 const KTextEditor::DocumentPrivate *doc() const
804 {
805 return m_doc;
806 }
807
808public Q_SLOTS:
809 void slotUpdateUndo();
810 void toggleInsert();
811 void reloadFile();
812 void toggleWWMarker();
813 void toggleNPSpaces();
814 void toggleWordCount(bool on);
815 void toggleWriteLock();
816 void switchToCmdLine();
817 void slotReadWriteChanged();
818 void toggleCamelCaseCursor();
819
820Q_SIGNALS:
821 void dropEventPass(QDropEvent *);
822
823public:
824 /**
825 * Folding handler for this view.
826 * @return folding handler
827 */
828 Kate::TextFolding &textFolding()
829 {
830 return m_textFolding;
831 }
832
833public:
834 void slotTextInserted(KTextEditor::View *view, const KTextEditor::Cursor position, const QString &text);
835
836 void exportHtmlToFile(const QString &file);
837
838private Q_SLOTS:
839 void slotDocumentReloaded();
840 void slotDocumentAboutToReload();
841 void slotGotFocus();
842 void slotLostFocus();
843 void slotSaveCanceled(const QString &error);
844 void slotConfigDialog();
845 void exportHtmlToClipboard();
846 void exportHtmlToFile();
847
848public Q_SLOTS:
849 void slotFoldToplevelNodes();
850 void slotExpandToplevelNodes();
851 void slotToggleFolding();
852 void slotToggleFoldingsInRange();
853
854private:
855 KTEXTEDITOR_NO_EXPORT
856 void setupLayout();
857 KTEXTEDITOR_NO_EXPORT
858 void setupConnections();
859 KTEXTEDITOR_NO_EXPORT
860 void setupActions();
861 KTEXTEDITOR_NO_EXPORT
862 void setupEditActions();
863 KTEXTEDITOR_NO_EXPORT
864 void setupCodeFolding();
865 KTEXTEDITOR_NO_EXPORT
866 void setupSpeechActions();
867
868 std::vector<QAction *> m_editActions;
869 QAction *m_editUndo;
870 QAction *m_editRedo;
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;
887
888 KSelectAction *m_setEndOfLine;
889 KToggleAction *m_addBom;
890
891 QAction *m_cut;
892 QAction *m_copy;
893 QAction *m_copyHtmlAction;
894 QAction *m_paste;
895 QAction *m_clipboardHistory;
896 // always nullptr if paste selection isn't supported
897 QAction *m_pasteSelection = nullptr;
898 QAction *m_swapWithClipboard;
899 QAction *m_selectAll;
900 QAction *m_deSelect;
901 QAction *m_screenshotSelection = nullptr;
902
903 QActionGroup *m_inputModeActions;
904
905 KToggleAction *m_toggleBlockSelection;
906 KToggleAction *m_toggleInsert;
907 KToggleAction *m_toggleWriteLock;
908 KToggleAction *m_forceRTLDirection;
909
910 bool m_hasWrap;
911 bool m_forceRTL = false;
912 bool m_accessibilityEnabled = false;
913
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;
921
922 //* margins
923 QSpacerItem *m_topSpacer;
924 QSpacerItem *m_leftSpacer;
925 QSpacerItem *m_rightSpacer;
926 QSpacerItem *m_bottomSpacer;
927
928private Q_SLOTS:
929 void slotHlChanged();
930
931 /**
932 * Configuration
933 */
934public:
935 inline KateViewConfig *config()
936 {
937 return m_config;
938 }
939
940 void updateConfig();
941
942 void updateDocumentConfig();
943
944 void updateRendererConfig();
945
946private Q_SLOTS:
947 void updateFoldingConfig();
948
949private:
950 bool m_startingUp;
951 bool m_updatingDocumentConfig;
952
953 // stores the current selection
954 Kate::TextRange m_selection;
955
956 // do we select normal or blockwise ?
957 bool blockSelect;
958
959 // templates
960public:
961 bool insertTemplateInternal(const KTextEditor::Cursor insertPosition, const QString &templateString, const QString &script = QString());
962
963 /**
964 * Accessors to the bars...
965 */
966public:
967 KateViewBar *bottomViewBar() const;
968 KateDictionaryBar *dictionaryBar();
969
970private:
971 KTEXTEDITOR_NO_EXPORT
972 KateGotoBar *gotoBar();
973
974 /**
975 * viewbar + its widgets
976 * they are created on demand...
977 */
978private:
979 // created in constructor of the view
980 KateViewBar *m_bottomViewBar;
981
982 // created on demand..., only access them through the above accessors....
983 KateGotoBar *m_gotoBar;
984 KateDictionaryBar *m_dictionaryBar;
985
986 // input modes
987public:
988 KateAbstractInputMode *currentInputMode() const;
989
990public:
991 KTextEditor::Range visibleRange();
992
993protected:
994 bool event(QEvent *e) override;
995
996 KToggleAction *m_toggleOnTheFlySpellCheck;
997 KateSpellingMenu *m_spellingMenu;
998
999protected Q_SLOTS:
1000 void toggleOnTheFlySpellCheck(bool b);
1001
1002public Q_SLOTS:
1003 void changeDictionary();
1004 void reflectOnTheFlySpellCheckStatus(bool enabled);
1005
1006public:
1007 KateSpellingMenu *spellingMenu();
1008
1009private:
1010 bool m_userContextMenuSet;
1011
1012private Q_SLOTS:
1013 /**
1014 * save folding state before document reload
1015 */
1016 void saveFoldingState();
1017
1018 /**
1019 * restore folding state after document reload
1020 */
1021 void applyFoldingState();
1022
1023public:
1024 /**
1025 * Clear any saved folding state
1026 */
1027 void clearFoldingState();
1028
1029private:
1030 KTEXTEDITOR_NO_EXPORT
1031 void clearHighlights();
1032 KTEXTEDITOR_NO_EXPORT
1033 void createHighlights();
1034
1035private:
1036 KTEXTEDITOR_NO_EXPORT
1037 void selectionChangedForHighlights();
1038
1039 /**
1040 * saved folding state
1041 */
1042 QJsonDocument m_savedFoldingState;
1043
1044 QString m_currentTextForHighlights;
1045
1046 std::vector<std::unique_ptr<KTextEditor::MovingRange>> m_rangesForHighlights;
1047
1048public:
1049 /**
1050 * Attribute of a range changed or range with attribute changed in given line range.
1051 * @param lineRange line range that the change spans
1052 * @param needsRepaint do we need to trigger repaints? e.g. if ranges with attributes change
1053 */
1054 void notifyAboutRangeChange(KTextEditor::LineRange lineRange, bool needsRepaint, Kate::TextRange *deleteRange);
1055
1056private Q_SLOTS:
1057 /**
1058 * Delayed update for view after text ranges changed
1059 */
1060 void slotDelayedUpdateOfView();
1061
1062Q_SIGNALS:
1063 /**
1064 * Delayed update for view after text ranges changed
1065 */
1066 void delayedUpdateOfView();
1067
1068 /**
1069 * Emitted whenever the caret enter or leave a range.
1070 * ATM only used by KateStatusBar to update the dict button
1071 */
1072 void caretChangedRange(KTextEditor::View *);
1073
1074public:
1075 /**
1076 * set of ranges which had the mouse inside last time, used for rendering
1077 * @return set of ranges which had the mouse inside last time checked
1078 */
1079 const QSet<Kate::TextRange *> *rangesMouseIn() const
1080 {
1081 return &m_rangesMouseIn;
1082 }
1083
1084 /**
1085 * set of ranges which had the caret inside last time, used for rendering
1086 * @return set of ranges which had the caret inside last time checked
1087 */
1088 const QSet<Kate::TextRange *> *rangesCaretIn() const
1089 {
1090 return &m_rangesCaretIn;
1091 }
1092
1093 /**
1094 * check if ranges changed for mouse in and caret in
1095 * @param activationType type of activation to check
1096 */
1097 void updateRangesIn(KTextEditor::Attribute::ActivationType activationType);
1098
1099 //
1100 // helpers for delayed view update after ranges changes
1101 //
1102private:
1103 /**
1104 * delayed update timer
1105 */
1106 QTimer m_delayedUpdateTimer;
1107
1108 /**
1109 * line range to update
1110 */
1111 KTextEditor::LineRange m_lineToUpdateRange;
1112
1113 /**
1114 * set of ranges which had the mouse inside last time
1115 */
1116 QSet<Kate::TextRange *> m_rangesMouseIn;
1117
1118 /**
1119 * set of ranges which had the caret inside last time
1120 */
1121 QSet<Kate::TextRange *> m_rangesCaretIn;
1122
1123 //
1124 // forward impl for KTextEditor::MessageInterface
1125 //
1126public:
1127 /**
1128 * Used by Document::postMessage().
1129 */
1130 void postMessage(KTextEditor::Message *message, QList<std::shared_ptr<QAction>> actions);
1131
1132private:
1133 /**
1134 * Message widgets showing KTextEditor::Messages.
1135 * The index of the array maps to the enum KTextEditor::Message::MessagePosition.
1136 */
1137 std::array<KateMessageWidget *, 5> m_messageWidgets{{nullptr}};
1138 /** Layout for floating notifications */
1139 KateMessageLayout *m_notificationLayout = nullptr;
1140
1141 // for unit test 'tests/messagetest.cpp'
1142public:
1143 KateMessageWidget *messageWidget();
1144
1145private:
1146 /**
1147 * The main window responsible for this view, if any
1148 */
1150
1151 //
1152 // KTextEditor::PrintInterface
1153 //
1154public Q_SLOTS:
1155 bool print() override;
1156 void printPreview() override;
1157
1158public:
1159 /**
1160 * Get the view status bar
1161 * @return status bar, in enabled
1162 */
1163 KateStatusBar *statusBar() const
1164 {
1165 return m_statusBar;
1166 }
1167
1168 /**
1169 * Toogle status bar, e.g. create or remove it
1170 */
1171 void toggleStatusBar();
1172
1173 /**
1174 * Get the encoding menu
1175 * @return the encoding menu
1176 */
1177 KateViewEncodingAction *encodingAction() const
1178 {
1179 return m_encodingAction;
1180 }
1181
1182 /**
1183 * Get the mode menu
1184 * @return the mode menu
1185 */
1186 KateModeMenu *modeAction() const
1187 {
1188 return m_modeAction;
1189 }
1190
1191private:
1192 /**
1193 * the status bar of this view
1194 */
1195 KateStatusBar *m_statusBar;
1196
1197 /**
1198 * the encoding selection menu, used by view + status bar
1199 */
1200 KateViewEncodingAction *m_encodingAction;
1201
1202 /**
1203 * the mode selection menu, used by view
1204 */
1205 KateModeMenu *m_modeAction;
1206
1207 /**
1208 * is automatic invocation of completion disabled temporarily?
1209 */
1210 bool m_temporaryAutomaticInvocationDisabled;
1211
1212public:
1213 /**
1214 * Returns the attribute for the default style \p defaultStyle.
1215 */
1216 Attribute::Ptr defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle defaultStyle) const override;
1217
1218 /**
1219 * Get the list of AttributeBlocks for a given \p line in the document.
1220 *
1221 * \return list of AttributeBlocks for given \p line.
1222 */
1223 QList<KTextEditor::AttributeBlock> lineAttributes(int line) override;
1224
1225private:
1226 // remember folding state to prevent refolding the first line if it was manually unfolded,
1227 // e.g. when saving a file or changing other config vars
1228 bool m_autoFoldedFirstLine;
1229
1230public:
1231 void setScrollPositionInternal(KTextEditor::Cursor cursor);
1232
1233 void setHorizontalScrollPositionInternal(int x);
1234
1235 KTextEditor::Cursor maxScrollPositionInternal() const;
1236
1237 int firstDisplayedLineInternal(LineType lineType) const;
1238
1239 int lastDisplayedLineInternal(LineType lineType) const;
1240
1241 QRect textAreaRectInternal() const;
1242
1243private:
1244 /**
1245 * script action menu, stored in scoped pointer to ensure
1246 * destruction before other QObject auto-cleanup as it
1247 * manage sub objects on its own that have this view as parent
1248 */
1249 std::unique_ptr<KateScriptActionMenu> m_scriptActionMenu;
1250
1251 // for showSearchWrappedHint()
1252 QPointer<KTextEditor::Message> m_wrappedMessage;
1253 bool m_isLastSearchReversed = false;
1254};
1255
1256}
1257
1258#endif
A delegate for rendering line annotation information and handling events.
An model for providing line annotation information.
ActivationType
Several automatic activation mechanisms exist for associated attributes.
Definition attribute.h:244
An item model for providing code completion, and meta information for enhanced presentation.
The Cursor represents a position in a Document.
Definition cursor.h:75
static constexpr Cursor invalid() noexcept
Returns an invalid cursor.
Definition cursor.h:112
Backend of KTextEditor::Document related public KTextEditor interfaces.
A KParts derived class representing a text document.
Definition document.h:284
A source of inline notes for a document.
An object representing lines from a start line to an end line.
Definition linerange.h:41
This class allows the application that embeds the KTextEditor component to allow it to access parts o...
Definition mainwindow.h:47
This class holds a Message to display in Views.
Definition message.h:94
An object representing a section of text, from one Cursor to another.
static constexpr Range invalid() noexcept
Returns an invalid range.
Class to provide text hints for a View.
A text widget with KXMLGUIClient that represents a Document.
Definition view.h:244
This is the code completion's main widget, and also contains the core interface logic.
Internal data container for KTextEditor::InlineNote interface.
Class to layout KTextEditor::Messages in KateView.
This class implements a message widget based on KMessageWidget.
Handles all of the work of rendering the text (used for the views and printing)
Tools > Scripts menu This menu is filled with the command line scripts exported via the scripting sup...
Class representing the folding information for a TextBuffer.
Class representing a 'clever' text range.
Q_SCRIPTABLE Q_NOREPLY void start()
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
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)
QAction * find(const QObject *recvr, const char *slot, QObject *parent)
QAction * clear(const QObject *recvr, const char *slot, QObject *parent)
QAction * print(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)
bool operator==(const StyleDelim &l, const StyleDelim &r)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 3 2025 12:00:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.