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

KDE's Doxygen guidelines are available online.