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

KDE's Doxygen guidelines are available online.